Repository navigation
W2: package entry points work in CommonJS, ESM and bundlers - #6
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
W2: package entry points
What. No
exportsmap, so Node ESM loaded the CommonJS builddist/index.jsforimport:import Datalyr from '@datalyr/api'gave the whole module object andnew Datalyr()threwDatalyr is not a constructor.dist/index.mjsanddist/index.d.mtswere built and shipped but Node never used them.Change (package.json only):
exports:.→import{typesdist/index.d.mts,defaultdist/index.mjs},require{typesdist/index.d.ts,defaultdist/index.js}; plus./package.jsonand./dist/*so existing deep imports (@datalyr/api/dist/index.js) keep resolving.main,moduleandtypesunchanged (older tools and TypeScriptnode10resolution still use them).Test. Proof projects below (built tarball installed into real projects). No unit test: nothing in
src/changed.Proof: built tarball vs published 1.3.4
npm ci && npm run build && npm packon this branch, thennpm install <tarball>into throwaway projects (typescript 5.9.3, @types/node 20.19.9, Node 26.5.0). "Before" isnpm install @datalyr/api@1.3.4.new (require('@datalyr/api').default)(…)andnew (require(…).Datalyr)(…)import Datalyr from→new Datalyr()Datalyr is not a constructorimport { Datalyr } from→new Datalyr()moduleResolution: node16, ESM projecttsc --noEmitonnew Datalyr()(default) andnew Named()(named)This expression is not constructablemoduleResolution: bundlerTarball contents
npm pack --dry-runfile list before (origin/main package.json) and after: 7 files each, identical paths and sizes; the only difference ispackage.json(1061 → 1372 bytes).Changes to what the SDK sends
None. Entry points only.
Not done
Nothing.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.