@jsenv/plugin-bundling 2.1.7 → 2.1.9
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 +4 -4
- package/src/css/css_bundling_lightning_css.js +28 -26
- package/src/{js_module/file_url_converter.js → file_url_converter.js} +10 -10
- package/src/js_classic/bundle_js_classic.js +2 -2
- package/src/js_module/bundle_js_modules.js +121 -124
- package/src/jsenv_plugin_bundling.js +13 -13
- package/src/main.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-bundling",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@jsenv/babel-plugins": "1.1.6",
|
|
28
|
-
"@jsenv/log": "3.3.
|
|
28
|
+
"@jsenv/log": "3.3.5",
|
|
29
29
|
"@jsenv/url-meta": "8.1.0",
|
|
30
30
|
"@jsenv/urls": "2.0.0",
|
|
31
31
|
"@jsenv/sourcemap": "1.0.10",
|
|
32
|
-
"acorn-import-assertions": "1.
|
|
32
|
+
"acorn-import-assertions": "1.9.0",
|
|
33
33
|
"lightningcss": "1.20.0",
|
|
34
|
-
"rollup": "3.21.
|
|
34
|
+
"rollup": "3.21.8"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@jsenv/core": "*"
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
2
|
+
import { fileUrlConverter } from "../file_url_converter.js";
|
|
2
3
|
|
|
3
4
|
// Do not use until https://github.com/parcel-bundler/parcel-css/issues/181
|
|
4
5
|
export const bundleCss = async ({ cssUrlInfos, context }) => {
|
|
5
|
-
const bundledCssUrlInfos = {}
|
|
6
|
-
const { bundleAsync } = await import("lightningcss")
|
|
7
|
-
const targets = runtimeCompatToTargets(context.runtimeCompat)
|
|
6
|
+
const bundledCssUrlInfos = {};
|
|
7
|
+
const { bundleAsync } = await import("lightningcss");
|
|
8
|
+
const targets = runtimeCompatToTargets(context.runtimeCompat);
|
|
8
9
|
for (const cssUrlInfo of cssUrlInfos) {
|
|
10
|
+
const filename = fileUrlConverter.asFilePath(cssUrlInfo.originalUrl);
|
|
9
11
|
const { code, map } = await bundleAsync({
|
|
10
|
-
filename
|
|
12
|
+
filename,
|
|
11
13
|
targets,
|
|
12
14
|
minify: false,
|
|
13
15
|
resolver: {
|
|
14
16
|
read: (specifier) => {
|
|
15
|
-
const fileUrlObject =
|
|
16
|
-
const fileUrl = String(fileUrlObject)
|
|
17
|
-
const urlInfo = context.urlGraph.getUrlInfo(fileUrl)
|
|
18
|
-
return urlInfo.content
|
|
17
|
+
const fileUrlObject = fileUrlConverter.asFileUrl(specifier);
|
|
18
|
+
const fileUrl = String(fileUrlObject);
|
|
19
|
+
const urlInfo = context.urlGraph.getUrlInfo(fileUrl);
|
|
20
|
+
return urlInfo.content;
|
|
19
21
|
},
|
|
20
22
|
resolve(specifier, from) {
|
|
21
|
-
const fileUrlObject = new URL(specifier, pathToFileURL(from))
|
|
22
|
-
const filePath = fileURLToPath(fileUrlObject)
|
|
23
|
-
return filePath
|
|
23
|
+
const fileUrlObject = new URL(specifier, pathToFileURL(from));
|
|
24
|
+
const filePath = fileURLToPath(fileUrlObject);
|
|
25
|
+
return filePath;
|
|
24
26
|
},
|
|
25
27
|
},
|
|
26
|
-
})
|
|
28
|
+
});
|
|
27
29
|
bundledCssUrlInfos[cssUrlInfo.url] = {
|
|
28
30
|
data: {
|
|
29
31
|
bundlerName: "lightningcss",
|
|
@@ -31,26 +33,26 @@ export const bundleCss = async ({ cssUrlInfos, context }) => {
|
|
|
31
33
|
contentType: "text/css",
|
|
32
34
|
content: String(code),
|
|
33
35
|
sourcemap: map,
|
|
34
|
-
}
|
|
36
|
+
};
|
|
35
37
|
}
|
|
36
|
-
return bundledCssUrlInfos
|
|
37
|
-
}
|
|
38
|
+
return bundledCssUrlInfos;
|
|
39
|
+
};
|
|
38
40
|
|
|
39
41
|
const runtimeCompatToTargets = (runtimeCompat) => {
|
|
40
|
-
const targets = {}
|
|
41
|
-
|
|
42
|
-
const version = runtimeCompat[runtimeName]
|
|
42
|
+
const targets = {};
|
|
43
|
+
["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
|
|
44
|
+
const version = runtimeCompat[runtimeName];
|
|
43
45
|
if (version) {
|
|
44
|
-
targets[runtimeName] = versionToBits(version)
|
|
46
|
+
targets[runtimeName] = versionToBits(version);
|
|
45
47
|
}
|
|
46
|
-
})
|
|
47
|
-
return targets
|
|
48
|
-
}
|
|
48
|
+
});
|
|
49
|
+
return targets;
|
|
50
|
+
};
|
|
49
51
|
|
|
50
52
|
const versionToBits = (version) => {
|
|
51
53
|
const [major, minor = 0, patch = 0] = version
|
|
52
54
|
.split("-")[0]
|
|
53
55
|
.split(".")
|
|
54
|
-
.map((v) => parseInt(v, 10))
|
|
55
|
-
return (major << 16) | (minor << 8) | patch
|
|
56
|
-
}
|
|
56
|
+
.map((v) => parseInt(v, 10));
|
|
57
|
+
return (major << 16) | (minor << 8) | patch;
|
|
58
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { fileSystemPathToUrl, urlToFileSystemPath } from "@jsenv/urls"
|
|
1
|
+
import { fileSystemPathToUrl, urlToFileSystemPath } from "@jsenv/urls";
|
|
2
2
|
|
|
3
3
|
export const fileUrlConverter = {
|
|
4
4
|
asFilePath: (fileUrl) => {
|
|
5
|
-
const filePath = urlToFileSystemPath(fileUrl)
|
|
6
|
-
const urlObject = new URL(fileUrl)
|
|
7
|
-
const { searchParams } = urlObject
|
|
8
|
-
return `${filePath}${stringifyQuery(searchParams)}
|
|
5
|
+
const filePath = urlToFileSystemPath(fileUrl);
|
|
6
|
+
const urlObject = new URL(fileUrl);
|
|
7
|
+
const { searchParams } = urlObject;
|
|
8
|
+
return `${filePath}${stringifyQuery(searchParams)}`;
|
|
9
9
|
},
|
|
10
10
|
asFileUrl: (filePath) => {
|
|
11
11
|
return decodeURIComponent(fileSystemPathToUrl(filePath)).replace(
|
|
12
12
|
/[=](?=&|$)/g,
|
|
13
13
|
"",
|
|
14
|
-
)
|
|
14
|
+
);
|
|
15
15
|
},
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
const stringifyQuery = (searchParams) => {
|
|
19
|
-
const search = searchParams.toString()
|
|
20
|
-
return search ? `?${search}` : ""
|
|
21
|
-
}
|
|
19
|
+
const search = searchParams.toString();
|
|
20
|
+
return search ? `?${search}` : "";
|
|
21
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url"
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
2
|
|
|
3
|
-
import { URL_META } from "@jsenv/url-meta"
|
|
4
|
-
import { isFileSystemPath } from "@jsenv/urls"
|
|
5
|
-
import { createDetailedMessage } from "@jsenv/log"
|
|
6
|
-
import { sourcemapConverter } from "@jsenv/sourcemap"
|
|
7
|
-
import { globalThisClientFileUrl } from "@jsenv/core/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js"
|
|
3
|
+
import { URL_META } from "@jsenv/url-meta";
|
|
4
|
+
import { isFileSystemPath } from "@jsenv/urls";
|
|
5
|
+
import { createDetailedMessage } from "@jsenv/log";
|
|
6
|
+
import { sourcemapConverter } from "@jsenv/sourcemap";
|
|
7
|
+
import { globalThisClientFileUrl } from "@jsenv/core/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js";
|
|
8
8
|
|
|
9
|
-
import { fileUrlConverter } from "
|
|
9
|
+
import { fileUrlConverter } from "../file_url_converter.js";
|
|
10
10
|
|
|
11
11
|
export const bundleJsModules = async ({
|
|
12
12
|
jsModuleUrlInfos,
|
|
@@ -30,32 +30,32 @@ export const bundleJsModules = async ({
|
|
|
30
30
|
urlGraph,
|
|
31
31
|
runtimeCompat,
|
|
32
32
|
sourcemaps,
|
|
33
|
-
} = context
|
|
33
|
+
} = context;
|
|
34
34
|
|
|
35
|
-
let manualChunks
|
|
35
|
+
let manualChunks;
|
|
36
36
|
if (Object.keys(chunks).length) {
|
|
37
|
-
const associations = URL_META.resolveAssociations(chunks, rootDirectoryUrl)
|
|
37
|
+
const associations = URL_META.resolveAssociations(chunks, rootDirectoryUrl);
|
|
38
38
|
manualChunks = (id) => {
|
|
39
39
|
if (rollupOutput.manualChunks) {
|
|
40
|
-
const manualChunkName = rollupOutput.manualChunks(id)
|
|
40
|
+
const manualChunkName = rollupOutput.manualChunks(id);
|
|
41
41
|
if (manualChunkName) {
|
|
42
|
-
return manualChunkName
|
|
42
|
+
return manualChunkName;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
const url = fileUrlConverter.asFileUrl(id)
|
|
46
|
-
const urlObject = new URL(url)
|
|
47
|
-
urlObject.search = ""
|
|
48
|
-
const urlWithoutSearch = urlObject.href
|
|
45
|
+
const url = fileUrlConverter.asFileUrl(id);
|
|
46
|
+
const urlObject = new URL(url);
|
|
47
|
+
urlObject.search = "";
|
|
48
|
+
const urlWithoutSearch = urlObject.href;
|
|
49
49
|
const meta = URL_META.applyAssociations({
|
|
50
50
|
url: urlWithoutSearch,
|
|
51
51
|
associations,
|
|
52
|
-
})
|
|
53
|
-
const chunkName = Object.keys(meta).find((key) => meta[key])
|
|
54
|
-
return chunkName || null
|
|
55
|
-
}
|
|
52
|
+
});
|
|
53
|
+
const chunkName = Object.keys(meta).find((key) => meta[key]);
|
|
54
|
+
return chunkName || null;
|
|
55
|
+
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const resultRef = { current: null }
|
|
58
|
+
const resultRef = { current: null };
|
|
59
59
|
try {
|
|
60
60
|
await applyRollupPlugins({
|
|
61
61
|
rollup,
|
|
@@ -83,29 +83,25 @@ export const bundleJsModules = async ({
|
|
|
83
83
|
input: [],
|
|
84
84
|
onwarn: (warning) => {
|
|
85
85
|
if (warning.code === "CIRCULAR_DEPENDENCY") {
|
|
86
|
-
return
|
|
86
|
+
return;
|
|
87
87
|
}
|
|
88
88
|
if (warning.code === "THIS_IS_UNDEFINED") {
|
|
89
|
-
const fileUrl = pathToFileURL(warning.id).href
|
|
89
|
+
const fileUrl = pathToFileURL(warning.id).href;
|
|
90
90
|
if (fileUrl === globalThisClientFileUrl) {
|
|
91
|
-
return
|
|
91
|
+
return;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
if (warning.code === "EVAL") {
|
|
95
95
|
// ideally we should disable only for jsenv files
|
|
96
|
-
return
|
|
96
|
+
return;
|
|
97
97
|
}
|
|
98
|
-
logger.warn(String(warning))
|
|
98
|
+
logger.warn(String(warning));
|
|
99
99
|
},
|
|
100
100
|
...rollupInput,
|
|
101
101
|
},
|
|
102
102
|
rollupOutput: {
|
|
103
103
|
compact: context.minification,
|
|
104
|
-
|
|
105
|
-
// - rollup rename InlineContent export into one letter export like "n"
|
|
106
|
-
// - inline content detection cannot detect new InlineContent() calls
|
|
107
|
-
// -> inline content is not detected, among other things url are not versioned
|
|
108
|
-
minifyInternalExports: false, // context.minification,
|
|
104
|
+
minifyInternalExports: context.minification,
|
|
109
105
|
generatedCode: {
|
|
110
106
|
arrowFunctions: context.isSupportedOnCurrentClients("arrow_function"),
|
|
111
107
|
constBindings: context.isSupportedOnCurrentClients("const_bindings"),
|
|
@@ -119,18 +115,18 @@ export const bundleJsModules = async ({
|
|
|
119
115
|
...rollupOutput,
|
|
120
116
|
manualChunks,
|
|
121
117
|
},
|
|
122
|
-
})
|
|
123
|
-
return resultRef.current.jsModuleBundleUrlInfos
|
|
118
|
+
});
|
|
119
|
+
return resultRef.current.jsModuleBundleUrlInfos;
|
|
124
120
|
} catch (e) {
|
|
125
121
|
if (e.code === "MISSING_EXPORT") {
|
|
126
122
|
const detailedMessage = createDetailedMessage(e.message, {
|
|
127
123
|
frame: e.frame,
|
|
128
|
-
})
|
|
129
|
-
throw new Error(detailedMessage, { cause: e })
|
|
124
|
+
});
|
|
125
|
+
throw new Error(detailedMessage, { cause: e });
|
|
130
126
|
}
|
|
131
|
-
throw e
|
|
127
|
+
throw e;
|
|
132
128
|
}
|
|
133
|
-
}
|
|
129
|
+
};
|
|
134
130
|
|
|
135
131
|
const rollupPluginJsenv = ({
|
|
136
132
|
// logger,
|
|
@@ -149,43 +145,43 @@ const rollupPluginJsenv = ({
|
|
|
149
145
|
resultRef,
|
|
150
146
|
}) => {
|
|
151
147
|
let _rollupEmitFile = () => {
|
|
152
|
-
throw new Error("not implemented")
|
|
153
|
-
}
|
|
148
|
+
throw new Error("not implemented");
|
|
149
|
+
};
|
|
154
150
|
const format = jsModuleUrlInfos.some((jsModuleUrlInfo) =>
|
|
155
151
|
jsModuleUrlInfo.filename.endsWith(".cjs"),
|
|
156
152
|
)
|
|
157
153
|
? "cjs"
|
|
158
|
-
: "esm"
|
|
154
|
+
: "esm";
|
|
159
155
|
const emitChunk = (chunk) => {
|
|
160
156
|
return _rollupEmitFile({
|
|
161
157
|
type: "chunk",
|
|
162
158
|
...chunk,
|
|
163
|
-
})
|
|
164
|
-
}
|
|
165
|
-
let importCanBeBundled = () => true
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
let importCanBeBundled = () => true;
|
|
166
162
|
if (include) {
|
|
167
163
|
const associations = URL_META.resolveAssociations(
|
|
168
164
|
{ bundle: include },
|
|
169
165
|
rootDirectoryUrl,
|
|
170
|
-
)
|
|
166
|
+
);
|
|
171
167
|
importCanBeBundled = (url) => {
|
|
172
|
-
return URL_META.applyAssociations({ url, associations }).bundle
|
|
173
|
-
}
|
|
168
|
+
return URL_META.applyAssociations({ url, associations }).bundle;
|
|
169
|
+
};
|
|
174
170
|
}
|
|
175
|
-
const urlImporters = {}
|
|
171
|
+
const urlImporters = {};
|
|
176
172
|
|
|
177
173
|
return {
|
|
178
174
|
name: "jsenv",
|
|
179
175
|
async buildStart() {
|
|
180
|
-
_rollupEmitFile = (...args) => this.emitFile(...args)
|
|
181
|
-
let previousNonEntryPointModuleId
|
|
176
|
+
_rollupEmitFile = (...args) => this.emitFile(...args);
|
|
177
|
+
let previousNonEntryPointModuleId;
|
|
182
178
|
jsModuleUrlInfos.forEach((jsModuleUrlInfo) => {
|
|
183
|
-
const id = jsModuleUrlInfo.url
|
|
179
|
+
const id = jsModuleUrlInfo.url;
|
|
184
180
|
if (jsModuleUrlInfo.isEntryPoint) {
|
|
185
181
|
emitChunk({
|
|
186
182
|
id,
|
|
187
|
-
})
|
|
188
|
-
return
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
189
185
|
}
|
|
190
186
|
emitChunk({
|
|
191
187
|
id,
|
|
@@ -197,33 +193,33 @@ const rollupPluginJsenv = ({
|
|
|
197
193
|
: jsModuleUrlInfo.dependents.size < 2
|
|
198
194
|
? "allow-extension"
|
|
199
195
|
: "strict",
|
|
200
|
-
})
|
|
201
|
-
previousNonEntryPointModuleId = id
|
|
202
|
-
})
|
|
196
|
+
});
|
|
197
|
+
previousNonEntryPointModuleId = id;
|
|
198
|
+
});
|
|
203
199
|
},
|
|
204
200
|
async generateBundle(outputOptions, rollupResult) {
|
|
205
|
-
_rollupEmitFile = (...args) => this.emitFile(...args)
|
|
201
|
+
_rollupEmitFile = (...args) => this.emitFile(...args);
|
|
206
202
|
|
|
207
|
-
const jsModuleBundleUrlInfos = {}
|
|
203
|
+
const jsModuleBundleUrlInfos = {};
|
|
208
204
|
Object.keys(rollupResult).forEach((fileName) => {
|
|
209
|
-
const rollupFileInfo = rollupResult[fileName]
|
|
205
|
+
const rollupFileInfo = rollupResult[fileName];
|
|
210
206
|
// there is 3 types of file: "placeholder", "asset", "chunk"
|
|
211
207
|
if (rollupFileInfo.type === "chunk") {
|
|
212
208
|
const sourceUrls = Object.keys(rollupFileInfo.modules).map((id) =>
|
|
213
209
|
fileUrlConverter.asFileUrl(id),
|
|
214
|
-
)
|
|
210
|
+
);
|
|
215
211
|
|
|
216
|
-
let url
|
|
217
|
-
let originalUrl
|
|
212
|
+
let url;
|
|
213
|
+
let originalUrl;
|
|
218
214
|
if (rollupFileInfo.facadeModuleId) {
|
|
219
|
-
url = fileUrlConverter.asFileUrl(rollupFileInfo.facadeModuleId)
|
|
220
|
-
originalUrl = url
|
|
215
|
+
url = fileUrlConverter.asFileUrl(rollupFileInfo.facadeModuleId);
|
|
216
|
+
originalUrl = url;
|
|
221
217
|
} else {
|
|
222
|
-
url = new URL(rollupFileInfo.fileName, buildDirectoryUrl).href
|
|
218
|
+
url = new URL(rollupFileInfo.fileName, buildDirectoryUrl).href;
|
|
223
219
|
if (rollupFileInfo.isDynamicEntry) {
|
|
224
|
-
originalUrl = sourceUrls[sourceUrls.length - 1]
|
|
220
|
+
originalUrl = sourceUrls[sourceUrls.length - 1];
|
|
225
221
|
} else {
|
|
226
|
-
originalUrl = url
|
|
222
|
+
originalUrl = url;
|
|
227
223
|
}
|
|
228
224
|
}
|
|
229
225
|
|
|
@@ -243,13 +239,13 @@ const rollupPluginJsenv = ({
|
|
|
243
239
|
contentType: "text/javascript",
|
|
244
240
|
content: rollupFileInfo.code,
|
|
245
241
|
sourcemap: rollupFileInfo.map,
|
|
246
|
-
}
|
|
247
|
-
jsModuleBundleUrlInfos[url] = jsModuleBundleUrlInfo
|
|
242
|
+
};
|
|
243
|
+
jsModuleBundleUrlInfos[url] = jsModuleBundleUrlInfo;
|
|
248
244
|
}
|
|
249
|
-
})
|
|
245
|
+
});
|
|
250
246
|
resultRef.current = {
|
|
251
247
|
jsModuleBundleUrlInfos,
|
|
252
|
-
}
|
|
248
|
+
};
|
|
253
249
|
},
|
|
254
250
|
outputOptions: (outputOptions) => {
|
|
255
251
|
// const sourcemapFile = buildDirectoryUrl
|
|
@@ -259,97 +255,98 @@ const rollupPluginJsenv = ({
|
|
|
259
255
|
sourcemap: sourcemaps === "file" || sourcemaps === "inline",
|
|
260
256
|
// sourcemapFile,
|
|
261
257
|
sourcemapPathTransform: (relativePath) => {
|
|
262
|
-
return new URL(relativePath, buildDirectoryUrl).href
|
|
258
|
+
return new URL(relativePath, buildDirectoryUrl).href;
|
|
263
259
|
},
|
|
264
260
|
entryFileNames: () => {
|
|
265
|
-
return `[name].js
|
|
261
|
+
return `[name].js`;
|
|
266
262
|
},
|
|
267
263
|
chunkFileNames: (chunkInfo) => {
|
|
268
264
|
const insideJs = willBeInsideJsDirectory({
|
|
269
265
|
chunkInfo,
|
|
270
266
|
fileUrlConverter,
|
|
271
267
|
jsModuleUrlInfos,
|
|
272
|
-
})
|
|
273
|
-
let nameFromUrlInfo
|
|
268
|
+
});
|
|
269
|
+
let nameFromUrlInfo;
|
|
274
270
|
if (chunkInfo.facadeModuleId) {
|
|
275
|
-
const url = fileUrlConverter.asFileUrl(chunkInfo.facadeModuleId)
|
|
271
|
+
const url = fileUrlConverter.asFileUrl(chunkInfo.facadeModuleId);
|
|
276
272
|
const urlInfo = jsModuleUrlInfos.find(
|
|
277
273
|
(jsModuleUrlInfo) => jsModuleUrlInfo.url === url,
|
|
278
|
-
)
|
|
274
|
+
);
|
|
279
275
|
if (urlInfo) {
|
|
280
|
-
nameFromUrlInfo = urlInfo.filename
|
|
276
|
+
nameFromUrlInfo = urlInfo.filename;
|
|
281
277
|
}
|
|
282
278
|
}
|
|
283
|
-
const name = nameFromUrlInfo || `${chunkInfo.name}.js
|
|
284
|
-
return insideJs ? `${assetsDirectory}js/${name}` : `${name}
|
|
279
|
+
const name = nameFromUrlInfo || `${chunkInfo.name}.js`;
|
|
280
|
+
return insideJs ? `${assetsDirectory}js/${name}` : `${name}`;
|
|
285
281
|
},
|
|
286
282
|
// https://rollupjs.org/guide/en/#outputpaths
|
|
287
283
|
// paths: (id) => {
|
|
288
284
|
// return id
|
|
289
285
|
// },
|
|
290
|
-
})
|
|
286
|
+
});
|
|
291
287
|
},
|
|
292
288
|
// https://rollupjs.org/guide/en/#resolvedynamicimport
|
|
293
289
|
resolveDynamicImport: (specifier, importer) => {
|
|
294
290
|
if (preserveDynamicImport) {
|
|
295
|
-
let urlObject
|
|
291
|
+
let urlObject;
|
|
296
292
|
if (specifier[0] === "/") {
|
|
297
|
-
urlObject = new URL(specifier.slice(1), rootDirectoryUrl)
|
|
293
|
+
urlObject = new URL(specifier.slice(1), rootDirectoryUrl);
|
|
298
294
|
} else {
|
|
299
295
|
if (isFileSystemPath(importer)) {
|
|
300
|
-
importer = fileUrlConverter.asFileUrl(importer)
|
|
296
|
+
importer = fileUrlConverter.asFileUrl(importer);
|
|
301
297
|
}
|
|
302
|
-
urlObject = new URL(specifier, importer)
|
|
298
|
+
urlObject = new URL(specifier, importer);
|
|
303
299
|
}
|
|
304
|
-
const searchParamsToAdd =
|
|
300
|
+
const searchParamsToAdd =
|
|
301
|
+
augmentDynamicImportUrlSearchParams(urlObject);
|
|
305
302
|
if (searchParamsToAdd) {
|
|
306
303
|
Object.keys(searchParamsToAdd).forEach((key) => {
|
|
307
|
-
const value = searchParamsToAdd[key]
|
|
304
|
+
const value = searchParamsToAdd[key];
|
|
308
305
|
if (value === undefined) {
|
|
309
|
-
urlObject.searchParams.delete(key)
|
|
306
|
+
urlObject.searchParams.delete(key);
|
|
310
307
|
} else {
|
|
311
|
-
urlObject.searchParams.set(key, value)
|
|
308
|
+
urlObject.searchParams.set(key, value);
|
|
312
309
|
}
|
|
313
|
-
})
|
|
310
|
+
});
|
|
314
311
|
}
|
|
315
|
-
return { external: true, id: urlObject.href }
|
|
312
|
+
return { external: true, id: urlObject.href };
|
|
316
313
|
}
|
|
317
|
-
return null
|
|
314
|
+
return null;
|
|
318
315
|
},
|
|
319
316
|
resolveId: (specifier, importer = rootDirectoryUrl) => {
|
|
320
317
|
if (isFileSystemPath(importer)) {
|
|
321
|
-
importer = fileUrlConverter.asFileUrl(importer)
|
|
318
|
+
importer = fileUrlConverter.asFileUrl(importer);
|
|
322
319
|
}
|
|
323
|
-
let url
|
|
320
|
+
let url;
|
|
324
321
|
if (specifier[0] === "/") {
|
|
325
|
-
url = new URL(specifier.slice(1), rootDirectoryUrl).href
|
|
322
|
+
url = new URL(specifier.slice(1), rootDirectoryUrl).href;
|
|
326
323
|
} else {
|
|
327
|
-
url = new URL(specifier, importer).href
|
|
324
|
+
url = new URL(specifier, importer).href;
|
|
328
325
|
}
|
|
329
|
-
const existingImporter = urlImporters[url]
|
|
326
|
+
const existingImporter = urlImporters[url];
|
|
330
327
|
if (!existingImporter) {
|
|
331
|
-
urlImporters[url] = importer
|
|
328
|
+
urlImporters[url] = importer;
|
|
332
329
|
}
|
|
333
330
|
if (!url.startsWith("file:")) {
|
|
334
|
-
return { id: url, external: true }
|
|
331
|
+
return { id: url, external: true };
|
|
335
332
|
}
|
|
336
333
|
if (!importCanBeBundled(url)) {
|
|
337
|
-
return { id: url, external: true }
|
|
334
|
+
return { id: url, external: true };
|
|
338
335
|
}
|
|
339
|
-
const urlInfo = urlGraph.getUrlInfo(url)
|
|
336
|
+
const urlInfo = urlGraph.getUrlInfo(url);
|
|
340
337
|
if (!urlInfo) {
|
|
341
|
-
// happen when excluded by
|
|
342
|
-
return { id: url, external: true }
|
|
338
|
+
// happen when excluded by referenceAnalysis.include
|
|
339
|
+
return { id: url, external: true };
|
|
343
340
|
}
|
|
344
341
|
if (!urlInfo.shouldHandle) {
|
|
345
|
-
return { id: url, external: true }
|
|
342
|
+
return { id: url, external: true };
|
|
346
343
|
}
|
|
347
|
-
const filePath = fileUrlConverter.asFilePath(url)
|
|
348
|
-
return filePath
|
|
344
|
+
const filePath = fileUrlConverter.asFilePath(url);
|
|
345
|
+
return filePath;
|
|
349
346
|
},
|
|
350
347
|
async load(rollupId) {
|
|
351
|
-
const fileUrl = fileUrlConverter.asFileUrl(rollupId)
|
|
352
|
-
const urlInfo = urlGraph.getUrlInfo(fileUrl)
|
|
348
|
+
const fileUrl = fileUrlConverter.asFileUrl(rollupId);
|
|
349
|
+
const urlInfo = urlGraph.getUrlInfo(fileUrl);
|
|
353
350
|
return {
|
|
354
351
|
code: urlInfo.content,
|
|
355
352
|
map:
|
|
@@ -357,10 +354,10 @@ const rollupPluginJsenv = ({
|
|
|
357
354
|
urlInfo.sourcemap
|
|
358
355
|
? sourcemapConverter.toFilePaths(urlInfo.sourcemap)
|
|
359
356
|
: null,
|
|
360
|
-
}
|
|
357
|
+
};
|
|
361
358
|
},
|
|
362
|
-
}
|
|
363
|
-
}
|
|
359
|
+
};
|
|
360
|
+
};
|
|
364
361
|
|
|
365
362
|
const applyRollupPlugins = async ({
|
|
366
363
|
rollup,
|
|
@@ -369,10 +366,10 @@ const applyRollupPlugins = async ({
|
|
|
369
366
|
rollupOutput,
|
|
370
367
|
}) => {
|
|
371
368
|
if (!rollup) {
|
|
372
|
-
const rollupModule = await import("rollup")
|
|
373
|
-
rollup = rollupModule.rollup
|
|
369
|
+
const rollupModule = await import("rollup");
|
|
370
|
+
rollup = rollupModule.rollup;
|
|
374
371
|
}
|
|
375
|
-
const { importAssertions } = await import("acorn-import-assertions")
|
|
372
|
+
const { importAssertions } = await import("acorn-import-assertions");
|
|
376
373
|
const rollupReturnValue = await rollup({
|
|
377
374
|
...rollupInput,
|
|
378
375
|
plugins: rollupPlugins,
|
|
@@ -380,10 +377,10 @@ const applyRollupPlugins = async ({
|
|
|
380
377
|
importAssertions,
|
|
381
378
|
...(rollupInput.acornInjectPlugins || []),
|
|
382
379
|
],
|
|
383
|
-
})
|
|
384
|
-
const rollupOutputArray = await rollupReturnValue.generate(rollupOutput)
|
|
385
|
-
return rollupOutputArray
|
|
386
|
-
}
|
|
380
|
+
});
|
|
381
|
+
const rollupOutputArray = await rollupReturnValue.generate(rollupOutput);
|
|
382
|
+
return rollupOutputArray;
|
|
383
|
+
};
|
|
387
384
|
|
|
388
385
|
const willBeInsideJsDirectory = ({
|
|
389
386
|
chunkInfo,
|
|
@@ -396,19 +393,19 @@ const willBeInsideJsDirectory = ({
|
|
|
396
393
|
// both will be inside the js/ directory
|
|
397
394
|
if (!chunkInfo.facadeModuleId) {
|
|
398
395
|
// generated by rollup
|
|
399
|
-
return true
|
|
396
|
+
return true;
|
|
400
397
|
}
|
|
401
|
-
const url = fileUrlConverter.asFileUrl(chunkInfo.facadeModuleId)
|
|
398
|
+
const url = fileUrlConverter.asFileUrl(chunkInfo.facadeModuleId);
|
|
402
399
|
const jsModuleUrlInfo = jsModuleUrlInfos.find(
|
|
403
400
|
(jsModuleUrlInfo) => jsModuleUrlInfo.url === url,
|
|
404
|
-
)
|
|
401
|
+
);
|
|
405
402
|
if (!jsModuleUrlInfo) {
|
|
406
403
|
// generated by rollup
|
|
407
|
-
return true
|
|
404
|
+
return true;
|
|
408
405
|
}
|
|
409
406
|
if (!jsModuleUrlInfo.isEntryPoint) {
|
|
410
407
|
// not an entry point, jsenv will put it inside js/ directory
|
|
411
|
-
return true
|
|
408
|
+
return true;
|
|
412
409
|
}
|
|
413
|
-
return false
|
|
414
|
-
}
|
|
410
|
+
return false;
|
|
411
|
+
};
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { bundleCss } from "./css/css_bundling_lightning_css.js"
|
|
2
|
-
import { bundleJsClassic } from "./js_classic/bundle_js_classic.js"
|
|
3
|
-
import { bundleJsModules } from "./js_module/bundle_js_modules.js"
|
|
1
|
+
import { bundleCss } from "./css/css_bundling_lightning_css.js";
|
|
2
|
+
import { bundleJsClassic } from "./js_classic/bundle_js_classic.js";
|
|
3
|
+
import { bundleJsModules } from "./js_module/bundle_js_modules.js";
|
|
4
4
|
|
|
5
5
|
export const jsenvPluginBundling = ({
|
|
6
6
|
css = {},
|
|
7
7
|
js_classic = {},
|
|
8
8
|
js_module = {},
|
|
9
9
|
} = {}) => {
|
|
10
|
-
const bundle = {}
|
|
10
|
+
const bundle = {};
|
|
11
11
|
|
|
12
12
|
if (css) {
|
|
13
13
|
bundle.css = (cssUrlInfos, context) => {
|
|
14
14
|
return bundleCss({
|
|
15
15
|
cssUrlInfos,
|
|
16
16
|
context,
|
|
17
|
-
})
|
|
18
|
-
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
20
|
if (js_classic) {
|
|
21
21
|
bundle.js_classic = (jsClassicUrlInfos, context) => {
|
|
22
22
|
return bundleJsClassic({
|
|
23
23
|
jsClassicUrlInfos,
|
|
24
24
|
context,
|
|
25
|
-
})
|
|
26
|
-
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
27
|
}
|
|
28
28
|
if (js_module) {
|
|
29
29
|
if (js_module === true) {
|
|
30
|
-
js_module = {}
|
|
30
|
+
js_module = {};
|
|
31
31
|
}
|
|
32
32
|
bundle.js_module = (jsModuleUrlInfos, context) => {
|
|
33
33
|
return bundleJsModules({
|
|
34
34
|
jsModuleUrlInfos,
|
|
35
35
|
context,
|
|
36
36
|
...js_module,
|
|
37
|
-
})
|
|
38
|
-
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return {
|
|
42
42
|
name: "jsenv:bundling",
|
|
43
43
|
appliesDuring: "build",
|
|
44
44
|
bundle,
|
|
45
|
-
}
|
|
46
|
-
}
|
|
45
|
+
};
|
|
46
|
+
};
|
package/src/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { jsenvPluginBundling } from "./jsenv_plugin_bundling.js"
|
|
2
|
-
export { bundleJsModules } from "./js_module/bundle_js_modules.js"
|
|
1
|
+
export { jsenvPluginBundling } from "./jsenv_plugin_bundling.js";
|
|
2
|
+
export { bundleJsModules } from "./js_module/bundle_js_modules.js";
|