@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
|
@@ -57,15 +57,15 @@ import {
|
|
|
57
57
|
getHtmlNodePosition,
|
|
58
58
|
getHtmlNodeText,
|
|
59
59
|
setHtmlNodeText,
|
|
60
|
-
} from "@jsenv/ast"
|
|
61
|
-
import { generateInlineContentUrl, urlToRelativeUrl } from "@jsenv/urls"
|
|
60
|
+
} from "@jsenv/ast";
|
|
61
|
+
import { generateInlineContentUrl, urlToRelativeUrl } from "@jsenv/urls";
|
|
62
62
|
|
|
63
|
-
import { injectSupervisorIntoJs } from "./js_supervisor_injection.js"
|
|
63
|
+
import { injectSupervisorIntoJs } from "./js_supervisor_injection.js";
|
|
64
64
|
|
|
65
65
|
export const supervisorFileUrl = new URL(
|
|
66
66
|
"./client/supervisor.js",
|
|
67
67
|
import.meta.url,
|
|
68
|
-
).href
|
|
68
|
+
).href;
|
|
69
69
|
|
|
70
70
|
export const injectSupervisorIntoHTML = async (
|
|
71
71
|
{ content, url },
|
|
@@ -79,11 +79,11 @@ export const injectSupervisorIntoHTML = async (
|
|
|
79
79
|
inlineAsRemote,
|
|
80
80
|
},
|
|
81
81
|
) => {
|
|
82
|
-
const htmlAst = parseHtmlString(content)
|
|
83
|
-
const mutations = []
|
|
84
|
-
const actions = []
|
|
82
|
+
const htmlAst = parseHtmlString(content);
|
|
83
|
+
const mutations = [];
|
|
84
|
+
const actions = [];
|
|
85
85
|
|
|
86
|
-
const scriptInfos = []
|
|
86
|
+
const scriptInfos = [];
|
|
87
87
|
// 1. Find inline and remote scripts
|
|
88
88
|
{
|
|
89
89
|
const handleInlineScript = (
|
|
@@ -91,7 +91,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
91
91
|
{ type, extension, textContent },
|
|
92
92
|
) => {
|
|
93
93
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
94
|
-
getHtmlNodePosition(scriptNode, { preferOriginal: true })
|
|
94
|
+
getHtmlNodePosition(scriptNode, { preferOriginal: true });
|
|
95
95
|
const inlineScriptUrl = generateInlineContentUrl({
|
|
96
96
|
url,
|
|
97
97
|
extension: extension || ".js",
|
|
@@ -99,7 +99,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
99
99
|
column,
|
|
100
100
|
lineEnd,
|
|
101
101
|
columnEnd,
|
|
102
|
-
})
|
|
102
|
+
});
|
|
103
103
|
const inlineScriptSrc = generateInlineScriptSrc({
|
|
104
104
|
type,
|
|
105
105
|
textContent,
|
|
@@ -107,7 +107,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
107
107
|
isOriginal,
|
|
108
108
|
line,
|
|
109
109
|
column,
|
|
110
|
-
})
|
|
110
|
+
});
|
|
111
111
|
onInlineScript({
|
|
112
112
|
type,
|
|
113
113
|
textContent,
|
|
@@ -116,26 +116,26 @@ export const injectSupervisorIntoHTML = async (
|
|
|
116
116
|
line,
|
|
117
117
|
column,
|
|
118
118
|
src: inlineScriptSrc,
|
|
119
|
-
})
|
|
119
|
+
});
|
|
120
120
|
if (inlineAsRemote) {
|
|
121
121
|
// prefere la version src
|
|
122
|
-
scriptInfos.push({ type, src: inlineScriptSrc })
|
|
122
|
+
scriptInfos.push({ type, src: inlineScriptSrc });
|
|
123
123
|
const remoteJsSupervised = generateCodeToSuperviseScriptWithSrc({
|
|
124
124
|
type,
|
|
125
125
|
src: inlineScriptSrc,
|
|
126
|
-
})
|
|
126
|
+
});
|
|
127
127
|
mutations.push(() => {
|
|
128
128
|
setHtmlNodeText(scriptNode, remoteJsSupervised, {
|
|
129
129
|
indentation: "auto",
|
|
130
|
-
})
|
|
130
|
+
});
|
|
131
131
|
setHtmlNodeAttributes(scriptNode, {
|
|
132
132
|
"jsenv-cooked-by": "jsenv:supervisor",
|
|
133
133
|
"src": undefined,
|
|
134
134
|
"inlined-from-src": inlineScriptSrc,
|
|
135
|
-
})
|
|
136
|
-
})
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
137
|
} else {
|
|
138
|
-
scriptInfos.push({ type, src: inlineScriptSrc, isInline: true })
|
|
138
|
+
scriptInfos.push({ type, src: inlineScriptSrc, isInline: true });
|
|
139
139
|
actions.push(async () => {
|
|
140
140
|
try {
|
|
141
141
|
const inlineJsSupervised = await injectSupervisorIntoJs({
|
|
@@ -144,15 +144,15 @@ export const injectSupervisorIntoHTML = async (
|
|
|
144
144
|
url: inlineScriptUrl,
|
|
145
145
|
type,
|
|
146
146
|
inlineSrc: inlineScriptSrc,
|
|
147
|
-
})
|
|
147
|
+
});
|
|
148
148
|
mutations.push(() => {
|
|
149
149
|
setHtmlNodeText(scriptNode, inlineJsSupervised, {
|
|
150
150
|
indentation: "auto",
|
|
151
|
-
})
|
|
151
|
+
});
|
|
152
152
|
setHtmlNodeAttributes(scriptNode, {
|
|
153
153
|
"jsenv-cooked-by": "jsenv:supervisor",
|
|
154
|
-
})
|
|
155
|
-
})
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
156
|
} catch (e) {
|
|
157
157
|
if (e.code === "PARSE_ERROR") {
|
|
158
158
|
// mutations.push(() => {
|
|
@@ -161,62 +161,64 @@ export const injectSupervisorIntoHTML = async (
|
|
|
161
161
|
// })
|
|
162
162
|
// })
|
|
163
163
|
// on touche a rien
|
|
164
|
-
return
|
|
164
|
+
return;
|
|
165
165
|
}
|
|
166
|
-
throw e
|
|
166
|
+
throw e;
|
|
167
167
|
}
|
|
168
|
-
})
|
|
168
|
+
});
|
|
169
169
|
}
|
|
170
|
-
}
|
|
170
|
+
};
|
|
171
171
|
const handleScriptWithSrc = (scriptNode, { type, src }) => {
|
|
172
|
-
scriptInfos.push({ type, src })
|
|
172
|
+
scriptInfos.push({ type, src });
|
|
173
173
|
const remoteJsSupervised = generateCodeToSuperviseScriptWithSrc({
|
|
174
174
|
type,
|
|
175
175
|
src,
|
|
176
|
-
})
|
|
176
|
+
});
|
|
177
177
|
mutations.push(() => {
|
|
178
|
-
setHtmlNodeText(scriptNode, remoteJsSupervised, {
|
|
178
|
+
setHtmlNodeText(scriptNode, remoteJsSupervised, {
|
|
179
|
+
indentation: "auto",
|
|
180
|
+
});
|
|
179
181
|
setHtmlNodeAttributes(scriptNode, {
|
|
180
182
|
"jsenv-cooked-by": "jsenv:supervisor",
|
|
181
183
|
"src": undefined,
|
|
182
184
|
"inlined-from-src": src,
|
|
183
|
-
})
|
|
184
|
-
})
|
|
185
|
-
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
186
188
|
visitHtmlNodes(htmlAst, {
|
|
187
189
|
script: (scriptNode) => {
|
|
188
|
-
const { type, extension } = analyzeScriptNode(scriptNode)
|
|
190
|
+
const { type, extension } = analyzeScriptNode(scriptNode);
|
|
189
191
|
if (type !== "js_classic" && type !== "js_module") {
|
|
190
|
-
return
|
|
192
|
+
return;
|
|
191
193
|
}
|
|
192
194
|
if (getHtmlNodeAttribute(scriptNode, "jsenv-injected-by")) {
|
|
193
|
-
return
|
|
195
|
+
return;
|
|
194
196
|
}
|
|
195
|
-
const noSupervisor = getHtmlNodeAttribute(scriptNode, "no-supervisor")
|
|
197
|
+
const noSupervisor = getHtmlNodeAttribute(scriptNode, "no-supervisor");
|
|
196
198
|
if (noSupervisor !== undefined) {
|
|
197
|
-
return
|
|
199
|
+
return;
|
|
198
200
|
}
|
|
199
201
|
|
|
200
|
-
const scriptNodeText = getHtmlNodeText(scriptNode)
|
|
202
|
+
const scriptNodeText = getHtmlNodeText(scriptNode);
|
|
201
203
|
if (scriptNodeText) {
|
|
202
204
|
handleInlineScript(scriptNode, {
|
|
203
205
|
type,
|
|
204
206
|
extension,
|
|
205
207
|
textContent: scriptNodeText,
|
|
206
|
-
})
|
|
207
|
-
return
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
208
210
|
}
|
|
209
|
-
const src = getHtmlNodeAttribute(scriptNode, "src")
|
|
211
|
+
const src = getHtmlNodeAttribute(scriptNode, "src");
|
|
210
212
|
if (src) {
|
|
211
|
-
const urlObject = new URL(src, "http://example.com")
|
|
213
|
+
const urlObject = new URL(src, "http://example.com");
|
|
212
214
|
if (urlObject.searchParams.has("inline")) {
|
|
213
|
-
return
|
|
215
|
+
return;
|
|
214
216
|
}
|
|
215
|
-
handleScriptWithSrc(scriptNode, { type, src })
|
|
216
|
-
return
|
|
217
|
+
handleScriptWithSrc(scriptNode, { type, src });
|
|
218
|
+
return;
|
|
217
219
|
}
|
|
218
220
|
},
|
|
219
|
-
})
|
|
221
|
+
});
|
|
220
222
|
}
|
|
221
223
|
// 2. Inject supervisor js file + setup call
|
|
222
224
|
{
|
|
@@ -228,7 +230,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
228
230
|
scriptInfos,
|
|
229
231
|
},
|
|
230
232
|
" ",
|
|
231
|
-
)
|
|
233
|
+
);
|
|
232
234
|
injectHtmlNodeAsEarlyAsPossible(
|
|
233
235
|
htmlAst,
|
|
234
236
|
createHtmlNode({
|
|
@@ -236,7 +238,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
236
238
|
textContent: `window.__supervisor__.setup({${setupParamsSource}})`,
|
|
237
239
|
}),
|
|
238
240
|
"jsenv:supervisor",
|
|
239
|
-
)
|
|
241
|
+
);
|
|
240
242
|
injectHtmlNodeAsEarlyAsPossible(
|
|
241
243
|
htmlAst,
|
|
242
244
|
createHtmlNode({
|
|
@@ -244,36 +246,36 @@ export const injectSupervisorIntoHTML = async (
|
|
|
244
246
|
src: supervisorScriptSrc,
|
|
245
247
|
}),
|
|
246
248
|
"jsenv:supervisor",
|
|
247
|
-
)
|
|
249
|
+
);
|
|
248
250
|
}
|
|
249
251
|
// 3. Perform actions (transforming inline script content) and html mutations
|
|
250
252
|
if (actions.length > 0) {
|
|
251
|
-
await Promise.all(actions.map((action) => action()))
|
|
253
|
+
await Promise.all(actions.map((action) => action()));
|
|
252
254
|
}
|
|
253
|
-
mutations.forEach((mutation) => mutation())
|
|
254
|
-
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
255
|
+
mutations.forEach((mutation) => mutation());
|
|
256
|
+
const htmlModified = stringifyHtmlAst(htmlAst);
|
|
255
257
|
return {
|
|
256
258
|
content: htmlModified,
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
+
};
|
|
260
|
+
};
|
|
259
261
|
|
|
260
262
|
const stringifyParams = (params, prefix = "") => {
|
|
261
|
-
const source = JSON.stringify(params, null, prefix)
|
|
263
|
+
const source = JSON.stringify(params, null, prefix);
|
|
262
264
|
if (prefix.length) {
|
|
263
265
|
// remove leading "{\n"
|
|
264
266
|
// remove leading prefix
|
|
265
267
|
// remove trailing "\n}"
|
|
266
|
-
return source.slice(2 + prefix.length, -2)
|
|
268
|
+
return source.slice(2 + prefix.length, -2);
|
|
267
269
|
}
|
|
268
270
|
// remove leading "{"
|
|
269
271
|
// remove trailing "}"
|
|
270
|
-
return source.slice(1, -1)
|
|
271
|
-
}
|
|
272
|
+
return source.slice(1, -1);
|
|
273
|
+
};
|
|
272
274
|
|
|
273
275
|
const generateCodeToSuperviseScriptWithSrc = ({ type, src }) => {
|
|
274
|
-
const srcEncoded = JSON.stringify(src)
|
|
276
|
+
const srcEncoded = JSON.stringify(src);
|
|
275
277
|
if (type === "js_module") {
|
|
276
|
-
return `window.__supervisor__.superviseScriptTypeModule(${srcEncoded}, (url) => import(url))
|
|
278
|
+
return `window.__supervisor__.superviseScriptTypeModule(${srcEncoded}, (url) => import(url));`;
|
|
277
279
|
}
|
|
278
|
-
return `window.__supervisor__.superviseScript(${srcEncoded})
|
|
279
|
-
}
|
|
280
|
+
return `window.__supervisor__.superviseScript(${srcEncoded});`;
|
|
281
|
+
};
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
* and create a variable named "undefined"
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
import { urlToRelativeUrl } from "@jsenv/urls"
|
|
40
|
-
import { applyBabelPlugins } from "@jsenv/ast"
|
|
41
|
-
import { SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap"
|
|
39
|
+
import { urlToRelativeUrl } from "@jsenv/urls";
|
|
40
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
41
|
+
import { SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap";
|
|
42
42
|
|
|
43
43
|
export const injectSupervisorIntoJs = async ({
|
|
44
44
|
webServer,
|
|
@@ -50,7 +50,7 @@ export const injectSupervisorIntoJs = async ({
|
|
|
50
50
|
const babelPluginJsSupervisor =
|
|
51
51
|
type === "js_module"
|
|
52
52
|
? babelPluginJsModuleSupervisor
|
|
53
|
-
: babelPluginJsClassicSupervisor
|
|
53
|
+
: babelPluginJsClassicSupervisor;
|
|
54
54
|
const result = await applyBabelPlugins({
|
|
55
55
|
urlInfo: {
|
|
56
56
|
content,
|
|
@@ -58,116 +58,116 @@ export const injectSupervisorIntoJs = async ({
|
|
|
58
58
|
type,
|
|
59
59
|
},
|
|
60
60
|
babelPlugins: [[babelPluginJsSupervisor, { inlineSrc }]],
|
|
61
|
-
})
|
|
62
|
-
let code = result.code
|
|
63
|
-
let map = result.map
|
|
64
|
-
const sourcemapDataUrl = generateSourcemapDataUrl(map)
|
|
61
|
+
});
|
|
62
|
+
let code = result.code;
|
|
63
|
+
let map = result.map;
|
|
64
|
+
const sourcemapDataUrl = generateSourcemapDataUrl(map);
|
|
65
65
|
code = SOURCEMAP.writeComment({
|
|
66
66
|
contentType: "text/javascript",
|
|
67
67
|
content: code,
|
|
68
68
|
specifier: sourcemapDataUrl,
|
|
69
|
-
})
|
|
69
|
+
});
|
|
70
70
|
code = `${code}
|
|
71
|
-
//# sourceURL=${urlToRelativeUrl(url, webServer.rootDirectoryUrl)}
|
|
72
|
-
return code
|
|
73
|
-
}
|
|
71
|
+
//# sourceURL=${urlToRelativeUrl(url, webServer.rootDirectoryUrl)}`;
|
|
72
|
+
return code;
|
|
73
|
+
};
|
|
74
74
|
|
|
75
75
|
const babelPluginJsModuleSupervisor = (babel) => {
|
|
76
|
-
const t = babel.types
|
|
76
|
+
const t = babel.types;
|
|
77
77
|
|
|
78
78
|
return {
|
|
79
79
|
name: "js-module-supervisor",
|
|
80
80
|
visitor: {
|
|
81
81
|
Program: (programPath, state) => {
|
|
82
|
-
const { inlineSrc } = state.opts
|
|
83
|
-
if (state.file.metadata.jsExecutionInstrumented) return
|
|
84
|
-
state.file.metadata.jsExecutionInstrumented = true
|
|
82
|
+
const { inlineSrc } = state.opts;
|
|
83
|
+
if (state.file.metadata.jsExecutionInstrumented) return;
|
|
84
|
+
state.file.metadata.jsExecutionInstrumented = true;
|
|
85
85
|
|
|
86
|
-
const urlNode = t.stringLiteral(inlineSrc)
|
|
86
|
+
const urlNode = t.stringLiteral(inlineSrc);
|
|
87
87
|
const startCallNode = createSupervisionCall({
|
|
88
88
|
t,
|
|
89
89
|
urlNode,
|
|
90
90
|
methodName: "jsModuleStart",
|
|
91
|
-
})
|
|
91
|
+
});
|
|
92
92
|
const endCallNode = createSupervisionCall({
|
|
93
93
|
t,
|
|
94
94
|
urlNode,
|
|
95
95
|
methodName: "jsModuleEnd",
|
|
96
|
-
})
|
|
96
|
+
});
|
|
97
97
|
const errorCallNode = createSupervisionCall({
|
|
98
98
|
t,
|
|
99
99
|
urlNode,
|
|
100
100
|
methodName: "jsModuleError",
|
|
101
101
|
args: [t.identifier("e")],
|
|
102
|
-
})
|
|
102
|
+
});
|
|
103
103
|
|
|
104
|
-
const bodyPath = programPath.get("body")
|
|
105
|
-
const importNodes = []
|
|
106
|
-
const topLevelNodes = []
|
|
104
|
+
const bodyPath = programPath.get("body");
|
|
105
|
+
const importNodes = [];
|
|
106
|
+
const topLevelNodes = [];
|
|
107
107
|
for (const topLevelNodePath of bodyPath) {
|
|
108
|
-
const topLevelNode = topLevelNodePath.node
|
|
108
|
+
const topLevelNode = topLevelNodePath.node;
|
|
109
109
|
if (t.isImportDeclaration(topLevelNode)) {
|
|
110
|
-
importNodes.push(topLevelNode)
|
|
110
|
+
importNodes.push(topLevelNode);
|
|
111
111
|
} else {
|
|
112
|
-
topLevelNodes.push(topLevelNode)
|
|
112
|
+
topLevelNodes.push(topLevelNode);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
// replace all import nodes with dynamic imports
|
|
117
|
-
const dynamicImports = []
|
|
117
|
+
const dynamicImports = [];
|
|
118
118
|
importNodes.forEach((importNode) => {
|
|
119
119
|
const dynamicImportConversion = convertStaticImportIntoDynamicImport(
|
|
120
120
|
importNode,
|
|
121
121
|
t,
|
|
122
|
-
)
|
|
122
|
+
);
|
|
123
123
|
if (Array.isArray(dynamicImportConversion)) {
|
|
124
|
-
dynamicImports.push(...dynamicImportConversion)
|
|
124
|
+
dynamicImports.push(...dynamicImportConversion);
|
|
125
125
|
} else {
|
|
126
|
-
dynamicImports.push(dynamicImportConversion)
|
|
126
|
+
dynamicImports.push(dynamicImportConversion);
|
|
127
127
|
}
|
|
128
|
-
})
|
|
128
|
+
});
|
|
129
129
|
|
|
130
130
|
const tryCatchNode = t.tryStatement(
|
|
131
131
|
t.blockStatement([...dynamicImports, ...topLevelNodes, endCallNode]),
|
|
132
132
|
t.catchClause(t.identifier("e"), t.blockStatement([errorCallNode])),
|
|
133
|
-
)
|
|
134
|
-
programPath.replaceWith(t.program([startCallNode, tryCatchNode]))
|
|
133
|
+
);
|
|
134
|
+
programPath.replaceWith(t.program([startCallNode, tryCatchNode]));
|
|
135
135
|
},
|
|
136
136
|
},
|
|
137
|
-
}
|
|
138
|
-
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
139
|
|
|
140
140
|
const convertStaticImportIntoDynamicImport = (staticImportNode, t) => {
|
|
141
141
|
const awaitExpression = t.awaitExpression(
|
|
142
142
|
t.callExpression(t.import(), [
|
|
143
143
|
t.stringLiteral(staticImportNode.source.value),
|
|
144
144
|
]),
|
|
145
|
-
)
|
|
145
|
+
);
|
|
146
146
|
|
|
147
147
|
// import "./file.js" -> await import("./file.js")
|
|
148
148
|
if (staticImportNode.specifiers.length === 0) {
|
|
149
|
-
return t.expressionStatement(awaitExpression)
|
|
149
|
+
return t.expressionStatement(awaitExpression);
|
|
150
150
|
}
|
|
151
151
|
if (staticImportNode.specifiers.length === 1) {
|
|
152
|
-
const [firstSpecifier] = staticImportNode.specifiers
|
|
152
|
+
const [firstSpecifier] = staticImportNode.specifiers;
|
|
153
153
|
if (firstSpecifier.type === "ImportNamespaceSpecifier") {
|
|
154
154
|
return t.variableDeclaration("const", [
|
|
155
155
|
t.variableDeclarator(
|
|
156
156
|
t.identifier(firstSpecifier.local.name),
|
|
157
157
|
awaitExpression,
|
|
158
158
|
),
|
|
159
|
-
])
|
|
159
|
+
]);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
if (staticImportNode.specifiers.length === 2) {
|
|
163
|
-
const [first, second] = staticImportNode.specifiers
|
|
163
|
+
const [first, second] = staticImportNode.specifiers;
|
|
164
164
|
if (
|
|
165
165
|
first.type === "ImportDefaultSpecifier" &&
|
|
166
166
|
second.type === "ImportNamespaceSpecifier"
|
|
167
167
|
) {
|
|
168
168
|
const namespaceDeclaration = t.variableDeclaration("const", [
|
|
169
169
|
t.variableDeclarator(t.identifier(second.local.name), awaitExpression),
|
|
170
|
-
])
|
|
170
|
+
]);
|
|
171
171
|
const defaultDeclaration = t.variableDeclaration("const", [
|
|
172
172
|
t.variableDeclarator(
|
|
173
173
|
t.identifier(first.local.name),
|
|
@@ -176,8 +176,8 @@ const convertStaticImportIntoDynamicImport = (staticImportNode, t) => {
|
|
|
176
176
|
t.identifier("default"),
|
|
177
177
|
),
|
|
178
178
|
),
|
|
179
|
-
])
|
|
180
|
-
return [namespaceDeclaration, defaultDeclaration]
|
|
179
|
+
]);
|
|
180
|
+
return [namespaceDeclaration, defaultDeclaration];
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
@@ -191,19 +191,19 @@ const convertStaticImportIntoDynamicImport = (staticImportNode, t) => {
|
|
|
191
191
|
t.identifier(specifier.local.name),
|
|
192
192
|
false, // computed
|
|
193
193
|
false, // shorthand
|
|
194
|
-
)
|
|
194
|
+
);
|
|
195
195
|
}
|
|
196
196
|
// if (specifier.type === "ImportNamespaceSpecifier") {
|
|
197
197
|
// return t.restElement(t.identifier(specifier.local.name))
|
|
198
198
|
// }
|
|
199
|
-
const isRenamed = specifier.imported.name !== specifier.local.name
|
|
199
|
+
const isRenamed = specifier.imported.name !== specifier.local.name;
|
|
200
200
|
if (isRenamed) {
|
|
201
201
|
return t.objectProperty(
|
|
202
202
|
t.identifier(specifier.imported.name),
|
|
203
203
|
t.identifier(specifier.local.name),
|
|
204
204
|
false, // computed
|
|
205
205
|
false, // shorthand
|
|
206
|
-
)
|
|
206
|
+
);
|
|
207
207
|
}
|
|
208
208
|
// shorthand must be true
|
|
209
209
|
return t.objectProperty(
|
|
@@ -211,59 +211,59 @@ const convertStaticImportIntoDynamicImport = (staticImportNode, t) => {
|
|
|
211
211
|
t.identifier(specifier.local.name),
|
|
212
212
|
false, // computed
|
|
213
213
|
true, // shorthand
|
|
214
|
-
)
|
|
214
|
+
);
|
|
215
215
|
}),
|
|
216
|
-
)
|
|
216
|
+
);
|
|
217
217
|
const variableDeclarator = t.variableDeclarator(
|
|
218
218
|
objectPattern,
|
|
219
219
|
awaitExpression,
|
|
220
|
-
)
|
|
220
|
+
);
|
|
221
221
|
const variableDeclaration = t.variableDeclaration("const", [
|
|
222
222
|
variableDeclarator,
|
|
223
|
-
])
|
|
224
|
-
return variableDeclaration
|
|
225
|
-
}
|
|
223
|
+
]);
|
|
224
|
+
return variableDeclaration;
|
|
225
|
+
};
|
|
226
226
|
|
|
227
227
|
const babelPluginJsClassicSupervisor = (babel) => {
|
|
228
|
-
const t = babel.types
|
|
228
|
+
const t = babel.types;
|
|
229
229
|
|
|
230
230
|
return {
|
|
231
231
|
name: "js-classic-supervisor",
|
|
232
232
|
visitor: {
|
|
233
233
|
Program: (programPath, state) => {
|
|
234
|
-
const { inlineSrc } = state.opts
|
|
235
|
-
if (state.file.metadata.jsExecutionInstrumented) return
|
|
236
|
-
state.file.metadata.jsExecutionInstrumented = true
|
|
234
|
+
const { inlineSrc } = state.opts;
|
|
235
|
+
if (state.file.metadata.jsExecutionInstrumented) return;
|
|
236
|
+
state.file.metadata.jsExecutionInstrumented = true;
|
|
237
237
|
|
|
238
|
-
const urlNode = t.stringLiteral(inlineSrc)
|
|
238
|
+
const urlNode = t.stringLiteral(inlineSrc);
|
|
239
239
|
const startCallNode = createSupervisionCall({
|
|
240
240
|
t,
|
|
241
241
|
urlNode,
|
|
242
242
|
methodName: "jsClassicStart",
|
|
243
|
-
})
|
|
243
|
+
});
|
|
244
244
|
const endCallNode = createSupervisionCall({
|
|
245
245
|
t,
|
|
246
246
|
urlNode,
|
|
247
247
|
methodName: "jsClassicEnd",
|
|
248
|
-
})
|
|
248
|
+
});
|
|
249
249
|
const errorCallNode = createSupervisionCall({
|
|
250
250
|
t,
|
|
251
251
|
urlNode,
|
|
252
252
|
methodName: "jsClassicError",
|
|
253
253
|
args: [t.identifier("e")],
|
|
254
|
-
})
|
|
254
|
+
});
|
|
255
255
|
|
|
256
|
-
const topLevelNodes = programPath.node.body
|
|
256
|
+
const topLevelNodes = programPath.node.body;
|
|
257
257
|
const tryCatchNode = t.tryStatement(
|
|
258
258
|
t.blockStatement([...topLevelNodes, endCallNode]),
|
|
259
259
|
t.catchClause(t.identifier("e"), t.blockStatement([errorCallNode])),
|
|
260
|
-
)
|
|
260
|
+
);
|
|
261
261
|
|
|
262
|
-
programPath.replaceWith(t.program([startCallNode, tryCatchNode]))
|
|
262
|
+
programPath.replaceWith(t.program([startCallNode, tryCatchNode]));
|
|
263
263
|
},
|
|
264
264
|
},
|
|
265
|
-
}
|
|
266
|
-
}
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
267
|
|
|
268
268
|
const createSupervisionCall = ({ t, methodName, urlNode, args = [] }) => {
|
|
269
269
|
return t.expressionStatement(
|
|
@@ -279,5 +279,5 @@ const createSupervisionCall = ({ t, methodName, urlNode, args = [] }) => {
|
|
|
279
279
|
),
|
|
280
280
|
[],
|
|
281
281
|
null,
|
|
282
|
-
)
|
|
283
|
-
}
|
|
282
|
+
);
|
|
283
|
+
};
|