@jsenv/core 34.1.5 → 34.2.1
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/js/s.js.map +2 -2
- package/dist/jsenv.js +101 -194
- package/package.json +2 -2
- package/src/build/build.js +18 -20
- package/src/dev/file_service.js +1 -1
- package/src/dev/start_dev_server.js +17 -16
- package/src/execute/web_server_param.js +5 -1
- package/src/kitchen/url_graph/url_info_transformations.js +1 -1
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +1 -1
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +3 -3
- package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/convert_js_module_to_js_classic.js +6 -2
- package/src/plugins/transpilation/{as_js_classic/jsenv_plugin_as_js_classic_conversion.js → js_module_fallback/jsenv_plugin_js_module_conversion.js} +13 -12
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +45 -0
- package/src/plugins/transpilation/{as_js_classic/jsenv_plugin_as_js_classic_html.js → js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js} +7 -7
- package/src/plugins/transpilation/{as_js_classic/jsenv_plugin_as_js_classic_workers.js → js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js} +3 -3
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +10 -11
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +2 -2
- package/src/test/execute_steps.js +1 -1
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +0 -61
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_library.js +0 -91
- /package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/async-to-promises.js +0 -0
- /package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/client/s.js +0 -0
- /package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/helpers/babel_plugin_transform_import_meta_resolve.js +0 -0
- /package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/helpers/babel_plugin_transform_import_meta_url.js +0 -0
- /package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/helpers/systemjs_old.js +0 -0
- /package/src/plugins/transpilation/{as_js_classic → js_module_fallback}/helpers-string.js +0 -0
package/src/build/build.js
CHANGED
|
@@ -66,7 +66,7 @@ import {
|
|
|
66
66
|
} from "../kitchen/web_workers.js"
|
|
67
67
|
import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url_analysis.js"
|
|
68
68
|
import { jsenvPluginInline } from "../plugins/inline/jsenv_plugin_inline.js"
|
|
69
|
-
import {
|
|
69
|
+
import { jsenvPluginJsModuleFallback } from "../plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js"
|
|
70
70
|
import { getCorePlugins } from "../plugins/plugins.js"
|
|
71
71
|
import { jsenvPluginLineBreakNormalization } from "./jsenv_plugin_line_break_normalization.js"
|
|
72
72
|
|
|
@@ -274,8 +274,8 @@ build "${entryPointKeys[0]}"`)
|
|
|
274
274
|
logger.info(`
|
|
275
275
|
build ${entryPointKeys.length} entry points`)
|
|
276
276
|
}
|
|
277
|
-
const
|
|
278
|
-
entryPoints[key].includes("?
|
|
277
|
+
const explicitJsModuleFallback = entryPointKeys.some((key) =>
|
|
278
|
+
entryPoints[key].includes("?js_module_fallback"),
|
|
279
279
|
)
|
|
280
280
|
const rawRedirections = new Map()
|
|
281
281
|
const bundleRedirections = new Map()
|
|
@@ -344,8 +344,8 @@ build ${entryPointKeys.length} entry points`)
|
|
|
344
344
|
directoryReferenceAllowed,
|
|
345
345
|
transpilation: {
|
|
346
346
|
...transpilation,
|
|
347
|
-
babelHelpersAsImport: !
|
|
348
|
-
|
|
347
|
+
babelHelpersAsImport: !explicitJsModuleFallback,
|
|
348
|
+
jsModuleFallbackOnJsClassic: false,
|
|
349
349
|
},
|
|
350
350
|
scenarioPlaceholders,
|
|
351
351
|
}),
|
|
@@ -393,9 +393,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
393
393
|
...(lineBreakNormalization
|
|
394
394
|
? [jsenvPluginLineBreakNormalization()]
|
|
395
395
|
: []),
|
|
396
|
-
|
|
397
|
-
jsClassicLibrary: false,
|
|
398
|
-
jsClassicFallback: true,
|
|
396
|
+
jsenvPluginJsModuleFallback({
|
|
399
397
|
systemJsInjection: true,
|
|
400
398
|
}),
|
|
401
399
|
jsenvPluginInline({
|
|
@@ -471,9 +469,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
471
469
|
)
|
|
472
470
|
return buildUrl
|
|
473
471
|
}
|
|
474
|
-
// from "
|
|
475
|
-
// - injecting "?
|
|
476
|
-
// - injecting "?
|
|
472
|
+
// from "js_module_fallback":
|
|
473
|
+
// - injecting "?js_module_fallback" for the first time
|
|
474
|
+
// - injecting "?js_module_fallback" because the parentUrl has it
|
|
477
475
|
if (reference.original) {
|
|
478
476
|
const urlBeforeRedirect = reference.original.url
|
|
479
477
|
const urlAfterRedirect = reference.url
|
|
@@ -511,7 +509,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
511
509
|
)
|
|
512
510
|
return buildUrl
|
|
513
511
|
}
|
|
514
|
-
// from "
|
|
512
|
+
// from "js_module_fallback":
|
|
515
513
|
// - to inject "s.js"
|
|
516
514
|
if (reference.injected) {
|
|
517
515
|
const buildUrl = buildUrlsGenerator.generate(reference.url, {
|
|
@@ -533,7 +531,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
533
531
|
// files from root directory but not given to rollup nor postcss
|
|
534
532
|
if (rawUrlInfo) {
|
|
535
533
|
const referencedUrlObject = new URL(reference.url)
|
|
536
|
-
referencedUrlObject.searchParams.delete("
|
|
534
|
+
referencedUrlObject.searchParams.delete("as_js_classic")
|
|
537
535
|
const buildUrl = buildUrlsGenerator.generate(
|
|
538
536
|
referencedUrlObject.href,
|
|
539
537
|
{
|
|
@@ -584,8 +582,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
584
582
|
const generatedUrlObject = new URL(reference.generatedUrl)
|
|
585
583
|
generatedUrlObject.searchParams.delete("js_classic")
|
|
586
584
|
generatedUrlObject.searchParams.delete("js_module")
|
|
585
|
+
generatedUrlObject.searchParams.delete("js_module_fallback")
|
|
587
586
|
generatedUrlObject.searchParams.delete("as_js_classic")
|
|
588
|
-
generatedUrlObject.searchParams.delete("as_js_classic_library")
|
|
589
587
|
generatedUrlObject.searchParams.delete("as_js_module")
|
|
590
588
|
generatedUrlObject.searchParams.delete("as_json_module")
|
|
591
589
|
generatedUrlObject.searchParams.delete("as_css_module")
|
|
@@ -632,7 +630,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
632
630
|
}
|
|
633
631
|
const { reference } = context
|
|
634
632
|
// reference injected during "postbuild":
|
|
635
|
-
// - happens for "
|
|
633
|
+
// - happens for "js_module_fallback" injecting "s.js"
|
|
636
634
|
if (reference.injected) {
|
|
637
635
|
const [ref, rawUrlInfo] = rawGraphKitchen.injectReference({
|
|
638
636
|
...reference,
|
|
@@ -645,7 +643,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
645
643
|
return fromBundleOrRawGraph(reference.url)
|
|
646
644
|
}
|
|
647
645
|
// reference updated during "postbuild":
|
|
648
|
-
// - happens for "
|
|
646
|
+
// - happens for "js_module_fallback"
|
|
649
647
|
if (reference.original) {
|
|
650
648
|
return fromBundleOrRawGraph(reference.original.url)
|
|
651
649
|
}
|
|
@@ -750,7 +748,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
750
748
|
// cleanup unused urls (avoid bundling things that are not actually used)
|
|
751
749
|
// happens for:
|
|
752
750
|
// - js import assertions
|
|
753
|
-
// -
|
|
751
|
+
// - as_js_classic
|
|
754
752
|
if (!isUsed(rawUrlInfo)) {
|
|
755
753
|
rawGraph.deleteUrlInfo(rawUrlInfo.url)
|
|
756
754
|
return
|
|
@@ -1126,10 +1124,10 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1126
1124
|
}
|
|
1127
1125
|
versionMap.set(urlInfo.url, version)
|
|
1128
1126
|
const buildUrlObject = new URL(urlInfo.url)
|
|
1129
|
-
// remove ?
|
|
1127
|
+
// remove ?js_module_fallback
|
|
1130
1128
|
// this information is already hold into ".nomodule"
|
|
1129
|
+
buildUrlObject.searchParams.delete("js_module_fallback")
|
|
1131
1130
|
buildUrlObject.searchParams.delete("as_js_classic")
|
|
1132
|
-
buildUrlObject.searchParams.delete("as_js_classic_library")
|
|
1133
1131
|
buildUrlObject.searchParams.delete("as_js_module")
|
|
1134
1132
|
buildUrlObject.searchParams.delete("as_json_module")
|
|
1135
1133
|
buildUrlObject.searchParams.delete("as_css_module")
|
|
@@ -1599,7 +1597,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1599
1597
|
const buildInlineRelativeUrls = []
|
|
1600
1598
|
const getBuildRelativeUrl = (url) => {
|
|
1601
1599
|
const urlObject = new URL(url)
|
|
1602
|
-
urlObject.searchParams.delete("
|
|
1600
|
+
urlObject.searchParams.delete("js_module_fallback")
|
|
1603
1601
|
urlObject.searchParams.delete("as_css_module")
|
|
1604
1602
|
urlObject.searchParams.delete("as_json_module")
|
|
1605
1603
|
urlObject.searchParams.delete("as_text_module")
|
package/src/dev/file_service.js
CHANGED
|
@@ -370,7 +370,7 @@ export const createFileService = ({
|
|
|
370
370
|
if (code === "PARSE_ERROR") {
|
|
371
371
|
// when possible let browser re-throw the syntax error
|
|
372
372
|
// it's not possible to do that when url info content is not available
|
|
373
|
-
// (happens for as_js_classic
|
|
373
|
+
// (happens for as_js_classic for instance)
|
|
374
374
|
if (urlInfo.content !== undefined) {
|
|
375
375
|
return {
|
|
376
376
|
url: reference.url,
|
|
@@ -134,24 +134,11 @@ export const startDevServer = async ({
|
|
|
134
134
|
port,
|
|
135
135
|
requestWaitingMs: 60_000,
|
|
136
136
|
services: [
|
|
137
|
-
{
|
|
138
|
-
injectResponseHeaders: () => {
|
|
139
|
-
return { "x-server-name": "jsenv_dev_server" }
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
jsenvServiceCORS({
|
|
143
|
-
accessControlAllowRequestOrigin: true,
|
|
144
|
-
accessControlAllowRequestMethod: true,
|
|
145
|
-
accessControlAllowRequestHeaders: true,
|
|
146
|
-
accessControlAllowedRequestHeaders: [
|
|
147
|
-
...jsenvAccessControlAllowedHeaders,
|
|
148
|
-
"x-jsenv-execution-id",
|
|
149
|
-
],
|
|
150
|
-
accessControlAllowCredentials: true,
|
|
151
|
-
timingAllowOrigin: true,
|
|
152
|
-
}),
|
|
153
137
|
{
|
|
154
138
|
handleRequest: (request) => {
|
|
139
|
+
if (request.headers["x-server-inspect"]) {
|
|
140
|
+
return { status: 200 }
|
|
141
|
+
}
|
|
155
142
|
if (request.pathname === "/__params__.json") {
|
|
156
143
|
const json = JSON.stringify({
|
|
157
144
|
sourceDirectoryUrl,
|
|
@@ -167,7 +154,21 @@ export const startDevServer = async ({
|
|
|
167
154
|
}
|
|
168
155
|
return null
|
|
169
156
|
},
|
|
157
|
+
injectResponseHeaders: () => {
|
|
158
|
+
return { server: "jsenv_dev_server/1" }
|
|
159
|
+
},
|
|
170
160
|
},
|
|
161
|
+
jsenvServiceCORS({
|
|
162
|
+
accessControlAllowRequestOrigin: true,
|
|
163
|
+
accessControlAllowRequestMethod: true,
|
|
164
|
+
accessControlAllowRequestHeaders: true,
|
|
165
|
+
accessControlAllowedRequestHeaders: [
|
|
166
|
+
...jsenvAccessControlAllowedHeaders,
|
|
167
|
+
"x-jsenv-execution-id",
|
|
168
|
+
],
|
|
169
|
+
accessControlAllowCredentials: true,
|
|
170
|
+
timingAllowOrigin: true,
|
|
171
|
+
}),
|
|
171
172
|
...services,
|
|
172
173
|
{
|
|
173
174
|
name: "jsenv:omega_file_service",
|
|
@@ -45,9 +45,13 @@ export const assertAndNormalizeWebServer = async (webServer) => {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
const { headers } = await basicFetch(webServer.origin, {
|
|
48
|
+
method: "GET",
|
|
48
49
|
rejectUnauthorized: false,
|
|
50
|
+
headers: {
|
|
51
|
+
"x-server-inspect": "1",
|
|
52
|
+
},
|
|
49
53
|
})
|
|
50
|
-
if (headers["
|
|
54
|
+
if (String(headers["server"]).includes("jsenv_dev_server")) {
|
|
51
55
|
webServer.isJsenvDevServer = true
|
|
52
56
|
const { json } = await basicFetch(`${webServer.origin}/__params__.json`, {
|
|
53
57
|
rejectUnauthorized: false,
|
|
@@ -87,9 +87,9 @@ export const createUrlInfoTransformer = ({
|
|
|
87
87
|
// during build it's urlInfo.url to be inside the build
|
|
88
88
|
// but otherwise it's generatedUrl to be inside .jsenv/ directory
|
|
89
89
|
const generatedUrlObject = new URL(urlInfo.generatedUrl)
|
|
90
|
+
generatedUrlObject.searchParams.delete("js_module_fallback")
|
|
90
91
|
generatedUrlObject.searchParams.delete("as_js_module")
|
|
91
92
|
generatedUrlObject.searchParams.delete("as_js_classic")
|
|
92
|
-
generatedUrlObject.searchParams.delete("as_js_classic_library")
|
|
93
93
|
const urlForSourcemap = generatedUrlObject.href
|
|
94
94
|
urlInfo.sourcemapGeneratedUrl = generateSourcemapFileUrl(urlForSourcemap)
|
|
95
95
|
|
|
@@ -51,9 +51,9 @@ export const jsenvPluginRibbon = ({
|
|
|
51
51
|
tagName: "script",
|
|
52
52
|
type: "module",
|
|
53
53
|
textContent: `
|
|
54
|
-
import { injectRibbon } from "${ribbonClientFileReference.generatedSpecifier}"
|
|
55
|
-
|
|
56
|
-
injectRibbon(${paramsJson})
|
|
54
|
+
import { injectRibbon } from "${ribbonClientFileReference.generatedSpecifier}"
|
|
55
|
+
|
|
56
|
+
injectRibbon(${paramsJson})
|
|
57
57
|
`,
|
|
58
58
|
})
|
|
59
59
|
injectHtmlNode(htmlAst, scriptNode, "jsenv:ribbon")
|
|
@@ -12,13 +12,17 @@ import { requireBabelPlugin } from "../babel/require_babel_plugin.js"
|
|
|
12
12
|
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
13
13
|
import { babelPluginTransformImportMetaResolve } from "./helpers/babel_plugin_transform_import_meta_resolve.js"
|
|
14
14
|
|
|
15
|
-
// import { jsenvPluginAsJsClassicLibrary } from "./jsenv_plugin_as_js_classic_library.js"
|
|
16
15
|
// because of https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/84
|
|
17
16
|
import customAsyncToPromises from "./async-to-promises.js"
|
|
18
17
|
|
|
18
|
+
export const systemJsClientFileUrlDefault = new URL(
|
|
19
|
+
"./client/s.js",
|
|
20
|
+
import.meta.url,
|
|
21
|
+
).href
|
|
22
|
+
|
|
19
23
|
export const convertJsModuleToJsClassic = async ({
|
|
20
24
|
systemJsInjection,
|
|
21
|
-
systemJsClientFileUrl,
|
|
25
|
+
systemJsClientFileUrl = systemJsClientFileUrlDefault,
|
|
22
26
|
urlInfo,
|
|
23
27
|
jsModuleUrlInfo,
|
|
24
28
|
}) => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* - propagate ?
|
|
3
|
-
* - perform conversion from js module to js classic when url uses ?
|
|
2
|
+
* - propagate "?js_module_fallback" query string param on urls
|
|
3
|
+
* - perform conversion from js module to js classic when url uses "?js_module_fallback"
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { injectQueryParams } from "@jsenv/urls"
|
|
7
7
|
import { convertJsModuleToJsClassic } from "./convert_js_module_to_js_classic.js"
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const jsenvPluginJsModuleConversion = ({
|
|
10
10
|
systemJsInjection,
|
|
11
11
|
systemJsClientFileUrl,
|
|
12
12
|
generateJsClassicFilename,
|
|
@@ -25,37 +25,38 @@ export const jsenvPluginAsJsClassicConversion = ({
|
|
|
25
25
|
return false
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const shouldPropagateJsModuleConversion = (reference, context) => {
|
|
29
29
|
if (isReferencingJsModule(reference, context)) {
|
|
30
30
|
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
31
31
|
if (!parentUrlInfo) {
|
|
32
32
|
return false
|
|
33
33
|
}
|
|
34
34
|
const parentGotAsJsClassic = new URL(parentUrlInfo.url).searchParams.has(
|
|
35
|
-
"
|
|
35
|
+
"js_module_fallback",
|
|
36
36
|
)
|
|
37
37
|
return parentGotAsJsClassic
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
return false
|
|
41
40
|
}
|
|
41
|
+
|
|
42
42
|
const markAsJsClassicProxy = (reference) => {
|
|
43
43
|
reference.expectedType = "js_classic"
|
|
44
44
|
reference.filename = generateJsClassicFilename(reference.url)
|
|
45
45
|
}
|
|
46
|
+
|
|
46
47
|
const turnIntoJsClassicProxy = (reference) => {
|
|
47
48
|
const urlTransformed = injectQueryParams(reference.url, {
|
|
48
|
-
|
|
49
|
+
js_module_fallback: "",
|
|
49
50
|
})
|
|
50
51
|
markAsJsClassicProxy(reference)
|
|
51
52
|
return urlTransformed
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
return {
|
|
55
|
-
name: "jsenv:
|
|
56
|
+
name: "jsenv:js_module_conversion",
|
|
56
57
|
appliesDuring: "*",
|
|
57
58
|
redirectUrl: (reference, context) => {
|
|
58
|
-
if (reference.searchParams.has("
|
|
59
|
+
if (reference.searchParams.has("js_module_fallback")) {
|
|
59
60
|
markAsJsClassicProxy(reference)
|
|
60
61
|
return null
|
|
61
62
|
}
|
|
@@ -65,7 +66,7 @@ export const jsenvPluginAsJsClassicConversion = ({
|
|
|
65
66
|
// (because it's the transpiled equivalent of static and dynamic imports)
|
|
66
67
|
// And not other references otherwise we could try to transform inline resources
|
|
67
68
|
// or specifiers inside new URL()...
|
|
68
|
-
if (
|
|
69
|
+
if (shouldPropagateJsModuleConversion(reference, context)) {
|
|
69
70
|
return turnIntoJsClassicProxy(reference, context)
|
|
70
71
|
}
|
|
71
72
|
return null
|
|
@@ -75,9 +76,9 @@ export const jsenvPluginAsJsClassicConversion = ({
|
|
|
75
76
|
context.getWithoutSearchParam({
|
|
76
77
|
urlInfo,
|
|
77
78
|
context,
|
|
78
|
-
searchParam: "
|
|
79
|
+
searchParam: "js_module_fallback",
|
|
79
80
|
// override the expectedType to "js_module"
|
|
80
|
-
// because when there is ?
|
|
81
|
+
// because when there is ?js_module_fallback it means the underlying resource
|
|
81
82
|
// is a js_module
|
|
82
83
|
expectedType: "js_module",
|
|
83
84
|
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { urlToFilename } from "@jsenv/urls"
|
|
2
|
+
import { systemJsClientFileUrlDefault } from "./convert_js_module_to_js_classic.js"
|
|
3
|
+
import { jsenvPluginJsModuleConversion } from "./jsenv_plugin_js_module_conversion.js"
|
|
4
|
+
import { jsenvPluginJsModuleFallbackInsideHtml } from "./jsenv_plugin_js_module_fallback_inside_html.js"
|
|
5
|
+
import { jsenvPluginJsModuleFallbackOnWorkers } from "./jsenv_plugin_js_module_fallback_on_workers.js"
|
|
6
|
+
|
|
7
|
+
export const jsenvPluginJsModuleFallback = ({
|
|
8
|
+
systemJsInjection = true,
|
|
9
|
+
systemJsClientFileUrl = systemJsClientFileUrlDefault,
|
|
10
|
+
}) => {
|
|
11
|
+
return [
|
|
12
|
+
jsenvPluginJsModuleFallbackInsideHtml({
|
|
13
|
+
systemJsInjection,
|
|
14
|
+
systemJsClientFileUrl,
|
|
15
|
+
}),
|
|
16
|
+
jsenvPluginJsModuleFallbackOnWorkers(),
|
|
17
|
+
jsenvPluginJsModuleConversion({
|
|
18
|
+
systemJsInjection,
|
|
19
|
+
systemJsClientFileUrl,
|
|
20
|
+
generateJsClassicFilename,
|
|
21
|
+
}),
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const generateJsClassicFilename = (url) => {
|
|
26
|
+
const filename = urlToFilename(url)
|
|
27
|
+
let [basename, extension] = splitFileExtension(filename)
|
|
28
|
+
const { searchParams } = new URL(url)
|
|
29
|
+
if (
|
|
30
|
+
searchParams.has("as_json_module") ||
|
|
31
|
+
searchParams.has("as_css_module") ||
|
|
32
|
+
searchParams.has("as_text_module")
|
|
33
|
+
) {
|
|
34
|
+
extension = ".js"
|
|
35
|
+
}
|
|
36
|
+
return `${basename}.nomodule${extension}`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const splitFileExtension = (filename) => {
|
|
40
|
+
const dotLastIndex = filename.lastIndexOf(".")
|
|
41
|
+
if (dotLastIndex === -1) {
|
|
42
|
+
return [filename, ""]
|
|
43
|
+
}
|
|
44
|
+
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
|
|
45
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* when <script type="module"> cannot be used:
|
|
3
|
-
* - ?
|
|
3
|
+
* - ?js_module_fallback is injected into the src of <script type="module">
|
|
4
4
|
* - js inside <script type="module"> is transformed into classic js
|
|
5
5
|
* - <link rel="modulepreload"> are converted to <link rel="preload">
|
|
6
6
|
*/
|
|
@@ -19,16 +19,16 @@ import {
|
|
|
19
19
|
import { injectQueryParams, urlToRelativeUrl } from "@jsenv/urls"
|
|
20
20
|
import { SOURCEMAP } from "@jsenv/sourcemap"
|
|
21
21
|
|
|
22
|
-
export const
|
|
22
|
+
export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
23
23
|
systemJsInjection,
|
|
24
24
|
systemJsClientFileUrl,
|
|
25
25
|
}) => {
|
|
26
26
|
const turnIntoJsClassicProxy = (reference) => {
|
|
27
|
-
return injectQueryParams(reference.url, {
|
|
27
|
+
return injectQueryParams(reference.url, { js_module_fallback: "" })
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return {
|
|
31
|
-
name: "jsenv:
|
|
31
|
+
name: "jsenv:js_module_fallback_inside_html",
|
|
32
32
|
appliesDuring: "*",
|
|
33
33
|
redirectUrl: {
|
|
34
34
|
link_href: (reference, context) => {
|
|
@@ -208,7 +208,7 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
208
208
|
tagName: "script",
|
|
209
209
|
textContent: systemJsUrlInfo.content,
|
|
210
210
|
}),
|
|
211
|
-
"jsenv:
|
|
211
|
+
"jsenv:js_module_fallback",
|
|
212
212
|
)
|
|
213
213
|
})
|
|
214
214
|
}
|
|
@@ -236,7 +236,7 @@ const isOrWasExpectingJsModule = (reference) => {
|
|
|
236
236
|
const isExpectingJsModule = (reference) => {
|
|
237
237
|
return (
|
|
238
238
|
reference.expectedType === "js_module" ||
|
|
239
|
-
reference.searchParams.has("
|
|
240
|
-
reference.searchParams.has("
|
|
239
|
+
reference.searchParams.has("js_module_fallback") ||
|
|
240
|
+
reference.searchParams.has("as_js_classic")
|
|
241
241
|
)
|
|
242
242
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { injectQueryParams } from "@jsenv/urls"
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const jsenvPluginJsModuleFallbackOnWorkers = () => {
|
|
17
17
|
const turnIntoJsClassicProxy = (reference) => {
|
|
18
18
|
reference.mutation = (magicSource) => {
|
|
19
19
|
magicSource.replace({
|
|
@@ -22,11 +22,11 @@ export const jsenvPluginAsJsClassicWorkers = () => {
|
|
|
22
22
|
replacement: JSON.stringify("classic"),
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
|
-
return injectQueryParams(reference.url, {
|
|
25
|
+
return injectQueryParams(reference.url, { js_module_fallback: "" })
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return {
|
|
29
|
-
name: "jsenv:
|
|
29
|
+
name: "jsenv:js_module_fallback_on_workers",
|
|
30
30
|
appliesDuring: "*",
|
|
31
31
|
redirectUrl: {
|
|
32
32
|
js_url: (reference, context) => {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { jsenvPluginCssTranspilation } from "./css/jsenv_plugin_css_transpilation.js"
|
|
11
11
|
import { jsenvPluginImportAssertions } from "./import_assertions/jsenv_plugin_import_assertions.js"
|
|
12
|
-
import {
|
|
12
|
+
import { jsenvPluginJsModuleFallback } from "./js_module_fallback/jsenv_plugin_js_module_fallback.js"
|
|
13
13
|
import { jsenvPluginAsJsModule } from "./as_js_module/jsenv_plugin_as_js_module.js"
|
|
14
14
|
import { jsenvPluginBabel } from "./babel/jsenv_plugin_babel.js"
|
|
15
15
|
import { jsenvPluginTopLevelAwait } from "./jsenv_plugin_top_level_await.js"
|
|
@@ -18,12 +18,10 @@ import { jsenvPluginImportMetaResolve } from "./jsenv_plugin_import_meta_resolve
|
|
|
18
18
|
export const jsenvPluginTranspilation = ({
|
|
19
19
|
importAssertions = true,
|
|
20
20
|
css = true,
|
|
21
|
-
|
|
22
|
-
// build sets jsClassicFallback: false during first step of the build
|
|
21
|
+
// build sets jsModuleFallbackOnJsClassic: false during first step of the build
|
|
23
22
|
// and re-enable it in the second phase (when performing the bundling)
|
|
24
23
|
// so that bundling is applied on js modules THEN it is converted to js classic if needed
|
|
25
|
-
|
|
26
|
-
systemJsInjection = true,
|
|
24
|
+
jsModuleFallbackOnJsClassic = true,
|
|
27
25
|
topLevelAwait = true,
|
|
28
26
|
importMetaResolve = true,
|
|
29
27
|
babelHelpersAsImport = true,
|
|
@@ -32,6 +30,9 @@ export const jsenvPluginTranspilation = ({
|
|
|
32
30
|
if (importAssertions === true) {
|
|
33
31
|
importAssertions = {}
|
|
34
32
|
}
|
|
33
|
+
if (jsModuleFallbackOnJsClassic === true) {
|
|
34
|
+
jsModuleFallbackOnJsClassic = {}
|
|
35
|
+
}
|
|
35
36
|
return [
|
|
36
37
|
...(importMetaResolve ? [jsenvPluginImportMetaResolve()] : []),
|
|
37
38
|
...(importAssertions
|
|
@@ -43,13 +44,11 @@ export const jsenvPluginTranspilation = ({
|
|
|
43
44
|
getCustomBabelPlugins,
|
|
44
45
|
babelHelpersAsImport,
|
|
45
46
|
}),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
systemJsInjection,
|
|
50
|
-
}),
|
|
47
|
+
...(jsModuleFallbackOnJsClassic
|
|
48
|
+
? [jsenvPluginJsModuleFallback(jsModuleFallbackOnJsClassic)]
|
|
49
|
+
: []),
|
|
51
50
|
jsenvPluginAsJsModule(),
|
|
52
|
-
// topLevelAwait must come after
|
|
51
|
+
// topLevelAwait must come after jsModuleFallback because it's related to the module format
|
|
53
52
|
// so we want to wait to know the module format before transforming things related to top level await
|
|
54
53
|
...(topLevelAwait ? [jsenvPluginTopLevelAwait(topLevelAwait)] : []),
|
|
55
54
|
...(css ? [jsenvPluginCssTranspilation()] : []),
|
|
@@ -11,8 +11,8 @@ export const jsenvPluginReferenceExpectedTypes = () => {
|
|
|
11
11
|
if (searchParams.has("js_classic")) {
|
|
12
12
|
reference.expectedType = "js_classic"
|
|
13
13
|
} else if (
|
|
14
|
-
searchParams.has("
|
|
15
|
-
searchParams.has("
|
|
14
|
+
searchParams.has("js_module_fallback") ||
|
|
15
|
+
searchParams.has("as_js_classic")
|
|
16
16
|
) {
|
|
17
17
|
reference.expectedType = "js_classic"
|
|
18
18
|
} else if (searchParams.has("as_js_module")) {
|
|
@@ -309,7 +309,7 @@ export const executeSteps = async (
|
|
|
309
309
|
failFast &&
|
|
310
310
|
executionResult.status !== "completed" &&
|
|
311
311
|
counters.done < counters.total
|
|
312
|
-
if (isLastExecutionLog) {
|
|
312
|
+
if (isLastExecutionLog && logger.levels.info) {
|
|
313
313
|
executionLog.write("\n")
|
|
314
314
|
}
|
|
315
315
|
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { urlToFilename } from "@jsenv/urls"
|
|
2
|
-
import { jsenvPluginAsJsClassicConversion } from "./jsenv_plugin_as_js_classic_conversion.js"
|
|
3
|
-
import { jsenvPluginAsJsClassicHtml } from "./jsenv_plugin_as_js_classic_html.js"
|
|
4
|
-
import { jsenvPluginAsJsClassicWorkers } from "./jsenv_plugin_as_js_classic_workers.js"
|
|
5
|
-
import { jsenvPluginAsJsClassicLibrary } from "./jsenv_plugin_as_js_classic_library.js"
|
|
6
|
-
|
|
7
|
-
export const jsenvPluginAsJsClassic = ({
|
|
8
|
-
jsClassicLibrary,
|
|
9
|
-
jsClassicFallback,
|
|
10
|
-
systemJsInjection,
|
|
11
|
-
}) => {
|
|
12
|
-
const systemJsClientFileUrl = new URL("./client/s.js", import.meta.url).href
|
|
13
|
-
|
|
14
|
-
const generateJsClassicFilename = (url) => {
|
|
15
|
-
const filename = urlToFilename(url)
|
|
16
|
-
let [basename, extension] = splitFileExtension(filename)
|
|
17
|
-
const { searchParams } = new URL(url)
|
|
18
|
-
if (
|
|
19
|
-
searchParams.has("as_json_module") ||
|
|
20
|
-
searchParams.has("as_css_module") ||
|
|
21
|
-
searchParams.has("as_text_module")
|
|
22
|
-
) {
|
|
23
|
-
extension = ".js"
|
|
24
|
-
}
|
|
25
|
-
return `${basename}.nomodule${extension}`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const splitFileExtension = (filename) => {
|
|
29
|
-
const dotLastIndex = filename.lastIndexOf(".")
|
|
30
|
-
if (dotLastIndex === -1) {
|
|
31
|
-
return [filename, ""]
|
|
32
|
-
}
|
|
33
|
-
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return [
|
|
37
|
-
...(jsClassicLibrary
|
|
38
|
-
? [
|
|
39
|
-
jsenvPluginAsJsClassicLibrary({
|
|
40
|
-
systemJsInjection,
|
|
41
|
-
systemJsClientFileUrl,
|
|
42
|
-
generateJsClassicFilename,
|
|
43
|
-
}),
|
|
44
|
-
]
|
|
45
|
-
: []),
|
|
46
|
-
...(jsClassicFallback
|
|
47
|
-
? [
|
|
48
|
-
jsenvPluginAsJsClassicHtml({
|
|
49
|
-
systemJsInjection,
|
|
50
|
-
systemJsClientFileUrl,
|
|
51
|
-
}),
|
|
52
|
-
jsenvPluginAsJsClassicWorkers(),
|
|
53
|
-
jsenvPluginAsJsClassicConversion({
|
|
54
|
-
systemJsInjection,
|
|
55
|
-
systemJsClientFileUrl,
|
|
56
|
-
generateJsClassicFilename,
|
|
57
|
-
}),
|
|
58
|
-
]
|
|
59
|
-
: []),
|
|
60
|
-
]
|
|
61
|
-
}
|