@jsenv/core 30.2.0 → 30.3.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/dist/controllable_child_process.mjs +1 -1
- package/dist/controllable_worker_thread.mjs +1 -1
- package/dist/js/execute_using_dynamic_import.js +2 -2
- package/dist/js/v8_coverage.js +4 -4
- package/dist/main.js +240 -91
- package/package.json +3 -3
- package/src/build/build.js +141 -44
- package/src/build/{inject_global_version_mappings.js → version_mappings_injection.js} +44 -33
- package/src/dev/file_service.js +12 -4
- package/src/kitchen/compat/features_compatibility.js +59 -0
- package/src/kitchen/kitchen.js +5 -1
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +13 -22
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +1 -5
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "30.
|
|
3
|
+
"version": "30.3.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"@c88/v8-coverage": "0.1.1",
|
|
68
68
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
69
69
|
"@jsenv/abort": "4.2.4",
|
|
70
|
-
"@jsenv/ast": "2.0.
|
|
70
|
+
"@jsenv/ast": "2.0.1",
|
|
71
71
|
"@jsenv/babel-plugins": "1.1.2",
|
|
72
|
-
"@jsenv/plugin-bundling": "1.1.
|
|
72
|
+
"@jsenv/plugin-bundling": "1.1.1",
|
|
73
73
|
"@jsenv/filesystem": "4.1.9",
|
|
74
74
|
"@jsenv/importmap": "1.2.1",
|
|
75
75
|
"@jsenv/integrity": "0.0.1",
|
package/src/build/build.js
CHANGED
|
@@ -56,9 +56,13 @@ import {
|
|
|
56
56
|
|
|
57
57
|
import { createUrlGraph } from "../kitchen/url_graph.js"
|
|
58
58
|
import { createKitchen } from "../kitchen/kitchen.js"
|
|
59
|
+
import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js"
|
|
59
60
|
import { createUrlGraphLoader } from "../kitchen/url_graph/url_graph_loader.js"
|
|
60
61
|
import { createUrlGraphSummary } from "../kitchen/url_graph/url_graph_report.js"
|
|
61
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
isWebWorkerEntryPointReference,
|
|
64
|
+
isWebWorkerUrlInfo,
|
|
65
|
+
} from "../kitchen/web_workers.js"
|
|
62
66
|
import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url_analysis.js"
|
|
63
67
|
import { jsenvPluginInline } from "../plugins/inline/jsenv_plugin_inline.js"
|
|
64
68
|
import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js"
|
|
@@ -66,7 +70,10 @@ import { getCorePlugins } from "../plugins/plugins.js"
|
|
|
66
70
|
|
|
67
71
|
import { GRAPH } from "./graph_utils.js"
|
|
68
72
|
import { createBuildUrlsGenerator } from "./build_urls_generator.js"
|
|
69
|
-
import {
|
|
73
|
+
import {
|
|
74
|
+
injectVersionMappingsAsGlobal,
|
|
75
|
+
injectVersionMappingsAsImportmap,
|
|
76
|
+
} from "./version_mappings_injection.js"
|
|
70
77
|
import { createVersionGenerator } from "./version_generator.js"
|
|
71
78
|
|
|
72
79
|
// default runtimeCompat corresponds to
|
|
@@ -116,13 +123,13 @@ export const build = async ({
|
|
|
116
123
|
signal = new AbortController().signal,
|
|
117
124
|
handleSIGINT = true,
|
|
118
125
|
logLevel = "info",
|
|
119
|
-
runtimeCompat = defaultRuntimeCompat,
|
|
120
126
|
rootDirectoryUrl,
|
|
121
127
|
buildDirectoryUrl,
|
|
122
128
|
assetsDirectory = "",
|
|
123
|
-
base = runtimeCompat.node ? "./" : "/",
|
|
124
129
|
entryPoints = {},
|
|
125
130
|
|
|
131
|
+
runtimeCompat = defaultRuntimeCompat,
|
|
132
|
+
base = runtimeCompat.node ? "./" : "/",
|
|
126
133
|
plugins = [],
|
|
127
134
|
sourcemaps = false,
|
|
128
135
|
sourcemapsSourcesContent,
|
|
@@ -133,6 +140,7 @@ export const build = async ({
|
|
|
133
140
|
transpilation = {},
|
|
134
141
|
versioning = !runtimeCompat.node,
|
|
135
142
|
versioningMethod = "search_param", // "filename", "search_param"
|
|
143
|
+
versioningViaImportmap = true,
|
|
136
144
|
lineBreakNormalization = process.platform === "win32",
|
|
137
145
|
|
|
138
146
|
clientFiles = {
|
|
@@ -221,6 +229,28 @@ build ${entryPointKeys.length} entry points`)
|
|
|
221
229
|
const versioningRedirections = new Map()
|
|
222
230
|
const entryUrls = []
|
|
223
231
|
const rawGraph = createUrlGraph()
|
|
232
|
+
const contextSharedDuringBuild = {
|
|
233
|
+
systemJsTranspilation: (() => {
|
|
234
|
+
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node")
|
|
235
|
+
if (nodeRuntimeEnabled) return false
|
|
236
|
+
if (!RUNTIME_COMPAT.isSupported(runtimeCompat, "script_type_module"))
|
|
237
|
+
return true
|
|
238
|
+
if (!RUNTIME_COMPAT.isSupported(runtimeCompat, "import_dynamic"))
|
|
239
|
+
return true
|
|
240
|
+
if (!RUNTIME_COMPAT.isSupported(runtimeCompat, "import_meta"))
|
|
241
|
+
return true
|
|
242
|
+
if (
|
|
243
|
+
versioning &&
|
|
244
|
+
versioningViaImportmap &&
|
|
245
|
+
!RUNTIME_COMPAT.isSupported(runtimeCompat, "importmap")
|
|
246
|
+
)
|
|
247
|
+
return true
|
|
248
|
+
return false
|
|
249
|
+
})(),
|
|
250
|
+
minification: plugins.some(
|
|
251
|
+
(plugin) => plugin.name === "jsenv:minification",
|
|
252
|
+
),
|
|
253
|
+
}
|
|
224
254
|
const rawGraphKitchen = createKitchen({
|
|
225
255
|
signal,
|
|
226
256
|
logLevel,
|
|
@@ -228,6 +258,7 @@ build ${entryPointKeys.length} entry points`)
|
|
|
228
258
|
urlGraph: rawGraph,
|
|
229
259
|
build: true,
|
|
230
260
|
runtimeCompat,
|
|
261
|
+
...contextSharedDuringBuild,
|
|
231
262
|
plugins: [
|
|
232
263
|
...plugins,
|
|
233
264
|
{
|
|
@@ -299,6 +330,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
299
330
|
urlGraph: finalGraph,
|
|
300
331
|
build: true,
|
|
301
332
|
runtimeCompat,
|
|
333
|
+
...contextSharedDuringBuild,
|
|
302
334
|
plugins: [
|
|
303
335
|
urlAnalysisPlugin,
|
|
304
336
|
jsenvPluginAsJsClassic({
|
|
@@ -877,6 +909,56 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
877
909
|
disabled: logger.levels.debug || !logger.levels.info,
|
|
878
910
|
})
|
|
879
911
|
try {
|
|
912
|
+
const canUseImportmap =
|
|
913
|
+
finalEntryUrls.every((finalEntryUrl) => {
|
|
914
|
+
const finalEntryUrlInfo = finalGraph.getUrlInfo(finalEntryUrl)
|
|
915
|
+
return finalEntryUrlInfo.type === "html"
|
|
916
|
+
}) &&
|
|
917
|
+
finalGraphKitchen.kitchenContext.isSupportedOnCurrentClients(
|
|
918
|
+
"importmap",
|
|
919
|
+
)
|
|
920
|
+
const preferWithoutVersioning = (reference) => {
|
|
921
|
+
const parentUrlInfo = finalGraph.getUrlInfo(reference.parentUrl)
|
|
922
|
+
if (parentUrlInfo.jsQuote) {
|
|
923
|
+
return {
|
|
924
|
+
type: "global",
|
|
925
|
+
source: `${parentUrlInfo.jsQuote}+__v__(${JSON.stringify(
|
|
926
|
+
reference.specifier,
|
|
927
|
+
)})+${parentUrlInfo.jsQuote}`,
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
if (reference.type === "js_url") {
|
|
931
|
+
return {
|
|
932
|
+
type: "global",
|
|
933
|
+
source: `__v__(${JSON.stringify(reference.specifier)})`,
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
if (reference.type === "js_import") {
|
|
937
|
+
if (reference.subtype === "import_dynamic") {
|
|
938
|
+
return {
|
|
939
|
+
type: "global",
|
|
940
|
+
source: `__v__(${JSON.stringify(reference.specifier)})`,
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
if (reference.subtype === "import_meta_resolve") {
|
|
944
|
+
return {
|
|
945
|
+
type: "global",
|
|
946
|
+
source: `__v__(${JSON.stringify(reference.specifier)})`,
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
if (
|
|
950
|
+
canUseImportmap &&
|
|
951
|
+
!isReferencedByWorker(reference, finalGraph)
|
|
952
|
+
) {
|
|
953
|
+
return {
|
|
954
|
+
type: "importmap",
|
|
955
|
+
source: JSON.stringify(reference.specifier),
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
return null
|
|
960
|
+
}
|
|
961
|
+
|
|
880
962
|
// see also https://github.com/rollup/rollup/pull/4543
|
|
881
963
|
const contentVersionMap = new Map()
|
|
882
964
|
const hashCallbacks = []
|
|
@@ -939,18 +1021,11 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
939
1021
|
// (inline, data:, sourcemap, shouldHandle is false, ...)
|
|
940
1022
|
return null
|
|
941
1023
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
//
|
|
947
|
-
return null
|
|
948
|
-
}
|
|
949
|
-
if (
|
|
950
|
-
reference.type === "js_url" ||
|
|
951
|
-
reference.subtype === "import_dynamic"
|
|
952
|
-
) {
|
|
953
|
-
// __v__() makes versioning dynamic: no need to take into account
|
|
1024
|
+
if (preferWithoutVersioning(reference)) {
|
|
1025
|
+
// when versioning is dynamic no need to take into account
|
|
1026
|
+
// happend for:
|
|
1027
|
+
// - specifier mapped by window.__v__()
|
|
1028
|
+
// - specifier mapped by importmap
|
|
954
1029
|
return null
|
|
955
1030
|
}
|
|
956
1031
|
return dependencyContentVersion
|
|
@@ -1004,13 +1079,15 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1004
1079
|
})
|
|
1005
1080
|
|
|
1006
1081
|
const versionMappings = {}
|
|
1007
|
-
const
|
|
1082
|
+
const versionMappingsOnGlobalMap = new Set()
|
|
1083
|
+
const versionMappingsOnImportmap = new Set()
|
|
1008
1084
|
const versioningKitchen = createKitchen({
|
|
1009
1085
|
logLevel: logger.level,
|
|
1010
1086
|
rootDirectoryUrl: buildDirectoryUrl,
|
|
1011
1087
|
urlGraph: finalGraph,
|
|
1012
1088
|
build: true,
|
|
1013
1089
|
runtimeCompat,
|
|
1090
|
+
...contextSharedDuringBuild,
|
|
1014
1091
|
plugins: [
|
|
1015
1092
|
urlAnalysisPlugin,
|
|
1016
1093
|
jsenvPluginInline({
|
|
@@ -1085,24 +1162,14 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1085
1162
|
versioningRedirections.set(reference.url, versionedUrl)
|
|
1086
1163
|
buildUrls.set(versionedSpecifier, versionedUrl)
|
|
1087
1164
|
|
|
1088
|
-
const
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
reference.specifier,
|
|
1097
|
-
)})+${parentUrlInfo.jsQuote}`
|
|
1098
|
-
}
|
|
1099
|
-
if (
|
|
1100
|
-
reference.type === "js_url" ||
|
|
1101
|
-
reference.subtype === "import_dynamic" ||
|
|
1102
|
-
reference.subtype === "import_meta_resolve"
|
|
1103
|
-
) {
|
|
1104
|
-
usedVersionMappings.add(reference.specifier)
|
|
1105
|
-
return () => `__v__(${JSON.stringify(reference.specifier)})`
|
|
1165
|
+
const withoutVersioning = preferWithoutVersioning(reference)
|
|
1166
|
+
if (withoutVersioning) {
|
|
1167
|
+
if (withoutVersioning.type === "importmap") {
|
|
1168
|
+
versionMappingsOnImportmap.add(reference.specifier)
|
|
1169
|
+
} else {
|
|
1170
|
+
versionMappingsOnGlobalMap.add(reference.specifier)
|
|
1171
|
+
}
|
|
1172
|
+
return () => withoutVersioning.source
|
|
1106
1173
|
}
|
|
1107
1174
|
return versionedSpecifier
|
|
1108
1175
|
},
|
|
@@ -1154,27 +1221,49 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1154
1221
|
})
|
|
1155
1222
|
})
|
|
1156
1223
|
await versioningUrlGraphLoader.getAllLoadDonePromise(buildOperation)
|
|
1157
|
-
|
|
1224
|
+
const actions = []
|
|
1225
|
+
const visitors = []
|
|
1226
|
+
if (versionMappingsOnImportmap.size) {
|
|
1158
1227
|
const versionMappingsNeeded = {}
|
|
1159
|
-
|
|
1228
|
+
versionMappingsOnImportmap.forEach((specifier) => {
|
|
1160
1229
|
versionMappingsNeeded[specifier] = versionMappings[specifier]
|
|
1161
1230
|
})
|
|
1162
|
-
|
|
1163
|
-
|
|
1231
|
+
visitors.push((urlInfo) => {
|
|
1232
|
+
if (urlInfo.type === "html" && urlInfo.isEntryPoint) {
|
|
1233
|
+
actions.push(async () => {
|
|
1234
|
+
await injectVersionMappingsAsImportmap({
|
|
1235
|
+
urlInfo,
|
|
1236
|
+
kitchen: finalGraphKitchen,
|
|
1237
|
+
versionMappings: versionMappingsNeeded,
|
|
1238
|
+
})
|
|
1239
|
+
})
|
|
1240
|
+
}
|
|
1241
|
+
})
|
|
1242
|
+
}
|
|
1243
|
+
if (versionMappingsOnGlobalMap.size) {
|
|
1244
|
+
const versionMappingsNeeded = {}
|
|
1245
|
+
versionMappingsOnGlobalMap.forEach((specifier) => {
|
|
1246
|
+
versionMappingsNeeded[specifier] = versionMappings[specifier]
|
|
1247
|
+
})
|
|
1248
|
+
visitors.push((urlInfo) => {
|
|
1164
1249
|
if (urlInfo.isEntryPoint) {
|
|
1165
1250
|
actions.push(async () => {
|
|
1166
|
-
await
|
|
1251
|
+
await injectVersionMappingsAsGlobal({
|
|
1167
1252
|
urlInfo,
|
|
1168
1253
|
kitchen: finalGraphKitchen,
|
|
1169
1254
|
versionMappings: versionMappingsNeeded,
|
|
1170
|
-
minification: plugins.some(
|
|
1171
|
-
(plugin) => plugin.name === "jsenv:minification",
|
|
1172
|
-
),
|
|
1173
1255
|
})
|
|
1174
1256
|
})
|
|
1175
1257
|
}
|
|
1176
1258
|
})
|
|
1177
|
-
|
|
1259
|
+
}
|
|
1260
|
+
if (visitors.length) {
|
|
1261
|
+
GRAPH.forEach(finalGraph, (urlInfo) => {
|
|
1262
|
+
visitors.forEach((visitor) => visitor(urlInfo))
|
|
1263
|
+
})
|
|
1264
|
+
if (actions.length) {
|
|
1265
|
+
await Promise.all(actions.map((action) => action()))
|
|
1266
|
+
}
|
|
1178
1267
|
}
|
|
1179
1268
|
} catch (e) {
|
|
1180
1269
|
versioningTask.fail()
|
|
@@ -1648,3 +1737,11 @@ const canUseVersionedUrl = (urlInfo) => {
|
|
|
1648
1737
|
}
|
|
1649
1738
|
return urlInfo.type !== "webmanifest"
|
|
1650
1739
|
}
|
|
1740
|
+
|
|
1741
|
+
const isReferencedByWorker = (reference, graph) => {
|
|
1742
|
+
const urlInfo = graph.getUrlInfo(reference.url)
|
|
1743
|
+
const dependentWorker = graph.findDependent(urlInfo, (dependentUrlInfo) => {
|
|
1744
|
+
return isWebWorkerUrlInfo(dependentUrlInfo)
|
|
1745
|
+
})
|
|
1746
|
+
return Boolean(dependentWorker)
|
|
1747
|
+
}
|
|
@@ -10,17 +10,16 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { isWebWorkerUrlInfo } from "@jsenv/core/src/kitchen/web_workers.js"
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const injectVersionMappingsAsGlobal = async ({
|
|
14
14
|
urlInfo,
|
|
15
15
|
kitchen,
|
|
16
16
|
versionMappings,
|
|
17
|
-
minification,
|
|
18
17
|
}) => {
|
|
19
18
|
const injector = injectors[urlInfo.type]
|
|
20
19
|
if (injector) {
|
|
21
20
|
const { content, sourcemap } = await injector(urlInfo, {
|
|
22
21
|
versionMappings,
|
|
23
|
-
minification,
|
|
22
|
+
minification: kitchen.kitchenContext.minification,
|
|
24
23
|
})
|
|
25
24
|
kitchen.urlInfoTransformer.applyFinalTransformations(urlInfo, {
|
|
26
25
|
content,
|
|
@@ -28,12 +27,8 @@ export const injectVersionMappings = async ({
|
|
|
28
27
|
})
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
const injectors = {
|
|
33
31
|
html: (urlInfo, { versionMappings, minification }) => {
|
|
34
|
-
// ideally we would inject an importmap but browser support is too low
|
|
35
|
-
// (even worse for worker/service worker)
|
|
36
|
-
// so for now we inject code into entry points
|
|
37
32
|
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
38
33
|
storeOriginalPositions: false,
|
|
39
34
|
})
|
|
@@ -43,7 +38,7 @@ const injectors = {
|
|
|
43
38
|
tagName: "script",
|
|
44
39
|
textContent: generateClientCodeForVersionMappings(versionMappings, {
|
|
45
40
|
globalName: "window",
|
|
46
|
-
|
|
41
|
+
minification,
|
|
47
42
|
}),
|
|
48
43
|
}),
|
|
49
44
|
"jsenv:versioning",
|
|
@@ -52,49 +47,65 @@ const injectors = {
|
|
|
52
47
|
content: stringifyHtmlAst(htmlAst),
|
|
53
48
|
}
|
|
54
49
|
},
|
|
55
|
-
js_classic: (
|
|
56
|
-
|
|
57
|
-
versionMappings,
|
|
58
|
-
minify: minification || minification.js_classic,
|
|
59
|
-
})
|
|
60
|
-
},
|
|
61
|
-
js_module: (urlInfo, { versionMappings, minification }) => {
|
|
62
|
-
return jsInjector(urlInfo, {
|
|
63
|
-
versionMappings,
|
|
64
|
-
minify: minification || minification.js_module,
|
|
65
|
-
})
|
|
66
|
-
},
|
|
50
|
+
js_classic: (...args) => jsInjector(...args),
|
|
51
|
+
js_module: (...args) => jsInjector(...args),
|
|
67
52
|
}
|
|
68
|
-
|
|
69
|
-
const jsInjector = (urlInfo, { versionMappings, minify }) => {
|
|
53
|
+
const jsInjector = (urlInfo, { versionMappings, minification }) => {
|
|
70
54
|
const magicSource = createMagicSource(urlInfo.content)
|
|
71
55
|
magicSource.prepend(
|
|
72
56
|
generateClientCodeForVersionMappings(versionMappings, {
|
|
73
57
|
globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
|
|
74
|
-
|
|
58
|
+
minification,
|
|
75
59
|
}),
|
|
76
60
|
)
|
|
77
61
|
return magicSource.toContentAndSourcemap()
|
|
78
62
|
}
|
|
79
|
-
|
|
80
63
|
const generateClientCodeForVersionMappings = (
|
|
81
64
|
versionMappings,
|
|
82
|
-
{ globalName,
|
|
65
|
+
{ globalName, minification },
|
|
83
66
|
) => {
|
|
84
|
-
if (
|
|
67
|
+
if (minification) {
|
|
85
68
|
return `;(function(){var m = ${JSON.stringify(
|
|
86
69
|
versionMappings,
|
|
87
70
|
)}; ${globalName}.__v__ = function (s) { return m[s] || s }; })();`
|
|
88
71
|
}
|
|
89
72
|
return `
|
|
90
73
|
;(function() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
|
|
74
|
+
var __versionMappings__ = ${JSON.stringify(versionMappings, null, " ")};
|
|
75
|
+
${globalName}.__v__ = function (specifier) {
|
|
76
|
+
return __versionMappings__[specifier] || specifier
|
|
77
|
+
};
|
|
97
78
|
})();
|
|
98
|
-
|
|
99
79
|
`
|
|
100
80
|
}
|
|
81
|
+
|
|
82
|
+
export const injectVersionMappingsAsImportmap = async ({
|
|
83
|
+
urlInfo,
|
|
84
|
+
kitchen,
|
|
85
|
+
versionMappings,
|
|
86
|
+
}) => {
|
|
87
|
+
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
88
|
+
storeOriginalPositions: false,
|
|
89
|
+
})
|
|
90
|
+
// jsenv_plugin_importmap.js is removing importmap during build
|
|
91
|
+
// it means at this point we know HTML has no importmap in it
|
|
92
|
+
// we can safely inject one
|
|
93
|
+
const importmapNode = createHtmlNode({
|
|
94
|
+
tagName: "script",
|
|
95
|
+
type: "importmap",
|
|
96
|
+
textContent: kitchen.kitchenContext.minification
|
|
97
|
+
? JSON.stringify({ imports: versionMappings })
|
|
98
|
+
: `
|
|
99
|
+
{
|
|
100
|
+
"imports": {${JSON.stringify(versionMappings, null, " ").slice(
|
|
101
|
+
1,
|
|
102
|
+
-1,
|
|
103
|
+
)} }
|
|
104
|
+
}
|
|
105
|
+
`,
|
|
106
|
+
})
|
|
107
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, importmapNode, "jsenv:versioning")
|
|
108
|
+
kitchen.urlInfoTransformer.applyFinalTransformations(urlInfo, {
|
|
109
|
+
content: stringifyHtmlAst(htmlAst),
|
|
110
|
+
})
|
|
111
|
+
}
|
package/src/dev/file_service.js
CHANGED
|
@@ -10,6 +10,7 @@ import { URL_META } from "@jsenv/url-meta"
|
|
|
10
10
|
|
|
11
11
|
import { createUrlGraph } from "@jsenv/core/src/kitchen/url_graph.js"
|
|
12
12
|
import { createKitchen } from "@jsenv/core/src/kitchen/kitchen.js"
|
|
13
|
+
import { RUNTIME_COMPAT } from "@jsenv/core/src/kitchen/compat/runtime_compat.js"
|
|
13
14
|
import { getCorePlugins } from "@jsenv/core/src/plugins/plugins.js"
|
|
14
15
|
import { jsenvPluginServerEventsClientInjection } from "@jsenv/core/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js"
|
|
15
16
|
import { parseUserAgentHeader } from "./user_agent.js"
|
|
@@ -111,16 +112,22 @@ export const createFileService = ({
|
|
|
111
112
|
onUrlInfo(urlInfo)
|
|
112
113
|
})
|
|
113
114
|
})
|
|
115
|
+
const clientRuntimeCompat = { [runtimeName]: runtimeVersion }
|
|
114
116
|
const kitchen = createKitchen({
|
|
115
117
|
signal,
|
|
116
118
|
logLevel,
|
|
117
119
|
rootDirectoryUrl,
|
|
120
|
+
urlGraph,
|
|
118
121
|
dev: true,
|
|
119
122
|
runtimeCompat,
|
|
120
|
-
clientRuntimeCompat
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
clientRuntimeCompat,
|
|
124
|
+
systemJsTranspilation:
|
|
125
|
+
!RUNTIME_COMPAT.isSupported(
|
|
126
|
+
clientRuntimeCompat,
|
|
127
|
+
"script_type_module",
|
|
128
|
+
) ||
|
|
129
|
+
!RUNTIME_COMPAT.isSupported(clientRuntimeCompat, "import_dynamic") ||
|
|
130
|
+
!RUNTIME_COMPAT.isSupported(clientRuntimeCompat, "import_meta"),
|
|
124
131
|
plugins: [
|
|
125
132
|
...plugins,
|
|
126
133
|
...getCorePlugins({
|
|
@@ -141,6 +148,7 @@ export const createFileService = ({
|
|
|
141
148
|
ribbon,
|
|
142
149
|
}),
|
|
143
150
|
],
|
|
151
|
+
minification: false,
|
|
144
152
|
sourcemaps,
|
|
145
153
|
sourcemapsSourcesProtocol,
|
|
146
154
|
sourcemapsSourcesContent,
|
|
@@ -60,6 +60,7 @@ export const featuresCompatMap = {
|
|
|
60
60
|
chrome: "89",
|
|
61
61
|
opera: "76",
|
|
62
62
|
samsung: "15",
|
|
63
|
+
firefox: "108",
|
|
63
64
|
},
|
|
64
65
|
import_type_json: {
|
|
65
66
|
chrome: "91",
|
|
@@ -155,4 +156,62 @@ export const featuresCompatMap = {
|
|
|
155
156
|
android: "4",
|
|
156
157
|
node: "4",
|
|
157
158
|
},
|
|
159
|
+
arrow_function: {
|
|
160
|
+
chrome: "47",
|
|
161
|
+
opera: "34",
|
|
162
|
+
edge: "13",
|
|
163
|
+
firefox: "45",
|
|
164
|
+
safari: "10",
|
|
165
|
+
node: "6",
|
|
166
|
+
ios: "10",
|
|
167
|
+
samsung: "5",
|
|
168
|
+
electron: "0.36",
|
|
169
|
+
},
|
|
170
|
+
const_bindings: {
|
|
171
|
+
chrome: "41",
|
|
172
|
+
opera: "28",
|
|
173
|
+
edge: "12",
|
|
174
|
+
firefox: "46",
|
|
175
|
+
safari: "10",
|
|
176
|
+
node: "4",
|
|
177
|
+
ie: "11",
|
|
178
|
+
ios: "10",
|
|
179
|
+
samsung: "3.4",
|
|
180
|
+
electron: "0.22",
|
|
181
|
+
},
|
|
182
|
+
object_properties_shorthand: {
|
|
183
|
+
chrome: "43",
|
|
184
|
+
opera: "30",
|
|
185
|
+
edge: "12",
|
|
186
|
+
firefox: "33",
|
|
187
|
+
safari: "9",
|
|
188
|
+
node: "4",
|
|
189
|
+
ios: "9",
|
|
190
|
+
samsung: "4",
|
|
191
|
+
electron: "0.28",
|
|
192
|
+
},
|
|
193
|
+
reserved_words: {
|
|
194
|
+
chrome: "13",
|
|
195
|
+
opera: "10.50",
|
|
196
|
+
edge: "12",
|
|
197
|
+
firefox: "2",
|
|
198
|
+
safari: "3.1",
|
|
199
|
+
node: "0.10",
|
|
200
|
+
ie: "9",
|
|
201
|
+
android: "4.4",
|
|
202
|
+
ios: "6",
|
|
203
|
+
phantom: "2",
|
|
204
|
+
samsung: "1",
|
|
205
|
+
electron: "0.20",
|
|
206
|
+
},
|
|
207
|
+
symbols: {
|
|
208
|
+
chrome: "38",
|
|
209
|
+
opera: "25",
|
|
210
|
+
edge: "12",
|
|
211
|
+
firefox: "36",
|
|
212
|
+
safari: "9",
|
|
213
|
+
ios: "9",
|
|
214
|
+
samsung: "4",
|
|
215
|
+
node: "0.12",
|
|
216
|
+
},
|
|
158
217
|
}
|
package/src/kitchen/kitchen.js
CHANGED
|
@@ -28,14 +28,16 @@ export const createKitchen = ({
|
|
|
28
28
|
logLevel,
|
|
29
29
|
|
|
30
30
|
rootDirectoryUrl,
|
|
31
|
+
urlGraph,
|
|
31
32
|
dev = false,
|
|
32
33
|
build = false,
|
|
33
34
|
runtimeCompat,
|
|
34
35
|
// during dev/test clientRuntimeCompat is a single runtime
|
|
35
36
|
// during build clientRuntimeCompat is runtimeCompat
|
|
36
37
|
clientRuntimeCompat = runtimeCompat,
|
|
37
|
-
|
|
38
|
+
systemJsTranspilation,
|
|
38
39
|
plugins,
|
|
40
|
+
minification,
|
|
39
41
|
sourcemaps = dev ? "inline" : "none", // "programmatic" and "file" also allowed
|
|
40
42
|
sourcemapsSourcesProtocol,
|
|
41
43
|
sourcemapsSourcesContent,
|
|
@@ -53,12 +55,14 @@ export const createKitchen = ({
|
|
|
53
55
|
build,
|
|
54
56
|
runtimeCompat,
|
|
55
57
|
clientRuntimeCompat,
|
|
58
|
+
systemJsTranspilation,
|
|
56
59
|
isSupportedOnCurrentClients: (feature) => {
|
|
57
60
|
return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
|
|
58
61
|
},
|
|
59
62
|
isSupportedOnFutureClients: (feature) => {
|
|
60
63
|
return RUNTIME_COMPAT.isSupported(runtimeCompat, feature)
|
|
61
64
|
},
|
|
65
|
+
minification,
|
|
62
66
|
sourcemaps,
|
|
63
67
|
outDirectoryUrl,
|
|
64
68
|
}
|
|
@@ -23,8 +23,6 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
23
23
|
systemJsInjection,
|
|
24
24
|
systemJsClientFileUrl,
|
|
25
25
|
}) => {
|
|
26
|
-
let shouldTransformScriptTypeModule
|
|
27
|
-
|
|
28
26
|
const turnIntoJsClassicProxy = (reference) => {
|
|
29
27
|
return injectQueryParams(reference.url, { as_js_classic: "" })
|
|
30
28
|
}
|
|
@@ -32,26 +30,16 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
32
30
|
return {
|
|
33
31
|
name: "jsenv:as_js_classic_html",
|
|
34
32
|
appliesDuring: "*",
|
|
35
|
-
init: (context) => {
|
|
36
|
-
const nodeRuntimeEnabled = Object.keys(context.runtimeCompat).includes(
|
|
37
|
-
"node",
|
|
38
|
-
)
|
|
39
|
-
shouldTransformScriptTypeModule = nodeRuntimeEnabled
|
|
40
|
-
? false
|
|
41
|
-
: !context.isSupportedOnCurrentClients("script_type_module") ||
|
|
42
|
-
!context.isSupportedOnCurrentClients("import_dynamic") ||
|
|
43
|
-
!context.isSupportedOnCurrentClients("import_meta")
|
|
44
|
-
},
|
|
45
33
|
redirectUrl: {
|
|
46
|
-
link_href: (reference) => {
|
|
34
|
+
link_href: (reference, context) => {
|
|
47
35
|
if (
|
|
48
|
-
|
|
36
|
+
context.systemJsTranspilation &&
|
|
49
37
|
reference.subtype === "modulepreload"
|
|
50
38
|
) {
|
|
51
39
|
return turnIntoJsClassicProxy(reference)
|
|
52
40
|
}
|
|
53
41
|
if (
|
|
54
|
-
|
|
42
|
+
context.systemJsTranspilation &&
|
|
55
43
|
reference.subtype === "preload" &&
|
|
56
44
|
reference.expectedType === "js_module"
|
|
57
45
|
) {
|
|
@@ -59,18 +47,18 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
59
47
|
}
|
|
60
48
|
return null
|
|
61
49
|
},
|
|
62
|
-
script_src: (reference) => {
|
|
50
|
+
script_src: (reference, context) => {
|
|
63
51
|
if (
|
|
64
|
-
|
|
52
|
+
context.systemJsTranspilation &&
|
|
65
53
|
reference.expectedType === "js_module"
|
|
66
54
|
) {
|
|
67
55
|
return turnIntoJsClassicProxy(reference)
|
|
68
56
|
}
|
|
69
57
|
return null
|
|
70
58
|
},
|
|
71
|
-
js_url: (reference) => {
|
|
59
|
+
js_url: (reference, context) => {
|
|
72
60
|
if (
|
|
73
|
-
|
|
61
|
+
context.systemJsTranspilation &&
|
|
74
62
|
reference.expectedType === "js_module"
|
|
75
63
|
) {
|
|
76
64
|
return turnIntoJsClassicProxy(reference)
|
|
@@ -101,7 +89,10 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
101
89
|
if (!isOrWasExpectingJsModule(reference)) {
|
|
102
90
|
return
|
|
103
91
|
}
|
|
104
|
-
if (
|
|
92
|
+
if (
|
|
93
|
+
rel === "modulepreload" &&
|
|
94
|
+
reference.expectedType === "js_classic"
|
|
95
|
+
) {
|
|
105
96
|
mutations.push(() => {
|
|
106
97
|
setHtmlNodeAttributes(node, {
|
|
107
98
|
rel: "preload",
|
|
@@ -110,7 +101,7 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
110
101
|
})
|
|
111
102
|
})
|
|
112
103
|
}
|
|
113
|
-
if (rel === "preload") {
|
|
104
|
+
if (rel === "preload" && reference.expectedType === "js_classic") {
|
|
114
105
|
mutations.push(() => {
|
|
115
106
|
setHtmlNodeAttributes(node, { crossorigin: undefined })
|
|
116
107
|
})
|
|
@@ -137,7 +128,7 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
137
128
|
setHtmlNodeAttributes(node, { type: undefined })
|
|
138
129
|
})
|
|
139
130
|
}
|
|
140
|
-
} else if (
|
|
131
|
+
} else if (context.systemJsTranspilation) {
|
|
141
132
|
mutations.push(() => {
|
|
142
133
|
setHtmlNodeAttributes(node, { type: undefined })
|
|
143
134
|
})
|