@jsenv/core 27.0.0-alpha.6 → 27.0.0-alpha.60
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/event_source_client.js +545 -0
- package/dist/event_source_client.js.map +187 -0
- package/dist/html_supervisor_installer.js +1236 -0
- package/dist/html_supervisor_installer.js.map +337 -0
- package/dist/html_supervisor_setup.js +95 -0
- package/dist/html_supervisor_setup.js.map +57 -0
- package/dist/import_meta_hot.js +86 -0
- package/dist/import_meta_hot.js.map +42 -0
- package/main.js +8 -1
- package/package.json +30 -28
- package/readme.md +6 -14
- package/src/build/build.js +943 -555
- package/src/build/build_urls_generator.js +48 -23
- package/src/build/graph_utils.js +31 -0
- package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
- package/src/build/inject_service_worker_urls.js +79 -0
- package/src/build/resync_ressource_hints.js +68 -0
- package/src/build/start_build_server.js +192 -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 +136 -30
- package/src/execute/execute.js +31 -6
- package/src/execute/run.js +19 -56
- package/src/execute/runtimes/browsers/from_playwright.js +207 -147
- package/src/execute/runtimes/node/controllable_file.mjs +26 -10
- package/src/execute/runtimes/node/node_execution_performance.js +67 -0
- package/src/execute/runtimes/node/node_process.js +280 -39
- package/src/jsenv_root_directory_url.js +1 -0
- 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} +66 -4
- package/src/omega/compat/runtime_compat.js +50 -0
- package/src/omega/errors.js +51 -58
- package/src/omega/fetched_content_compliance.js +24 -0
- package/src/omega/file_url_converter.js +8 -50
- package/src/omega/kitchen.js +482 -304
- package/src/omega/omega_server.js +2 -3
- package/src/omega/server/file_service.js +53 -25
- package/src/omega/server/user_agent.js +4 -2
- package/src/omega/url_graph/url_graph_load.js +22 -7
- package/src/omega/url_graph/url_graph_report.js +98 -48
- package/src/omega/url_graph/url_info_transformations.js +26 -9
- package/src/omega/url_graph.js +80 -16
- 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 +46 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +27 -0
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
- package/src/plugins/bundling/css/bundle_css.js +140 -0
- package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
- package/src/plugins/bundling/js_module/bundle_js_module.js +309 -0
- package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +34 -0
- package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +54 -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 +8 -5
- 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/plugins/html_supervisor/client/html_supervisor_installer.js +242 -0
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +79 -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 +83 -61
- 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 +105 -0
- package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +33 -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 +39 -33
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +67 -0
- 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} +65 -44
- 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 +297 -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/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +146 -0
- package/src/{omega → plugins}/plugin_controller.js +42 -11
- package/src/plugins/plugins.js +92 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js +874 -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 +199 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +270 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +55 -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 +12 -19
- 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 +45 -27
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
- 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/plugins/transpilation/fetch_original_url_info.js +30 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +181 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +80 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
- package/src/plugins/url_analysis/css/css_urls.js +49 -0
- package/src/plugins/url_analysis/html/html_urls.js +269 -0
- package/src/plugins/url_analysis/js/js_urls.js +67 -0
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +18 -0
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +17 -0
- package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
- package/src/plugins/url_version/jsenv_plugin_url_version.js +28 -0
- package/src/test/execute_plan.js +30 -18
- package/src/test/execute_test_plan.js +23 -8
- package/src/test/logs_file_execution.js +9 -8
- package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +0 -225
- 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/jsenv_plugin_autoreload.js +0 -374
- 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/html_supervisor/client/html_supervisor_installer.js +0 -168
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
- package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
- 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 -210
- package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
- package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
- package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +0 -50
- package/src/omega/core_plugins.js +0 -39
- package/src/omega/runtime_support/runtime_support.js +0 -20
- package/src/omega/url_graph/url_graph_sort.js +0 -29
- 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
package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
export const babelPluginMetadataImportAssertions = () => {
|
|
2
|
-
return {
|
|
3
|
-
name: "metadata-import-assertions",
|
|
4
|
-
visitor: {
|
|
5
|
-
Program: (programPath, state) => {
|
|
6
|
-
const importAssertions = collectProgramImportAssertions(programPath)
|
|
7
|
-
state.file.metadata.importAssertions = importAssertions
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
* Jsenv wont touch code where "specifier" or "type" is dynamic (see code below)
|
|
15
|
-
* ```js
|
|
16
|
-
* const file ="./style.css"
|
|
17
|
-
* const type = "css"
|
|
18
|
-
* import(file, { assert: { type }})
|
|
19
|
-
* ```
|
|
20
|
-
* Jsenv could throw an error because we know browser will fail to execute the code
|
|
21
|
-
* because import assertions are not supported.
|
|
22
|
-
* But for now (as it is simpler to do so) we let the browser throw the error
|
|
23
|
-
*/
|
|
24
|
-
const collectProgramImportAssertions = (programPath) => {
|
|
25
|
-
const importAssertions = []
|
|
26
|
-
programPath.traverse({
|
|
27
|
-
CallExpression: (path) => {
|
|
28
|
-
if (path.node.callee.type !== "Import") {
|
|
29
|
-
// Some other function call, not import();
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
if (path.node.arguments[0].type !== "StringLiteral") {
|
|
33
|
-
// Non-string argument, probably a variable or expression, e.g.
|
|
34
|
-
// import(moduleId)
|
|
35
|
-
// import('./' + moduleName)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
const args = path.node.arguments
|
|
39
|
-
const secondArg = args[1]
|
|
40
|
-
if (!secondArg) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
const { properties } = secondArg
|
|
44
|
-
const assertProperty = properties.find((property) => {
|
|
45
|
-
return property.key.name === "assert"
|
|
46
|
-
})
|
|
47
|
-
if (!assertProperty) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
const assertProperties = assertProperty.value.properties
|
|
51
|
-
const typePropertyNode = assertProperties.find((property) => {
|
|
52
|
-
return property.key.name === "type"
|
|
53
|
-
})
|
|
54
|
-
if (!typePropertyNode) {
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
const typePropertyValue = typePropertyNode.value
|
|
58
|
-
if (typePropertyValue.type !== "StringLiteral") {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
const type = typePropertyValue.value
|
|
62
|
-
importAssertions.push({
|
|
63
|
-
path,
|
|
64
|
-
assert: {
|
|
65
|
-
type,
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
ImportDeclaration: (path) => {
|
|
71
|
-
const { assertions } = path.node
|
|
72
|
-
if (!assertions) {
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
if (assertions.length === 0) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
const typeAssertion = assertions.find(
|
|
79
|
-
(assertion) => assertion.key.name === "type",
|
|
80
|
-
)
|
|
81
|
-
if (!typeAssertion) {
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
const typeNode = typeAssertion.value
|
|
85
|
-
if (typeNode.type !== "StringLiteral") {
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
const type = typeNode.value
|
|
89
|
-
importAssertions.push({
|
|
90
|
-
path,
|
|
91
|
-
assert: {
|
|
92
|
-
type,
|
|
93
|
-
},
|
|
94
|
-
})
|
|
95
|
-
},
|
|
96
|
-
})
|
|
97
|
-
return importAssertions
|
|
98
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const convertJsonTextToJavascriptModule = ({ content }) => {
|
|
2
|
-
// here we could do the following
|
|
3
|
-
// return export default jsonText
|
|
4
|
-
// This would return valid js, that would be minified later
|
|
5
|
-
// however we will prefer using JSON.parse because it's faster
|
|
6
|
-
// for js engine to parse JSON than JS
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
contentType: "application/javascript",
|
|
10
|
-
content: `export default JSON.parse(${JSON.stringify(content.trim())})`,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
|
-
import { ContentType } from "@jsenv/utils/src/content_type.js"
|
|
3
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
4
|
-
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
5
|
-
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
6
|
-
|
|
7
|
-
import { babelPluginMetadataImportAssertions } from "./helpers/babel_plugin_metadata_import_assertions.js"
|
|
8
|
-
import { convertJsonTextToJavascriptModule } from "./helpers/json_module.js"
|
|
9
|
-
import { convertTextToJavascriptModule } from "./helpers/text_module.js"
|
|
10
|
-
|
|
11
|
-
export const jsenvPluginImportAssertions = () => {
|
|
12
|
-
const importAssertions = [
|
|
13
|
-
{
|
|
14
|
-
name: "jsenv:import_assertions",
|
|
15
|
-
appliesDuring: "*",
|
|
16
|
-
transform: {
|
|
17
|
-
js_module: async (
|
|
18
|
-
{ url, generatedUrl, content },
|
|
19
|
-
{ scenario, isSupportedOnRuntime, referenceUtils },
|
|
20
|
-
) => {
|
|
21
|
-
const importTypesToHandle = getImportTypesToHandle({
|
|
22
|
-
scenario,
|
|
23
|
-
isSupportedOnRuntime,
|
|
24
|
-
})
|
|
25
|
-
if (importTypesToHandle.length === 0) {
|
|
26
|
-
return null
|
|
27
|
-
}
|
|
28
|
-
const { metadata } = await applyBabelPlugins({
|
|
29
|
-
babelPlugins: [babelPluginMetadataImportAssertions],
|
|
30
|
-
url,
|
|
31
|
-
generatedUrl,
|
|
32
|
-
content,
|
|
33
|
-
})
|
|
34
|
-
const { importAssertions } = metadata
|
|
35
|
-
const magicSource = createMagicSource(content)
|
|
36
|
-
importAssertions.forEach((importAssertion) => {
|
|
37
|
-
const assertType = importAssertion.assert.type
|
|
38
|
-
if (!importTypesToHandle.includes(assertType)) {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
const { path } = importAssertion
|
|
42
|
-
const { node } = path
|
|
43
|
-
const importType = `${assertType}_module`
|
|
44
|
-
if (node.type === "CallExpression") {
|
|
45
|
-
const importSpecifierPath = path.get("arguments")[0]
|
|
46
|
-
const specifier = importSpecifierPath.node.value
|
|
47
|
-
const newSpecifier = injectQueryParamsIntoSpecifier(specifier, {
|
|
48
|
-
[importType]: "",
|
|
49
|
-
})
|
|
50
|
-
const [newReference, newUrlInfo] = referenceUtils.updateSpecifier(
|
|
51
|
-
JSON.stringify(specifier),
|
|
52
|
-
newSpecifier,
|
|
53
|
-
)
|
|
54
|
-
newUrlInfo.data.importType = importType
|
|
55
|
-
magicSource.replace({
|
|
56
|
-
start: importSpecifierPath.node.start,
|
|
57
|
-
end: importSpecifierPath.node.end,
|
|
58
|
-
replacement: newReference.generatedSpecifier,
|
|
59
|
-
})
|
|
60
|
-
const secondArgPath = path.get("arguments")[1]
|
|
61
|
-
magicSource.remove({
|
|
62
|
-
start: secondArgPath.node.start,
|
|
63
|
-
end: secondArgPath.node.end,
|
|
64
|
-
})
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
const importSpecifierPath = path.get("source")
|
|
68
|
-
const specifier = importSpecifierPath.node.value
|
|
69
|
-
const newSpecifier = injectQueryParamsIntoSpecifier(specifier, {
|
|
70
|
-
[importType]: "",
|
|
71
|
-
})
|
|
72
|
-
const [newReference, newUrlInfo] = referenceUtils.updateSpecifier(
|
|
73
|
-
JSON.stringify(specifier),
|
|
74
|
-
newSpecifier,
|
|
75
|
-
)
|
|
76
|
-
newUrlInfo.data.importType = importType
|
|
77
|
-
magicSource.replace({
|
|
78
|
-
start: importSpecifierPath.node.start,
|
|
79
|
-
end: importSpecifierPath.node.end,
|
|
80
|
-
replacement: newReference.generatedSpecifier,
|
|
81
|
-
})
|
|
82
|
-
const assertionsPath = path.get("assertions")[0]
|
|
83
|
-
magicSource.remove({
|
|
84
|
-
start: assertionsPath.node.start,
|
|
85
|
-
end: assertionsPath.node.end,
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
return magicSource.toContentAndSourcemap()
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
]
|
|
93
|
-
|
|
94
|
-
const importTypeJson = {
|
|
95
|
-
name: "jsenv:import_type_json",
|
|
96
|
-
appliesDuring: "*",
|
|
97
|
-
finalize: ({ url, contentType, content }) => {
|
|
98
|
-
if (!new URL(url).searchParams.has("json_module")) {
|
|
99
|
-
return null
|
|
100
|
-
}
|
|
101
|
-
if (contentType !== "application/json") {
|
|
102
|
-
throw new Error(
|
|
103
|
-
`Unexpected content type on ${url}, should be "application/json" but got ${contentType}`,
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
return convertJsonTextToJavascriptModule({
|
|
107
|
-
content,
|
|
108
|
-
})
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// not standard but I expect this to happen one day?
|
|
113
|
-
const importTypeText = {
|
|
114
|
-
name: "jsenv:import_type_text",
|
|
115
|
-
appliesDuring: "*",
|
|
116
|
-
finalize: ({ url, contentType, content }) => {
|
|
117
|
-
if (!new URL(url).searchParams.has("text_module")) {
|
|
118
|
-
return null
|
|
119
|
-
}
|
|
120
|
-
if (ContentType.isTextual(contentType)) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
`Unexpected content type on ${url}, should be "text/*" but got ${contentType}`,
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
return convertTextToJavascriptModule({
|
|
126
|
-
content,
|
|
127
|
-
})
|
|
128
|
-
},
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return [
|
|
132
|
-
importAssertions,
|
|
133
|
-
importTypeJson,
|
|
134
|
-
jsenvPluginImportTypeCss(),
|
|
135
|
-
importTypeText,
|
|
136
|
-
]
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const jsenvPluginImportTypeCss = () => {
|
|
140
|
-
const inlineContentClientFileUrl = new URL(
|
|
141
|
-
"../inline/client/inline_content.js",
|
|
142
|
-
import.meta.url,
|
|
143
|
-
).href
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
name: "jsenv:import_type_css",
|
|
147
|
-
appliesDuring: "*",
|
|
148
|
-
// load the original css url
|
|
149
|
-
load: ({ data }, { urlGraph, load }) => {
|
|
150
|
-
if (data.importType !== "css_module") {
|
|
151
|
-
return null
|
|
152
|
-
}
|
|
153
|
-
return load({
|
|
154
|
-
reference: data.originalReference,
|
|
155
|
-
urlInfo: urlGraph.getUrlInfo(data.originalReference.url),
|
|
156
|
-
})
|
|
157
|
-
},
|
|
158
|
-
transform: ({ url, data, contentType, content }, { referenceUtils }) => {
|
|
159
|
-
if (data.importType !== "css_module") {
|
|
160
|
-
return null
|
|
161
|
-
}
|
|
162
|
-
if (contentType !== "text/css") {
|
|
163
|
-
throw new Error(
|
|
164
|
-
`Unexpected content type on ${url}, should be "text/css" but got ${contentType}`,
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
const [reference] = referenceUtils.inject({
|
|
168
|
-
type: "js_import_export",
|
|
169
|
-
specifier: inlineContentClientFileUrl,
|
|
170
|
-
})
|
|
171
|
-
const cssText = JS_QUOTES.escapeSpecialChars(content, {
|
|
172
|
-
// If template string is choosen and runtime do not support template literals
|
|
173
|
-
// it's ok because "jsenv:new_inline_content" plugin executes after this one
|
|
174
|
-
// and convert template strings into raw strings
|
|
175
|
-
canUseTemplateString: true,
|
|
176
|
-
})
|
|
177
|
-
return {
|
|
178
|
-
type: "js_module",
|
|
179
|
-
contentType: "application/javascript",
|
|
180
|
-
content: `import { InlineContent } from ${reference.generatedSpecifier}
|
|
181
|
-
|
|
182
|
-
const css = new InlineContent(${cssText}, { type: "text/css" })
|
|
183
|
-
const stylesheet = new CSSStyleSheet()
|
|
184
|
-
stylesheet.replaceSync(css.text)
|
|
185
|
-
export default stylesheet`,
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const getImportTypesToHandle = ({ scenario, isSupportedOnRuntime }) => {
|
|
192
|
-
// during build always replace import assertions with the js:
|
|
193
|
-
// - means rollup can bundle more js file together
|
|
194
|
-
// - means url versioning can work for css inlined in js
|
|
195
|
-
// - avoid rollup to see import assertions
|
|
196
|
-
// We would have to tell rollup to ignore import with assertion
|
|
197
|
-
if (scenario === "build") {
|
|
198
|
-
return ["json", "css", "text"]
|
|
199
|
-
}
|
|
200
|
-
const importTypes = []
|
|
201
|
-
if (!isSupportedOnRuntime("import_type_json")) {
|
|
202
|
-
importTypes.push("json")
|
|
203
|
-
}
|
|
204
|
-
if (!isSupportedOnRuntime("import_type_css")) {
|
|
205
|
-
importTypes.push("css")
|
|
206
|
-
}
|
|
207
|
-
if (!isSupportedOnRuntime("import_type_text")) {
|
|
208
|
-
importTypes.push("text")
|
|
209
|
-
}
|
|
210
|
-
return importTypes
|
|
211
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { jsenvPluginJsAndCssInsideHtml } from "./jsenv_plugin_js_and_css_inside_html.js"
|
|
2
|
-
import { jsenvPluginNewInlineContent } from "./jsenv_plugin_new_inline_content.js"
|
|
3
|
-
import { jsenvPluginDataUrls } from "./jsenv_plugin_data_urls.js"
|
|
4
|
-
import { jsenvPluginInlineQueryParam } from "./jsenv_plugin_inline_query_param.js"
|
|
5
|
-
|
|
6
|
-
export const jsenvPluginInline = ({ allowEscapeForVersioning } = {}) => {
|
|
7
|
-
return [
|
|
8
|
-
jsenvPluginJsAndCssInsideHtml(),
|
|
9
|
-
jsenvPluginNewInlineContent({ allowEscapeForVersioning }),
|
|
10
|
-
jsenvPluginDataUrls(),
|
|
11
|
-
jsenvPluginInlineQueryParam(),
|
|
12
|
-
]
|
|
13
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Needs to be updated so that it sill works in the following cases:
|
|
3
|
-
* - templates literals transformed to regular stuff by babel
|
|
4
|
-
* - tagged name renamed by rollup
|
|
5
|
-
* - the template named is minified by terser
|
|
6
|
-
* In the cases above I must remain capable to recoginize the template literal
|
|
7
|
-
* to be able to update the urls inside (and even version the urls)
|
|
8
|
-
* because url versioning happens after minification it can be challenging
|
|
9
|
-
*
|
|
10
|
-
* TODO: use "keep_classnames" https://github.com/terser/terser#compress-options
|
|
11
|
-
* so that new InlineContent can be recognized after minification
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
15
|
-
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
16
|
-
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
17
|
-
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
18
|
-
|
|
19
|
-
export const jsenvPluginNewInlineContent = ({ allowEscapeForVersioning }) => {
|
|
20
|
-
return {
|
|
21
|
-
name: "jsenv:new_inline_content",
|
|
22
|
-
appliesDuring: "*",
|
|
23
|
-
transform: {
|
|
24
|
-
js_module: async (
|
|
25
|
-
{ url, generatedUrl, content, originalContent },
|
|
26
|
-
{ referenceUtils, cook, isSupportedOnRuntime },
|
|
27
|
-
) => {
|
|
28
|
-
const { metadata } = await applyBabelPlugins({
|
|
29
|
-
babelPlugins: [babelPluginMetadataInlineContentCalls],
|
|
30
|
-
url,
|
|
31
|
-
generatedUrl,
|
|
32
|
-
content,
|
|
33
|
-
})
|
|
34
|
-
const { inlineContentCalls } = metadata
|
|
35
|
-
if (inlineContentCalls.length === 0) {
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
const magicSource = createMagicSource(content)
|
|
39
|
-
await inlineContentCalls.reduce(async (previous, inlineContentCall) => {
|
|
40
|
-
await previous
|
|
41
|
-
const inlineUrl = generateInlineContentUrl({
|
|
42
|
-
url,
|
|
43
|
-
extension: {
|
|
44
|
-
"application/json": ".json",
|
|
45
|
-
"text/css": ".css",
|
|
46
|
-
"text/plain": ".txt",
|
|
47
|
-
"application/octet-stream": "",
|
|
48
|
-
}[inlineContentCall.contentType],
|
|
49
|
-
line: inlineContentCall.line,
|
|
50
|
-
column: inlineContentCall.column,
|
|
51
|
-
lineEnd: inlineContentCall.lineEnd,
|
|
52
|
-
columnEnd: inlineContentCall.columnEnd,
|
|
53
|
-
})
|
|
54
|
-
let { quote } = inlineContentCall
|
|
55
|
-
if (
|
|
56
|
-
quote === "`" &&
|
|
57
|
-
!isSupportedOnRuntime("transform-template-literals")
|
|
58
|
-
) {
|
|
59
|
-
// if quote is "`" and template literals are not supported
|
|
60
|
-
// we'll use a regular string (single or double quote)
|
|
61
|
-
// when rendering the string
|
|
62
|
-
quote = JS_QUOTES.pickBest(inlineContentCall.content)
|
|
63
|
-
}
|
|
64
|
-
const [inlineReference, inlineUrlInfo] = referenceUtils.foundInline({
|
|
65
|
-
type: "js_inline_content",
|
|
66
|
-
isOriginal: content === originalContent,
|
|
67
|
-
line: inlineContentCall.line,
|
|
68
|
-
column: inlineContentCall.column,
|
|
69
|
-
specifier: inlineUrl,
|
|
70
|
-
contentType: inlineContentCall.contentType,
|
|
71
|
-
content: inlineContentCall.content,
|
|
72
|
-
})
|
|
73
|
-
inlineUrlInfo.jsQuote = quote
|
|
74
|
-
inlineReference.escape = (value) =>
|
|
75
|
-
JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote })
|
|
76
|
-
await cook({
|
|
77
|
-
reference: inlineReference,
|
|
78
|
-
urlInfo: inlineUrlInfo,
|
|
79
|
-
})
|
|
80
|
-
magicSource.replace({
|
|
81
|
-
start: inlineContentCall.start,
|
|
82
|
-
end: inlineContentCall.end,
|
|
83
|
-
replacement: JS_QUOTES.escapeSpecialChars(inlineUrlInfo.content, {
|
|
84
|
-
quote,
|
|
85
|
-
allowEscapeForVersioning,
|
|
86
|
-
}),
|
|
87
|
-
})
|
|
88
|
-
}, Promise.resolve())
|
|
89
|
-
return magicSource.toContentAndSourcemap()
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const babelPluginMetadataInlineContentCalls = () => {
|
|
96
|
-
return {
|
|
97
|
-
name: "metadata-inline-content-calls",
|
|
98
|
-
visitor: {
|
|
99
|
-
Program: (programPath, state) => {
|
|
100
|
-
const inlineContentCalls = []
|
|
101
|
-
programPath.traverse({
|
|
102
|
-
NewExpression: (path) => {
|
|
103
|
-
const newInlineContentCall = parseAsNewInlineContentCall(path)
|
|
104
|
-
if (newInlineContentCall) {
|
|
105
|
-
inlineContentCalls.push(newInlineContentCall)
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
state.file.metadata.inlineContentCalls = inlineContentCalls
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const parseAsNewInlineContentCall = (path) => {
|
|
116
|
-
const node = path.node
|
|
117
|
-
if (node.callee.type === "Identifier") {
|
|
118
|
-
// terser rename import to use a shorter name
|
|
119
|
-
const name = getOriginalName(path, node.callee.name)
|
|
120
|
-
if (name !== "InlineContent") {
|
|
121
|
-
return null
|
|
122
|
-
}
|
|
123
|
-
} else if (node.callee.id) {
|
|
124
|
-
// terser might combine new InlineContent('') declaration and usage
|
|
125
|
-
if (node.callee.id.type !== "Identifier") {
|
|
126
|
-
return null
|
|
127
|
-
}
|
|
128
|
-
const name = getOriginalName(path, node.callee.id.name)
|
|
129
|
-
if (name !== "InlineContent") {
|
|
130
|
-
return null
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (node.arguments.length !== 2) {
|
|
134
|
-
return null
|
|
135
|
-
}
|
|
136
|
-
const [firstArg, secondArg] = node.arguments
|
|
137
|
-
if (secondArg.type !== "ObjectExpression") {
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
const typePropertyNode = secondArg.properties.find((property) => {
|
|
141
|
-
return (
|
|
142
|
-
property.key.type === "Identifier" &&
|
|
143
|
-
property.key.name === "type" &&
|
|
144
|
-
property.type === "ObjectProperty" &&
|
|
145
|
-
property.value.type === "StringLiteral"
|
|
146
|
-
)
|
|
147
|
-
})
|
|
148
|
-
if (!typePropertyNode) {
|
|
149
|
-
return null
|
|
150
|
-
}
|
|
151
|
-
const type = typePropertyNode.value.value
|
|
152
|
-
if (firstArg.type === "StringLiteral") {
|
|
153
|
-
const position = getNodePosition(firstArg)
|
|
154
|
-
return {
|
|
155
|
-
nodeType: "StringLiteral",
|
|
156
|
-
quote: firstArg.extra.raw[0],
|
|
157
|
-
contentType: type,
|
|
158
|
-
content: firstArg.value,
|
|
159
|
-
...position,
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (firstArg.type === "TemplateLiteral") {
|
|
163
|
-
const quasis = firstArg.quasis
|
|
164
|
-
if (quasis.length !== 1) {
|
|
165
|
-
return null
|
|
166
|
-
}
|
|
167
|
-
const templateElementNode = quasis[0]
|
|
168
|
-
const position = getNodePosition(firstArg)
|
|
169
|
-
return {
|
|
170
|
-
nodeType: "TemplateLiteral",
|
|
171
|
-
quote: "`",
|
|
172
|
-
contentType: type,
|
|
173
|
-
content: templateElementNode.value.cooked,
|
|
174
|
-
...position,
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return null
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const getNodePosition = (node) => {
|
|
181
|
-
return {
|
|
182
|
-
start: node.start,
|
|
183
|
-
end: node.end,
|
|
184
|
-
line: node.loc.start.line,
|
|
185
|
-
column: node.loc.start.column,
|
|
186
|
-
lineEnd: node.loc.end.line,
|
|
187
|
-
columnEnd: node.loc.end.column,
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const getOriginalName = (path, name) => {
|
|
192
|
-
const binding = path.scope.getBinding(name)
|
|
193
|
-
if (!binding) {
|
|
194
|
-
return name
|
|
195
|
-
}
|
|
196
|
-
if (binding.path.type === "ImportSpecifier") {
|
|
197
|
-
const importedName = binding.path.node.imported.name
|
|
198
|
-
if (name === importedName) {
|
|
199
|
-
return name
|
|
200
|
-
}
|
|
201
|
-
return getOriginalName(path, importedName)
|
|
202
|
-
}
|
|
203
|
-
if (binding.path.type === "VariableDeclarator") {
|
|
204
|
-
if (binding.path.node.init.type === "Identifier") {
|
|
205
|
-
const previousName = binding.path.node.init.name
|
|
206
|
-
return getOriginalName(path, previousName)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return name
|
|
210
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const jsenvPluginLeadingSlash = () => {
|
|
2
|
-
return {
|
|
3
|
-
name: "jsenv:leading_slash",
|
|
4
|
-
appliesDuring: "*",
|
|
5
|
-
resolve: ({ specifier }, { rootDirectoryUrl }) => {
|
|
6
|
-
if (specifier[0] !== "/") {
|
|
7
|
-
return null
|
|
8
|
-
}
|
|
9
|
-
return new URL(specifier.slice(1), rootDirectoryUrl).href
|
|
10
|
-
},
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* - should I restore eventual search params lost during node esm resolution
|
|
3
|
-
* - what about symlinks?
|
|
4
|
-
* It feels like I should apply symlink (when we don't want to preserve them)
|
|
5
|
-
* once a file:/// url is found, regardless
|
|
6
|
-
* if that comes from node resolution or anything else (not even magic resolution)
|
|
7
|
-
* it should likely be an other plugin happening after the others
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
applyNodeEsmResolution,
|
|
12
|
-
lookupPackageScope,
|
|
13
|
-
readPackageJson,
|
|
14
|
-
} from "@jsenv/node-esm-resolution"
|
|
15
|
-
|
|
16
|
-
export const jsenvPluginNodeEsmResolution = ({
|
|
17
|
-
// https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
18
|
-
packageConditions = ["browser", "import"],
|
|
19
|
-
} = {}) => {
|
|
20
|
-
const nodeEsmResolution = {
|
|
21
|
-
name: "jsenv:node_esm_resolve",
|
|
22
|
-
appliesDuring: "*",
|
|
23
|
-
resolve: {
|
|
24
|
-
js_import_export: ({ parentUrl, specifier }) => {
|
|
25
|
-
const { url } = applyNodeEsmResolution({
|
|
26
|
-
conditions: packageConditions,
|
|
27
|
-
parentUrl,
|
|
28
|
-
specifier,
|
|
29
|
-
})
|
|
30
|
-
return url
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
load: ({ url }) => {
|
|
34
|
-
if (url.startsWith("file:///@ignore/")) {
|
|
35
|
-
return {
|
|
36
|
-
content: "export default {}",
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return null
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const packageVersionInUrl = {
|
|
44
|
-
name: "jsenv:package_url_version",
|
|
45
|
-
appliesDuring: {
|
|
46
|
-
dev: true,
|
|
47
|
-
test: true,
|
|
48
|
-
},
|
|
49
|
-
transformReferencedUrl: ({ url }, { rootDirectoryUrl }) => {
|
|
50
|
-
if (!url.startsWith("file:")) {
|
|
51
|
-
return null
|
|
52
|
-
}
|
|
53
|
-
// without this check a file inside a project without package.json
|
|
54
|
-
// could be considered as a node module if there is a ancestor package.json
|
|
55
|
-
// but we want to version only node modules
|
|
56
|
-
if (!url.includes("/node_modules/")) {
|
|
57
|
-
return null
|
|
58
|
-
}
|
|
59
|
-
const urlObject = new URL(url)
|
|
60
|
-
if (urlObject.searchParams.has("v")) {
|
|
61
|
-
return null
|
|
62
|
-
}
|
|
63
|
-
const packageUrl = lookupPackageScope(url)
|
|
64
|
-
if (!packageUrl) {
|
|
65
|
-
return null
|
|
66
|
-
}
|
|
67
|
-
if (packageUrl === rootDirectoryUrl) {
|
|
68
|
-
return null
|
|
69
|
-
}
|
|
70
|
-
const packageVersion = readPackageJson(packageUrl).version
|
|
71
|
-
urlObject.searchParams.set("v", packageVersion)
|
|
72
|
-
return urlObject.href
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return [nodeEsmResolution, packageVersionInUrl]
|
|
77
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export const jsenvPluginUrlVersion = ({
|
|
2
|
-
longTermCache = false, // will become true once things get more stable
|
|
3
|
-
} = {}) => {
|
|
4
|
-
return {
|
|
5
|
-
name: "jsenv:url_version",
|
|
6
|
-
appliesDuring: "*", // maybe only during dev?
|
|
7
|
-
normalize: ({ url }) => {
|
|
8
|
-
// "v" search param goal is to enable long-term cache
|
|
9
|
-
// for server response headers
|
|
10
|
-
// it is also used by hmr to bypass browser cache
|
|
11
|
-
// this goal is achieved when we reach this part of the code
|
|
12
|
-
// We get rid of this params so that urlGraph and other parts of the code
|
|
13
|
-
// recognize the url (it is not considered as a different url)
|
|
14
|
-
const urlObject = new URL(url)
|
|
15
|
-
urlObject.searchParams.delete("v")
|
|
16
|
-
return urlObject.href
|
|
17
|
-
},
|
|
18
|
-
transformReferencedUrl: ({ url, data }) => {
|
|
19
|
-
if (!data.version) {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
const urlObject = new URL(url)
|
|
23
|
-
if (urlObject.searchParams.has("v")) {
|
|
24
|
-
return null
|
|
25
|
-
}
|
|
26
|
-
urlObject.searchParams.set("v", data.version)
|
|
27
|
-
return urlObject.href
|
|
28
|
-
},
|
|
29
|
-
augmentResponse: ({ url }) => {
|
|
30
|
-
if (!longTermCache) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
const urlObject = new URL(url)
|
|
34
|
-
if (!urlObject.searchParams.has("v")) {
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
if (urlObject.searchParams.has("hmr")) {
|
|
38
|
-
return null
|
|
39
|
-
}
|
|
40
|
-
// When url is versioned put it in browser cache for 30 days
|
|
41
|
-
return {
|
|
42
|
-
headers: {
|
|
43
|
-
"cache-control": `private,max-age=${SECONDS_IN_30_DAYS},immutable`,
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30
|