@jsenv/core 35.0.3 → 35.0.4
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/html/explorer.html +107 -107
- package/dist/js/new_stylesheet.js +3 -0
- package/dist/js/s.js.map +3 -3
- package/package.json +1 -1
- package/src/build/build.js +589 -587
- package/src/build/build_urls_generator.js +44 -44
- package/src/build/graph_utils.js +14 -14
- package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
- package/src/build/line_break_unix.js +11 -11
- package/src/build/start_build_server.js +37 -37
- package/src/build/version_generator.js +7 -7
- package/src/build/version_mappings_injection.js +23 -23
- package/src/dev/file_service.js +132 -132
- package/src/dev/start_dev_server.js +56 -56
- package/src/dev/user_agent.js +8 -8
- package/src/helpers/basic_fetch.js +24 -24
- package/src/helpers/command/command.js +28 -28
- package/src/helpers/lookup_package_directory.js +19 -16
- package/src/helpers/ping_server.js +17 -17
- package/src/helpers/require_from_jsenv.js +2 -2
- package/src/helpers/watch_source_files.js +9 -9
- package/src/helpers/web_url_converter.js +10 -10
- package/src/helpers/worker_reload.js +27 -27
- package/src/kitchen/compat/features_compatibility.js +1 -1
- package/src/kitchen/compat/runtime_compat.js +26 -24
- package/src/kitchen/errors.js +75 -75
- package/src/kitchen/fetched_content_compliance.js +8 -8
- package/src/kitchen/kitchen.js +251 -250
- package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
- package/src/kitchen/url_graph/url_graph_loader.js +30 -30
- package/src/kitchen/url_graph/url_graph_report.js +57 -57
- package/src/kitchen/url_graph/url_info_transformations.js +77 -77
- package/src/kitchen/url_graph.js +121 -121
- package/src/kitchen/url_specifier_encoding.js +21 -21
- package/src/kitchen/web_workers.js +5 -5
- package/src/main.js +3 -3
- package/src/plugins/autoreload/client/autoreload.js +96 -96
- package/src/plugins/autoreload/client/reload.js +56 -56
- package/src/plugins/autoreload/client/url_helpers.js +13 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
- package/src/plugins/explorer/client/explorer.html +107 -107
- package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
- package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
- package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
- package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
- package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
- package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
- package/src/plugins/plugin_controller.js +124 -124
- package/src/plugins/plugins.js +27 -27
- package/src/plugins/ribbon/client/ribbon.js +6 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
- package/src/plugins/server_events/client/connection_manager.js +52 -52
- package/src/plugins/server_events/client/event_source_connection.js +36 -36
- package/src/plugins/server_events/client/events_manager.js +37 -37
- package/src/plugins/server_events/client/server_events_client.js +7 -7
- package/src/plugins/server_events/client/web_socket_connection.js +39 -39
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
- package/src/plugins/server_events/server_events_dispatcher.js +43 -43
- package/src/plugins/supervisor/client/supervisor.js +455 -450
- package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
- package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
- package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
- package/src/plugins/url_analysis/css/css_urls.js +12 -12
- package/src/plugins/url_analysis/html/html_urls.js +85 -85
- package/src/plugins/url_analysis/js/js_urls.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - <link rel="modulepreload"> are converted to <link rel="preload">
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { readFileSync } from "node:fs"
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
9
|
import {
|
|
10
10
|
parseHtmlString,
|
|
11
11
|
visitHtmlNodes,
|
|
@@ -15,17 +15,17 @@ import {
|
|
|
15
15
|
analyzeScriptNode,
|
|
16
16
|
injectHtmlNodeAsEarlyAsPossible,
|
|
17
17
|
createHtmlNode,
|
|
18
|
-
} from "@jsenv/ast"
|
|
19
|
-
import { injectQueryParams, urlToRelativeUrl } from "@jsenv/urls"
|
|
20
|
-
import { SOURCEMAP } from "@jsenv/sourcemap"
|
|
18
|
+
} from "@jsenv/ast";
|
|
19
|
+
import { injectQueryParams, urlToRelativeUrl } from "@jsenv/urls";
|
|
20
|
+
import { SOURCEMAP } from "@jsenv/sourcemap";
|
|
21
21
|
|
|
22
22
|
export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
23
23
|
systemJsInjection,
|
|
24
24
|
systemJsClientFileUrl,
|
|
25
25
|
}) => {
|
|
26
26
|
const turnIntoJsClassicProxy = (reference) => {
|
|
27
|
-
return injectQueryParams(reference.url, { js_module_fallback: "" })
|
|
28
|
-
}
|
|
27
|
+
return injectQueryParams(reference.url, { js_module_fallback: "" });
|
|
28
|
+
};
|
|
29
29
|
|
|
30
30
|
return {
|
|
31
31
|
name: "jsenv:js_module_fallback_inside_html",
|
|
@@ -36,58 +36,58 @@ export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
|
36
36
|
context.systemJsTranspilation &&
|
|
37
37
|
reference.subtype === "modulepreload"
|
|
38
38
|
) {
|
|
39
|
-
return turnIntoJsClassicProxy(reference)
|
|
39
|
+
return turnIntoJsClassicProxy(reference);
|
|
40
40
|
}
|
|
41
41
|
if (
|
|
42
42
|
context.systemJsTranspilation &&
|
|
43
43
|
reference.subtype === "preload" &&
|
|
44
44
|
reference.expectedType === "js_module"
|
|
45
45
|
) {
|
|
46
|
-
return turnIntoJsClassicProxy(reference)
|
|
46
|
+
return turnIntoJsClassicProxy(reference);
|
|
47
47
|
}
|
|
48
|
-
return null
|
|
48
|
+
return null;
|
|
49
49
|
},
|
|
50
50
|
script: (reference, context) => {
|
|
51
51
|
if (
|
|
52
52
|
context.systemJsTranspilation &&
|
|
53
53
|
reference.expectedType === "js_module"
|
|
54
54
|
) {
|
|
55
|
-
return turnIntoJsClassicProxy(reference)
|
|
55
|
+
return turnIntoJsClassicProxy(reference);
|
|
56
56
|
}
|
|
57
|
-
return null
|
|
57
|
+
return null;
|
|
58
58
|
},
|
|
59
59
|
js_url: (reference, context) => {
|
|
60
60
|
if (
|
|
61
61
|
context.systemJsTranspilation &&
|
|
62
62
|
reference.expectedType === "js_module"
|
|
63
63
|
) {
|
|
64
|
-
return turnIntoJsClassicProxy(reference)
|
|
64
|
+
return turnIntoJsClassicProxy(reference);
|
|
65
65
|
}
|
|
66
|
-
return null
|
|
66
|
+
return null;
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
69
|
finalizeUrlContent: {
|
|
70
70
|
html: async (urlInfo, context) => {
|
|
71
|
-
const htmlAst = parseHtmlString(urlInfo.content)
|
|
72
|
-
const mutations = []
|
|
71
|
+
const htmlAst = parseHtmlString(urlInfo.content);
|
|
72
|
+
const mutations = [];
|
|
73
73
|
visitHtmlNodes(htmlAst, {
|
|
74
74
|
link: (node) => {
|
|
75
|
-
const rel = getHtmlNodeAttribute(node, "rel")
|
|
75
|
+
const rel = getHtmlNodeAttribute(node, "rel");
|
|
76
76
|
if (rel !== "modulepreload" && rel !== "preload") {
|
|
77
|
-
return
|
|
77
|
+
return;
|
|
78
78
|
}
|
|
79
|
-
const href = getHtmlNodeAttribute(node, "href")
|
|
79
|
+
const href = getHtmlNodeAttribute(node, "href");
|
|
80
80
|
if (!href) {
|
|
81
|
-
return
|
|
81
|
+
return;
|
|
82
82
|
}
|
|
83
83
|
const reference = context.referenceUtils.find(
|
|
84
84
|
(ref) =>
|
|
85
85
|
ref.generatedSpecifier === href &&
|
|
86
86
|
ref.type === "link_href" &&
|
|
87
87
|
ref.subtype === rel,
|
|
88
|
-
)
|
|
88
|
+
);
|
|
89
89
|
if (!isOrWasExpectingJsModule(reference)) {
|
|
90
|
-
return
|
|
90
|
+
return;
|
|
91
91
|
}
|
|
92
92
|
if (
|
|
93
93
|
rel === "modulepreload" &&
|
|
@@ -98,73 +98,73 @@ export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
|
98
98
|
rel: "preload",
|
|
99
99
|
as: "script",
|
|
100
100
|
crossorigin: undefined,
|
|
101
|
-
})
|
|
102
|
-
})
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
103
|
}
|
|
104
104
|
if (rel === "preload" && reference.expectedType === "js_classic") {
|
|
105
105
|
mutations.push(() => {
|
|
106
|
-
setHtmlNodeAttributes(node, { crossorigin: undefined })
|
|
107
|
-
})
|
|
106
|
+
setHtmlNodeAttributes(node, { crossorigin: undefined });
|
|
107
|
+
});
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
script: (node) => {
|
|
111
|
-
const { type } = analyzeScriptNode(node)
|
|
111
|
+
const { type } = analyzeScriptNode(node);
|
|
112
112
|
if (type !== "js_module") {
|
|
113
|
-
return
|
|
113
|
+
return;
|
|
114
114
|
}
|
|
115
|
-
const src = getHtmlNodeAttribute(node, "src")
|
|
115
|
+
const src = getHtmlNodeAttribute(node, "src");
|
|
116
116
|
if (src) {
|
|
117
117
|
const reference = context.referenceUtils.find(
|
|
118
118
|
(ref) =>
|
|
119
119
|
ref.generatedSpecifier === src &&
|
|
120
120
|
ref.type === "script" &&
|
|
121
121
|
ref.subtype === "js_module",
|
|
122
|
-
)
|
|
122
|
+
);
|
|
123
123
|
if (!reference) {
|
|
124
|
-
return
|
|
124
|
+
return;
|
|
125
125
|
}
|
|
126
126
|
if (reference.expectedType === "js_classic") {
|
|
127
127
|
mutations.push(() => {
|
|
128
|
-
setHtmlNodeAttributes(node, { type: undefined })
|
|
129
|
-
})
|
|
128
|
+
setHtmlNodeAttributes(node, { type: undefined });
|
|
129
|
+
});
|
|
130
130
|
}
|
|
131
131
|
} else if (context.systemJsTranspilation) {
|
|
132
132
|
mutations.push(() => {
|
|
133
|
-
setHtmlNodeAttributes(node, { type: undefined })
|
|
134
|
-
})
|
|
133
|
+
setHtmlNodeAttributes(node, { type: undefined });
|
|
134
|
+
});
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
|
-
})
|
|
137
|
+
});
|
|
138
138
|
|
|
139
139
|
if (systemJsInjection) {
|
|
140
|
-
let needsSystemJs = false
|
|
140
|
+
let needsSystemJs = false;
|
|
141
141
|
for (const reference of urlInfo.references) {
|
|
142
142
|
if (reference.isResourceHint) {
|
|
143
143
|
// we don't cook resource hints
|
|
144
144
|
// because they might refer to resource that will be modified during build
|
|
145
145
|
// It also means something else HAVE to reference that url in order to cook it
|
|
146
146
|
// so that the preload is deleted by "resync_resource_hints.js" otherwise
|
|
147
|
-
continue
|
|
147
|
+
continue;
|
|
148
148
|
}
|
|
149
149
|
if (isOrWasExpectingJsModule(reference)) {
|
|
150
150
|
const dependencyUrlInfo = context.urlGraph.getUrlInfo(
|
|
151
151
|
reference.url,
|
|
152
|
-
)
|
|
152
|
+
);
|
|
153
153
|
try {
|
|
154
|
-
await context.cook(dependencyUrlInfo, { reference })
|
|
154
|
+
await context.cook(dependencyUrlInfo, { reference });
|
|
155
155
|
if (dependencyUrlInfo.data.jsClassicFormat === "system") {
|
|
156
|
-
needsSystemJs = true
|
|
157
|
-
break
|
|
156
|
+
needsSystemJs = true;
|
|
157
|
+
break;
|
|
158
158
|
}
|
|
159
159
|
} catch (e) {
|
|
160
160
|
if (context.dev && e.code !== "PARSE_ERROR") {
|
|
161
|
-
needsSystemJs = true
|
|
161
|
+
needsSystemJs = true;
|
|
162
162
|
// ignore cooking error, the browser will trigger it again on fetch
|
|
163
163
|
// + disable cache for this html file because when browser will reload
|
|
164
164
|
// the error might be gone and we might need to inject systemjs
|
|
165
|
-
urlInfo.headers["cache-control"] = "no-store"
|
|
165
|
+
urlInfo.headers["cache-control"] = "no-store";
|
|
166
166
|
} else {
|
|
167
|
-
throw e
|
|
167
|
+
throw e;
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
}
|
|
@@ -174,21 +174,21 @@ export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
|
174
174
|
let systemJsFileContent = readFileSync(
|
|
175
175
|
new URL(systemJsClientFileUrl),
|
|
176
176
|
{ encoding: "utf8" },
|
|
177
|
-
)
|
|
177
|
+
);
|
|
178
178
|
const sourcemapFound = SOURCEMAP.readComment({
|
|
179
179
|
contentType: "text/javascript",
|
|
180
180
|
content: systemJsFileContent,
|
|
181
|
-
})
|
|
181
|
+
});
|
|
182
182
|
if (sourcemapFound) {
|
|
183
183
|
const sourcemapFileUrl = new URL(
|
|
184
184
|
sourcemapFound.specifier,
|
|
185
185
|
systemJsClientFileUrl,
|
|
186
|
-
)
|
|
186
|
+
);
|
|
187
187
|
systemJsFileContent = SOURCEMAP.writeComment({
|
|
188
188
|
contentType: "text/javascript",
|
|
189
189
|
content: systemJsFileContent,
|
|
190
190
|
specifier: urlToRelativeUrl(sourcemapFileUrl, urlInfo.url),
|
|
191
|
-
})
|
|
191
|
+
});
|
|
192
192
|
}
|
|
193
193
|
const [systemJsReference, systemJsUrlInfo] =
|
|
194
194
|
context.referenceUtils.inject({
|
|
@@ -198,10 +198,10 @@ export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
|
198
198
|
contentType: "text/javascript",
|
|
199
199
|
content: systemJsFileContent,
|
|
200
200
|
specifier: "s.js",
|
|
201
|
-
})
|
|
201
|
+
});
|
|
202
202
|
await context.cook(systemJsUrlInfo, {
|
|
203
203
|
reference: systemJsReference,
|
|
204
|
-
})
|
|
204
|
+
});
|
|
205
205
|
injectHtmlNodeAsEarlyAsPossible(
|
|
206
206
|
htmlAst,
|
|
207
207
|
createHtmlNode({
|
|
@@ -209,34 +209,34 @@ export const jsenvPluginJsModuleFallbackInsideHtml = ({
|
|
|
209
209
|
textContent: systemJsUrlInfo.content,
|
|
210
210
|
}),
|
|
211
211
|
"jsenv:js_module_fallback",
|
|
212
|
-
)
|
|
213
|
-
})
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
if (mutations.length === 0) {
|
|
217
|
-
return null
|
|
217
|
+
return null;
|
|
218
218
|
}
|
|
219
|
-
await Promise.all(mutations.map((mutation) => mutation()))
|
|
220
|
-
return stringifyHtmlAst(htmlAst)
|
|
219
|
+
await Promise.all(mutations.map((mutation) => mutation()));
|
|
220
|
+
return stringifyHtmlAst(htmlAst);
|
|
221
221
|
},
|
|
222
222
|
},
|
|
223
|
-
}
|
|
224
|
-
}
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
225
|
|
|
226
226
|
const isOrWasExpectingJsModule = (reference) => {
|
|
227
227
|
if (isExpectingJsModule(reference)) {
|
|
228
|
-
return true
|
|
228
|
+
return true;
|
|
229
229
|
}
|
|
230
230
|
if (reference.original && isExpectingJsModule(reference.original)) {
|
|
231
|
-
return true
|
|
231
|
+
return true;
|
|
232
232
|
}
|
|
233
|
-
return false
|
|
234
|
-
}
|
|
233
|
+
return false;
|
|
234
|
+
};
|
|
235
235
|
|
|
236
236
|
const isExpectingJsModule = (reference) => {
|
|
237
237
|
return (
|
|
238
238
|
reference.expectedType === "js_module" ||
|
|
239
239
|
reference.searchParams.has("js_module_fallback") ||
|
|
240
240
|
reference.searchParams.has("as_js_classic")
|
|
241
|
-
)
|
|
242
|
-
}
|
|
241
|
+
);
|
|
242
|
+
};
|
package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* new SharedWorker("shared_worker.js?js_module_fallback", { type: "classic" })
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { injectQueryParams } from "@jsenv/urls"
|
|
14
|
+
import { injectQueryParams } from "@jsenv/urls";
|
|
15
15
|
|
|
16
16
|
export const jsenvPluginJsModuleFallbackOnWorkers = () => {
|
|
17
17
|
const turnIntoJsClassicProxy = (reference) => {
|
|
@@ -20,10 +20,10 @@ export const jsenvPluginJsModuleFallbackOnWorkers = () => {
|
|
|
20
20
|
start: reference.typePropertyNode.value.start,
|
|
21
21
|
end: reference.typePropertyNode.value.end,
|
|
22
22
|
replacement: JSON.stringify("classic"),
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
return injectQueryParams(reference.url, { js_module_fallback: "" })
|
|
26
|
-
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return injectQueryParams(reference.url, { js_module_fallback: "" });
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
return {
|
|
29
29
|
name: "jsenv:js_module_fallback_on_workers",
|
|
@@ -31,32 +31,32 @@ export const jsenvPluginJsModuleFallbackOnWorkers = () => {
|
|
|
31
31
|
redirectUrl: {
|
|
32
32
|
js_url: (reference, context) => {
|
|
33
33
|
if (reference.expectedType !== "js_module") {
|
|
34
|
-
return null
|
|
34
|
+
return null;
|
|
35
35
|
}
|
|
36
36
|
if (reference.expectedSubtype === "worker") {
|
|
37
37
|
if (context.isSupportedOnCurrentClients("worker_type_module")) {
|
|
38
|
-
return null
|
|
38
|
+
return null;
|
|
39
39
|
}
|
|
40
|
-
return turnIntoJsClassicProxy(reference)
|
|
40
|
+
return turnIntoJsClassicProxy(reference);
|
|
41
41
|
}
|
|
42
42
|
if (reference.expectedSubtype === "service_worker") {
|
|
43
43
|
if (
|
|
44
44
|
context.isSupportedOnCurrentClients("service_worker_type_module")
|
|
45
45
|
) {
|
|
46
|
-
return null
|
|
46
|
+
return null;
|
|
47
47
|
}
|
|
48
|
-
return turnIntoJsClassicProxy(reference)
|
|
48
|
+
return turnIntoJsClassicProxy(reference);
|
|
49
49
|
}
|
|
50
50
|
if (reference.expectedSubtype === "shared_worker") {
|
|
51
51
|
if (
|
|
52
52
|
context.isSupportedOnCurrentClients("shared_worker_type_module")
|
|
53
53
|
) {
|
|
54
|
-
return null
|
|
54
|
+
return null;
|
|
55
55
|
}
|
|
56
|
-
return turnIntoJsClassicProxy(reference)
|
|
56
|
+
return turnIntoJsClassicProxy(reference);
|
|
57
57
|
}
|
|
58
|
-
return null
|
|
58
|
+
return null;
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
|
-
}
|
|
62
|
-
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
1
|
+
import { createMagicSource } from "@jsenv/sourcemap";
|
|
2
2
|
|
|
3
3
|
export const jsenvPluginImportMetaResolve = () => {
|
|
4
4
|
return {
|
|
@@ -6,43 +6,43 @@ export const jsenvPluginImportMetaResolve = () => {
|
|
|
6
6
|
appliesDuring: "*",
|
|
7
7
|
init: (context) => {
|
|
8
8
|
if (context.isSupportedOnCurrentClients("import_meta_resolve")) {
|
|
9
|
-
return false
|
|
9
|
+
return false;
|
|
10
10
|
}
|
|
11
11
|
// keep it untouched, systemjs will handle it
|
|
12
12
|
if (context.systemJsTranspilation) {
|
|
13
|
-
return false
|
|
13
|
+
return false;
|
|
14
14
|
}
|
|
15
|
-
return true
|
|
15
|
+
return true;
|
|
16
16
|
},
|
|
17
17
|
transformUrlContent: {
|
|
18
18
|
js_module: async (urlInfo, context) => {
|
|
19
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
19
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
20
20
|
context.referenceUtils._references.forEach((ref) => {
|
|
21
21
|
if (ref.subtype === "import_meta_resolve") {
|
|
22
|
-
const originalSpecifierLength = Buffer.byteLength(ref.specifier)
|
|
22
|
+
const originalSpecifierLength = Buffer.byteLength(ref.specifier);
|
|
23
23
|
const specifierLength = Buffer.byteLength(
|
|
24
24
|
ref.generatedSpecifier.slice(1, -1), // remove `"` around
|
|
25
|
-
)
|
|
25
|
+
);
|
|
26
26
|
const specifierLengthDiff =
|
|
27
|
-
specifierLength - originalSpecifierLength
|
|
28
|
-
const end = ref.node.end + specifierLengthDiff
|
|
27
|
+
specifierLength - originalSpecifierLength;
|
|
28
|
+
const end = ref.node.end + specifierLengthDiff;
|
|
29
29
|
magicSource.replace({
|
|
30
30
|
start: ref.node.start,
|
|
31
31
|
end,
|
|
32
32
|
replacement: `new URL(${ref.generatedSpecifier}, import.meta.url).href`,
|
|
33
|
-
})
|
|
34
|
-
const currentLengthBeforeSpecifier = "import.meta.resolve(".length
|
|
35
|
-
const newLengthBeforeSpecifier = "new URL(".length
|
|
33
|
+
});
|
|
34
|
+
const currentLengthBeforeSpecifier = "import.meta.resolve(".length;
|
|
35
|
+
const newLengthBeforeSpecifier = "new URL(".length;
|
|
36
36
|
const lengthDiff =
|
|
37
|
-
currentLengthBeforeSpecifier - newLengthBeforeSpecifier
|
|
38
|
-
ref.specifierColumn -= lengthDiff
|
|
39
|
-
ref.specifierStart -= lengthDiff
|
|
37
|
+
currentLengthBeforeSpecifier - newLengthBeforeSpecifier;
|
|
38
|
+
ref.specifierColumn -= lengthDiff;
|
|
39
|
+
ref.specifierStart -= lengthDiff;
|
|
40
40
|
ref.specifierEnd =
|
|
41
|
-
ref.specifierStart + Buffer.byteLength(ref.generatedSpecifier)
|
|
41
|
+
ref.specifierStart + Buffer.byteLength(ref.generatedSpecifier);
|
|
42
42
|
}
|
|
43
|
-
})
|
|
44
|
-
return magicSource.toContentAndSourcemap()
|
|
43
|
+
});
|
|
44
|
+
return magicSource.toContentAndSourcemap();
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
|
-
}
|
|
48
|
-
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { applyBabelPlugins } from "@jsenv/ast"
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
2
2
|
|
|
3
|
-
import { requireBabelPlugin } from "./babel/require_babel_plugin.js"
|
|
3
|
+
import { requireBabelPlugin } from "./babel/require_babel_plugin.js";
|
|
4
4
|
|
|
5
5
|
export const jsenvPluginTopLevelAwait = () => {
|
|
6
6
|
return {
|
|
@@ -8,19 +8,19 @@ export const jsenvPluginTopLevelAwait = () => {
|
|
|
8
8
|
appliesDuring: "*",
|
|
9
9
|
init: (context) => {
|
|
10
10
|
if (context.isSupportedOnCurrentClients("top_level_await")) {
|
|
11
|
-
return false
|
|
11
|
+
return false;
|
|
12
12
|
}
|
|
13
13
|
// keep it untouched, systemjs will handle it
|
|
14
14
|
if (context.systemJsTranspilation) {
|
|
15
|
-
return false
|
|
15
|
+
return false;
|
|
16
16
|
}
|
|
17
|
-
return true
|
|
17
|
+
return true;
|
|
18
18
|
},
|
|
19
19
|
transformUrlContent: {
|
|
20
20
|
js_module: async (urlInfo) => {
|
|
21
|
-
const usesTLA = await usesTopLevelAwait(urlInfo)
|
|
21
|
+
const usesTLA = await usesTopLevelAwait(urlInfo);
|
|
22
22
|
if (!usesTLA) {
|
|
23
|
-
return null
|
|
23
|
+
return null;
|
|
24
24
|
}
|
|
25
25
|
const { code, map } = await applyBabelPlugins({
|
|
26
26
|
urlInfo,
|
|
@@ -44,44 +44,44 @@ export const jsenvPluginTopLevelAwait = () => {
|
|
|
44
44
|
},
|
|
45
45
|
],
|
|
46
46
|
],
|
|
47
|
-
})
|
|
47
|
+
});
|
|
48
48
|
return {
|
|
49
49
|
content: code,
|
|
50
50
|
sourcemap: map,
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
|
-
}
|
|
55
|
-
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
56
|
|
|
57
57
|
const usesTopLevelAwait = async (urlInfo) => {
|
|
58
58
|
if (!urlInfo.content.includes("await ")) {
|
|
59
|
-
return false
|
|
59
|
+
return false;
|
|
60
60
|
}
|
|
61
61
|
const { metadata } = await applyBabelPlugins({
|
|
62
62
|
urlInfo,
|
|
63
63
|
babelPlugins: [babelPluginMetadataUsesTopLevelAwait],
|
|
64
|
-
})
|
|
65
|
-
return metadata.usesTopLevelAwait
|
|
66
|
-
}
|
|
64
|
+
});
|
|
65
|
+
return metadata.usesTopLevelAwait;
|
|
66
|
+
};
|
|
67
67
|
|
|
68
68
|
const babelPluginMetadataUsesTopLevelAwait = () => {
|
|
69
69
|
return {
|
|
70
70
|
name: "metadata-uses-top-level-await",
|
|
71
71
|
visitor: {
|
|
72
72
|
Program: (programPath, state) => {
|
|
73
|
-
let usesTopLevelAwait = false
|
|
73
|
+
let usesTopLevelAwait = false;
|
|
74
74
|
programPath.traverse({
|
|
75
75
|
AwaitExpression: (path) => {
|
|
76
|
-
const closestFunction = path.getFunctionParent()
|
|
76
|
+
const closestFunction = path.getFunctionParent();
|
|
77
77
|
if (!closestFunction || closestFunction.type === "Program") {
|
|
78
|
-
usesTopLevelAwait = true
|
|
79
|
-
path.stop()
|
|
78
|
+
usesTopLevelAwait = true;
|
|
79
|
+
path.stop();
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
-
})
|
|
83
|
-
state.file.metadata.usesTopLevelAwait = usesTopLevelAwait
|
|
82
|
+
});
|
|
83
|
+
state.file.metadata.usesTopLevelAwait = usesTopLevelAwait;
|
|
84
84
|
},
|
|
85
85
|
},
|
|
86
|
-
}
|
|
87
|
-
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* of this plugin
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { jsenvPluginCssTranspilation } from "./css/jsenv_plugin_css_transpilation.js"
|
|
11
|
-
import { jsenvPluginImportAssertions } from "./import_assertions/jsenv_plugin_import_assertions.js"
|
|
12
|
-
import { jsenvPluginJsModuleFallback } from "./js_module_fallback/jsenv_plugin_js_module_fallback.js"
|
|
13
|
-
import { jsenvPluginAsJsModule } from "./as_js_module/jsenv_plugin_as_js_module.js"
|
|
14
|
-
import { jsenvPluginBabel } from "./babel/jsenv_plugin_babel.js"
|
|
15
|
-
import { jsenvPluginTopLevelAwait } from "./jsenv_plugin_top_level_await.js"
|
|
16
|
-
import { jsenvPluginImportMetaResolve } from "./jsenv_plugin_import_meta_resolve.js"
|
|
10
|
+
import { jsenvPluginCssTranspilation } from "./css/jsenv_plugin_css_transpilation.js";
|
|
11
|
+
import { jsenvPluginImportAssertions } from "./import_assertions/jsenv_plugin_import_assertions.js";
|
|
12
|
+
import { jsenvPluginJsModuleFallback } from "./js_module_fallback/jsenv_plugin_js_module_fallback.js";
|
|
13
|
+
import { jsenvPluginAsJsModule } from "./as_js_module/jsenv_plugin_as_js_module.js";
|
|
14
|
+
import { jsenvPluginBabel } from "./babel/jsenv_plugin_babel.js";
|
|
15
|
+
import { jsenvPluginTopLevelAwait } from "./jsenv_plugin_top_level_await.js";
|
|
16
|
+
import { jsenvPluginImportMetaResolve } from "./jsenv_plugin_import_meta_resolve.js";
|
|
17
17
|
|
|
18
18
|
export const jsenvPluginTranspilation = ({
|
|
19
19
|
importAssertions = true,
|
|
@@ -28,10 +28,10 @@ export const jsenvPluginTranspilation = ({
|
|
|
28
28
|
getCustomBabelPlugins,
|
|
29
29
|
}) => {
|
|
30
30
|
if (importAssertions === true) {
|
|
31
|
-
importAssertions = {}
|
|
31
|
+
importAssertions = {};
|
|
32
32
|
}
|
|
33
33
|
if (jsModuleFallbackOnJsClassic === true) {
|
|
34
|
-
jsModuleFallbackOnJsClassic = {}
|
|
34
|
+
jsModuleFallbackOnJsClassic = {};
|
|
35
35
|
}
|
|
36
36
|
return [
|
|
37
37
|
...(importMetaResolve ? [jsenvPluginImportMetaResolve()] : []),
|
|
@@ -52,5 +52,5 @@ export const jsenvPluginTranspilation = ({
|
|
|
52
52
|
// so we want to wait to know the module format before transforming things related to top level await
|
|
53
53
|
...(topLevelAwait ? [jsenvPluginTopLevelAwait(topLevelAwait)] : []),
|
|
54
54
|
...(css ? [jsenvPluginCssTranspilation()] : []),
|
|
55
|
-
]
|
|
56
|
-
}
|
|
55
|
+
];
|
|
56
|
+
};
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { parseCssUrls } from "@jsenv/ast"
|
|
6
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
5
|
+
import { parseCssUrls } from "@jsenv/ast";
|
|
6
|
+
import { createMagicSource } from "@jsenv/sourcemap";
|
|
7
7
|
|
|
8
8
|
export const parseAndTransformCssUrls = async (urlInfo, context) => {
|
|
9
9
|
const cssUrls = await parseCssUrls({
|
|
10
10
|
css: urlInfo.content,
|
|
11
11
|
url: urlInfo.originalUrl,
|
|
12
|
-
})
|
|
13
|
-
const actions = []
|
|
14
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
12
|
+
});
|
|
13
|
+
const actions = [];
|
|
14
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
15
15
|
for (const cssUrl of cssUrls) {
|
|
16
16
|
const [reference] = context.referenceUtils.found({
|
|
17
17
|
type: cssUrl.type,
|
|
@@ -20,20 +20,20 @@ export const parseAndTransformCssUrls = async (urlInfo, context) => {
|
|
|
20
20
|
specifierEnd: cssUrl.end,
|
|
21
21
|
specifierLine: cssUrl.line,
|
|
22
22
|
specifierColumn: cssUrl.column,
|
|
23
|
-
})
|
|
23
|
+
});
|
|
24
24
|
actions.push(async () => {
|
|
25
25
|
const replacement = await context.referenceUtils.readGeneratedSpecifier(
|
|
26
26
|
reference,
|
|
27
|
-
)
|
|
27
|
+
);
|
|
28
28
|
magicSource.replace({
|
|
29
29
|
start: cssUrl.start,
|
|
30
30
|
end: cssUrl.end,
|
|
31
31
|
replacement,
|
|
32
|
-
})
|
|
33
|
-
})
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
34
|
}
|
|
35
35
|
if (actions.length > 0) {
|
|
36
|
-
await Promise.all(actions.map((action) => action()))
|
|
36
|
+
await Promise.all(actions.map((action) => action()));
|
|
37
37
|
}
|
|
38
|
-
return magicSource.toContentAndSourcemap()
|
|
39
|
-
}
|
|
38
|
+
return magicSource.toContentAndSourcemap();
|
|
39
|
+
};
|