Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MJS wrappers of ./cjs/subdir/*.js are incorrectly created at ./cjs/*-wrapper.mjs #253

Open
BinToss opened this issue May 19, 2024 · 3 comments

Comments

@BinToss
Copy link

BinToss commented May 19, 2024

The wrappers then try and fail to import their CJS module from './*.cjs'
The path of the wrappers depend on their CJS module's InputMap key.

Additionally...
The pattern for an InputMap key prohibits '/' characters.
image

Removing the '/' characters from the keys causes the "-wrapper.m,js" files to be created at ./cjs/*-wrapper.mjs instead of alongside the CJS files at ./cjs/dotnet/*.cjs
This doesn't work. The wrappers' import statements treat the CJS modules as if they're in the same directory and will fail to load them.
image

@BinToss
Copy link
Author

BinToss commented May 22, 2024

I tried a quick and easy fix. It didn't work.

Instead of changing the pattern for the InputMap keys, the path of an MJS wrapper should not be affected by the Input Map key at all and should be created alongside the CJS output.


.keysOf(string().match(/^[a-zA-Z0-9-_]+$/u)),

.keysOf(string().match(/^[/a-zA-Z0-9-_]+$/u)),
                          ^

This change causes the wrapper files to be created in the correct directory, but their import will now add the directories in the InputMap key to the import path, thereby breaking the import path again.

Before this change:

// ./cjs/dotnetHelpers-wrapper.mjs
// Bundled with Packemon: https://packemon.dev
// This is an MJS wrapper for a sibling CJS file

// should be './dotnet/dotnetHelpers.cjs'
import data from './dotnetHelpers.cjs';

export const { configureDotnetNugetPush, configurePrepareCmd, nugetDefault } = data;

After this change and InputMap key prefixed with dotnet/:

// ./cjs/dotnet/dotnetHelpers-wrapper.mjs
// Bundled with Packemon: https://packemon.dev
// This is an MJS wrapper for a sibling CJS file

// should be './dotnetHelpers.cjs'
import data from './dotnet/dotnetHelpers.cjs';

export const { configureDotnetNugetPush, configurePrepareCmd, nugetDefault } = data;

@milesj
Copy link
Owner

milesj commented May 22, 2024

Whats your packemon config look like?

@BinToss
Copy link
Author

BinToss commented Oct 8, 2024

Whats your packemon config look like?

Just saw this...five months later.

This is the the configuration for my CJS releases.
https://github.com/HaloSPV3/HCE.Shared/blob/ee2836923772f46440894da7f5b7be5376d1cbaf/packemon.config.ts
https://github.com/HaloSPV3/HCE.Shared/blob/ee2836923772f46440894da7f5b7be5376d1cbaf/package.json#L131-L147

And the configs for my w.i.p. MJS branches which do not have this issue.
https://github.com/HaloSPV3/HCE.Shared/blob/next/v3.0.0/packemon.config.ts
https://github.com/HaloSPV3/HCE.Shared/blob/048a22b4e9c2c49f0e4b71bb900a2ac175b810d8/package.json#L122


I decided to stop targeting CJS for multiple reasons. One reason was this issue, but another was because Semantic Release had finally fully migrated to MJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants