@jsenv/plugin-bundling 2.2.1 → 2.4.0
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.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@jsenv/log": "3.4.0",
|
|
28
28
|
"@jsenv/url-meta": "8.1.0",
|
|
29
|
-
"@jsenv/urls": "2.
|
|
30
|
-
"@jsenv/sourcemap": "1.0
|
|
29
|
+
"@jsenv/urls": "2.1.0",
|
|
30
|
+
"@jsenv/sourcemap": "1.1.0",
|
|
31
31
|
"acorn-import-assertions": "1.9.0",
|
|
32
|
-
"lightningcss": "1.21.
|
|
33
|
-
"rollup": "3.
|
|
32
|
+
"lightningcss": "1.21.5",
|
|
33
|
+
"rollup": "3.26.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@jsenv/core": "*"
|
|
@@ -2,10 +2,10 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
2
2
|
import { fileUrlConverter } from "../file_url_converter.js";
|
|
3
3
|
|
|
4
4
|
// Do not use until https://github.com/parcel-bundler/parcel-css/issues/181
|
|
5
|
-
export const bundleCss = async (
|
|
5
|
+
export const bundleCss = async (cssUrlInfos) => {
|
|
6
6
|
const bundledCssUrlInfos = {};
|
|
7
7
|
const { bundleAsync } = await import("lightningcss");
|
|
8
|
-
const targets = runtimeCompatToTargets(context.runtimeCompat);
|
|
8
|
+
const targets = runtimeCompatToTargets(cssUrlInfos[0].context.runtimeCompat);
|
|
9
9
|
for (const cssUrlInfo of cssUrlInfos) {
|
|
10
10
|
const filename = fileUrlConverter.asFilePath(cssUrlInfo.originalUrl);
|
|
11
11
|
const { code, map } = await bundleAsync({
|
|
@@ -16,7 +16,7 @@ export const bundleCss = async ({ cssUrlInfos, context }) => {
|
|
|
16
16
|
read: (specifier) => {
|
|
17
17
|
const fileUrlObject = fileUrlConverter.asFileUrl(specifier);
|
|
18
18
|
const fileUrl = String(fileUrlObject);
|
|
19
|
-
const urlInfo =
|
|
19
|
+
const urlInfo = cssUrlInfo.graph.getUrlInfo(fileUrl);
|
|
20
20
|
return urlInfo.content;
|
|
21
21
|
},
|
|
22
22
|
resolve(specifier, from) {
|
|
@@ -5,29 +5,35 @@ import { sourcemapConverter } from "@jsenv/sourcemap";
|
|
|
5
5
|
|
|
6
6
|
import { fileUrlConverter } from "../file_url_converter.js";
|
|
7
7
|
|
|
8
|
-
export const bundleJsModules = async (
|
|
8
|
+
export const bundleJsModules = async (
|
|
9
9
|
jsModuleUrlInfos,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
{
|
|
11
|
+
buildDirectoryUrl,
|
|
12
|
+
include,
|
|
13
|
+
chunks = {},
|
|
14
|
+
strictExports = false,
|
|
15
|
+
preserveDynamicImport = false,
|
|
16
|
+
augmentDynamicImportUrlSearchParams = () => {},
|
|
17
|
+
rollup,
|
|
18
|
+
rollupInput = {},
|
|
19
|
+
rollupOutput = {},
|
|
20
|
+
rollupPlugins = [],
|
|
21
|
+
},
|
|
22
|
+
) => {
|
|
21
23
|
const {
|
|
22
24
|
signal,
|
|
23
25
|
logger,
|
|
24
26
|
rootDirectoryUrl,
|
|
25
|
-
buildDirectoryUrl,
|
|
26
27
|
assetsDirectory,
|
|
27
|
-
urlGraph,
|
|
28
28
|
runtimeCompat,
|
|
29
29
|
sourcemaps,
|
|
30
|
-
|
|
30
|
+
minification,
|
|
31
|
+
isSupportedOnCurrentClients,
|
|
32
|
+
} = jsModuleUrlInfos[0].context;
|
|
33
|
+
const graph = jsModuleUrlInfos[0].graph;
|
|
34
|
+
if (buildDirectoryUrl === undefined) {
|
|
35
|
+
buildDirectoryUrl = jsModuleUrlInfos[0].context.buildDirectoryUrl;
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
let manualChunks;
|
|
33
39
|
if (Object.keys(chunks).length) {
|
|
@@ -64,7 +70,7 @@ export const bundleJsModules = async ({
|
|
|
64
70
|
rootDirectoryUrl,
|
|
65
71
|
buildDirectoryUrl,
|
|
66
72
|
assetsDirectory,
|
|
67
|
-
|
|
73
|
+
graph,
|
|
68
74
|
jsModuleUrlInfos,
|
|
69
75
|
|
|
70
76
|
runtimeCompat,
|
|
@@ -91,17 +97,16 @@ export const bundleJsModules = async ({
|
|
|
91
97
|
...rollupInput,
|
|
92
98
|
},
|
|
93
99
|
rollupOutput: {
|
|
94
|
-
compact:
|
|
95
|
-
minifyInternalExports:
|
|
100
|
+
compact: minification,
|
|
101
|
+
minifyInternalExports: minification,
|
|
96
102
|
generatedCode: {
|
|
97
|
-
arrowFunctions:
|
|
98
|
-
constBindings:
|
|
99
|
-
objectShorthand:
|
|
103
|
+
arrowFunctions: isSupportedOnCurrentClients("arrow_function"),
|
|
104
|
+
constBindings: isSupportedOnCurrentClients("const_bindings"),
|
|
105
|
+
objectShorthand: isSupportedOnCurrentClients(
|
|
100
106
|
"object_properties_shorthand",
|
|
101
107
|
),
|
|
102
|
-
reservedNamesAsProps:
|
|
103
|
-
|
|
104
|
-
symbols: context.isSupportedOnCurrentClients("symbols"),
|
|
108
|
+
reservedNamesAsProps: isSupportedOnCurrentClients("reserved_words"),
|
|
109
|
+
symbols: isSupportedOnCurrentClients("symbols"),
|
|
105
110
|
},
|
|
106
111
|
...rollupOutput,
|
|
107
112
|
manualChunks,
|
|
@@ -124,7 +129,7 @@ const rollupPluginJsenv = ({
|
|
|
124
129
|
rootDirectoryUrl,
|
|
125
130
|
buildDirectoryUrl,
|
|
126
131
|
assetsDirectory,
|
|
127
|
-
|
|
132
|
+
graph,
|
|
128
133
|
jsModuleUrlInfos,
|
|
129
134
|
sourcemaps,
|
|
130
135
|
|
|
@@ -174,16 +179,35 @@ const rollupPluginJsenv = ({
|
|
|
174
179
|
});
|
|
175
180
|
return;
|
|
176
181
|
}
|
|
182
|
+
let preserveSignature;
|
|
183
|
+
if (strictExports) {
|
|
184
|
+
preserveSignature = "strict";
|
|
185
|
+
} else {
|
|
186
|
+
// When referenced only once we can enable allow-extension
|
|
187
|
+
// otherwise stick to strict exports to ensure all importers
|
|
188
|
+
// receive the correct exports
|
|
189
|
+
let firstStrongRef = null;
|
|
190
|
+
let hasMoreThanOneStrongRefFromOther = false;
|
|
191
|
+
for (const referenceFromOther of jsModuleUrlInfo.referenceFromOthersSet) {
|
|
192
|
+
if (referenceFromOther.isWeak) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (firstStrongRef) {
|
|
196
|
+
hasMoreThanOneStrongRefFromOther = true;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
firstStrongRef = referenceFromOther;
|
|
200
|
+
}
|
|
201
|
+
preserveSignature = hasMoreThanOneStrongRefFromOther
|
|
202
|
+
? "strict"
|
|
203
|
+
: "allow-extension";
|
|
204
|
+
}
|
|
177
205
|
emitChunk({
|
|
178
206
|
id,
|
|
179
207
|
implicitlyLoadedAfterOneOf: previousNonEntryPointModuleId
|
|
180
208
|
? [previousNonEntryPointModuleId]
|
|
181
209
|
: null,
|
|
182
|
-
preserveSignature
|
|
183
|
-
? "strict"
|
|
184
|
-
: jsModuleUrlInfo.dependents.size < 2
|
|
185
|
-
? "allow-extension"
|
|
186
|
-
: "strict",
|
|
210
|
+
preserveSignature,
|
|
187
211
|
});
|
|
188
212
|
previousNonEntryPointModuleId = id;
|
|
189
213
|
});
|
|
@@ -324,7 +348,7 @@ const rollupPluginJsenv = ({
|
|
|
324
348
|
if (!importCanBeBundled(url)) {
|
|
325
349
|
return { id: url, external: true };
|
|
326
350
|
}
|
|
327
|
-
const urlInfo =
|
|
351
|
+
const urlInfo = graph.getUrlInfo(url);
|
|
328
352
|
if (!urlInfo) {
|
|
329
353
|
// happen when excluded by referenceAnalysis.include
|
|
330
354
|
return { id: url, external: true };
|
|
@@ -337,7 +361,7 @@ const rollupPluginJsenv = ({
|
|
|
337
361
|
},
|
|
338
362
|
async load(rollupId) {
|
|
339
363
|
const fileUrl = fileUrlConverter.asFileUrl(rollupId);
|
|
340
|
-
const urlInfo =
|
|
364
|
+
const urlInfo = graph.getUrlInfo(fileUrl);
|
|
341
365
|
return {
|
|
342
366
|
code: urlInfo.content,
|
|
343
367
|
map:
|
|
@@ -10,31 +10,21 @@ export const jsenvPluginBundling = ({
|
|
|
10
10
|
const bundle = {};
|
|
11
11
|
|
|
12
12
|
if (css) {
|
|
13
|
-
bundle.css = (cssUrlInfos
|
|
14
|
-
return bundleCss(
|
|
15
|
-
cssUrlInfos,
|
|
16
|
-
context,
|
|
17
|
-
});
|
|
13
|
+
bundle.css = (cssUrlInfos) => {
|
|
14
|
+
return bundleCss(cssUrlInfos);
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
17
|
if (js_classic) {
|
|
21
|
-
bundle.js_classic = (jsClassicUrlInfos
|
|
22
|
-
return bundleJsClassic(
|
|
23
|
-
jsClassicUrlInfos,
|
|
24
|
-
context,
|
|
25
|
-
});
|
|
18
|
+
bundle.js_classic = (jsClassicUrlInfos) => {
|
|
19
|
+
return bundleJsClassic(jsClassicUrlInfos);
|
|
26
20
|
};
|
|
27
21
|
}
|
|
28
22
|
if (js_module) {
|
|
29
23
|
if (js_module === true) {
|
|
30
24
|
js_module = {};
|
|
31
25
|
}
|
|
32
|
-
bundle.js_module = (jsModuleUrlInfos
|
|
33
|
-
return bundleJsModules(
|
|
34
|
-
jsModuleUrlInfos,
|
|
35
|
-
context,
|
|
36
|
-
...js_module,
|
|
37
|
-
});
|
|
26
|
+
bundle.js_module = (jsModuleUrlInfos) => {
|
|
27
|
+
return bundleJsModules(jsModuleUrlInfos, js_module);
|
|
38
28
|
};
|
|
39
29
|
}
|
|
40
30
|
|