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

Expand info on module condition and dual package hazard #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link

No description provided.

@@ -3665,17 +3665,17 @@ body:

- p: >
The following condition is also automatically included when the [platform](#platform)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that especially the change to mention neutral platform here is especially important because otherwise this could be misread by other implementers.

@@ -3705,6 +3705,13 @@ body:
that can work with node because node deliberately doesn't implement loading
ESM using `require`.

- p: >
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have also found out that to improve code portability between bundlers etc we are forced to structure things like this when the default export is involved:

// dist/pkg.mjs
export * from "./pkg.cjs.js";
export { _default as default } from "./pkg.cjs.default.js";

// dist/pkg.cjs.default.js
exports._default = require('./pkg.cjs.js').default

// dist/pkg.cjs.js
/*
  transpiled CJS content of the package with all named exports and named default
  don't try to avoid `.default` here
*/

The same problem spills into TS declarations:

// dist/pkg.d.mts
export * from "./index.js"; // yes, we are in the declaration file but we are using .js extension here
export { _default as default } from "./pkg.cjs.default.js";

// dist/pkg.cjs.default.d.ts
export { default as _default } from "./index.js"

// dist/index.d.ts
/*
  actual type declarations produced by TS
*/

I'm not sure if you want to include any of this in your docs though. It gets a little bit crazy and I wish that we wouldn't have to do those steps but here we are.

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

Successfully merging this pull request may close these issues.

1 participant