-
Notifications
You must be signed in to change notification settings - Fork 15
[CDX-398] Backwards Compatibility Fix for CJS users #480
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,17 @@ | |||||||||||||
| "version": "2.90.0", | ||||||||||||||
| "description": "Constructor.io JavaScript client", | ||||||||||||||
| "main": "lib/constructorio.js", | ||||||||||||||
| "module": "lib/esm/constructorio.js", | ||||||||||||||
| "types": "lib/types/index.d.ts", | ||||||||||||||
| "exports": { | ||||||||||||||
|
Mudaafi marked this conversation as resolved.
|
||||||||||||||
| ".": { | ||||||||||||||
| "types": "./lib/types/index.d.ts", | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, adding something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered that actually. I discarded it though, but I'll need to dig up the reason |
||||||||||||||
| "import": "./lib/esm/constructorio.mjs", | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: The The safest fix is to provide a separate types condition per entry-point kind: "." : {
"import": {
"types": "./lib/types/index.d.mts",
"default": "./lib/esm/constructorio.mjs"
},
"require": {
"types": "./lib/types/index.d.ts",
"default": "./lib/constructorio.js"
}
}Where
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting. I would've thought that Node environments would use the Node SDK, but no harm keeping it consistent post-change unless it requires something weird. Good catch |
||||||||||||||
| "require": "./lib/constructorio.js", | ||||||||||||||
| "default": "./lib/constructorio.js" | ||||||||||||||
| }, | ||||||||||||||
| "./lib/*": "./lib/*", | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: This catch-all pattern restores access to deep paths like This is worth either:
At minimum, a code comment would help future maintainers understand why the wildcard is there and what it does/does not support.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You already listed this as limitation number 1, but I think we can just fix it
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh. we'll have to consider other extensions as well like |
||||||||||||||
| "./package.json": "./package.json" | ||||||||||||||
| }, | ||||||||||||||
| "scripts": { | ||||||||||||||
| "clean": "sudo rm -rf node_modules package-lock.json", | ||||||||||||||
| "version": "node ./src/generateVersion.js && npm run docs && git add ./docs/* && npm run bundle && git add -A ./dist && git add ./src/version.js", | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,7 @@ require('esbuild').build({ | |
| define: { | ||
| global: 'window', | ||
| }, | ||
| outfile: './lib/esm/constructorio.js', | ||
| // .mjs so Node classifies this as ESM without `"type": "module"`, which would | ||
| // reclassify every .js in the package and break CJS consumers. | ||
| outfile: './lib/esm/constructorio.mjs', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The comment above this line is clear and well-written. One small addition would be to also note that any consumers who previously referenced |
||
| }).catch(() => process.exit(1)); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modern bundlers ignore the module when exports match, so keeping it changes nothing for them. It only helps old tooling, which just reads the fields and now falls back to CJS
Can we just put it back as
"module": "lib/esm/constructorio.mjs"?Then limitation #3 is gone then