@jsenv/plugin-bundling 2.10.18 → 2.10.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-bundling",
3
- "version": "2.10.18",
3
+ "version": "2.10.20",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@jsenv/humanize": "1.7.8",
25
25
  "@jsenv/node-esm-resolution": "1.3.5",
26
- "@jsenv/sourcemap": "1.4.2",
26
+ "@jsenv/sourcemap": "1.4.3",
27
27
  "@jsenv/url-meta": "8.5.7",
28
28
  "@jsenv/urls": "2.9.10",
29
29
  "lightningcss": "1.33.0",
@@ -370,8 +370,24 @@ const rollupPluginJsenv = ({
370
370
  return new URL(specifier, importer);
371
371
  };
372
372
 
373
+ // The id forks a module into an isolated copy, so a module asked for twice
374
+ // gets ONE id and stays one copy — two isolated groups reaching the same
375
+ // dependency share it instead of each carrying an identical file. The
376
+ // counter below is then only what it is for: telling apart two DIFFERENT
377
+ // modules whose basename happens to be the same.
378
+ //
379
+ // Sharing costs the isolation nothing here: what is shared is reached
380
+ // through a dynamic import, so it is still loaded on demand, by whoever
381
+ // actually asks for it, and neither group loads the other's code.
373
382
  const dynamicImportIdSet = new Set();
383
+ const dynamicImportIdMap = new Map();
374
384
  const assignDynamicImportId = (urlImportedDynamically) => {
385
+ const dynamicImportIdFromMap = dynamicImportIdMap.get(
386
+ urlImportedDynamically,
387
+ );
388
+ if (dynamicImportIdFromMap) {
389
+ return dynamicImportIdFromMap;
390
+ }
375
391
  const urlInfo = kitchen.graph.getUrlInfo(urlImportedDynamically);
376
392
  let dynamicImportIdBase =
377
393
  urlInfo && urlInfo.filenameHint
@@ -385,6 +401,7 @@ const rollupPluginJsenv = ({
385
401
  }
386
402
  const dynamicImportId = dynamicImportIdCandidate;
387
403
  dynamicImportIdSet.add(dynamicImportId);
404
+ dynamicImportIdMap.set(urlImportedDynamically, dynamicImportId);
388
405
  return dynamicImportId;
389
406
  };
390
407
 
@@ -618,6 +635,23 @@ const rollupPluginJsenv = ({
618
635
  const originalFileUrl = getOriginalUrl(chunkInfo, true);
619
636
  const urlInfo = kitchen.graph.getUrlInfo(originalFileUrl);
620
637
  if (urlInfo && urlInfo.filenameHint) {
638
+ // The hint is read with the dynamic import id stripped, so every
639
+ // isolated copy of a module hands back the same name and rollup
640
+ // separates them with a counter of its own — a second numbering
641
+ // of one collision, in another format, beside the directory the
642
+ // id already names. The id IS what makes a copy distinct, so it
643
+ // is what the file is called; where nothing collides it spells
644
+ // the hint back.
645
+ const dynamicImportId = new URL(
646
+ getOriginalUrl(chunkInfo, false),
647
+ ).searchParams.get("dynamic_import_id");
648
+ if (dynamicImportId) {
649
+ const { filenameHint } = urlInfo;
650
+ const dotIndex = filenameHint.lastIndexOf(".");
651
+ const extension =
652
+ dotIndex === -1 ? "" : filenameHint.slice(dotIndex);
653
+ return `${dynamicImportId}${extension}`;
654
+ }
621
655
  return urlInfo.filenameHint;
622
656
  }
623
657
  }