@jsenv/core 27.0.0-alpha.12 → 27.0.0-alpha.15
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/main.js +4 -0
- package/package.json +15 -11
- package/readme.md +4 -12
- package/src/build/build.js +451 -388
- package/src/build/build_urls_generator.js +23 -20
- package/src/build/graph_utils.js +31 -0
- package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +31 -14
- package/src/build/inject_service_worker_urls.js +66 -12
- package/src/build/resync_ressource_hints.js +83 -0
- package/src/build/start_build_server.js +176 -0
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
- package/src/dev/start_dev_server.js +16 -22
- package/src/execute/execute.js +19 -6
- package/src/execute/run.js +17 -54
- package/src/execute/runtimes/browsers/from_playwright.js +167 -146
- package/src/execute/runtimes/node/node_process.js +281 -37
- package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
- package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +30 -7
- package/src/omega/{runtime_support/runtime_support.js → compat/runtime_compat.js} +14 -16
- package/src/omega/errors.js +51 -58
- package/src/omega/fetched_content_compliance.js +24 -0
- package/src/omega/kitchen.js +403 -283
- package/src/omega/server/file_service.js +9 -11
- package/src/omega/url_graph/url_graph_load.js +13 -7
- package/src/omega/url_graph/url_graph_report.js +7 -5
- package/src/omega/url_graph.js +22 -10
- package/src/omega/web_workers.js +42 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +41 -0
- package/src/{dev/plugins/autoreload/jsenv_plugin_autoreload.js → plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js} +25 -166
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +25 -0
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
- package/src/plugins/bundling/css/bundle_css.js +17 -0
- package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
- package/src/{build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js → plugins/bundling/js_module/bundle_js_module.js} +100 -75
- package/src/plugins/bundling/jsenv_plugin_bundling.js +51 -0
- package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +48 -41
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
- package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +7 -4
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_installer.js +3 -2
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_setup.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +38 -46
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +98 -0
- package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +26 -8
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
- package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +37 -31
- package/src/{omega/core_plugins → plugins}/inject_globals/jsenv_plugin_inject_globals.js +4 -6
- package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
- package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +61 -40
- package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +263 -0
- package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
- package/src/plugins/minification/css/minify_css.js +9 -0
- package/src/plugins/minification/html/minify_html.js +15 -0
- package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
- package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
- package/src/plugins/minification/json/minify_json.js +8 -0
- package/src/{omega/core_plugins → plugins}/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +15 -15
- package/src/{omega → plugins}/plugin_controller.js +18 -10
- package/src/plugins/plugins.js +73 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js +808 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
- package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
- package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +191 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +156 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_top_level_await.js +37 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +133 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +3 -21
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +29 -27
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
- package/src/{omega/core_plugins → plugins/transpilation}/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +243 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +40 -0
- package/src/plugins/url_references/css/css_urls.js +49 -0
- package/src/plugins/url_references/html/html_urls.js +273 -0
- package/src/plugins/url_references/js/js_urls.js +170 -0
- package/src/plugins/url_references/jsenv_plugin_url_references.js +18 -0
- package/src/plugins/url_references/webmanifest/webmanifest_urls.js +17 -0
- package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
- package/src/{omega/core_plugins → plugins}/url_version/jsenv_plugin_url_version.js +8 -8
- package/src/test/execute_plan.js +23 -11
- package/src/test/execute_test_plan.js +9 -6
- package/src/test/logs_file_execution.js +8 -7
- package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
- package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
- package/src/dev/plugins/autoreload/sse_service.js +0 -149
- package/src/execute/runtimes/node/controlled_process.js +0 -316
- package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
- package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
- package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
- package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
- package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
- package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -207
- package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
- package/src/omega/core_plugins.js +0 -42
- package/src/omega/url_mentions/css_url_mentions.js +0 -63
- package/src/omega/url_mentions/html_url_mentions.js +0 -185
- package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
- package/src/omega/url_mentions/parse_url_mentions.js +0 -37
- package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
|
@@ -0,0 +1 @@
|
|
|
1
|
+
s.js exists to ease jsenv ability to find the file.
|
package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import babelParser from "@babel/parser"
|
|
2
|
+
|
|
3
|
+
export const babelPluginTransformImportMetaUrl = (babel) => {
|
|
4
|
+
return {
|
|
5
|
+
name: "transform-import-meta-url",
|
|
6
|
+
visitor: {
|
|
7
|
+
Program: (programPath) => {
|
|
8
|
+
const currentUrlIdentifier =
|
|
9
|
+
programPath.scope.generateUidIdentifier("currentUrl")
|
|
10
|
+
let used = false
|
|
11
|
+
|
|
12
|
+
programPath.traverse({
|
|
13
|
+
MemberExpression: (path) => {
|
|
14
|
+
const node = path.node
|
|
15
|
+
if (
|
|
16
|
+
node.object.type === "MetaProperty" &&
|
|
17
|
+
node.object.property.name === "meta" &&
|
|
18
|
+
node.property.name === "url"
|
|
19
|
+
) {
|
|
20
|
+
// const node = babel.types.valueToNode(10)
|
|
21
|
+
const identifier = babel.types.identifier(
|
|
22
|
+
currentUrlIdentifier.name,
|
|
23
|
+
)
|
|
24
|
+
const expressionStatement =
|
|
25
|
+
babel.types.expressionStatement(identifier)
|
|
26
|
+
path.replaceWith(expressionStatement)
|
|
27
|
+
used = true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
if (used) {
|
|
32
|
+
const ast = generateExpressionAst(`document.currentScript.src`)
|
|
33
|
+
programPath.scope.push({
|
|
34
|
+
id: currentUrlIdentifier,
|
|
35
|
+
init: ast,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const generateExpressionAst = (expression, options) => {
|
|
44
|
+
const { parseExpression } = babelParser
|
|
45
|
+
const ast = parseExpression(expression, options)
|
|
46
|
+
return ast
|
|
47
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// const { clientRuntimeCompat, isSupportedOnCurrentClient } = context
|
|
2
|
+
// const shouldBeCompatibleWithNode =
|
|
3
|
+
// Object.keys(clientRuntimeCompat).includes("node")
|
|
4
|
+
// const requiredFeatureNames = [
|
|
5
|
+
// "import_dynamic",
|
|
6
|
+
// "top_level_await",
|
|
7
|
+
// "global_this",
|
|
8
|
+
// // when using node we assume the code won't use browser specific feature
|
|
9
|
+
// ...(shouldBeCompatibleWithNode
|
|
10
|
+
// ? []
|
|
11
|
+
// : [
|
|
12
|
+
// "script_type_module",
|
|
13
|
+
// "worker_type_module",
|
|
14
|
+
// "import_type_json",
|
|
15
|
+
// "import_type_css",
|
|
16
|
+
// ]),
|
|
17
|
+
// // "importmap",
|
|
18
|
+
// ]
|
|
19
|
+
// const needsSystemJs = featuresRelatedToSystemJs.some((featureName) => {
|
|
20
|
+
// const isRequired = requiredFeatureNames.includes(featureName)
|
|
21
|
+
// return isRequired && !isSupportedOnCurrentClient(featureName)
|
|
22
|
+
// })
|
|
23
|
+
// if (!needsSystemJs) {
|
|
24
|
+
// return null
|
|
25
|
+
// }
|
|
26
|
+
// const { code, map } = await applyBabelPlugins({
|
|
27
|
+
|
|
28
|
+
// })
|
|
29
|
+
// return {
|
|
30
|
+
// content: code,
|
|
31
|
+
// soourcemap: map,
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// const featuresRelatedToSystemJs = [
|
|
35
|
+
// "script_type_module",
|
|
36
|
+
// "worker_type_module",
|
|
37
|
+
// "import_dynamic",
|
|
38
|
+
// "import_type_json",
|
|
39
|
+
// "import_type_css",
|
|
40
|
+
// "top_level_await",
|
|
41
|
+
// // "importmap",
|
|
42
|
+
// // "worker_importmap",
|
|
43
|
+
// ]
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Something to keep in mind:
|
|
3
|
+
* When systemjs format is used by babel, it will generated UID based on
|
|
4
|
+
* the import specifier:
|
|
5
|
+
* https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
|
|
6
|
+
* But at this stage import specifier are absolute file urls
|
|
7
|
+
* So without minification these specifier are long and dependent
|
|
8
|
+
* on where the files are on the filesystem.
|
|
9
|
+
* This is mitigated by minification that will shorten them
|
|
10
|
+
* But ideally babel should not generate this in the first place
|
|
11
|
+
* and prefer to unique identifier based solely on the specifier basename for instance
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createRequire } from "node:module"
|
|
15
|
+
import { readFileSync, urlToFilename } from "@jsenv/filesystem"
|
|
16
|
+
|
|
17
|
+
import { requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
18
|
+
|
|
19
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
20
|
+
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
21
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
22
|
+
import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js"
|
|
23
|
+
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
24
|
+
import { jsenvPluginScriptTypeModuleAsClassic } from "./jsenv_plugin_script_type_module_as_classic.js"
|
|
25
|
+
import { jsenvPluginWorkersTypeModuleAsClassic } from "./jsenv_plugin_workers_type_module_as_classic.js"
|
|
26
|
+
import { jsenvPluginTopLevelAwait } from "./jsenv_plugin_top_level_await.js"
|
|
27
|
+
|
|
28
|
+
const require = createRequire(import.meta.url)
|
|
29
|
+
|
|
30
|
+
export const jsenvPluginAsJsClassic = ({ systemJsInjection }) => {
|
|
31
|
+
const systemJsClientFileUrl = new URL("./client/s.js", import.meta.url).href
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
asJsClassic({ systemJsInjection, systemJsClientFileUrl }),
|
|
35
|
+
jsenvPluginScriptTypeModuleAsClassic({
|
|
36
|
+
systemJsInjection,
|
|
37
|
+
systemJsClientFileUrl,
|
|
38
|
+
generateJsClassicFilename,
|
|
39
|
+
}),
|
|
40
|
+
jsenvPluginWorkersTypeModuleAsClassic({
|
|
41
|
+
generateJsClassicFilename,
|
|
42
|
+
}),
|
|
43
|
+
jsenvPluginTopLevelAwait(),
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const asJsClassic = ({ systemJsInjection, systemJsClientFileUrl }) => {
|
|
48
|
+
return {
|
|
49
|
+
name: "jsenv:as_js_classic",
|
|
50
|
+
appliesDuring: "*",
|
|
51
|
+
// forward ?as_js_classic to referenced urls
|
|
52
|
+
normalizeUrl: (reference, context) => {
|
|
53
|
+
if (reference.isInline) {
|
|
54
|
+
if (reference.contentType !== "text/javascript") {
|
|
55
|
+
// We want to propagate transformation of js module to js classic
|
|
56
|
+
// so we don't want to propagate when the reference is not js:
|
|
57
|
+
// - ignore "string" in `JSON.parse(string)` for instance
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
62
|
+
if (
|
|
63
|
+
!parentUrlInfo ||
|
|
64
|
+
!new URL(parentUrlInfo.url).searchParams.has("as_js_classic")
|
|
65
|
+
) {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
const urlTransformed = injectQueryParams(reference.url, {
|
|
69
|
+
as_js_classic: "",
|
|
70
|
+
})
|
|
71
|
+
reference.filename = generateJsClassicFilename(reference.url)
|
|
72
|
+
return urlTransformed
|
|
73
|
+
},
|
|
74
|
+
fetchUrlContent: async (urlInfo, context) => {
|
|
75
|
+
const urlObject = new URL(urlInfo.url)
|
|
76
|
+
const { searchParams } = urlObject
|
|
77
|
+
if (!searchParams.has("as_js_classic")) {
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
searchParams.delete("as_js_classic")
|
|
81
|
+
const originalUrl = urlObject.href
|
|
82
|
+
const originalReference = {
|
|
83
|
+
...(context.reference.original || context.reference),
|
|
84
|
+
// override the expectedType to "js_module"
|
|
85
|
+
// because when there is ?as_js_classic it means the underlying ressource
|
|
86
|
+
// is a js_module
|
|
87
|
+
expectedType: "js_module",
|
|
88
|
+
}
|
|
89
|
+
originalReference.url = originalUrl
|
|
90
|
+
const originalUrlInfo = context.urlGraph.reuseOrCreateUrlInfo(
|
|
91
|
+
originalReference.url,
|
|
92
|
+
)
|
|
93
|
+
await context.fetchUrlContent({
|
|
94
|
+
reference: originalReference,
|
|
95
|
+
urlInfo: originalUrlInfo,
|
|
96
|
+
})
|
|
97
|
+
const isJsEntryPoint =
|
|
98
|
+
// in general html files are entry points
|
|
99
|
+
// but during build js can be sepcified as an entry point
|
|
100
|
+
// (meaning there is no html file where we can inject systemjs)
|
|
101
|
+
// in that case we need to inject systemjs in the js file
|
|
102
|
+
originalUrlInfo.data.isEntryPoint ||
|
|
103
|
+
// In thoose case we need to inject systemjs the worker js file
|
|
104
|
+
originalUrlInfo.data.isWebWorkerEntryPoint
|
|
105
|
+
// if it's an entry point without dependency (it does not use import)
|
|
106
|
+
// then we can use UMD, otherwise we have to use systemjs
|
|
107
|
+
// because it is imported by systemjs
|
|
108
|
+
const jsClassicFormat =
|
|
109
|
+
isJsEntryPoint && !originalUrlInfo.data.usesImport ? "umd" : "system"
|
|
110
|
+
const { content, sourcemap } = await convertJsModuleToJsClassic({
|
|
111
|
+
systemJsInjection,
|
|
112
|
+
systemJsClientFileUrl,
|
|
113
|
+
urlInfo: originalUrlInfo,
|
|
114
|
+
isJsEntryPoint,
|
|
115
|
+
jsClassicFormat,
|
|
116
|
+
})
|
|
117
|
+
urlInfo.data.jsClassicFormat = jsClassicFormat
|
|
118
|
+
return {
|
|
119
|
+
type: "js_classic",
|
|
120
|
+
contentType: "text/javascript",
|
|
121
|
+
content,
|
|
122
|
+
sourcemap,
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const generateJsClassicFilename = (url) => {
|
|
129
|
+
const filename = urlToFilename(url)
|
|
130
|
+
const [basename, extension] = splitFileExtension(filename)
|
|
131
|
+
return `${basename}.es5${extension}`
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const splitFileExtension = (filename) => {
|
|
135
|
+
const dotLastIndex = filename.lastIndexOf(".")
|
|
136
|
+
if (dotLastIndex === -1) {
|
|
137
|
+
return [filename, ""]
|
|
138
|
+
}
|
|
139
|
+
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const convertJsModuleToJsClassic = async ({
|
|
143
|
+
systemJsInjection,
|
|
144
|
+
systemJsClientFileUrl,
|
|
145
|
+
urlInfo,
|
|
146
|
+
isJsEntryPoint,
|
|
147
|
+
jsClassicFormat,
|
|
148
|
+
}) => {
|
|
149
|
+
const { code, map } = await applyBabelPlugins({
|
|
150
|
+
babelPlugins: [
|
|
151
|
+
...(jsClassicFormat === "system"
|
|
152
|
+
? [
|
|
153
|
+
// propposal-dynamic-import required with systemjs for babel8:
|
|
154
|
+
// https://github.com/babel/babel/issues/10746
|
|
155
|
+
require("@babel/plugin-proposal-dynamic-import"),
|
|
156
|
+
[
|
|
157
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
158
|
+
{
|
|
159
|
+
topLevelAwait: "return",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
require("@babel/plugin-transform-modules-systemjs"),
|
|
163
|
+
]
|
|
164
|
+
: [
|
|
165
|
+
[
|
|
166
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
167
|
+
{
|
|
168
|
+
topLevelAwait: "simple",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
babelPluginTransformImportMetaUrl,
|
|
172
|
+
require("@babel/plugin-transform-modules-umd"),
|
|
173
|
+
]),
|
|
174
|
+
],
|
|
175
|
+
urlInfo,
|
|
176
|
+
})
|
|
177
|
+
if (systemJsInjection && jsClassicFormat === "system" && isJsEntryPoint) {
|
|
178
|
+
const magicSource = createMagicSource(code)
|
|
179
|
+
const systemjsCode = readFileSync(systemJsClientFileUrl, { as: "string" })
|
|
180
|
+
magicSource.prepend(`${systemjsCode}\n\n`)
|
|
181
|
+
const { content, sourcemap } = magicSource.toContentAndSourcemap()
|
|
182
|
+
return {
|
|
183
|
+
content,
|
|
184
|
+
sourcemap: await composeTwoSourcemaps(map, sourcemap),
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
content: code,
|
|
189
|
+
sourcemap: map,
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHtmlNodeAttributeByName,
|
|
3
|
+
getHtmlNodeTextNode,
|
|
4
|
+
parseHtmlString,
|
|
5
|
+
removeHtmlNodeAttribute,
|
|
6
|
+
stringifyHtmlAst,
|
|
7
|
+
visitHtmlAst,
|
|
8
|
+
htmlNodePosition,
|
|
9
|
+
setHtmlNodeGeneratedText,
|
|
10
|
+
injectScriptAsEarlyAsPossible,
|
|
11
|
+
createHtmlNode,
|
|
12
|
+
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
13
|
+
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
14
|
+
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
15
|
+
|
|
16
|
+
export const jsenvPluginScriptTypeModuleAsClassic = ({
|
|
17
|
+
systemJsInjection,
|
|
18
|
+
systemJsClientFileUrl,
|
|
19
|
+
generateJsClassicFilename,
|
|
20
|
+
}) => {
|
|
21
|
+
return {
|
|
22
|
+
name: "jsenv:script_type_module_as_classic",
|
|
23
|
+
appliesDuring: "*",
|
|
24
|
+
transformUrlContent: {
|
|
25
|
+
html: async (urlInfo, context) => {
|
|
26
|
+
if (
|
|
27
|
+
context.isSupportedOnCurrentClients("script_type_module") &&
|
|
28
|
+
context.isSupportedOnCurrentClients("import_dynamic")
|
|
29
|
+
) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
const htmlAst = parseHtmlString(urlInfo.content)
|
|
33
|
+
const actions = []
|
|
34
|
+
const jsModuleUrlInfos = []
|
|
35
|
+
const visitScriptTypeModule = (node) => {
|
|
36
|
+
if (node.nodeName !== "script") {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const typeAttribute = getHtmlNodeAttributeByName(node, "type")
|
|
40
|
+
if (!typeAttribute || typeAttribute.value !== "module") {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
const srcAttribute = getHtmlNodeAttributeByName(node, "src")
|
|
44
|
+
if (srcAttribute) {
|
|
45
|
+
actions.push(async () => {
|
|
46
|
+
const specifier = srcAttribute.value
|
|
47
|
+
const reference =
|
|
48
|
+
context.referenceUtils.findByGeneratedSpecifier(specifier)
|
|
49
|
+
const [newReference, newUrlInfo] = context.referenceUtils.update(
|
|
50
|
+
reference,
|
|
51
|
+
{
|
|
52
|
+
expectedType: "js_classic",
|
|
53
|
+
specifier: injectQueryParamsIntoSpecifier(specifier, {
|
|
54
|
+
as_js_classic: "",
|
|
55
|
+
}),
|
|
56
|
+
filename: generateJsClassicFilename(reference.url),
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
removeHtmlNodeAttribute(node, typeAttribute)
|
|
60
|
+
srcAttribute.value = newReference.generatedSpecifier
|
|
61
|
+
// during dev it means js modules will be cooked before server sends the HTML
|
|
62
|
+
// it's ok because:
|
|
63
|
+
// - during dev script_type_module are supported (dev use a recent browser)
|
|
64
|
+
// - even if browser is not supported it still works it's jus a bit slower
|
|
65
|
+
// because it needs to decide if systemjs will be injected or not
|
|
66
|
+
await context.cook({
|
|
67
|
+
reference: newReference,
|
|
68
|
+
urlInfo: newUrlInfo,
|
|
69
|
+
})
|
|
70
|
+
jsModuleUrlInfos.push(newUrlInfo)
|
|
71
|
+
})
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
const textNode = getHtmlNodeTextNode(node)
|
|
75
|
+
actions.push(async () => {
|
|
76
|
+
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
77
|
+
htmlNodePosition.readNodePosition(node, {
|
|
78
|
+
preferOriginal: true,
|
|
79
|
+
})
|
|
80
|
+
let inlineScriptUrl = generateInlineContentUrl({
|
|
81
|
+
url: urlInfo.url,
|
|
82
|
+
extension: ".js",
|
|
83
|
+
line,
|
|
84
|
+
column,
|
|
85
|
+
lineEnd,
|
|
86
|
+
columnEnd,
|
|
87
|
+
})
|
|
88
|
+
const [inlineReference] = context.referenceUtils.foundInline({
|
|
89
|
+
node,
|
|
90
|
+
type: "script_src",
|
|
91
|
+
expectedType: "js_module",
|
|
92
|
+
// we remove 1 to the line because imagine the following html:
|
|
93
|
+
// <script>console.log('ok')</script>
|
|
94
|
+
// -> content starts same line as <script>
|
|
95
|
+
line: line - 1,
|
|
96
|
+
column,
|
|
97
|
+
isOriginalPosition: isOriginal,
|
|
98
|
+
specifier: inlineScriptUrl,
|
|
99
|
+
contentType: "application/javascript",
|
|
100
|
+
content: textNode.value,
|
|
101
|
+
})
|
|
102
|
+
const [newReference, newUrlInfo] = context.referenceUtils.update(
|
|
103
|
+
inlineReference,
|
|
104
|
+
{
|
|
105
|
+
expectedType: "js_classic",
|
|
106
|
+
specifier: injectQueryParamsIntoSpecifier(inlineScriptUrl, {
|
|
107
|
+
as_js_classic: "",
|
|
108
|
+
}),
|
|
109
|
+
filename: generateJsClassicFilename(inlineReference.url),
|
|
110
|
+
},
|
|
111
|
+
)
|
|
112
|
+
await context.cook({
|
|
113
|
+
reference: newReference,
|
|
114
|
+
urlInfo: newUrlInfo,
|
|
115
|
+
})
|
|
116
|
+
removeHtmlNodeAttribute(node, typeAttribute)
|
|
117
|
+
setHtmlNodeGeneratedText(node, {
|
|
118
|
+
generatedText: newUrlInfo.content,
|
|
119
|
+
generatedBy: "jsenv:script_type_module_as_classic",
|
|
120
|
+
})
|
|
121
|
+
jsModuleUrlInfos.push(newUrlInfo)
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
visitHtmlAst(htmlAst, (node) => {
|
|
125
|
+
visitScriptTypeModule(node)
|
|
126
|
+
})
|
|
127
|
+
if (actions.length === 0) {
|
|
128
|
+
return null
|
|
129
|
+
}
|
|
130
|
+
await Promise.all(actions.map((action) => action()))
|
|
131
|
+
if (systemJsInjection) {
|
|
132
|
+
const needsSystemJs = jsModuleUrlInfos.some(
|
|
133
|
+
(jsModuleUrlInfo) =>
|
|
134
|
+
jsModuleUrlInfo.data.jsClassicFormat === "system",
|
|
135
|
+
)
|
|
136
|
+
if (needsSystemJs) {
|
|
137
|
+
const [systemJsReference] = context.referenceUtils.inject({
|
|
138
|
+
type: "script_src",
|
|
139
|
+
expectedType: "js_classic",
|
|
140
|
+
specifier: systemJsClientFileUrl,
|
|
141
|
+
})
|
|
142
|
+
injectScriptAsEarlyAsPossible(
|
|
143
|
+
htmlAst,
|
|
144
|
+
createHtmlNode({
|
|
145
|
+
"tagName": "script",
|
|
146
|
+
"src": systemJsReference.generatedSpecifier,
|
|
147
|
+
"injected-by": "jsenv:script_type_module_as_classic",
|
|
148
|
+
}),
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return stringifyHtmlAst(htmlAst)
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
2
|
+
|
|
3
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
4
|
+
|
|
5
|
+
export const jsenvPluginTopLevelAwait = () => {
|
|
6
|
+
return {
|
|
7
|
+
name: "jsenv:top_level_await",
|
|
8
|
+
appliesDuring: "*",
|
|
9
|
+
transformUrlContent: {
|
|
10
|
+
js_module: async (urlInfo, context) => {
|
|
11
|
+
if (!urlInfo.data.usesTopLevelAwait) {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
if (context.isSupportedOnCurrentClients("top_level_await")) {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
const { code, map } = await applyBabelPlugins({
|
|
18
|
+
urlInfo,
|
|
19
|
+
babelPlugins: [
|
|
20
|
+
[
|
|
21
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
22
|
+
{
|
|
23
|
+
// Maybe we could pass target: "es6" when we support arrow function
|
|
24
|
+
// https://github.com/rpetrich/babel-plugin-transform-async-to-promises/blob/92755ff8c943c97596523e586b5fa515c2e99326/async-to-promises.ts#L55
|
|
25
|
+
topLevelAwait: "simple",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
],
|
|
29
|
+
})
|
|
30
|
+
return {
|
|
31
|
+
content: code,
|
|
32
|
+
sourcemap: map,
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
|
+
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
3
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
4
|
+
import {
|
|
5
|
+
analyzeNewWorkerOrNewSharedWorker,
|
|
6
|
+
analyzeServiceWorkerRegisterCall,
|
|
7
|
+
} from "@jsenv/utils/js_ast/js_static_analysis.js"
|
|
8
|
+
|
|
9
|
+
// TODO: handle also service worker and shared worker in this plugin
|
|
10
|
+
export const jsenvPluginWorkersTypeModuleAsClassic = ({
|
|
11
|
+
generateJsClassicFilename,
|
|
12
|
+
}) => {
|
|
13
|
+
const transformJsWorkerTypes = async (urlInfo, context) => {
|
|
14
|
+
const workersToTranspile = getWorkersToTranspile(urlInfo, context)
|
|
15
|
+
if (
|
|
16
|
+
!workersToTranspile.worker &&
|
|
17
|
+
!workersToTranspile.serviceWorker &&
|
|
18
|
+
!workersToTranspile.sharedServiceWorker
|
|
19
|
+
) {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
const { metadata } = await applyBabelPlugins({
|
|
23
|
+
babelPlugins: [
|
|
24
|
+
[
|
|
25
|
+
babelPluginMetadataWorkerMentions,
|
|
26
|
+
{
|
|
27
|
+
workersToTranspile,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
],
|
|
31
|
+
urlInfo,
|
|
32
|
+
})
|
|
33
|
+
const { workerMentions } = metadata
|
|
34
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
35
|
+
workerMentions.forEach((workerMention) => {
|
|
36
|
+
if (workerMention.expectedType !== "js_module") {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const specifier = workerMention.specifier
|
|
40
|
+
const reference = context.referenceUtils.findByGeneratedSpecifier(
|
|
41
|
+
JSON.stringify(specifier),
|
|
42
|
+
)
|
|
43
|
+
const [newReference] = context.referenceUtils.update(reference, {
|
|
44
|
+
expectedType: "js_classic",
|
|
45
|
+
specifier: injectQueryParamsIntoSpecifier(specifier, {
|
|
46
|
+
as_js_classic: "",
|
|
47
|
+
}),
|
|
48
|
+
filename: generateJsClassicFilename(reference.url),
|
|
49
|
+
})
|
|
50
|
+
magicSource.replace({
|
|
51
|
+
start: workerMention.start,
|
|
52
|
+
end: workerMention.end,
|
|
53
|
+
replacement: newReference.generatedSpecifier,
|
|
54
|
+
})
|
|
55
|
+
magicSource.replace({
|
|
56
|
+
start: workerMention.typeArgNode.value.start,
|
|
57
|
+
end: workerMention.typeArgNode.value.end,
|
|
58
|
+
replacement: JSON.stringify("classic"),
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
return magicSource.toContentAndSourcemap()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
name: "jsenv:workers_type_module_as_classic",
|
|
66
|
+
appliesDuring: "*",
|
|
67
|
+
transformUrlContent: {
|
|
68
|
+
js_module: transformJsWorkerTypes,
|
|
69
|
+
js_classic: transformJsWorkerTypes,
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const getWorkersToTranspile = (urlInfo, context) => {
|
|
75
|
+
let worker = false
|
|
76
|
+
let serviceWorker = false
|
|
77
|
+
let sharedWorker = false
|
|
78
|
+
for (const reference of urlInfo.references) {
|
|
79
|
+
if (reference.expectedType !== "js_module") {
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
if (
|
|
83
|
+
reference.expectedSubtype === "worker" &&
|
|
84
|
+
!context.isSupportedOnCurrentClients("worker_type_module")
|
|
85
|
+
) {
|
|
86
|
+
worker = true
|
|
87
|
+
}
|
|
88
|
+
if (
|
|
89
|
+
reference.expectedSubtype === "service_worker" &&
|
|
90
|
+
!context.isSupportedOnCurrentClients("service_worker_type_module")
|
|
91
|
+
) {
|
|
92
|
+
serviceWorker = true
|
|
93
|
+
}
|
|
94
|
+
if (
|
|
95
|
+
reference.expectedSubtype === "shared_worker" &&
|
|
96
|
+
!context.isSupportedOnCurrentClients("shared_worker_type_module")
|
|
97
|
+
) {
|
|
98
|
+
sharedWorker = true
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { worker, serviceWorker, sharedWorker }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const babelPluginMetadataWorkerMentions = (_, { workersToTranspile }) => {
|
|
105
|
+
return {
|
|
106
|
+
name: "metadata-worker-mentions",
|
|
107
|
+
visitor: {
|
|
108
|
+
Program(programPath, state) {
|
|
109
|
+
const workerMentions = []
|
|
110
|
+
const visitors = {
|
|
111
|
+
NewExpression: (path) => {
|
|
112
|
+
if (workersToTranspile.worker || workersToTranspile.sharedWorker) {
|
|
113
|
+
const mentions = analyzeNewWorkerOrNewSharedWorker(path)
|
|
114
|
+
if (mentions) {
|
|
115
|
+
workerMentions.push(...mentions)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
if (workersToTranspile.serviceWorker) {
|
|
121
|
+
visitors.CallExpression = (path) => {
|
|
122
|
+
const mentions = analyzeServiceWorkerRegisterCall(path)
|
|
123
|
+
if (mentions) {
|
|
124
|
+
workerMentions.push(...mentions)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
programPath.traverse(visitors)
|
|
129
|
+
state.file.metadata.workerMentions = workerMentions
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
}
|
|
File without changes
|
package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js
RENAMED
|
File without changes
|
|
File without changes
|
package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js
RENAMED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { getBabelHelperFileUrl, requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
2
2
|
import { babelPluginCompatMap } from "./babel_plugins_compatibility.js"
|
|
3
3
|
|
|
4
|
-
export const getBaseBabelPluginStructure = ({
|
|
5
|
-
url,
|
|
6
|
-
isSupportedOnRuntime,
|
|
7
|
-
usesTopLevelAwait,
|
|
8
|
-
// // https://github.com/rpetrich/babel-plugin-transform-async-to-promises/blob/92755ff8c943c97596523e586b5fa515c2e99326/async-to-promises.ts#L55
|
|
9
|
-
topLevelAwait = "simple",
|
|
10
|
-
isJsModule,
|
|
11
|
-
}) => {
|
|
4
|
+
export const getBaseBabelPluginStructure = ({ url, isSupported }) => {
|
|
12
5
|
const isBabelPluginNeeded = (babelPluginName) => {
|
|
13
|
-
return !
|
|
6
|
+
return !isSupported(babelPluginCompatMap[babelPluginName])
|
|
14
7
|
}
|
|
15
8
|
|
|
16
9
|
const babelPluginStructure = {}
|
|
@@ -37,18 +30,7 @@ export const getBaseBabelPluginStructure = ({
|
|
|
37
30
|
babelPluginStructure["proposal-unicode-property-regex"] =
|
|
38
31
|
requireBabelPlugin("@babel/plugin-proposal-unicode-property-regex")
|
|
39
32
|
}
|
|
40
|
-
if (
|
|
41
|
-
isJsModule &&
|
|
42
|
-
usesTopLevelAwait &&
|
|
43
|
-
!isSupportedOnRuntime("top_level_await")
|
|
44
|
-
) {
|
|
45
|
-
babelPluginStructure["transform-async-to-promises"] = [
|
|
46
|
-
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
47
|
-
{
|
|
48
|
-
topLevelAwait,
|
|
49
|
-
},
|
|
50
|
-
]
|
|
51
|
-
} else if (isBabelPluginNeeded("transform-async-to-promises")) {
|
|
33
|
+
if (isBabelPluginNeeded("transform-async-to-promises")) {
|
|
52
34
|
babelPluginStructure["transform-async-to-promises"] = requireBabelPlugin(
|
|
53
35
|
"babel-plugin-transform-async-to-promises",
|
|
54
36
|
)
|
|
File without changes
|