Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion scripts/build-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ require('esbuild').build({
define: {
global: 'window',
},
external: ['@constructor-io/constructorio-id', 'crc-32'],
outfile: './lib/esm/constructorio.js',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important Issue: Removing the external option causes @constructor-io/constructorio-id and crc-32 to be bundled directly into lib/esm/constructorio.js, which is the "module" entry point consumed by downstream bundlers (webpack, rollup, vite, etc.).

This has two concrete risks:

  1. Duplicate code / broken singleton semantics: If a consumer (or another package) also depends on @constructor-io/constructorio-id, their bundler will now include two separate copies — one inside this bundle, one resolved normally. This is particularly problematic for @constructor-io/constructorio-id, which likely maintains internal singleton state (session/visitor IDs). Two copies means two independent instances, which can corrupt ID tracking.

  2. Bundle size increase: Both packages are dependencies in package.json, so consumers already receive them. Bundling them into lib/esm/ means consuming applications carry the bytes twice.

The dist/esm/ build (bundle-esm.js) is the appropriate place to bundle everything, as it targets standalone/CDN usage where the consumer has no package manager. The lib/esm/ build targets module-aware bundlers that should resolve dependencies themselves.

Recommended fix: Restore the external array, or if intentional, document the reasoning clearly and consider whether these packages should be moved to peerDependencies to signal that the consumer must provide them (which would be inconsistent with the current approach). At minimum, add a comment explaining why bundling into lib/esm/ is desired here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The PR has no description, which makes it hard to understand the intent. The title says "Bundle required packages" but there's no explanation of what problem this solves (e.g., were consumers seeing missing-module errors? Was constructorio-id not being resolved correctly in some environments?).

Please add a PR description explaining:

  • What problem was observed
  • Why bundling into lib/esm/ (rather than only dist/esm/) solves it
  • Any tradeoffs acknowledged (duplicate instances, bundle size)

This context is important for future maintainers who encounter issues tracing back to this change.

}).catch(() => process.exit(1));
Loading