@jsenv/core 40.0.7 → 40.0.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/dist/build/build.js +10765 -0
- package/dist/jsenv_core.js +25 -13
- package/dist/jsenv_core_packages.js +16728 -7022
- package/dist/{js → start_build_server}/start_build_server.js +7 -8
- package/dist/{plugins.js → start_dev_server/start_dev_server.js} +964 -25
- package/package.json +11 -11
- package/src/build/build.js +15 -14
- package/src/build/build_specifier_manager.js +4 -0
- package/src/build/build_urls_generator.js +4 -0
- package/src/build/jsenv_plugin_mappings.js +69 -0
- package/src/build/jsenv_plugin_subbuilds.js +4 -0
- package/src/kitchen/kitchen.js +12 -0
- package/src/kitchen/out_directory_url.js +1 -0
- package/src/plugins/protocol_http/jsenv_plugin_protocol_http.js +6 -0
- package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +6 -1
- package/dist/js/build.js +0 -2636
- package/dist/js/start_dev_server.js +0 -840
- package/dist/main.js +0 -117
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "40.0.
|
|
3
|
+
"version": "40.0.9",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -78,22 +78,22 @@
|
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
80
80
|
"@jsenv/abort": "4.3.1",
|
|
81
|
-
"@jsenv/ast": "6.6.
|
|
82
|
-
"@jsenv/filesystem": "4.14.
|
|
81
|
+
"@jsenv/ast": "6.6.6",
|
|
82
|
+
"@jsenv/filesystem": "4.14.5",
|
|
83
83
|
"@jsenv/humanize": "1.3.1",
|
|
84
84
|
"@jsenv/importmap": "1.2.2",
|
|
85
85
|
"@jsenv/integrity": "0.0.2",
|
|
86
|
-
"@jsenv/js-module-fallback": "1.4.
|
|
86
|
+
"@jsenv/js-module-fallback": "1.4.4",
|
|
87
87
|
"@jsenv/node-esm-resolution": "1.1.0",
|
|
88
|
-
"@jsenv/plugin-bundling": "2.8.
|
|
88
|
+
"@jsenv/plugin-bundling": "2.8.6",
|
|
89
89
|
"@jsenv/plugin-minification": "1.6.2",
|
|
90
|
-
"@jsenv/plugin-supervisor": "1.6.
|
|
91
|
-
"@jsenv/plugin-transpilation": "1.5.
|
|
90
|
+
"@jsenv/plugin-supervisor": "1.6.11",
|
|
91
|
+
"@jsenv/plugin-transpilation": "1.5.7",
|
|
92
92
|
"@jsenv/runtime-compat": "1.3.4",
|
|
93
|
-
"@jsenv/server": "16.0.
|
|
94
|
-
"@jsenv/sourcemap": "1.3.
|
|
95
|
-
"@jsenv/url-meta": "8.5.
|
|
96
|
-
"@jsenv/urls": "2.
|
|
93
|
+
"@jsenv/server": "16.0.5",
|
|
94
|
+
"@jsenv/sourcemap": "1.3.3",
|
|
95
|
+
"@jsenv/url-meta": "8.5.6",
|
|
96
|
+
"@jsenv/urls": "2.7.0",
|
|
97
97
|
"@jsenv/utils": "2.2.1",
|
|
98
98
|
"string-width": "7.2.0"
|
|
99
99
|
},
|
package/src/build/build.js
CHANGED
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
} from "./build_params.js";
|
|
51
51
|
import { createBuildSpecifierManager } from "./build_specifier_manager.js";
|
|
52
52
|
import { jsenvPluginLineBreakNormalization } from "./jsenv_plugin_line_break_normalization.js";
|
|
53
|
+
import { jsenvPluginMappings } from "./jsenv_plugin_mappings.js";
|
|
53
54
|
import { jsenvPluginSubbuilds } from "./jsenv_plugin_subbuilds.js";
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -99,6 +100,7 @@ export const build = async ({
|
|
|
99
100
|
base = getDefaultBase(runtimeCompat),
|
|
100
101
|
ignore,
|
|
101
102
|
|
|
103
|
+
mappings,
|
|
102
104
|
subbuilds = [],
|
|
103
105
|
plugins = [],
|
|
104
106
|
referenceAnalysis = {},
|
|
@@ -179,7 +181,7 @@ export const build = async ({
|
|
|
179
181
|
outDirectoryUrl = `${packageDirectoryUrl}.jsenv/`;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
|
-
} else if (outDirectoryUrl
|
|
184
|
+
} else if (outDirectoryUrl) {
|
|
183
185
|
outDirectoryUrl = assertAndNormalizeDirectoryUrl(
|
|
184
186
|
outDirectoryUrl,
|
|
185
187
|
"outDirectoryUrl",
|
|
@@ -298,6 +300,7 @@ build ${entryPointKeys.length} entry points`);
|
|
|
298
300
|
let subbuildResults = [];
|
|
299
301
|
|
|
300
302
|
const rawPluginStore = createPluginStore([
|
|
303
|
+
...(mappings ? [jsenvPluginMappings(mappings)] : []),
|
|
301
304
|
...jsenvPluginSubbuilds(subbuilds, {
|
|
302
305
|
parentBuildParams: {
|
|
303
306
|
sourceDirectoryUrl,
|
|
@@ -307,6 +310,7 @@ build ${entryPointKeys.length} entry points`);
|
|
|
307
310
|
minification,
|
|
308
311
|
versioning,
|
|
309
312
|
versioningMethod,
|
|
313
|
+
outDirectoryUrl,
|
|
310
314
|
},
|
|
311
315
|
onCustomBuildDirectory: (subBuildRelativeUrl) => {
|
|
312
316
|
buildDirectoryCleanPatterns = {
|
|
@@ -528,30 +532,27 @@ build ${entryPointKeys.length} entry points`);
|
|
|
528
532
|
}
|
|
529
533
|
const referencedUrlInfo = referenceToOther.urlInfo;
|
|
530
534
|
if (referencedUrlInfo.isInline) {
|
|
531
|
-
if (referencedUrlInfo.type
|
|
532
|
-
|
|
533
|
-
referencedUrlInfo.referenceToOthersSet.forEach(
|
|
534
|
-
(jsModuleReferenceToOther) => {
|
|
535
|
-
if (jsModuleReferenceToOther.type === "js_import") {
|
|
536
|
-
const inlineUrlInfo = jsModuleReferenceToOther.urlInfo;
|
|
537
|
-
addToBundlerIfAny(inlineUrlInfo);
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
);
|
|
535
|
+
if (referencedUrlInfo.type !== "js_module") {
|
|
536
|
+
continue;
|
|
541
537
|
}
|
|
542
|
-
|
|
538
|
+
addToBundlerIfAny(referencedUrlInfo);
|
|
543
539
|
continue;
|
|
544
540
|
}
|
|
545
541
|
addToBundlerIfAny(referencedUrlInfo);
|
|
546
542
|
}
|
|
547
543
|
return;
|
|
548
544
|
}
|
|
549
|
-
// File referenced with
|
|
545
|
+
// File referenced with
|
|
546
|
+
// - new URL("./file.js", import.meta.url)
|
|
547
|
+
// - import.meta.resolve("./file.js")
|
|
550
548
|
// are entry points that should be bundled
|
|
551
549
|
// For instance we will bundle service worker/workers detected like this
|
|
552
550
|
if (rawUrlInfo.type === "js_module") {
|
|
553
551
|
for (const referenceToOther of rawUrlInfo.referenceToOthersSet) {
|
|
554
|
-
if (
|
|
552
|
+
if (
|
|
553
|
+
referenceToOther.type === "js_url" ||
|
|
554
|
+
referenceToOther.subtype === "import_meta_resolve"
|
|
555
|
+
) {
|
|
555
556
|
const referencedUrlInfo = referenceToOther.urlInfo;
|
|
556
557
|
let isAlreadyBundled = false;
|
|
557
558
|
for (const referenceFromOther of referencedUrlInfo.referenceFromOthersSet) {
|
|
@@ -238,6 +238,7 @@ export const createBuildSpecifierManager = ({
|
|
|
238
238
|
js_classic: undefined, // TODO: add comment to explain who is using this
|
|
239
239
|
entry_point: undefined,
|
|
240
240
|
dynamic_import: undefined,
|
|
241
|
+
dynamic_import_id: undefined,
|
|
241
242
|
};
|
|
242
243
|
},
|
|
243
244
|
formatReference: (reference) => {
|
|
@@ -276,6 +277,9 @@ export const createBuildSpecifierManager = ({
|
|
|
276
277
|
const bundleInfo = bundleInfoMap.get(rawUrl);
|
|
277
278
|
if (bundleInfo) {
|
|
278
279
|
finalUrlInfo.remapReference = bundleInfo.remapReference;
|
|
280
|
+
if (!finalUrlInfo.filenameHint && bundleInfo.data.bundleRelativeUrl) {
|
|
281
|
+
finalUrlInfo.filenameHint = bundleInfo.data.bundleRelativeUrl;
|
|
282
|
+
}
|
|
279
283
|
return {
|
|
280
284
|
// url: bundleInfo.url,
|
|
281
285
|
originalUrl: bundleInfo.originalUrl,
|
|
@@ -131,6 +131,10 @@ const determineDirectoryPath = ({
|
|
|
131
131
|
});
|
|
132
132
|
return parentDirectoryPath;
|
|
133
133
|
}
|
|
134
|
+
const dynamicImportId = urlInfo.searchParams.get("dynamic_import_id");
|
|
135
|
+
if (dynamicImportId) {
|
|
136
|
+
return `${assetsDirectory}${dynamicImportId}/`;
|
|
137
|
+
}
|
|
134
138
|
if (urlInfo.isEntryPoint && !urlInfo.isDynamicEntryPoint) {
|
|
135
139
|
return "";
|
|
136
140
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { URL_META } from "@jsenv/url-meta";
|
|
2
|
+
|
|
3
|
+
export const jsenvPluginMappings = (mappings) => {
|
|
4
|
+
if (!mappings || Object.keys(mappings).length === 0) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const mappingResolvedMap = new Map();
|
|
9
|
+
return {
|
|
10
|
+
name: "jsenv:mappings",
|
|
11
|
+
appliesDuring: "build",
|
|
12
|
+
init: (context) => {
|
|
13
|
+
const kitchen = context.kitchen;
|
|
14
|
+
const sourceDirectoryUrl = context.rootDirectoryUrl;
|
|
15
|
+
for (const key of Object.keys(mappings)) {
|
|
16
|
+
const value = mappings[key];
|
|
17
|
+
const keyResolved = kitchen.resolve(key, sourceDirectoryUrl);
|
|
18
|
+
const valueResolved = kitchen.resolve(value, sourceDirectoryUrl);
|
|
19
|
+
mappingResolvedMap.set(keyResolved.url, valueResolved.url);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
redirectReference: (reference) => {
|
|
23
|
+
for (const [key, value] of mappingResolvedMap) {
|
|
24
|
+
const matchResult = URL_META.applyPatternMatching({
|
|
25
|
+
pattern: key,
|
|
26
|
+
url: reference.url,
|
|
27
|
+
});
|
|
28
|
+
if (!matchResult.matched) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (!value.includes("*")) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
const { matchGroups } = matchResult;
|
|
35
|
+
const parts = value.split("*");
|
|
36
|
+
let newUrl = "";
|
|
37
|
+
let index = 0;
|
|
38
|
+
for (const part of parts) {
|
|
39
|
+
newUrl += `${part}`;
|
|
40
|
+
if (index < parts.length - 1) {
|
|
41
|
+
newUrl += matchGroups[index];
|
|
42
|
+
}
|
|
43
|
+
index++;
|
|
44
|
+
}
|
|
45
|
+
return newUrl;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
53
|
+
// const plugin = jsenvPluginMappings({
|
|
54
|
+
// "emoji-regex/index.js": "emoji-regex/index.mjs",
|
|
55
|
+
// });
|
|
56
|
+
// plugin.init({
|
|
57
|
+
// rootDirectoryUrl: import.meta.resolve("./"),
|
|
58
|
+
// kitchen: {
|
|
59
|
+
// resolve: (specifier, importer) => {
|
|
60
|
+
// return applyNodeEsmResolution({
|
|
61
|
+
// parentUrl: importer,
|
|
62
|
+
// specifier,
|
|
63
|
+
// });
|
|
64
|
+
// },
|
|
65
|
+
// },
|
|
66
|
+
// });
|
|
67
|
+
// plugin.redirectReference({
|
|
68
|
+
// url: import.meta.resolve("emoji-regex/index.js"),
|
|
69
|
+
// });
|
|
@@ -18,6 +18,10 @@ export const jsenvPluginSubbuilds = (
|
|
|
18
18
|
},
|
|
19
19
|
...defaultChildBuildParams,
|
|
20
20
|
...subBuildParams,
|
|
21
|
+
outDirectoryUrl: new URL(
|
|
22
|
+
`./subbuild_${index}/`,
|
|
23
|
+
parentBuildParams.outDirectoryUrl,
|
|
24
|
+
),
|
|
21
25
|
};
|
|
22
26
|
const subBuildDirectoryUrl = subBuildParams.buildDirectoryUrl;
|
|
23
27
|
if (subBuildDirectoryUrl) {
|
package/src/kitchen/kitchen.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ANSI, createDetailedMessage, createLogger } from "@jsenv/humanize";
|
|
2
|
+
import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
2
3
|
import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
|
|
3
4
|
import { URL_META } from "@jsenv/url-meta";
|
|
4
5
|
import { normalizeUrl } from "@jsenv/urls";
|
|
@@ -51,6 +52,9 @@ export const createKitchen = ({
|
|
|
51
52
|
}) => {
|
|
52
53
|
const logger = createLogger({ logLevel });
|
|
53
54
|
|
|
55
|
+
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
56
|
+
const packageConditions = [nodeRuntimeEnabled ? "node" : "browser", "import"];
|
|
57
|
+
|
|
54
58
|
const kitchen = {
|
|
55
59
|
context: {
|
|
56
60
|
...initialContext,
|
|
@@ -70,6 +74,14 @@ export const createKitchen = ({
|
|
|
70
74
|
sourcemaps,
|
|
71
75
|
outDirectoryUrl,
|
|
72
76
|
},
|
|
77
|
+
resolve: (specifier, importer) => {
|
|
78
|
+
const { url, packageDirectoryUrl, packageJson } = applyNodeEsmResolution({
|
|
79
|
+
conditions: packageConditions,
|
|
80
|
+
parentUrl: importer,
|
|
81
|
+
specifier,
|
|
82
|
+
});
|
|
83
|
+
return { url, packageDirectoryUrl, packageJson };
|
|
84
|
+
},
|
|
73
85
|
graph: null,
|
|
74
86
|
urlInfoTransformer: null,
|
|
75
87
|
pluginController: null,
|
|
@@ -40,6 +40,7 @@ export const determineSourcemapFileUrl = (urlInfo) => {
|
|
|
40
40
|
generatedUrlObject.searchParams.delete("as_json_module");
|
|
41
41
|
generatedUrlObject.searchParams.delete("as_text_module");
|
|
42
42
|
generatedUrlObject.searchParams.delete("dynamic_import");
|
|
43
|
+
generatedUrlObject.searchParams.delete("dynamic_import_id");
|
|
43
44
|
generatedUrlObject.searchParams.delete("cjs_as_js_module");
|
|
44
45
|
const urlForSourcemap = generatedUrlObject.href;
|
|
45
46
|
return generateSourcemapFileUrl(urlForSourcemap);
|
|
@@ -36,6 +36,12 @@ export const jsenvPluginProtocolHttp = ({ include }) => {
|
|
|
36
36
|
// }
|
|
37
37
|
// return null;
|
|
38
38
|
// },
|
|
39
|
+
init: (context) => {
|
|
40
|
+
const outDirectoryUrl = context.outDirectoryUrl;
|
|
41
|
+
if (!outDirectoryUrl) {
|
|
42
|
+
throw new Error(`need outDirectoryUrl to write http files`);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
39
45
|
redirectReference: (reference) => {
|
|
40
46
|
if (!reference.url.startsWith("http")) {
|
|
41
47
|
return null;
|
|
@@ -315,7 +315,12 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
315
315
|
});
|
|
316
316
|
} else {
|
|
317
317
|
setHtmlNodeText(node, inlineUrlInfo.content, {
|
|
318
|
-
indentation:
|
|
318
|
+
indentation:
|
|
319
|
+
inlineUrlInfo.type === "js_classic" ||
|
|
320
|
+
inlineUrlInfo.type === "js_module"
|
|
321
|
+
? // indentation would mess with stack trace and sourcemap
|
|
322
|
+
false
|
|
323
|
+
: "auto",
|
|
319
324
|
});
|
|
320
325
|
setHtmlNodeAttributes(node, {
|
|
321
326
|
"jsenv-cooked-by": "jsenv:html_inline_content_analysis",
|