@jsenv/plugin-bundling 2.8.5 → 2.8.7
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.
|
|
3
|
+
"version": "2.8.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
],
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@jsenv/humanize": "1.
|
|
26
|
-
"@jsenv/url-meta": "8.5.
|
|
27
|
-
"@jsenv/urls": "2.7.
|
|
28
|
-
"@jsenv/sourcemap": "1.3.
|
|
25
|
+
"@jsenv/humanize": "1.4.0",
|
|
26
|
+
"@jsenv/url-meta": "8.5.6",
|
|
27
|
+
"@jsenv/urls": "2.7.1",
|
|
28
|
+
"@jsenv/sourcemap": "1.3.4",
|
|
29
29
|
"lightningcss": "1.29.2",
|
|
30
30
|
"rollup": "4.35.0"
|
|
31
31
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { lookupPackageDirectory, readPackageAtOrNull } from "@jsenv/filesystem";
|
|
2
2
|
import { createDetailedMessage } from "@jsenv/humanize";
|
|
3
|
-
import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
4
3
|
import { isSpecifierForNodeBuiltin } from "@jsenv/node-esm-resolution/src/node_builtin_specifiers.js";
|
|
5
4
|
import { sourcemapConverter } from "@jsenv/sourcemap";
|
|
6
5
|
import { URL_META } from "@jsenv/url-meta";
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
injectQueryParams,
|
|
9
8
|
isFileSystemPath,
|
|
10
9
|
urlToBasename,
|
|
10
|
+
urlToRelativeUrl,
|
|
11
11
|
} from "@jsenv/urls";
|
|
12
12
|
import { readFileSync } from "node:fs";
|
|
13
13
|
import { fileUrlConverter } from "../file_url_converter.js";
|
|
@@ -36,6 +36,8 @@ export const bundleJsModules = async (
|
|
|
36
36
|
sourcemaps,
|
|
37
37
|
isSupportedOnCurrentClients,
|
|
38
38
|
getPluginMeta,
|
|
39
|
+
kitchen,
|
|
40
|
+
assetsDirectory,
|
|
39
41
|
} = jsModuleUrlInfos[0].context;
|
|
40
42
|
const graph = jsModuleUrlInfos[0].graph;
|
|
41
43
|
if (buildDirectoryUrl === undefined) {
|
|
@@ -79,8 +81,8 @@ export const bundleJsModules = async (
|
|
|
79
81
|
workspaces = packageJSON.workspaces;
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
let nodeModuleChunkName =
|
|
83
|
-
let packagesChunkName =
|
|
84
|
+
let nodeModuleChunkName = `node_modules`;
|
|
85
|
+
let packagesChunkName = `packages`;
|
|
84
86
|
|
|
85
87
|
if (packageName) {
|
|
86
88
|
let packageNameAsFilename = packageName
|
|
@@ -90,6 +92,11 @@ export const bundleJsModules = async (
|
|
|
90
92
|
nodeModuleChunkName = `${packageNameAsFilename}_node_modules`;
|
|
91
93
|
packagesChunkName = `${packageNameAsFilename}_packages`;
|
|
92
94
|
}
|
|
95
|
+
if (assetsDirectory) {
|
|
96
|
+
nodeModuleChunkName = `${assetsDirectory}${nodeModuleChunkName}`;
|
|
97
|
+
packagesChunkName = `${assetsDirectory}${packagesChunkName}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
93
100
|
chunks[nodeModuleChunkName] = {
|
|
94
101
|
"file:///**/node_modules/": true,
|
|
95
102
|
...chunks.vendors,
|
|
@@ -159,6 +166,7 @@ export const bundleJsModules = async (
|
|
|
159
166
|
graph,
|
|
160
167
|
jsModuleUrlInfos,
|
|
161
168
|
PATH_AND_URL_CONVERTER,
|
|
169
|
+
kitchen,
|
|
162
170
|
|
|
163
171
|
runtimeCompat,
|
|
164
172
|
sourcemaps,
|
|
@@ -237,7 +245,7 @@ const rollupPluginJsenv = ({
|
|
|
237
245
|
jsModuleUrlInfos,
|
|
238
246
|
PATH_AND_URL_CONVERTER,
|
|
239
247
|
|
|
240
|
-
|
|
248
|
+
kitchen,
|
|
241
249
|
sourcemaps,
|
|
242
250
|
include,
|
|
243
251
|
preserveDynamicImports,
|
|
@@ -315,34 +323,39 @@ const rollupPluginJsenv = ({
|
|
|
315
323
|
"utf8",
|
|
316
324
|
);
|
|
317
325
|
const packageJSON = JSON.parse(packageFileContent);
|
|
318
|
-
|
|
319
|
-
if (Array.isArray(value)) {
|
|
320
|
-
const sideEffectPatterns = {};
|
|
321
|
-
for (const v of value) {
|
|
322
|
-
sideEffectPatterns[v] = true;
|
|
323
|
-
}
|
|
324
|
-
const associations = URL_META.resolveAssociations(
|
|
325
|
-
{ sideEffects: sideEffectPatterns },
|
|
326
|
-
packageDirectoryUrl,
|
|
327
|
-
);
|
|
328
|
-
const isMatching = (url) => {
|
|
329
|
-
const meta = URL_META.applyAssociations({ url, associations });
|
|
330
|
-
return meta.sideEffects || false;
|
|
331
|
-
};
|
|
332
|
-
packageSideEffectsCacheMap.set(packageDirectoryUrl, {
|
|
333
|
-
value: isMatching,
|
|
334
|
-
});
|
|
335
|
-
} else {
|
|
336
|
-
packageSideEffectsCacheMap.set(packageDirectoryUrl, { value });
|
|
337
|
-
}
|
|
338
|
-
return value;
|
|
326
|
+
return storePackageSideEffect(packageDirectoryUrl, packageJSON);
|
|
339
327
|
} catch {
|
|
328
|
+
return storePackageSideEffect(packageDirectoryUrl, null);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
const storePackageSideEffect = (packageDirectoryUrl, packageJson) => {
|
|
332
|
+
if (!packageJson) {
|
|
340
333
|
packageSideEffectsCacheMap.set(packageDirectoryUrl, { value: undefined });
|
|
341
334
|
return undefined;
|
|
342
335
|
}
|
|
336
|
+
const value = packageJson.sideEffects;
|
|
337
|
+
if (Array.isArray(value)) {
|
|
338
|
+
const sideEffectPatterns = {};
|
|
339
|
+
for (const v of value) {
|
|
340
|
+
sideEffectPatterns[v] = true;
|
|
341
|
+
}
|
|
342
|
+
const associations = URL_META.resolveAssociations(
|
|
343
|
+
{ sideEffects: sideEffectPatterns },
|
|
344
|
+
packageDirectoryUrl,
|
|
345
|
+
);
|
|
346
|
+
const isMatching = (url) => {
|
|
347
|
+
const meta = URL_META.applyAssociations({ url, associations });
|
|
348
|
+
return meta.sideEffects || false;
|
|
349
|
+
};
|
|
350
|
+
packageSideEffectsCacheMap.set(packageDirectoryUrl, {
|
|
351
|
+
value: isMatching,
|
|
352
|
+
});
|
|
353
|
+
return isMatching;
|
|
354
|
+
}
|
|
355
|
+
packageSideEffectsCacheMap.set(packageDirectoryUrl, { value });
|
|
356
|
+
return value;
|
|
343
357
|
};
|
|
344
|
-
|
|
345
|
-
const packageConditions = [nodeRuntimeEnabled ? "node" : "browser", "import"];
|
|
358
|
+
|
|
346
359
|
const inferSideEffectsFromResolvedUrl = (url) => {
|
|
347
360
|
if (url.startsWith("ignore:")) {
|
|
348
361
|
// console.log(`may have side effect: ${url}`);
|
|
@@ -376,12 +389,11 @@ const rollupPluginJsenv = ({
|
|
|
376
389
|
return inferSideEffectsFromResolvedUrl(url);
|
|
377
390
|
}
|
|
378
391
|
try {
|
|
379
|
-
const result =
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return inferSideEffectsFromResolvedUrl(result.url);
|
|
392
|
+
const result = kitchen.resolve(url, importer);
|
|
393
|
+
if (result.packageDirectoryUrl) {
|
|
394
|
+
storePackageSideEffect(result.packageDirectoryUrl, result.packageJson);
|
|
395
|
+
}
|
|
396
|
+
return inferSideEffectsFromResolvedUrl(url);
|
|
385
397
|
} catch {
|
|
386
398
|
return null;
|
|
387
399
|
}
|
|
@@ -482,7 +494,22 @@ const rollupPluginJsenv = ({
|
|
|
482
494
|
continue;
|
|
483
495
|
}
|
|
484
496
|
const importUrl = getOriginalUrl(importRollupFileInfo);
|
|
485
|
-
const
|
|
497
|
+
const importerBuildUrl = new URL(
|
|
498
|
+
rollupFileInfo.fileName,
|
|
499
|
+
buildDirectoryUrl,
|
|
500
|
+
).href;
|
|
501
|
+
const urlToImport = new URL(
|
|
502
|
+
importRollupFileInfo.fileName,
|
|
503
|
+
buildDirectoryUrl,
|
|
504
|
+
).href;
|
|
505
|
+
const specifierRelative = urlToRelativeUrl(
|
|
506
|
+
urlToImport,
|
|
507
|
+
importerBuildUrl,
|
|
508
|
+
);
|
|
509
|
+
const rollupSpecifier =
|
|
510
|
+
specifierRelative[0] === "."
|
|
511
|
+
? specifierRelative
|
|
512
|
+
: `./${specifierRelative}`;
|
|
486
513
|
specifierToUrlMap.set(rollupSpecifier, importUrl);
|
|
487
514
|
}
|
|
488
515
|
}
|
|
@@ -552,6 +579,7 @@ const rollupPluginJsenv = ({
|
|
|
552
579
|
reference.specifier,
|
|
553
580
|
);
|
|
554
581
|
if (!specifierBeforeRollup) {
|
|
582
|
+
// process.emitWarning?
|
|
555
583
|
console.warn(
|
|
556
584
|
`cannot remap "${reference.specifier}" back to specifier before rollup, this is unexpected.`,
|
|
557
585
|
);
|
|
@@ -706,6 +734,14 @@ const rollupPluginJsenv = ({
|
|
|
706
734
|
};
|
|
707
735
|
}
|
|
708
736
|
}
|
|
737
|
+
const urlInfo = graph.getUrlInfo(resolvedUrl);
|
|
738
|
+
if (urlInfo.type === "entry_build") {
|
|
739
|
+
return {
|
|
740
|
+
id: resolvedUrl,
|
|
741
|
+
external: true,
|
|
742
|
+
moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
|
|
743
|
+
};
|
|
744
|
+
}
|
|
709
745
|
return {
|
|
710
746
|
id: PATH_AND_URL_CONVERTER.asFilePath(resolvedUrl),
|
|
711
747
|
external: false,
|