Repository navigation
W2: package entry points work in CommonJS, ESM and bundlers - #29
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
package.jsonmainpointed at the browser script builddist/datalyr.js(an IIFE that assigns a localvar Datalyr), sorequire('@datalyr/web')returned{}. The CommonJS builddist/datalyr.cjs.jswas built but nothing pointed at it, and there was noexportsmap.Change (package.json only, no build or source change):
main→dist/datalyr.cjs.js;moduleandtypesunchanged.unpkgandjsdelivr→dist/datalyr.js, so a bare CDN URL for the npm package (cdn.jsdelivr.net/npm/@datalyr/web,unpkg.com/@datalyr/web) still serves the browser script it served before (both CDNs fell back tomain).exports:.→typesdist/index.d.ts,importdist/datalyr.esm.js,requiredist/datalyr.cjs.js,defaultdist/datalyr.esm.js; plus./package.jsonand./dist/*, so deep imports such as@datalyr/web/dist/datalyr.js,datalyr.replay.min.jsanddatalyr.pixels.min.jsstill resolve (checked withrequire.resolveandimport.meta.resolve).The main repo's
infra/trackingbuild readsdist/datalyr.jsandpackage.jsonby file path, not through package resolution, so it is unaffected.Test. Proof projects below (built tarball installed into real projects). No unit test: nothing in
src/changed.Proof: built tarball vs published 1.9.14
npm ci && npm run clean && npm run build && npm packon this branch, thennpm install <tarball>into throwaway projects (typescript 5.9.3, vite 6.3.5, Node 26.5.0). "Before" isnpm install @datalyr/web@1.9.14.require('@datalyr/web').default.initand.datalyr.initare functions{}(no keys)import datalyr from/import { datalyr } from,typeof init === 'function'initundefined on both (IIFE loaded as CJS)moduleResolution: node16, ESM project ("type": "module")tsc --noEmitonimport datalyr, { datalyr as named }+.initProperty 'init' does not existon the default importmoduleResolution: node16, CommonJS projectmoduleResolution: bundlerimport datalyr from '@datalyr/web'bundlesmodule)exportsimport)Tarball contents
npm pack --dry-runfile list before (origin/main package.json) and after: 157 files each, identical paths and sizes; the only difference ispackage.json(1798 → 2130 bytes).File list (after)
Changes to what the SDK sends
None. Entry points only; every build is from the same source and no built file changed.
Not done
node16/nodenextin an ESM project, default import.dist/index.d.tssits in a package with no"type", so TypeScript reads it as CommonJS types and the default import is typed as the whole module (datalyr.default.init). Named importimport { datalyr } from '@datalyr/web'is typed correctly. Fixing the default import needs an ESM declaration file (index.d.mts) or a.mjsESM build, which is a build change and outside this item (owner rule: keep the built files exactly as they are). Bundler resolution (Vite, Next.js, webpack) is unaffected.dist/datalyr.esm.jsis a.jsfile in a package without"type": "module"; Node loads it as ESM through module syntax detection (Node 20.19+ / 22.12+). On older Node, a nativeimportof the package fails with a syntax error. Before this PR it never worked on any Node version (gave{}). A.mjsbuild would remove this limit; same build-change reason as above.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.