Ship a luxon-bundled build alongside the external one - #23
Merged
Conversation
The published package left luxon as an external import, so dist/index.js
shipped a bare `import{DateTime}from"luxon"` specifier for the consumer to
resolve. This contradicted the README, which already claimed luxon was
bundled.
bike_index uses importmap-rails with no bundler, so that bare specifier
meant a second CDN pin and two chained cross-origin round trips (3.3 KB,
then 254 KB of unminified luxon) gating every Stimulus controller on every
page, since both are static imports.
- Drop --external:luxon from the esbuild build; dist/index.js is now
self-contained at 72.4 KB minified.
- Delete peerDependencies — luxon stays in devDependencies, which is all
esbuild needs at build time.
- Bump to 0.4.0.
main, exports and files still point at dist/index.js, and index.js is
unchanged, so the public API and pinned artifact path are stable.
Co-Authored-By: Claude <noreply@anthropic.com>
Bundling luxon unconditionally would have regressed consumers that use luxon directly: two copies means two module-scoped Settings objects, so their Settings.defaultLocale / defaultZone / now would silently stop applying to time-localizer's output. Verified with luxon 3.7.2 — Settings.defaultLocale = 'fr' rendered "2 nov." from the consumer's copy but "Nov 2" from the bundled one, with no error. Ship both builds of the same source instead: - dist/index.js keeps luxon external (peerDependency restored), so bundler consumers keep one deduped copy and their Settings apply. - dist/index.bundle.js inlines luxon for consumers with no bundler, reachable as @bikeindex/time-localizer/bundle or by file path. - README documents which build to use and warns against pairing the bundled one with your own luxon. Both are outputs of one source file, rebuilt together by prepublishOnly. Co-Authored-By: Claude <noreply@anthropic.com>
The lockfile was regenerated when peerDependencies was briefly removed and not refreshed when it came back, so it no longer matched package.json. Co-Authored-By: Claude <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.
@bikeindex/time-localizershipped a single build with luxon left external. That's right for consumers with a bundler, but bike_index uses importmap-rails with no bundler, where the bareimport{DateTime}from"luxon"specifier means a second CDN pin and two chained cross-origin round trips (3.3 KB, then 254 KB of unminified luxon) gating every Stimulus controller on every page, since both are static imports.Adds a second artifact rather than changing the existing one:
dist/index.js— unchanged. Luxon stays external and apeerDependency, so consumers that use luxon directly keep a single deduped copy.dist/index.bundle.js— new. Luxon inlined, 72.4 KB minified / 23 KB gzipped: one request, nothing to resolve. Available as@bikeindex/time-localizer/bundleor by file path over a CDN.The default build stays external because two copies of luxon means two module-scoped
Settingsobjects. WithSettings.defaultLocale = 'fr', a consumer's own luxon renders2 nov.while a bundled copy rendersNov 2;Settings.now— how you freeze time in tests — stops applying the same way. Neither case errors, so the standalone build is opt-in and the README warns against pairing it with your own luxon.Both artifacts build from one source file via
prepublishOnly, andindex.jsis untouched, so the public API is unchanged. Version goes to 0.4.0; publishing is still the separate manualnpm publishstep.