@jsenv/core 27.0.0-alpha.4 → 27.0.0-alpha.40
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 +549 -0
- package/dist/event_source_client.js.map +188 -0
- package/dist/html_supervisor_installer.js +1145 -0
- package/dist/html_supervisor_installer.js.map +322 -0
- package/dist/html_supervisor_setup.js +92 -0
- package/dist/html_supervisor_setup.js.map +57 -0
- package/main.js +8 -1
- package/package.json +22 -21
- package/readme.md +4 -12
- package/src/build/build.js +731 -433
- package/src/build/build_urls_generator.js +55 -21
- 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 +205 -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 +58 -26
- package/src/execute/execute.js +30 -4
- package/src/execute/run.js +19 -56
- package/src/execute/runtimes/browsers/from_playwright.js +201 -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 +414 -285
- package/src/omega/server/file_service.js +21 -22
- package/src/omega/url_graph/url_graph_load.js +14 -7
- package/src/omega/url_graph/url_graph_report.js +17 -15
- package/src/omega/url_graph/url_info_transformations.js +17 -5
- package/src/omega/url_graph.js +33 -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 +46 -0
- package/src/{dev/plugins/autoreload/jsenv_plugin_autoreload.js → plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js} +31 -172
- 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 +21 -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} +120 -79
- package/src/plugins/bundling/jsenv_plugin_bundling.js +51 -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/{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 +52 -55
- 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 +101 -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 +37 -31
- 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} +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 +296 -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 +39 -11
- package/src/plugins/plugins.js +89 -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 +183 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +256 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +93 -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 +4 -22
- 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 +37 -21
- 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 +200 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +70 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -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 +43 -0
- package/src/plugins/url_references/jsenv_plugin_imports_analysis.js +46 -0
- package/src/plugins/url_references/jsenv_plugin_url_analysis.js +18 -0
- package/src/plugins/url_references/jsenv_plugin_url_references.js +6 -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 +12 -15
- package/src/test/execute_plan.js +28 -11
- package/src/test/execute_test_plan.js +23 -8
- 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/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.js +0 -39
- package/src/omega/runtime_support/runtime_support.js +0 -20
- 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
|
@@ -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,39 +0,0 @@
|
|
|
1
|
-
import { jsenvPluginLeadingSlash } from "./core_plugins/leading_slash/jsenv_plugin_leading_slash.js"
|
|
2
|
-
import { jsenvPluginImportmap } from "./core_plugins/importmap/jsenv_plugin_importmap.js"
|
|
3
|
-
import { jsenvPluginUrlResolution } from "./core_plugins/url_resolution/jsenv_plugin_url_resolution.js"
|
|
4
|
-
import { jsenvPluginNodeEsmResolution } from "./core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js"
|
|
5
|
-
import { jsenvPluginUrlVersion } from "./core_plugins/url_version/jsenv_plugin_url_version.js"
|
|
6
|
-
import { jsenvPluginFileUrls } from "./core_plugins/file_urls/jsenv_plugin_file_urls.js"
|
|
7
|
-
import { jsenvPluginFileSystemMagic } from "./core_plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js"
|
|
8
|
-
import { jsenvPluginInline } from "./core_plugins/inline/jsenv_plugin_inline.js"
|
|
9
|
-
import { jsenvPluginHtmlSupervisor } from "./core_plugins/html_supervisor/jsenv_plugin_html_supervisor.js"
|
|
10
|
-
import { jsenvPluginCommonJsGlobals } from "./core_plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js"
|
|
11
|
-
import { jsenvPluginImportAssertions } from "./core_plugins/import_assertions/jsenv_plugin_import_assertions.js"
|
|
12
|
-
import { jsenvPluginImportMetaScenarios } from "./core_plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js"
|
|
13
|
-
import { jsenvPluginBabel } from "./core_plugins/babel/jsenv_plugin_babel.js"
|
|
14
|
-
|
|
15
|
-
export const getCorePlugins = ({
|
|
16
|
-
htmlSupervisor,
|
|
17
|
-
nodeEsmResolution,
|
|
18
|
-
fileSystemMagicResolution,
|
|
19
|
-
babel,
|
|
20
|
-
} = {}) => {
|
|
21
|
-
const asFewAsPossible = false // useful during dev
|
|
22
|
-
return [
|
|
23
|
-
...(asFewAsPossible ? [] : [jsenvPluginImportAssertions()]),
|
|
24
|
-
...(asFewAsPossible ? [] : [jsenvPluginHtmlSupervisor(htmlSupervisor)]), // before inline as it turns inline <script> into <script src>
|
|
25
|
-
...(asFewAsPossible ? [] : [jsenvPluginInline()]), // before "file urls" to resolve and load inline urls
|
|
26
|
-
jsenvPluginImportmap(), // before node esm to handle bare specifiers before node esm
|
|
27
|
-
jsenvPluginFileUrls(),
|
|
28
|
-
jsenvPluginLeadingSlash(),
|
|
29
|
-
jsenvPluginNodeEsmResolution(nodeEsmResolution), // before url resolution to handle "js_import_export" resolution
|
|
30
|
-
jsenvPluginUrlResolution(),
|
|
31
|
-
...(asFewAsPossible
|
|
32
|
-
? []
|
|
33
|
-
: [jsenvPluginFileSystemMagic(fileSystemMagicResolution)]),
|
|
34
|
-
jsenvPluginUrlVersion(),
|
|
35
|
-
...(asFewAsPossible ? [] : [jsenvPluginCommonJsGlobals()]),
|
|
36
|
-
...(asFewAsPossible ? [] : [jsenvPluginImportMetaScenarios()]),
|
|
37
|
-
jsenvPluginBabel(babel),
|
|
38
|
-
]
|
|
39
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { findHighestVersion } from "@jsenv/utils/semantic_versioning/highest_version.js"
|
|
2
|
-
|
|
3
|
-
export const isFeatureSupportedOnRuntimes = (
|
|
4
|
-
runtimeSupport,
|
|
5
|
-
featureCompat = {},
|
|
6
|
-
) => {
|
|
7
|
-
const runtimeNames = Object.keys(runtimeSupport)
|
|
8
|
-
return runtimeNames.every((runtimeName) => {
|
|
9
|
-
const runtimeVersion = runtimeSupport[runtimeName]
|
|
10
|
-
const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity"
|
|
11
|
-
const highestVersion = findHighestVersion(
|
|
12
|
-
runtimeVersion,
|
|
13
|
-
runtimeVersionCompatible,
|
|
14
|
-
)
|
|
15
|
-
if (highestVersion !== runtimeVersion) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
return true
|
|
19
|
-
})
|
|
20
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { applyPostCss } from "@jsenv/utils/css_ast/apply_post_css.js"
|
|
6
|
-
import { postCssPluginUrlVisitor } from "@jsenv/utils/css_ast/postcss_plugin_url_visitor.js"
|
|
7
|
-
import { replaceCssUrls } from "@jsenv/utils/css_ast/replace_css_urls.js"
|
|
8
|
-
|
|
9
|
-
export const parseCssUrlMentions = async ({ url, content }) => {
|
|
10
|
-
const cssUrlMentions = []
|
|
11
|
-
await applyPostCss({
|
|
12
|
-
sourcemaps: false,
|
|
13
|
-
plugins: [
|
|
14
|
-
postCssPluginUrlVisitor({
|
|
15
|
-
urlVisitor: ({ type, url, specifier, urlNode }) => {
|
|
16
|
-
cssUrlMentions.push({
|
|
17
|
-
type: `css_${type}`,
|
|
18
|
-
specifier,
|
|
19
|
-
start: urlNode.sourceIndex,
|
|
20
|
-
end: urlNode.sourceEndIndex,
|
|
21
|
-
url,
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
url,
|
|
27
|
-
content,
|
|
28
|
-
})
|
|
29
|
-
return {
|
|
30
|
-
urlMentions: cssUrlMentions,
|
|
31
|
-
replaceUrls: async (getReplacement) => {
|
|
32
|
-
// we can't use magic source because urlMention.start/end do not match the url specifier
|
|
33
|
-
// const magicSource = createMagicSource({ url, content })
|
|
34
|
-
// cssUrlMentions.forEach((urlMention) => {
|
|
35
|
-
// magicSource.replace({
|
|
36
|
-
// start: urlMention.start,
|
|
37
|
-
// end: urlMention.end,
|
|
38
|
-
// replacement: JSON.stringify(transformUrlMention(urlMention)),
|
|
39
|
-
// })
|
|
40
|
-
// })
|
|
41
|
-
// return magicSource.toContentAndSourcemap()
|
|
42
|
-
const result = await replaceCssUrls({
|
|
43
|
-
url,
|
|
44
|
-
content,
|
|
45
|
-
urlVisitor: ({ url, replace }) => {
|
|
46
|
-
const cssUrlMention = cssUrlMentions.find(
|
|
47
|
-
(urlMention) => urlMention.url === url,
|
|
48
|
-
)
|
|
49
|
-
if (cssUrlMention) {
|
|
50
|
-
const replacement = getReplacement(cssUrlMention)
|
|
51
|
-
if (replacement) {
|
|
52
|
-
replace(replacement)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
return {
|
|
58
|
-
content: result.content,
|
|
59
|
-
sourcemap: result.map,
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
}
|