@jsenv/plugin-bundling 2.8.4 → 2.8.5

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.8.4",
3
+ "version": "2.8.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,8 @@
24
24
  "dependencies": {
25
25
  "@jsenv/humanize": "1.3.1",
26
26
  "@jsenv/url-meta": "8.5.5",
27
- "@jsenv/urls": "2.6.3",
28
- "@jsenv/sourcemap": "1.3.2",
27
+ "@jsenv/urls": "2.7.0",
28
+ "@jsenv/sourcemap": "1.3.3",
29
29
  "lightningcss": "1.29.2",
30
30
  "rollup": "4.35.0"
31
31
  },
@@ -4,7 +4,11 @@ import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
4
4
  import { isSpecifierForNodeBuiltin } from "@jsenv/node-esm-resolution/src/node_builtin_specifiers.js";
5
5
  import { sourcemapConverter } from "@jsenv/sourcemap";
6
6
  import { URL_META } from "@jsenv/url-meta";
7
- import { isFileSystemPath } from "@jsenv/urls";
7
+ import {
8
+ injectQueryParams,
9
+ isFileSystemPath,
10
+ urlToBasename,
11
+ } from "@jsenv/urls";
8
12
  import { readFileSync } from "node:fs";
9
13
  import { fileUrlConverter } from "../file_url_converter.js";
10
14
 
@@ -15,7 +19,8 @@ export const bundleJsModules = async (
15
19
  include,
16
20
  chunks = {},
17
21
  strictExports = false,
18
- preserveDynamicImport = false,
22
+ isolateDynamicImports = undefined,
23
+ preserveDynamicImports = false,
19
24
  augmentDynamicImportUrlSearchParams = () => {},
20
25
  rollup,
21
26
  rollupInput = {},
@@ -36,155 +41,192 @@ export const bundleJsModules = async (
36
41
  if (buildDirectoryUrl === undefined) {
37
42
  buildDirectoryUrl = jsModuleUrlInfos[0].context.buildDirectoryUrl;
38
43
  }
44
+ const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
45
+ if (isolateDynamicImports === undefined && nodeRuntimeEnabled) {
46
+ isolateDynamicImports = true;
47
+ }
39
48
 
40
- let manualChunks;
41
- if (chunks) {
42
- let workspaces;
43
- let packageName;
44
- const packageDirectoryUrl = lookupPackageDirectory(rootDirectoryUrl);
45
- if (packageDirectoryUrl) {
46
- const packageJSON = readPackageAtOrNull(packageDirectoryUrl);
47
- if (packageJSON) {
48
- packageName = packageJSON.name;
49
- workspaces = packageJSON.workspaces;
50
- }
51
- }
52
- let nodeModuleChunkName = "node_modules";
53
- let packagesChunkName = "packages";
49
+ const PATH_AND_URL_CONVERTER = {
50
+ asFileUrl: fileUrlConverter.asFileUrl,
51
+ asFilePath: fileUrlConverter.asFilePath,
52
+ };
54
53
 
55
- if (packageName) {
56
- let packageNameAsFilename = packageName
57
- .replaceAll("@", "")
58
- .replaceAll("-", "_")
59
- .replaceAll("/", "_");
60
- nodeModuleChunkName = `${packageNameAsFilename}_node_modules`;
61
- packagesChunkName = `${packageNameAsFilename}_packages`;
62
- }
63
- chunks[nodeModuleChunkName] = {
64
- "file:///**/node_modules/": true,
65
- ...chunks.vendors,
66
- };
67
- if (workspaces) {
68
- const workspacePatterns = {};
69
- for (const workspace of workspaces) {
70
- const workspacePattern = new URL(
71
- workspace.endsWith("/*") ? workspace.slice(0, -1) : workspace,
72
- packageDirectoryUrl,
73
- ).href;
74
- workspacePatterns[workspacePattern] = true;
54
+ if (isolateDynamicImports) {
55
+ PATH_AND_URL_CONVERTER.asFileUrl = (path, stripDynamicImportId) => {
56
+ const fileUrl = fileUrlConverter.asFileUrl(path);
57
+ if (!stripDynamicImportId) {
58
+ return fileUrl;
75
59
  }
76
- chunks[packagesChunkName] = {
77
- ...workspacePatterns,
78
- ...chunks.workspaces,
79
- };
80
- }
60
+ if (!fileUrl.includes("dynamic_import_id")) {
61
+ return fileUrl;
62
+ }
63
+ return injectQueryParams(fileUrl, {
64
+ dynamic_import_id: undefined,
65
+ });
66
+ };
67
+ }
81
68
 
82
- const associations = URL_META.resolveAssociations(chunks, rootDirectoryUrl);
83
- manualChunks = (id, manualChunksApi) => {
84
- if (rollupOutput.manualChunks) {
85
- const manualChunkName = rollupOutput.manualChunks(id, manualChunksApi);
86
- if (manualChunkName) {
87
- return manualChunkName;
69
+ const generateBundleWithRollup = async () => {
70
+ let manualChunks;
71
+ if (chunks) {
72
+ let workspaces;
73
+ let packageName;
74
+ const packageDirectoryUrl = lookupPackageDirectory(rootDirectoryUrl);
75
+ if (packageDirectoryUrl) {
76
+ const packageJSON = readPackageAtOrNull(packageDirectoryUrl);
77
+ if (packageJSON) {
78
+ packageName = packageJSON.name;
79
+ workspaces = packageJSON.workspaces;
88
80
  }
89
81
  }
90
- const moduleInfo = manualChunksApi.getModuleInfo(id);
91
- if (moduleInfo.isEntry || moduleInfo.dynamicImporters.length) {
92
- return null;
82
+ let nodeModuleChunkName = "node_modules";
83
+ let packagesChunkName = "packages";
84
+
85
+ if (packageName) {
86
+ let packageNameAsFilename = packageName
87
+ .replaceAll("@", "")
88
+ .replaceAll("-", "_")
89
+ .replaceAll("/", "_");
90
+ nodeModuleChunkName = `${packageNameAsFilename}_node_modules`;
91
+ packagesChunkName = `${packageNameAsFilename}_packages`;
93
92
  }
94
- const url = fileUrlConverter.asFileUrl(id);
95
- const urlObject = new URL(url);
96
- urlObject.search = "";
97
- const urlWithoutSearch = urlObject.href;
98
- const meta = URL_META.applyAssociations({
99
- url: urlWithoutSearch,
100
- associations,
101
- });
102
- for (const chunkNameCandidate of Object.keys(meta)) {
103
- if (meta[chunkNameCandidate]) {
104
- return chunkNameCandidate;
93
+ chunks[nodeModuleChunkName] = {
94
+ "file:///**/node_modules/": true,
95
+ ...chunks.vendors,
96
+ };
97
+ if (workspaces) {
98
+ const workspacePatterns = {};
99
+ for (const workspace of workspaces) {
100
+ const workspacePattern = new URL(
101
+ workspace.endsWith("/*") ? workspace.slice(0, -1) : workspace,
102
+ packageDirectoryUrl,
103
+ ).href;
104
+ workspacePatterns[workspacePattern] = true;
105
105
  }
106
+ chunks[packagesChunkName] = {
107
+ ...workspacePatterns,
108
+ ...chunks.workspaces,
109
+ };
106
110
  }
107
- return undefined;
108
- };
109
- }
110
-
111
- const resultRef = { current: null };
112
- const willMinifyJsModule = Boolean(getPluginMeta("willMinifyJsModule"));
113
- try {
114
- await applyRollupPlugins({
115
- rollup,
116
- rollupPlugins: [
117
- ...rollupPlugins,
118
- rollupPluginJsenv({
119
- signal,
120
- logger,
121
- rootDirectoryUrl,
122
- buildDirectoryUrl,
123
- graph,
124
- jsModuleUrlInfos,
125
111
 
126
- runtimeCompat,
127
- sourcemaps,
128
- include,
129
- preserveDynamicImport,
130
- augmentDynamicImportUrlSearchParams,
131
- strictExports,
132
- resultRef,
133
- }),
134
- ],
135
- rollupInput: {
136
- input: [],
137
- onwarn: (warning) => {
138
- if (warning.code === "CIRCULAR_DEPENDENCY") {
139
- return;
140
- }
141
- if (warning.code === "EVAL") {
142
- // ideally we should disable only for jsenv files
143
- return;
144
- }
145
- if (
146
- warning.code === "INVALID_ANNOTATION" &&
147
- warning.loc.file.includes("/node_modules/")
148
- ) {
149
- return;
112
+ const associations = URL_META.resolveAssociations(
113
+ chunks,
114
+ rootDirectoryUrl,
115
+ );
116
+ manualChunks = (id, manualChunksApi) => {
117
+ if (rollupOutput.manualChunks) {
118
+ const manualChunkName = rollupOutput.manualChunks(
119
+ id,
120
+ manualChunksApi,
121
+ );
122
+ if (manualChunkName) {
123
+ return manualChunkName;
150
124
  }
151
- if (
152
- warning.code === "EMPTY_BUNDLE" &&
153
- (warning.names.join("").endsWith("node_modules") ||
154
- warning.names.join("").endsWith("packages"))
155
- ) {
156
- return;
125
+ }
126
+ const moduleInfo = manualChunksApi.getModuleInfo(id);
127
+ if (moduleInfo.isEntry || moduleInfo.dynamicImporters.length) {
128
+ return null;
129
+ }
130
+ const url = PATH_AND_URL_CONVERTER.asFileUrl(id);
131
+ const urlObject = new URL(url);
132
+ urlObject.search = "";
133
+ const urlWithoutSearch = urlObject.href;
134
+ const meta = URL_META.applyAssociations({
135
+ url: urlWithoutSearch,
136
+ associations,
137
+ });
138
+ for (const chunkNameCandidate of Object.keys(meta)) {
139
+ if (meta[chunkNameCandidate]) {
140
+ return chunkNameCandidate;
157
141
  }
158
- logger.warn(String(warning));
142
+ }
143
+ return undefined;
144
+ };
145
+ }
146
+
147
+ const resultRef = { current: null };
148
+ const willMinifyJsModule = Boolean(getPluginMeta("willMinifyJsModule"));
149
+ try {
150
+ await applyRollupPlugins({
151
+ rollup,
152
+ rollupPlugins: [
153
+ ...rollupPlugins,
154
+ rollupPluginJsenv({
155
+ signal,
156
+ logger,
157
+ rootDirectoryUrl,
158
+ buildDirectoryUrl,
159
+ graph,
160
+ jsModuleUrlInfos,
161
+ PATH_AND_URL_CONVERTER,
162
+
163
+ runtimeCompat,
164
+ sourcemaps,
165
+ include,
166
+ preserveDynamicImports,
167
+ augmentDynamicImportUrlSearchParams,
168
+ isolateDynamicImports,
169
+ strictExports,
170
+ resultRef,
171
+ }),
172
+ ],
173
+ rollupInput: {
174
+ input: [],
175
+ onwarn: (warning) => {
176
+ if (warning.code === "CIRCULAR_DEPENDENCY") {
177
+ return;
178
+ }
179
+ if (warning.code === "EVAL") {
180
+ // ideally we should disable only for jsenv files
181
+ return;
182
+ }
183
+ if (
184
+ warning.code === "INVALID_ANNOTATION" &&
185
+ warning.loc.file.includes("/node_modules/")
186
+ ) {
187
+ return;
188
+ }
189
+ if (
190
+ warning.code === "EMPTY_BUNDLE" &&
191
+ (warning.names.join("").endsWith("node_modules") ||
192
+ warning.names.join("").endsWith("packages"))
193
+ ) {
194
+ return;
195
+ }
196
+ logger.warn(String(warning));
197
+ },
198
+ ...rollupInput,
159
199
  },
160
- ...rollupInput,
161
- },
162
- rollupOutput: {
163
- compact: willMinifyJsModule,
164
- minifyInternalExports: willMinifyJsModule,
165
- generatedCode: {
166
- arrowFunctions: isSupportedOnCurrentClients("arrow_function"),
167
- constBindings: isSupportedOnCurrentClients("const_bindings"),
168
- objectShorthand: isSupportedOnCurrentClients(
169
- "object_properties_shorthand",
170
- ),
171
- reservedNamesAsProps: isSupportedOnCurrentClients("reserved_words"),
172
- symbols: isSupportedOnCurrentClients("symbols"),
200
+ rollupOutput: {
201
+ compact: willMinifyJsModule,
202
+ minifyInternalExports: willMinifyJsModule,
203
+ generatedCode: {
204
+ arrowFunctions: isSupportedOnCurrentClients("arrow_function"),
205
+ constBindings: isSupportedOnCurrentClients("const_bindings"),
206
+ objectShorthand: isSupportedOnCurrentClients(
207
+ "object_properties_shorthand",
208
+ ),
209
+ reservedNamesAsProps: isSupportedOnCurrentClients("reserved_words"),
210
+ symbols: isSupportedOnCurrentClients("symbols"),
211
+ },
212
+ ...rollupOutput,
213
+ manualChunks,
173
214
  },
174
- ...rollupOutput,
175
- manualChunks,
176
- },
177
- });
178
- return resultRef.current.jsModuleBundleUrlInfos;
179
- } catch (e) {
180
- if (e.code === "MISSING_EXPORT") {
181
- const detailedMessage = createDetailedMessage(e.message, {
182
- frame: e.frame,
183
215
  });
184
- throw new Error(detailedMessage, { cause: e });
216
+ return resultRef.current.jsModuleBundleUrlInfos;
217
+ } catch (e) {
218
+ if (e.code === "MISSING_EXPORT") {
219
+ const detailedMessage = createDetailedMessage(e.message, {
220
+ frame: e.frame,
221
+ });
222
+ throw new Error(detailedMessage, { cause: e });
223
+ }
224
+ throw e;
185
225
  }
186
- throw e;
187
- }
226
+ };
227
+
228
+ const jsModuleBundleUrlInfos = await generateBundleWithRollup();
229
+ return jsModuleBundleUrlInfos;
188
230
  };
189
231
 
190
232
  const rollupPluginJsenv = ({
@@ -193,11 +235,13 @@ const rollupPluginJsenv = ({
193
235
  buildDirectoryUrl,
194
236
  graph,
195
237
  jsModuleUrlInfos,
238
+ PATH_AND_URL_CONVERTER,
196
239
 
197
240
  runtimeCompat,
198
241
  sourcemaps,
199
242
  include,
200
- preserveDynamicImport,
243
+ preserveDynamicImports,
244
+ isolateDynamicImports,
201
245
  augmentDynamicImportUrlSearchParams,
202
246
  strictExports,
203
247
 
@@ -228,7 +272,7 @@ const rollupPluginJsenv = ({
228
272
  };
229
273
  }
230
274
 
231
- const getOriginalUrl = (rollupFileInfo) => {
275
+ const getOriginalUrl = (rollupFileInfo, stripDynamicImportId) => {
232
276
  if (
233
277
  // - explicitely emitted by emitChunk
234
278
  // - import.meta.resolve("")
@@ -238,13 +282,19 @@ const rollupPluginJsenv = ({
238
282
  ) {
239
283
  const { facadeModuleId } = rollupFileInfo;
240
284
  if (facadeModuleId) {
241
- return fileUrlConverter.asFileUrl(facadeModuleId);
285
+ return PATH_AND_URL_CONVERTER.asFileUrl(
286
+ facadeModuleId,
287
+ stripDynamicImportId,
288
+ );
242
289
  }
243
290
  }
244
291
  if (rollupFileInfo.isDynamicEntry) {
245
292
  const { moduleIds } = rollupFileInfo;
246
293
  const lastModuleId = moduleIds[moduleIds.length - 1];
247
- return fileUrlConverter.asFileUrl(lastModuleId);
294
+ return PATH_AND_URL_CONVERTER.asFileUrl(
295
+ lastModuleId,
296
+ stripDynamicImportId,
297
+ );
248
298
  }
249
299
  return new URL(rollupFileInfo.fileName, buildDirectoryUrl).href;
250
300
  };
@@ -337,6 +387,33 @@ const rollupPluginJsenv = ({
337
387
  }
338
388
  };
339
389
 
390
+ const resolveImport = (specifier, importer) => {
391
+ if (specifier[0] === "/") {
392
+ return new URL(specifier.slice(1), rootDirectoryUrl);
393
+ }
394
+ return new URL(specifier, importer);
395
+ };
396
+
397
+ const dynamicImportIdSet = new Set();
398
+ const assignDynamicImportId = (urlImportedDynamically) => {
399
+ const urlInfo = jsModuleUrlInfos[0].context.kitchen.graph.getUrlInfo(
400
+ urlImportedDynamically,
401
+ );
402
+ let dynamicImportIdBase =
403
+ urlInfo && urlInfo.filenameHint
404
+ ? filenameWithoutExtension(urlInfo.filenameHint)
405
+ : urlToBasename(urlImportedDynamically);
406
+ let dynamicImportIdCandidate = dynamicImportIdBase;
407
+ let positiveInteger = 1;
408
+ while (dynamicImportIdSet.has(dynamicImportIdCandidate)) {
409
+ dynamicImportIdCandidate = `${dynamicImportIdBase}_${positiveInteger}`;
410
+ positiveInteger++;
411
+ }
412
+ const dynamicImportId = dynamicImportIdCandidate;
413
+ dynamicImportIdSet.add(dynamicImportId);
414
+ return dynamicImportId;
415
+ };
416
+
340
417
  return {
341
418
  name: "jsenv",
342
419
  async buildStart() {
@@ -391,7 +468,7 @@ const rollupPluginJsenv = ({
391
468
  const createBundledFileInfo = (rollupFileInfo) => {
392
469
  const originalUrl = getOriginalUrl(rollupFileInfo);
393
470
  const sourceUrls = Object.keys(rollupFileInfo.modules).map((id) =>
394
- fileUrlConverter.asFileUrl(id),
471
+ PATH_AND_URL_CONVERTER.asFileUrl(id),
395
472
  );
396
473
 
397
474
  const specifierToUrlMap = new Map();
@@ -456,7 +533,7 @@ const rollupPluginJsenv = ({
456
533
  specifierToUrlMap.size > 0
457
534
  ? (reference) => {
458
535
  if (
459
- preserveDynamicImport &&
536
+ preserveDynamicImports &&
460
537
  reference.subtype === "dynamic_import"
461
538
  ) {
462
539
  // when dynamic import are preserved, no need to remap them
@@ -513,7 +590,7 @@ const rollupPluginJsenv = ({
513
590
  // const sourcemapFile = buildDirectoryUrl
514
591
  Object.assign(outputOptions, {
515
592
  format,
516
- dir: fileUrlConverter.asFilePath(rootDirectoryUrl),
593
+ dir: PATH_AND_URL_CONVERTER.asFilePath(rootDirectoryUrl),
517
594
  sourcemap: sourcemaps === "file" || sourcemaps === "inline",
518
595
  // sourcemapFile,
519
596
  sourcemapPathTransform: (relativePath) => {
@@ -524,7 +601,7 @@ const rollupPluginJsenv = ({
524
601
  },
525
602
  chunkFileNames: (chunkInfo) => {
526
603
  if (chunkInfo.isEntry) {
527
- const originalFileUrl = getOriginalUrl(chunkInfo);
604
+ const originalFileUrl = getOriginalUrl(chunkInfo, true);
528
605
  const jsModuleUrlInfo = jsModuleUrlInfos.find(
529
606
  (candidate) => candidate.url === originalFileUrl,
530
607
  );
@@ -532,87 +609,111 @@ const rollupPluginJsenv = ({
532
609
  return jsModuleUrlInfo.filenameHint;
533
610
  }
534
611
  }
612
+ if (chunkInfo.isDynamicEntry) {
613
+ const originalFileUrl = getOriginalUrl(chunkInfo, true);
614
+ const urlInfo =
615
+ jsModuleUrlInfos[0].context.kitchen.graph.getUrlInfo(
616
+ originalFileUrl,
617
+ );
618
+ if (urlInfo && urlInfo.filenameHint) {
619
+ return urlInfo.filenameHint;
620
+ }
621
+ }
535
622
  return `${chunkInfo.name}.js`;
536
623
  },
537
624
  });
538
625
  },
539
626
  // https://rollupjs.org/guide/en/#resolvedynamicimport
540
627
  resolveDynamicImport: (specifier, importer) => {
541
- if (!preserveDynamicImport) {
628
+ if (typeof specifier !== "string") {
629
+ // Receiving an ASTNode (specifier is dynamic)
542
630
  return null;
543
631
  }
544
- let urlObject;
545
- if (specifier[0] === "/") {
546
- urlObject = new URL(specifier.slice(1), rootDirectoryUrl);
547
- } else {
632
+ if (preserveDynamicImports) {
548
633
  if (isFileSystemPath(importer)) {
549
- importer = fileUrlConverter.asFileUrl(importer);
634
+ importer = PATH_AND_URL_CONVERTER.asFileUrl(importer);
635
+ }
636
+ const urlObject = resolveImport(specifier, importer);
637
+ if (!urlObject.href.startsWith("file:")) {
638
+ return { id: specifier, external: true };
639
+ }
640
+ const searchParamsToAdd =
641
+ augmentDynamicImportUrlSearchParams(urlObject);
642
+ if (searchParamsToAdd) {
643
+ injectQueryParams(urlObject, searchParamsToAdd);
550
644
  }
551
- urlObject = new URL(specifier, importer);
645
+ const id = urlObject.href;
646
+ return { id, external: true };
552
647
  }
553
- const searchParamsToAdd = augmentDynamicImportUrlSearchParams(urlObject);
554
- if (searchParamsToAdd) {
555
- Object.keys(searchParamsToAdd).forEach((key) => {
556
- const value = searchParamsToAdd[key];
557
- if (value === undefined) {
558
- urlObject.searchParams.delete(key);
559
- } else {
560
- urlObject.searchParams.set(key, value);
561
- }
648
+ if (isolateDynamicImports) {
649
+ if (isFileSystemPath(importer)) {
650
+ importer = PATH_AND_URL_CONVERTER.asFileUrl(importer);
651
+ }
652
+ const urlObject = resolveImport(specifier, importer);
653
+ if (!urlObject.href.startsWith("file:")) {
654
+ return { id: specifier, external: true };
655
+ }
656
+ const importId = assignDynamicImportId(urlObject.href);
657
+ injectQueryParams(urlObject, {
658
+ dynamic_import_id: importId,
562
659
  });
660
+ const url = urlObject.href;
661
+ const filePath = PATH_AND_URL_CONVERTER.asFilePath(url);
662
+ return { id: filePath };
563
663
  }
564
- return { external: true, id: urlObject.href };
664
+ return null;
565
665
  },
566
666
  resolveId: (specifier, importer = rootDirectoryUrl) => {
567
667
  if (isFileSystemPath(importer)) {
568
- importer = fileUrlConverter.asFileUrl(importer);
569
- }
570
- let url;
571
- if (specifier[0] === "/") {
572
- url = new URL(specifier.slice(1), rootDirectoryUrl).href;
573
- } else {
574
- url = new URL(specifier, importer).href;
668
+ importer = PATH_AND_URL_CONVERTER.asFileUrl(importer);
575
669
  }
576
-
577
- if (!url.startsWith("file:")) {
670
+ const resolvedUrlObject = resolveImport(specifier, importer);
671
+ const resolvedUrl = resolvedUrlObject.href;
672
+ if (!resolvedUrl.startsWith("file:")) {
578
673
  return {
579
- id: url,
674
+ id: resolvedUrl,
580
675
  external: true,
581
- moduleSideEffects: getModuleSideEffects(url, importer),
676
+ moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
582
677
  };
583
678
  }
584
- if (!importCanBeBundled(url)) {
679
+ if (!importCanBeBundled(resolvedUrl)) {
585
680
  return {
586
- id: url,
681
+ id: resolvedUrl,
587
682
  external: true,
588
- moduleSideEffects: getModuleSideEffects(url, importer),
683
+ moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
589
684
  };
590
685
  }
591
- const urlInfo = graph.getUrlInfo(url);
592
- if (!urlInfo) {
593
- // happen when excluded by referenceAnalysis.include
686
+ if (resolvedUrl.startsWith("ignore:")) {
594
687
  return {
595
- id: url,
688
+ id: resolvedUrl,
596
689
  external: true,
597
- moduleSideEffects: getModuleSideEffects(url, importer),
690
+ moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
598
691
  };
599
692
  }
600
- if (url.startsWith("ignore:")) {
601
- return {
602
- id: url,
603
- external: true,
604
- moduleSideEffects: getModuleSideEffects(url, importer),
605
- };
693
+ if (importer.includes("dynamic_import_id")) {
694
+ const importerUrlObject = new URL(importer);
695
+ const dynamicImportId =
696
+ importerUrlObject.searchParams.get("dynamic_import_id");
697
+ if (dynamicImportId) {
698
+ injectQueryParams(resolvedUrlObject, {
699
+ dynamic_import_id: dynamicImportId,
700
+ });
701
+ const isolatedResolvedUrl = resolvedUrlObject.href;
702
+ return {
703
+ id: PATH_AND_URL_CONVERTER.asFilePath(isolatedResolvedUrl),
704
+ external: false,
705
+ moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
706
+ };
707
+ }
606
708
  }
607
- const filePath = fileUrlConverter.asFilePath(url);
608
709
  return {
609
- id: filePath,
710
+ id: PATH_AND_URL_CONVERTER.asFilePath(resolvedUrl),
610
711
  external: false,
611
- moduleSideEffects: getModuleSideEffects(url, importer),
712
+ moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
612
713
  };
613
714
  },
614
715
  async load(rollupId) {
615
- const fileUrl = fileUrlConverter.asFileUrl(rollupId);
716
+ const fileUrl = PATH_AND_URL_CONVERTER.asFileUrl(rollupId, true);
616
717
  const urlInfo = graph.getUrlInfo(fileUrl);
617
718
  return {
618
719
  code: urlInfo.content,
@@ -647,3 +748,11 @@ const applyRollupPlugins = async ({
647
748
  const rollupOutputArray = await rollupReturnValue.generate(rollupOutput);
648
749
  return rollupOutputArray;
649
750
  };
751
+
752
+ const filenameWithoutExtension = (filename) => {
753
+ const dotLastIndex = filename.lastIndexOf(".");
754
+ if (dotLastIndex === -1) {
755
+ return filename;
756
+ }
757
+ return filename.slice(0, dotLastIndex);
758
+ };