@jsenv/plugin-bundling 2.9.3 → 2.9.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.9.3",
3
+ "version": "2.9.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,10 +25,10 @@
25
25
  "./tests/chunks_vendors/snapshots/1_vendors/vendors.js"
26
26
  ],
27
27
  "dependencies": {
28
- "@jsenv/humanize": "1.5.0",
29
- "@jsenv/url-meta": "8.5.6",
30
- "@jsenv/urls": "2.7.2",
31
- "@jsenv/sourcemap": "1.3.5",
28
+ "@jsenv/humanize": "1.5.2",
29
+ "@jsenv/url-meta": "8.5.7",
30
+ "@jsenv/urls": "2.7.4",
31
+ "@jsenv/sourcemap": "1.3.7",
32
32
  "lightningcss": "1.29.3",
33
33
  "rollup": "4.40.0"
34
34
  },
@@ -7,6 +7,7 @@ import {
7
7
  isFileSystemPath,
8
8
  urlToBasename,
9
9
  urlToExtension,
10
+ urlToFilename,
10
11
  urlToRelativeUrl,
11
12
  } from "@jsenv/urls";
12
13
  import { fileUrlConverter } from "../file_url_converter.js";
@@ -18,7 +19,7 @@ export const bundleJsModules = async (
18
19
  include,
19
20
  chunks = {},
20
21
  strictExports = false,
21
- isolateDynamicImports = undefined,
22
+ codeSplitting,
22
23
  preserveDynamicImports = false,
23
24
  augmentDynamicImportUrlSearchParams = () => {},
24
25
  rollup,
@@ -44,9 +45,10 @@ export const bundleJsModules = async (
44
45
  buildDirectoryUrl = jsModuleUrlInfos[0].context.buildDirectoryUrl;
45
46
  }
46
47
  const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
47
- if (isolateDynamicImports === undefined && nodeRuntimeEnabled) {
48
- isolateDynamicImports = true;
48
+ if (codeSplitting === undefined) {
49
+ codeSplitting = nodeRuntimeEnabled ? "isolate" : "reuse";
49
50
  }
51
+ const isolateDynamicImports = codeSplitting === "isolate";
50
52
 
51
53
  const PATH_AND_URL_CONVERTER = {
52
54
  asFileUrl: fileUrlConverter.asFileUrl,
@@ -91,10 +93,6 @@ export const bundleJsModules = async (
91
93
  nodeModuleChunkName = `${packageNameAsFilename}_node_modules`;
92
94
  packagesChunkName = `${packageNameAsFilename}_packages`;
93
95
  }
94
- if (assetsDirectory) {
95
- nodeModuleChunkName = `${assetsDirectory}${nodeModuleChunkName}`;
96
- packagesChunkName = `${assetsDirectory}${packagesChunkName}`;
97
- }
98
96
 
99
97
  chunks[nodeModuleChunkName] = {
100
98
  "file:///**/node_modules/": true,
@@ -111,7 +109,7 @@ export const bundleJsModules = async (
111
109
  }
112
110
  chunks[packagesChunkName] = {
113
111
  ...workspacePatterns,
114
- ...chunks.workspaces,
112
+ ...chunks.packages,
115
113
  };
116
114
  }
117
115
 
@@ -143,7 +141,18 @@ export const bundleJsModules = async (
143
141
  });
144
142
  for (const chunkNameCandidate of Object.keys(meta)) {
145
143
  if (meta[chunkNameCandidate]) {
146
- return chunkNameCandidate;
144
+ let chunkName = chunkNameCandidate;
145
+ if (assetsDirectory) {
146
+ chunkName = `${assetsDirectory}${chunkName}`;
147
+ }
148
+ const url = fileUrlConverter.asFileUrl(id);
149
+ const urlObject = new URL(url);
150
+ const dynamicImportId =
151
+ urlObject.searchParams.get("dynamic_import_id");
152
+ if (dynamicImportId) {
153
+ chunkName += `?dynamic_import_id=${dynamicImportId}`;
154
+ }
155
+ return chunkName;
147
156
  }
148
157
  }
149
158
  return undefined;
@@ -303,7 +312,30 @@ const rollupPluginJsenv = ({
303
312
  stripDynamicImportId,
304
313
  );
305
314
  }
306
- return new URL(rollupFileInfo.fileName, buildDirectoryUrl).href;
315
+ const buildUrlForRollup = new URL(
316
+ rollupFileInfo.fileName,
317
+ buildDirectoryUrl,
318
+ ).href;
319
+
320
+ const importerId = rollupFileInfo.moduleIds[0];
321
+ const importerUrl = fileUrlConverter.asFileUrl(importerId);
322
+ const importerUrlObject = new URL(importerUrl);
323
+ if (importerUrlObject.searchParams.has("dynamic_import_id")) {
324
+ const dynamicImportId =
325
+ importerUrlObject.searchParams.get("dynamic_import_id");
326
+ const extension = urlToExtension(buildUrlForRollup);
327
+ const suffix = `_dynamic_import_id_${dynamicImportId}${extension}`;
328
+ if (buildUrlForRollup.endsWith(suffix)) {
329
+ const nameBeforeSuffix = urlToFilename(buildUrlForRollup).slice(
330
+ 0,
331
+ -suffix.length,
332
+ );
333
+ const directoryUrl = new URL("./", buildUrlForRollup);
334
+ const buildUrlWithSearchParams = `${directoryUrl}${nameBeforeSuffix}${extension}?dynamic_import_id=${dynamicImportId}`;
335
+ return buildUrlWithSearchParams;
336
+ }
337
+ }
338
+ return buildUrlForRollup;
307
339
  };
308
340
 
309
341
  const getModuleSideEffects = (url) => {