@jsenv/core 27.0.0-alpha.10 → 27.0.0-alpha.13
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 +13 -7
- package/readme.md +4 -12
- package/src/build/build.js +438 -387
- 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/dev/plugins/autoreload/babel_plugin_metadata_import_meta_hot.js +1 -1
- package/src/dev/plugins/autoreload/client/import_meta_hot.js +3 -1
- package/src/dev/plugins/autoreload/html_hot_dependencies.js +2 -2
- package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +61 -51
- package/src/dev/plugins/autoreload/sse_service.js +23 -3
- 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 +10 -5
- package/src/execute/execute.js +10 -4
- 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 +396 -280
- 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/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/{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 +5 -7
- 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 +77 -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 +50 -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 +178 -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/preview/preview.js +3 -0
- package/src/test/execute_plan.js +18 -11
- package/src/test/execute_test_plan.js +5 -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/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
|
@@ -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,207 +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 (quote === "`" && !isSupportedOnRuntime("template_literals")) {
|
|
56
|
-
// if quote is "`" and template literals are not supported
|
|
57
|
-
// we'll use a regular string (single or double quote)
|
|
58
|
-
// when rendering the string
|
|
59
|
-
quote = JS_QUOTES.pickBest(inlineContentCall.content)
|
|
60
|
-
}
|
|
61
|
-
const [inlineReference, inlineUrlInfo] = referenceUtils.foundInline({
|
|
62
|
-
type: "js_inline_content",
|
|
63
|
-
isOriginal: content === originalContent,
|
|
64
|
-
line: inlineContentCall.line,
|
|
65
|
-
column: inlineContentCall.column,
|
|
66
|
-
specifier: inlineUrl,
|
|
67
|
-
contentType: inlineContentCall.contentType,
|
|
68
|
-
content: inlineContentCall.content,
|
|
69
|
-
})
|
|
70
|
-
inlineUrlInfo.jsQuote = quote
|
|
71
|
-
inlineReference.escape = (value) =>
|
|
72
|
-
JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote })
|
|
73
|
-
await cook({
|
|
74
|
-
reference: inlineReference,
|
|
75
|
-
urlInfo: inlineUrlInfo,
|
|
76
|
-
})
|
|
77
|
-
magicSource.replace({
|
|
78
|
-
start: inlineContentCall.start,
|
|
79
|
-
end: inlineContentCall.end,
|
|
80
|
-
replacement: JS_QUOTES.escapeSpecialChars(inlineUrlInfo.content, {
|
|
81
|
-
quote,
|
|
82
|
-
allowEscapeForVersioning,
|
|
83
|
-
}),
|
|
84
|
-
})
|
|
85
|
-
}, Promise.resolve())
|
|
86
|
-
return magicSource.toContentAndSourcemap()
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const babelPluginMetadataInlineContentCalls = () => {
|
|
93
|
-
return {
|
|
94
|
-
name: "metadata-inline-content-calls",
|
|
95
|
-
visitor: {
|
|
96
|
-
Program: (programPath, state) => {
|
|
97
|
-
const inlineContentCalls = []
|
|
98
|
-
programPath.traverse({
|
|
99
|
-
NewExpression: (path) => {
|
|
100
|
-
const newInlineContentCall = parseAsNewInlineContentCall(path)
|
|
101
|
-
if (newInlineContentCall) {
|
|
102
|
-
inlineContentCalls.push(newInlineContentCall)
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
})
|
|
106
|
-
state.file.metadata.inlineContentCalls = inlineContentCalls
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const parseAsNewInlineContentCall = (path) => {
|
|
113
|
-
const node = path.node
|
|
114
|
-
if (node.callee.type === "Identifier") {
|
|
115
|
-
// terser rename import to use a shorter name
|
|
116
|
-
const name = getOriginalName(path, node.callee.name)
|
|
117
|
-
if (name !== "InlineContent") {
|
|
118
|
-
return null
|
|
119
|
-
}
|
|
120
|
-
} else if (node.callee.id) {
|
|
121
|
-
// terser might combine new InlineContent('') declaration and usage
|
|
122
|
-
if (node.callee.id.type !== "Identifier") {
|
|
123
|
-
return null
|
|
124
|
-
}
|
|
125
|
-
const name = getOriginalName(path, node.callee.id.name)
|
|
126
|
-
if (name !== "InlineContent") {
|
|
127
|
-
return null
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (node.arguments.length !== 2) {
|
|
131
|
-
return null
|
|
132
|
-
}
|
|
133
|
-
const [firstArg, secondArg] = node.arguments
|
|
134
|
-
if (secondArg.type !== "ObjectExpression") {
|
|
135
|
-
return null
|
|
136
|
-
}
|
|
137
|
-
const typePropertyNode = secondArg.properties.find((property) => {
|
|
138
|
-
return (
|
|
139
|
-
property.key.type === "Identifier" &&
|
|
140
|
-
property.key.name === "type" &&
|
|
141
|
-
property.type === "ObjectProperty" &&
|
|
142
|
-
property.value.type === "StringLiteral"
|
|
143
|
-
)
|
|
144
|
-
})
|
|
145
|
-
if (!typePropertyNode) {
|
|
146
|
-
return null
|
|
147
|
-
}
|
|
148
|
-
const type = typePropertyNode.value.value
|
|
149
|
-
if (firstArg.type === "StringLiteral") {
|
|
150
|
-
const position = getNodePosition(firstArg)
|
|
151
|
-
return {
|
|
152
|
-
nodeType: "StringLiteral",
|
|
153
|
-
quote: firstArg.extra.raw[0],
|
|
154
|
-
contentType: type,
|
|
155
|
-
content: firstArg.value,
|
|
156
|
-
...position,
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (firstArg.type === "TemplateLiteral") {
|
|
160
|
-
const quasis = firstArg.quasis
|
|
161
|
-
if (quasis.length !== 1) {
|
|
162
|
-
return null
|
|
163
|
-
}
|
|
164
|
-
const templateElementNode = quasis[0]
|
|
165
|
-
const position = getNodePosition(firstArg)
|
|
166
|
-
return {
|
|
167
|
-
nodeType: "TemplateLiteral",
|
|
168
|
-
quote: "`",
|
|
169
|
-
contentType: type,
|
|
170
|
-
content: templateElementNode.value.cooked,
|
|
171
|
-
...position,
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return null
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const getNodePosition = (node) => {
|
|
178
|
-
return {
|
|
179
|
-
start: node.start,
|
|
180
|
-
end: node.end,
|
|
181
|
-
line: node.loc.start.line,
|
|
182
|
-
column: node.loc.start.column,
|
|
183
|
-
lineEnd: node.loc.end.line,
|
|
184
|
-
columnEnd: node.loc.end.column,
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const getOriginalName = (path, name) => {
|
|
189
|
-
const binding = path.scope.getBinding(name)
|
|
190
|
-
if (!binding) {
|
|
191
|
-
return name
|
|
192
|
-
}
|
|
193
|
-
if (binding.path.type === "ImportSpecifier") {
|
|
194
|
-
const importedName = binding.path.node.imported.name
|
|
195
|
-
if (name === importedName) {
|
|
196
|
-
return name
|
|
197
|
-
}
|
|
198
|
-
return getOriginalName(path, importedName)
|
|
199
|
-
}
|
|
200
|
-
if (binding.path.type === "VariableDeclarator") {
|
|
201
|
-
if (binding.path.node.init.type === "Identifier") {
|
|
202
|
-
const previousName = binding.path.node.init.name
|
|
203
|
-
return getOriginalName(path, previousName)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return name
|
|
207
|
-
}
|
|
@@ -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,42 +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 { jsenvPluginInjectGlobals } from "./core_plugins/inject_globals/jsenv_plugin_inject_globals.js"
|
|
14
|
-
import { jsenvPluginBabel } from "./core_plugins/babel/jsenv_plugin_babel.js"
|
|
15
|
-
|
|
16
|
-
export const getCorePlugins = ({
|
|
17
|
-
htmlSupervisor,
|
|
18
|
-
nodeEsmResolution,
|
|
19
|
-
fileSystemMagicResolution,
|
|
20
|
-
babel,
|
|
21
|
-
injectedGlobals,
|
|
22
|
-
} = {}) => {
|
|
23
|
-
const asFewAsPossible = false // useful during dev
|
|
24
|
-
return [
|
|
25
|
-
...(asFewAsPossible ? [] : [jsenvPluginImportAssertions()]),
|
|
26
|
-
...(asFewAsPossible ? [] : [jsenvPluginHtmlSupervisor(htmlSupervisor)]), // before inline as it turns inline <script> into <script src>
|
|
27
|
-
...(asFewAsPossible ? [] : [jsenvPluginInline()]), // before "file urls" to resolve and load inline urls
|
|
28
|
-
jsenvPluginImportmap(), // before node esm to handle bare specifiers before node esm
|
|
29
|
-
jsenvPluginFileUrls(),
|
|
30
|
-
jsenvPluginLeadingSlash(),
|
|
31
|
-
jsenvPluginNodeEsmResolution(nodeEsmResolution), // before url resolution to handle "js_import_export" resolution
|
|
32
|
-
jsenvPluginInjectGlobals(injectedGlobals),
|
|
33
|
-
jsenvPluginUrlResolution(),
|
|
34
|
-
...(asFewAsPossible
|
|
35
|
-
? []
|
|
36
|
-
: [jsenvPluginFileSystemMagic(fileSystemMagicResolution)]),
|
|
37
|
-
jsenvPluginUrlVersion(),
|
|
38
|
-
...(asFewAsPossible ? [] : [jsenvPluginCommonJsGlobals()]),
|
|
39
|
-
...(asFewAsPossible ? [] : [jsenvPluginImportMetaScenarios()]),
|
|
40
|
-
jsenvPluginBabel(babel),
|
|
41
|
-
]
|
|
42
|
-
}
|
|
@@ -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
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseHtmlString,
|
|
3
|
-
stringifyHtmlAst,
|
|
4
|
-
getHtmlNodeAttributeByName,
|
|
5
|
-
htmlNodePosition,
|
|
6
|
-
visitHtmlAst,
|
|
7
|
-
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
8
|
-
import { htmlAttributeSrcSet } from "@jsenv/utils/html_ast/html_attribute_src_set.js"
|
|
9
|
-
|
|
10
|
-
export const parseHtmlUrlMentions = ({ url, content, scenario }) => {
|
|
11
|
-
const htmlAst = parseHtmlString(content, {
|
|
12
|
-
storeOriginalPositions: scenario !== "build",
|
|
13
|
-
})
|
|
14
|
-
const htmlUrlMentions = collectHtmlUrlMentions({ url, htmlAst })
|
|
15
|
-
return {
|
|
16
|
-
urlMentions: htmlUrlMentions,
|
|
17
|
-
replaceUrls: (getReplacement) => {
|
|
18
|
-
htmlUrlMentions.forEach((urlMention) => {
|
|
19
|
-
const replacement = getReplacement(urlMention)
|
|
20
|
-
if (replacement) {
|
|
21
|
-
urlMention.attribute.value = replacement
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
return {
|
|
25
|
-
content: stringifyHtmlAst(htmlAst),
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const collectHtmlUrlMentions = ({ url, htmlAst }) => {
|
|
32
|
-
const htmlUrlMentions = []
|
|
33
|
-
const addDependency = ({ type, node, attribute, specifier }) => {
|
|
34
|
-
const injected = Boolean(getHtmlNodeAttributeByName(node, "injected-by"))
|
|
35
|
-
const srcGeneratedFromInlineContent = Boolean(
|
|
36
|
-
getHtmlNodeAttributeByName(node, "src-generated-from-inline-content"),
|
|
37
|
-
)
|
|
38
|
-
let position
|
|
39
|
-
if (srcGeneratedFromInlineContent) {
|
|
40
|
-
// when generated from inline content,
|
|
41
|
-
// line, column is not "src" nor "content-src" but "original-position"
|
|
42
|
-
position = htmlNodePosition.readNodePosition(node)
|
|
43
|
-
} else {
|
|
44
|
-
position = htmlNodePosition.readAttributePosition(node, attribute.name)
|
|
45
|
-
}
|
|
46
|
-
const { line, column, originalLine, originalColumn } = position
|
|
47
|
-
htmlUrlMentions.push({
|
|
48
|
-
type,
|
|
49
|
-
htmlNode: node,
|
|
50
|
-
attribute,
|
|
51
|
-
injected,
|
|
52
|
-
srcGeneratedFromInlineContent,
|
|
53
|
-
specifier,
|
|
54
|
-
line,
|
|
55
|
-
column,
|
|
56
|
-
originalLine,
|
|
57
|
-
originalColumn,
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
const onNode = (node) => {
|
|
61
|
-
if (node.nodeName === "link") {
|
|
62
|
-
visitAttributeAsUrlSpecifier({
|
|
63
|
-
type: "link_href",
|
|
64
|
-
node,
|
|
65
|
-
attributeName: "href",
|
|
66
|
-
})
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
// if (node.nodeName === "style") {
|
|
70
|
-
// // styles.push(node)
|
|
71
|
-
// return
|
|
72
|
-
// }
|
|
73
|
-
if (node.nodeName === "script") {
|
|
74
|
-
visitAttributeAsUrlSpecifier({
|
|
75
|
-
type: "script_src",
|
|
76
|
-
node,
|
|
77
|
-
attributeName: "src",
|
|
78
|
-
})
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
if (node.nodeName === "a") {
|
|
82
|
-
visitAttributeAsUrlSpecifier({
|
|
83
|
-
type: "a_href",
|
|
84
|
-
node,
|
|
85
|
-
attributeName: "href",
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
if (node.nodeName === "iframe") {
|
|
89
|
-
visitAttributeAsUrlSpecifier({
|
|
90
|
-
type: "iframe_src",
|
|
91
|
-
node,
|
|
92
|
-
attributeName: "src",
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
if (node.nodeName === "img") {
|
|
96
|
-
visitAttributeAsUrlSpecifier({
|
|
97
|
-
type: "img_src",
|
|
98
|
-
node,
|
|
99
|
-
attributeName: "src",
|
|
100
|
-
})
|
|
101
|
-
visitSrcset({
|
|
102
|
-
type: "img_srcset",
|
|
103
|
-
node,
|
|
104
|
-
})
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
if (node.nodeName === "source") {
|
|
108
|
-
visitAttributeAsUrlSpecifier({
|
|
109
|
-
type: "source_src",
|
|
110
|
-
node,
|
|
111
|
-
attributeName: "src",
|
|
112
|
-
})
|
|
113
|
-
visitSrcset({
|
|
114
|
-
type: "source_srcset",
|
|
115
|
-
node,
|
|
116
|
-
})
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
// svg <image> tag
|
|
120
|
-
if (node.nodeName === "image") {
|
|
121
|
-
visitAttributeAsUrlSpecifier({
|
|
122
|
-
type: "image_href",
|
|
123
|
-
node,
|
|
124
|
-
attributeName: "href",
|
|
125
|
-
})
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
if (node.nodeName === "use") {
|
|
129
|
-
visitAttributeAsUrlSpecifier({
|
|
130
|
-
type: "use_href",
|
|
131
|
-
node,
|
|
132
|
-
attributeName: "href",
|
|
133
|
-
})
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const visitAttributeAsUrlSpecifier = ({ type, node, attributeName }) => {
|
|
138
|
-
const attribute = getHtmlNodeAttributeByName(node, attributeName)
|
|
139
|
-
const value = attribute ? attribute.value : undefined
|
|
140
|
-
if (value) {
|
|
141
|
-
const inlinedBy = getHtmlNodeAttributeByName(node, "inlined-by")
|
|
142
|
-
if (inlinedBy) {
|
|
143
|
-
// during build the importmap is inlined
|
|
144
|
-
// and shoud not be considered as a dependency anymore
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
addDependency({
|
|
148
|
-
type,
|
|
149
|
-
node,
|
|
150
|
-
attribute,
|
|
151
|
-
specifier:
|
|
152
|
-
attributeName === "content-src" ? new URL(value, url).href : value,
|
|
153
|
-
})
|
|
154
|
-
} else if (attributeName === "src") {
|
|
155
|
-
visitAttributeAsUrlSpecifier({
|
|
156
|
-
type,
|
|
157
|
-
node,
|
|
158
|
-
attributeName: "content-src",
|
|
159
|
-
})
|
|
160
|
-
} else if (attributeName === "href") {
|
|
161
|
-
visitAttributeAsUrlSpecifier({
|
|
162
|
-
type,
|
|
163
|
-
node,
|
|
164
|
-
attributeName: "content-href",
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const visitSrcset = ({ type, node }) => {
|
|
169
|
-
const srcsetAttribute = getHtmlNodeAttributeByName(node, "srcset")
|
|
170
|
-
const srcset = srcsetAttribute ? srcsetAttribute.value : undefined
|
|
171
|
-
if (srcset) {
|
|
172
|
-
const srcCandidates = htmlAttributeSrcSet.parse(srcset)
|
|
173
|
-
srcCandidates.forEach((srcCandidate) => {
|
|
174
|
-
addDependency({
|
|
175
|
-
type,
|
|
176
|
-
node,
|
|
177
|
-
attribute: srcsetAttribute,
|
|
178
|
-
specifier: srcCandidate.specifier,
|
|
179
|
-
})
|
|
180
|
-
})
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
visitHtmlAst(htmlAst, onNode)
|
|
184
|
-
return htmlUrlMentions
|
|
185
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { collectProgramUrlMentions } from "@jsenv/utils/js_ast/program_url_mentions.js"
|
|
2
|
-
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
3
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
4
|
-
|
|
5
|
-
export const parseJsModuleUrlMentions = async ({
|
|
6
|
-
url,
|
|
7
|
-
generatedUrl,
|
|
8
|
-
content,
|
|
9
|
-
}) => {
|
|
10
|
-
const { metadata } = await applyBabelPlugins({
|
|
11
|
-
babelPlugins: [
|
|
12
|
-
babelPluginMetadataUrlMentions,
|
|
13
|
-
babelPluginMetadataUsesTopLevelAwait,
|
|
14
|
-
],
|
|
15
|
-
url,
|
|
16
|
-
generatedUrl,
|
|
17
|
-
content,
|
|
18
|
-
})
|
|
19
|
-
const { urlMentions, usesTopLevelAwait } = metadata
|
|
20
|
-
return {
|
|
21
|
-
urlMentions,
|
|
22
|
-
replaceUrls: async (getReplacement) => {
|
|
23
|
-
const magicSource = createMagicSource(content)
|
|
24
|
-
urlMentions.forEach((urlMention) => {
|
|
25
|
-
const replacement = getReplacement(urlMention)
|
|
26
|
-
if (replacement) {
|
|
27
|
-
const { start, end } = urlMention
|
|
28
|
-
magicSource.replace({
|
|
29
|
-
start,
|
|
30
|
-
end,
|
|
31
|
-
replacement,
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
return magicSource.toContentAndSourcemap()
|
|
36
|
-
},
|
|
37
|
-
data: {
|
|
38
|
-
usesTopLevelAwait,
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const babelPluginMetadataUrlMentions = () => {
|
|
44
|
-
return {
|
|
45
|
-
name: "metadata-url-mentions",
|
|
46
|
-
visitor: {
|
|
47
|
-
Program(programPath, state) {
|
|
48
|
-
const urlMentions = []
|
|
49
|
-
collectProgramUrlMentions(programPath).forEach(
|
|
50
|
-
({ type, subtype, path, specifierPath }) => {
|
|
51
|
-
const specifierNode = specifierPath.node
|
|
52
|
-
if (specifierNode.type === "StringLiteral") {
|
|
53
|
-
urlMentions.push({
|
|
54
|
-
type,
|
|
55
|
-
subtype,
|
|
56
|
-
path,
|
|
57
|
-
specifier: specifierNode.value,
|
|
58
|
-
start: specifierNode.start,
|
|
59
|
-
end: specifierNode.end,
|
|
60
|
-
line: specifierNode.loc.start.line,
|
|
61
|
-
column: specifierNode.loc.start.column,
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
)
|
|
66
|
-
state.file.metadata.urlMentions = urlMentions
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const babelPluginMetadataUsesTopLevelAwait = () => {
|
|
73
|
-
return {
|
|
74
|
-
name: "metadata-uses-top-level-await",
|
|
75
|
-
visitor: {
|
|
76
|
-
Program: (programPath, state) => {
|
|
77
|
-
let usesTopLevelAwait = false
|
|
78
|
-
programPath.traverse({
|
|
79
|
-
AwaitExpression: (awaitPath) => {
|
|
80
|
-
const closestFunction = awaitPath.getFunctionParent()
|
|
81
|
-
if (!closestFunction) {
|
|
82
|
-
usesTopLevelAwait = true
|
|
83
|
-
awaitPath.stop()
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
})
|
|
87
|
-
state.file.metadata.usesTopLevelAwait = usesTopLevelAwait
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { parseHtmlUrlMentions } from "./html_url_mentions.js"
|
|
2
|
-
import { parseCssUrlMentions } from "./css_url_mentions.js"
|
|
3
|
-
import { parseJsModuleUrlMentions } from "./js_module_url_mentions.js"
|
|
4
|
-
import { parseWorkerClassicUrlMentions } from "./worker_classic_url_mentions.js"
|
|
5
|
-
|
|
6
|
-
const parsers = {
|
|
7
|
-
html: parseHtmlUrlMentions,
|
|
8
|
-
css: parseCssUrlMentions,
|
|
9
|
-
js_classic: (urlInfo) => {
|
|
10
|
-
if (urlInfo.subtype === "worker" || urlInfo.subtype === "service_worker") {
|
|
11
|
-
return parseWorkerClassicUrlMentions(urlInfo)
|
|
12
|
-
}
|
|
13
|
-
return {}
|
|
14
|
-
},
|
|
15
|
-
js_module: parseJsModuleUrlMentions,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const parseUrlMentions = async ({ type, url, content, scenario }) => {
|
|
19
|
-
const parser = parsers[type]
|
|
20
|
-
if (!parser) {
|
|
21
|
-
return null
|
|
22
|
-
}
|
|
23
|
-
const {
|
|
24
|
-
urlMentions = [],
|
|
25
|
-
hotDecline = false,
|
|
26
|
-
hotAcceptSelf = false,
|
|
27
|
-
replaceUrls,
|
|
28
|
-
data,
|
|
29
|
-
} = await parser({ url, content, scenario })
|
|
30
|
-
return {
|
|
31
|
-
urlMentions,
|
|
32
|
-
hotDecline,
|
|
33
|
-
hotAcceptSelf,
|
|
34
|
-
replaceUrls,
|
|
35
|
-
data,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
2
|
-
|
|
3
|
-
export const jsenvPluginImportScriptsBundler = () => {
|
|
4
|
-
return {
|
|
5
|
-
name: "jsenv:import_scripts_bundler",
|
|
6
|
-
bundle: {
|
|
7
|
-
js_classic: async (workerUrlInfos, { urlGraph }) => {
|
|
8
|
-
const bundleResult = {}
|
|
9
|
-
workerUrlInfos.forEach((workerUrlInfo) => {
|
|
10
|
-
const magicSource = createMagicSource(workerUrlInfo.content)
|
|
11
|
-
const visitDependencies = (urlInfo) => {
|
|
12
|
-
urlInfo.dependencies.forEach((dependencyUrl) => {
|
|
13
|
-
const dependencyUrlInfo = urlGraph.getUrlInfo(dependencyUrl)
|
|
14
|
-
// what if there was some sourcemap for this urlInfo?
|
|
15
|
-
// we should compose it too
|
|
16
|
-
magicSource.append(dependencyUrlInfo.content)
|
|
17
|
-
visitDependencies(dependencyUrlInfo)
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
visitDependencies(workerUrlInfo)
|
|
21
|
-
const { content, sourcemap } = magicSource.toContentAndSourcemap()
|
|
22
|
-
bundleResult[workerUrlInfo.url] = {
|
|
23
|
-
type: "worker_classic",
|
|
24
|
-
content,
|
|
25
|
-
sourcemap,
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
return bundleResult
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const parseWorkerClassicUrlMentions = () => {
|
|
35
|
-
// use babel_plugin_inline_worker_imports.js
|
|
36
|
-
return {}
|
|
37
|
-
}
|