Repository navigation
build: leave ./unstable's libraries to the consumer's bundler - #1760
Merged
Merged
Conversation
Pro bundles ./unstable and imports Turf, polyclip-ts and lodash itself, so it shipped each twice. The entry now imports them by package name (a subpath of a package without an exports map by its file, as Node's ESM resolution needs), and the build fails on a package outside dependencies or on bundled library code. The e2e fixture loads a bundle of it, as Pro does.
… warnings in the load test
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.
./unstablenow leaves its libraries to the consumer's bundler instead of bundling them. Leaflet-Geoman Pro bundles this entry and also imports the same libraries itself, so until now it shipped Turf, polyclip-ts and lodash twice (class SweepEventappeared twice in Pro's min.js)../unstablebuild inbundle.mtsgets anexternal-packagesesbuild plugin:lodash/getbecomeslodash/get.js. With a plainpackages: 'external', Node fails withCannot find module '.../node_modules/lodash/get'.dependenciesorpeerDependencies.node_modulesis bundled into the entry, even through a relative path; the plugin checks the metafile for this.leaflet-geoman-unstable.js: 553,787 → 339,688 bytes. Its bare imports are@turf/boolean-contains,@turf/kinks,@turf/line-intersect,@turf/line-split,lodash/get.js,polyclip-tsandleaflet, all independenciesorpeerDependencies.distanddist/typesis byte-identical to the afefa35 build: 60 of 62 files. Onlyleaflet-geoman-unstable.jsand its.mapdiffer.cypress/fixtures/unstable.htmlloaded the raw entry in the browser, which can't resolve package imports. The build now also bundles the built entry intocypress/fixtures/unstable-bundle.js(git-ignored), the way @geoman-io packages use it, and the fixture loads that. ItsNODE_ENVdefine keeps the old browser behaviour:isDevelopment()was already true there.src/js/unstable.tsandbundle.mts, and the CHANGELOG line for./unstable, say the libraries are left to the consumer's bundler and why.Tests: new
test/unstable-entry.test.ts(unit, on the builtdist, whichpnpm install'spreparebuilds in CI):node_modulessource in the entry's source map;dependenciesorpeerDependencies(read with esbuild's metafile);nodeprocess, withPMandEditLineexported.Before the fix:
packages: 'external'build (339,679 bytes) fails the third withERR_MODULE_NOT_FOUND ... lodash/get.import 'tsx'fails the build with "'tsx' is from 'tsx', which is not in dependencies or peerDependencies";import '../../node_modules/lodash/get.js'fails it with "./unstable bundles node_modules/.pnpm/lodash@4.18.1/node_modules/lodash/isArray.js".Packed tarball, clean consumer with only the tarball and
leaflet@2.0.0-beta.4(npm, 29 packages):import('@geoman-io/leaflet-geoman-free/unstable')loads (31 exports), and the main entry loads as before../unstableapp: toolbar,unstable_insertVertex(lodash),hasSelfIntersection(kinks), a polygon cut (polyclip-ts) and a line cut (line-split, line-intersect) all return results../unstable,polyclip-tsand@turf/kinksbundles to 545,315 bytes with one SweepEvent class and onekinks. Against the afefa35 entry it is 641,092 bytes, with two of each.Checks: build, typecheck, lint, unit 106/106 (+3). Full e2e (Electron): base 486/486 (afefa35), PR 486/486.
Independent review (Opus 5.5) at 989c338: no blocking findings and two Low notes, both fixed in the next commit. A dependency that resolves outside node_modules (a
link:orfile:one) now fails the build with a clear error instead of an ENOENT. The Node load test no longer fails on a Node warning in stderr, only on an Error. The dist hashes are unchanged.Hashes of the afefa35 build and this PR (sha256,
dist):60 of 62 identical
leaflet-geoman-global.js9f085e754b880392leaflet-geoman-global.js.map12f75e22c0cd349aleaflet-geoman-global.min.jsea8d00c6633ffbdeleaflet-geoman-global.min.js.mapf8cd6042fc571b3dleaflet-geoman-unstable.js906002b8ecf97932e95c86274f6237aeleaflet-geoman-unstable.js.mapaaeda7bef5f17a57b20d016e868011caleaflet-geoman.css8d9f79b153a51c61leaflet-geoman.css.mapdc257a732fba5d1eleaflet-geoman.d.ts1304086d87db9e39leaflet-geoman.js824aa5625df8bda7leaflet-geoman.js.map916e494d0264ad48leaflet-geoman.min.js71eed7885a8f2f9aleaflet-geoman.min.js.mapb542247a165c916ftypes/assets/translations/index.d.ts2608c05776547f08types/js/Draw/L.PM.Draw.Circle.d.tsf1d67562b297bec9types/js/Draw/L.PM.Draw.CircleMarker.d.tse57cbaf650c7160atypes/js/Draw/L.PM.Draw.Cut.d.tsea5b3a75de00815atypes/js/Draw/L.PM.Draw.Line.d.ts59b41a6c5e0c34dftypes/js/Draw/L.PM.Draw.Marker.d.ts694ae95effee89cetypes/js/Draw/L.PM.Draw.Polygon.d.tse9b65c433adb8ff0types/js/Draw/L.PM.Draw.Rectangle.d.ts700b007783468424types/js/Draw/L.PM.Draw.Text.d.ts860244b340e4d428types/js/Draw/L.PM.Draw.d.ts975ae9bda6d45195types/js/Draw/L.PM.DrawTool.d.ts1d468f72dc6a76c2types/js/Edit/L.PM.Edit.Circle.d.tscced9f0918e52117types/js/Edit/L.PM.Edit.CircleMarker.d.ts2b467de6816df682types/js/Edit/L.PM.Edit.ImageOverlay.d.ts94f724dab90bdc0dtypes/js/Edit/L.PM.Edit.LayerGroup.d.ts6b37e316aae50df0types/js/Edit/L.PM.Edit.Line.d.ts9741b6bd31a7f836types/js/Edit/L.PM.Edit.Marker.d.ts6c5f2e91e2f71da3types/js/Edit/L.PM.Edit.Polygon.d.ts84ec61aae098ce7atypes/js/Edit/L.PM.Edit.Rectangle.d.tsb431dda5a0ebb921types/js/Edit/L.PM.Edit.Text.d.ts0b8cfecbc327a005types/js/Edit/L.PM.Edit.d.ts90f9a69e0ef26cc8types/js/L.PM.Map.d.ts3dc024a985e1713atypes/js/L.PM.Utils.d.ts805925f9b26ca381types/js/Mixins/Dragging.d.tse4c3ce66ef16e686types/js/Mixins/Events.d.ts855a52b9351306b7types/js/Mixins/Keyboard.d.ts0f35c8324211dae9types/js/Mixins/MarkerLimits.d.ts01d9f7181ac4d641types/js/Mixins/Modes/Mode.Drag.d.ts2bc99763e46ce49dtypes/js/Mixins/Modes/Mode.Edit.d.ts9648ec2fd649b64atypes/js/Mixins/Modes/Mode.Removal.d.tsb6cee798b49c10f9types/js/Mixins/Modes/Mode.Rotate.d.ts38e01e659f5e21cetypes/js/Mixins/Rotating.d.ts550987b4919dcc56types/js/Mixins/Snapping.d.ts90cbe5524c441286types/js/PM.d.ts7582d94e8bb444b1types/js/Toolbar/L.Controls.d.ts9fb5fcb1d4924e80types/js/Toolbar/L.PM.Toolbar.d.tsc5084b6ddd7d0226types/js/helpers/DragSession.d.ts9aa706761756ea44types/js/helpers/Matrix.d.ts0656b4771870a283types/js/helpers/ModeHelper.d.ts6037adc0366a7259types/js/helpers/ModeManager.d.ts422d8f66a40e50fftypes/js/helpers/classes.d.ts66fac5d922f0d1d1types/js/helpers/index.d.ts49f40ce1b831fb13types/js/helpers/language.d.tsda97688b7dec77a6types/js/helpers/options.d.ts69db7ae4b463dac5types/js/helpers/turfHelper.d.ts9fa1115c541c3492types/js/index.d.ts868726d81c167b7btypes/js/unstable.d.ts00177bb487943deatypes/types/leaflet-internals.d.ts0e4b5a27b3e1c53atypes/types/options.d.tsec3dcf8d71e807f6