@jsenv/core 33.0.2 → 34.0.1

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.
Files changed (32) hide show
  1. package/dist/js/autoreload.js +1 -4
  2. package/dist/js/supervisor.js +498 -290
  3. package/dist/jsenv.js +938 -370
  4. package/package.json +2 -3
  5. package/src/basic_fetch.js +23 -13
  6. package/src/build/start_build_server.js +3 -2
  7. package/src/dev/file_service.js +1 -1
  8. package/src/dev/start_dev_server.js +9 -6
  9. package/src/execute/execute.js +7 -18
  10. package/src/execute/runtimes/browsers/from_playwright.js +168 -32
  11. package/src/execute/runtimes/browsers/webkit.js +1 -1
  12. package/src/execute/web_server_param.js +68 -0
  13. package/src/kitchen/compat/features_compatibility.js +3 -0
  14. package/src/plugins/autoreload/client/reload.js +1 -4
  15. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +30 -18
  16. package/src/plugins/plugins.js +1 -1
  17. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +3 -2
  18. package/src/plugins/supervisor/client/supervisor.js +467 -287
  19. package/src/plugins/supervisor/html_supervisor_injection.js +281 -0
  20. package/src/plugins/supervisor/js_supervisor_injection.js +283 -0
  21. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +48 -233
  22. package/src/plugins/transpilation/as_js_classic/convert_js_module_to_js_classic.js +67 -30
  23. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +1 -1
  24. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -0
  25. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -1
  26. package/src/test/execute_steps.js +10 -18
  27. package/src/test/execute_test_plan.js +12 -60
  28. package/src/test/logs_file_execution.js +74 -28
  29. package/dist/js/babel_plugin_transform_modules_systemjs.cjs +0 -392
  30. package/dist/js/script_type_module_supervisor.js +0 -109
  31. package/src/plugins/supervisor/client/script_type_module_supervisor.js +0 -98
  32. package/src/plugins/transpilation/as_js_classic/babel_plugin_transform_modules_systemjs.cjs +0 -608
@@ -1,3 +1,4 @@
1
+ import wrapAnsi from "wrap-ansi"
1
2
  import {
2
3
  ANSI,
3
4
  UNICODE,
@@ -41,29 +42,48 @@ export const createExecutionLog = (
41
42
  timeEllapsed,
42
43
  memoryHeap,
43
44
  })
45
+ let log
44
46
  if (completedExecutionLogAbbreviation && status === "completed") {
45
- return `${description}${summary}`
47
+ log = `${description}${summary}`
48
+ } else {
49
+ const { consoleCalls = [], errors = [] } = executionResult
50
+ const consoleOutput = formatConsoleCalls(consoleCalls)
51
+ const errorsOutput = formatErrors(errors)
52
+ log = formatExecution({
53
+ label: `${description}${summary}`,
54
+ details: {
55
+ file: fileRelativeUrl,
56
+ ...(logRuntime ? { runtime: `${runtimeName}/${runtimeVersion}` } : {}),
57
+ ...(logEachDuration
58
+ ? {
59
+ duration:
60
+ status === "executing"
61
+ ? msAsEllapsedTime(Date.now() - startMs)
62
+ : msAsDuration(endMs - startMs),
63
+ }
64
+ : {}),
65
+ },
66
+ consoleOutput,
67
+ errorsOutput,
68
+ })
46
69
  }
47
- const { consoleCalls = [], errors = [] } = executionResult
48
- const consoleOutput = formatConsoleCalls(consoleCalls)
49
- const errorsOutput = formatErrors(errors)
50
- return formatExecution({
51
- label: `${description}${summary}`,
52
- details: {
53
- file: fileRelativeUrl,
54
- ...(logRuntime ? { runtime: `${runtimeName}/${runtimeVersion}` } : {}),
55
- ...(logEachDuration
56
- ? {
57
- duration:
58
- status === "executing"
59
- ? msAsEllapsedTime(Date.now() - startMs)
60
- : msAsDuration(endMs - startMs),
61
- }
62
- : {}),
63
- },
64
- consoleOutput,
65
- errorsOutput,
70
+
71
+ const { columns = 80 } = process.stdout
72
+ log = wrapAnsi(log, columns, {
73
+ trim: false,
74
+ hard: true,
75
+ wordWrap: false,
66
76
  })
77
+ if (endMs) {
78
+ if (completedExecutionLogAbbreviation) {
79
+ return `${log}\n`
80
+ }
81
+ if (executionIndex === counters.total - 1) {
82
+ return `${log}\n`
83
+ }
84
+ return `${log}\n\n`
85
+ }
86
+ return log
67
87
  }
68
88
 
69
89
  const formatErrors = (errors) => {
@@ -203,44 +223,70 @@ const createMixedDetails = ({ counters }) => {
203
223
  const descriptionFormatters = {
204
224
  executing: ({ index, total }) => {
205
225
  return ANSI.color(
206
- `executing ${index + 1} of ${total}`,
226
+ `executing ${padNumber(index, total)} of ${total}`,
207
227
  EXECUTION_COLORS.executing,
208
228
  )
209
229
  },
210
230
  aborted: ({ index, total }) => {
211
231
  return ANSI.color(
212
- `${UNICODE.FAILURE_RAW} execution ${index + 1} of ${total} aborted`,
232
+ `${UNICODE.FAILURE_RAW} execution ${padNumber(
233
+ index,
234
+ total,
235
+ )} of ${total} aborted`,
213
236
  EXECUTION_COLORS.aborted,
214
237
  )
215
238
  },
216
239
  timedout: ({ index, total, executionParams }) => {
217
240
  return ANSI.color(
218
- `${UNICODE.FAILURE_RAW} execution ${
219
- index + 1
220
- } of ${total} timeout after ${executionParams.allocatedMs}ms`,
241
+ `${UNICODE.FAILURE_RAW} execution ${padNumber(
242
+ index,
243
+ total,
244
+ )} of ${total} timeout after ${executionParams.allocatedMs}ms`,
221
245
  EXECUTION_COLORS.timedout,
222
246
  )
223
247
  },
224
248
  failed: ({ index, total }) => {
225
249
  return ANSI.color(
226
- `${UNICODE.FAILURE_RAW} execution ${index + 1} of ${total} failed`,
250
+ `${UNICODE.FAILURE_RAW} execution ${padNumber(
251
+ index,
252
+ total,
253
+ )} of ${total} failed`,
227
254
  EXECUTION_COLORS.failed,
228
255
  )
229
256
  },
230
257
  completed: ({ index, total }) => {
231
258
  return ANSI.color(
232
- `${UNICODE.OK_RAW} execution ${index + 1} of ${total} completed`,
259
+ `${UNICODE.OK_RAW} execution ${padNumber(
260
+ index,
261
+ total,
262
+ )} of ${total} completed`,
233
263
  EXECUTION_COLORS.completed,
234
264
  )
235
265
  },
236
266
  cancelled: ({ index, total }) => {
237
267
  return ANSI.color(
238
- `${UNICODE.FAILURE_RAW} execution ${index + 1} of ${total} cancelled`,
268
+ `${UNICODE.FAILURE_RAW} execution ${padNumber(
269
+ index,
270
+ total,
271
+ )} of ${total} cancelled`,
239
272
  EXECUTION_COLORS.cancelled,
240
273
  )
241
274
  },
242
275
  }
243
276
 
277
+ const padNumber = (index, total) => {
278
+ const number = index + 1
279
+ const numberWidth = String(number).length
280
+ const totalWith = String(total).length
281
+ let missingWidth = totalWith - numberWidth
282
+ let padded = ""
283
+ while (missingWidth--) {
284
+ padded += "0"
285
+ }
286
+ padded += number
287
+ return padded
288
+ }
289
+
244
290
  const formatConsoleCalls = (consoleCalls) => {
245
291
  if (consoleCalls.length === 0) {
246
292
  return ""
@@ -1,392 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", {
2
- value: true
3
- });
4
- exports.default = void 0;
5
- exports.getExportSpecifierName = getExportSpecifierName;
6
- var _helperPluginUtils = require("@babel/helper-plugin-utils");
7
- var _helperHoistVariables = require("@babel/helper-hoist-variables");
8
- var _core = require("@babel/core");
9
- var _helperModuleTransforms = require("@babel/helper-module-transforms");
10
- var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
11
- const buildTemplate = _core.template.statement(`
12
- SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
13
- "use strict";
14
- BEFORE_BODY;
15
- return {
16
- setters: SETTERS,
17
- execute: EXECUTE,
18
- };
19
- });
20
- `);
21
- const buildExportAll = _core.template.statement(`
22
- for (var KEY in TARGET) {
23
- if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY];
24
- }
25
- `);
26
- const MISSING_PLUGIN_WARNING = `\
27
- WARNING: Dynamic import() transformation must be enabled using the
28
- @babel/plugin-proposal-dynamic-import plugin. Babel 8 will
29
- no longer transform import() without using that plugin.
30
- `;
31
- function getExportSpecifierName(node, stringSpecifiers) {
32
- if (node.type === "Identifier") {
33
- return node.name;
34
- } else if (node.type === "StringLiteral") {
35
- const stringValue = node.value;
36
- if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) {
37
- stringSpecifiers.add(stringValue);
38
- }
39
- return stringValue;
40
- } else {
41
- throw new Error(`Expected export specifier to be either Identifier or StringLiteral, got ${node.type}`);
42
- }
43
- }
44
- function constructExportCall(path, exportIdent, exportNames, exportValues, exportStarTarget, stringSpecifiers) {
45
- const statements = [];
46
- if (!exportStarTarget) {
47
- if (exportNames.length === 1) {
48
- statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.stringLiteral(exportNames[0]), exportValues[0]])));
49
- } else {
50
- const objectProperties = [];
51
- for (let i = 0; i < exportNames.length; i++) {
52
- const exportName = exportNames[i];
53
- const exportValue = exportValues[i];
54
- objectProperties.push(_core.types.objectProperty(stringSpecifiers.has(exportName) ? _core.types.stringLiteral(exportName) : _core.types.identifier(exportName), exportValue));
55
- }
56
- statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.objectExpression(objectProperties)])));
57
- }
58
- } else {
59
- const exportObj = path.scope.generateUid("exportObj");
60
- statements.push(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(exportObj), _core.types.objectExpression([]))]));
61
- statements.push(buildExportAll({
62
- KEY: path.scope.generateUidIdentifier("key"),
63
- EXPORT_OBJ: _core.types.identifier(exportObj),
64
- TARGET: exportStarTarget
65
- }));
66
- for (let i = 0; i < exportNames.length; i++) {
67
- const exportName = exportNames[i];
68
- const exportValue = exportValues[i];
69
- statements.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(_core.types.identifier(exportObj), _core.types.identifier(exportName)), exportValue)));
70
- }
71
- statements.push(_core.types.expressionStatement(_core.types.callExpression(exportIdent, [_core.types.identifier(exportObj)])));
72
- }
73
- return statements;
74
- }
75
- var _default = (0, _helperPluginUtils.declare)((api, options) => {
76
- api.assertVersion(7);
77
- const {
78
- systemGlobal = "System",
79
- allowTopLevelThis = false
80
- } = options;
81
- const reassignmentVisited = new WeakSet();
82
- const reassignmentVisitor = {
83
- "AssignmentExpression|UpdateExpression"(path) {
84
- if (reassignmentVisited.has(path.node)) return;
85
- reassignmentVisited.add(path.node);
86
- const arg = path.isAssignmentExpression() ? path.get("left") : path.get("argument");
87
- if (arg.isObjectPattern() || arg.isArrayPattern()) {
88
- const exprs = [path.node];
89
- for (const name of Object.keys(arg.getBindingIdentifiers())) {
90
- if (this.scope.getBinding(name) !== path.scope.getBinding(name)) {
91
- return;
92
- }
93
- const exportedNames = this.exports[name];
94
- if (!exportedNames) continue;
95
- for (const exportedName of exportedNames) {
96
- exprs.push(this.buildCall(exportedName, _core.types.identifier(name)).expression);
97
- }
98
- }
99
- path.replaceWith(_core.types.sequenceExpression(exprs));
100
- return;
101
- }
102
- if (!arg.isIdentifier()) return;
103
- const name = arg.node.name;
104
- if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;
105
- const exportedNames = this.exports[name];
106
- if (!exportedNames) return;
107
- let node = path.node;
108
- const isPostUpdateExpression = _core.types.isUpdateExpression(node, {
109
- prefix: false
110
- });
111
- if (isPostUpdateExpression) {
112
- node = _core.types.binaryExpression(node.operator[0], _core.types.unaryExpression("+", _core.types.cloneNode(node.argument)), _core.types.numericLiteral(1));
113
- }
114
- for (const exportedName of exportedNames) {
115
- node = this.buildCall(exportedName, node).expression;
116
- }
117
- if (isPostUpdateExpression) {
118
- node = _core.types.sequenceExpression([node, path.node]);
119
- }
120
- path.replaceWith(node);
121
- }
122
- };
123
- return {
124
- name: "transform-modules-systemjs",
125
- pre() {
126
- this.file.set("@babel/plugin-transform-modules-*", "systemjs");
127
- },
128
- visitor: {
129
- CallExpression(path, state) {
130
- if (_core.types.isImport(path.node.callee)) {
131
- if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
132
- {
133
- console.warn(MISSING_PLUGIN_WARNING);
134
- }
135
- }
136
- path.replaceWith((0, _helperModuleTransforms.buildDynamicImport)(path.node, false, true, specifier => _core.types.callExpression(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("import")), [specifier])));
137
- }
138
- },
139
- MetaProperty(path, state) {
140
- if (path.node.meta.name === "import" && path.node.property.name === "meta") {
141
- path.replaceWith(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("meta")));
142
- }
143
- },
144
- ReferencedIdentifier(path, state) {
145
- if (path.node.name === "__moduleName" && !path.scope.hasBinding("__moduleName")) {
146
- path.replaceWith(_core.types.memberExpression(_core.types.identifier(state.contextIdent), _core.types.identifier("id")));
147
- }
148
- },
149
- Program: {
150
- enter(path, state) {
151
- state.contextIdent = path.scope.generateUid("context");
152
- state.stringSpecifiers = new Set();
153
- if (!allowTopLevelThis) {
154
- (0, _helperModuleTransforms.rewriteThis)(path);
155
- }
156
- },
157
- exit(path, state) {
158
- const scope = path.scope;
159
- const exportIdent = scope.generateUid("export");
160
- const {
161
- contextIdent,
162
- stringSpecifiers
163
- } = state;
164
- const exportMap = Object.create(null);
165
- const modules = [];
166
- const beforeBody = [];
167
- const setters = [];
168
- const sources = [];
169
- const variableIds = [];
170
- const removedPaths = [];
171
- function addExportName(key, val) {
172
- exportMap[key] = exportMap[key] || [];
173
- exportMap[key].push(val);
174
- }
175
- function pushModule(source, key, specifiers) {
176
- let module;
177
- modules.forEach(function (m) {
178
- if (m.key === source) {
179
- module = m;
180
- }
181
- });
182
- if (!module) {
183
- modules.push(module = {
184
- key: source,
185
- imports: [],
186
- exports: []
187
- });
188
- }
189
- module[key] = module[key].concat(specifiers);
190
- }
191
- function buildExportCall(name, val) {
192
- return _core.types.expressionStatement(_core.types.callExpression(_core.types.identifier(exportIdent), [_core.types.stringLiteral(name), val]));
193
- }
194
- const exportNames = [];
195
- const exportValues = [];
196
- const body = path.get("body");
197
- for (const path of body) {
198
- if (path.isFunctionDeclaration()) {
199
- beforeBody.push(path.node);
200
- removedPaths.push(path);
201
- } else if (path.isClassDeclaration()) {
202
- variableIds.push(_core.types.cloneNode(path.node.id));
203
- path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(path.node.id), _core.types.toExpression(path.node))));
204
- } else if (path.isVariableDeclaration()) {
205
- path.node.kind = "var";
206
- } else if (path.isImportDeclaration()) {
207
- const source = path.node.source.value;
208
- pushModule(source, "imports", path.node.specifiers);
209
- for (const name of Object.keys(path.getBindingIdentifiers())) {
210
- scope.removeBinding(name);
211
- variableIds.push(_core.types.identifier(name));
212
- }
213
- path.remove();
214
- } else if (path.isExportAllDeclaration()) {
215
- pushModule(path.node.source.value, "exports", path.node);
216
- path.remove();
217
- } else if (path.isExportDefaultDeclaration()) {
218
- const declar = path.node.declaration;
219
- if (_core.types.isClassDeclaration(declar)) {
220
- const id = declar.id;
221
- if (id) {
222
- exportNames.push("default");
223
- exportValues.push(scope.buildUndefinedNode());
224
- variableIds.push(_core.types.cloneNode(id));
225
- addExportName(id.name, "default");
226
- path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(id), _core.types.toExpression(declar))));
227
- } else {
228
- exportNames.push("default");
229
- exportValues.push(_core.types.toExpression(declar));
230
- removedPaths.push(path);
231
- }
232
- } else if (_core.types.isFunctionDeclaration(declar)) {
233
- const id = declar.id;
234
- if (id) {
235
- beforeBody.push(declar);
236
- exportNames.push("default");
237
- exportValues.push(_core.types.cloneNode(id));
238
- addExportName(id.name, "default");
239
- } else {
240
- exportNames.push("default");
241
- exportValues.push(_core.types.toExpression(declar));
242
- }
243
- removedPaths.push(path);
244
- } else {
245
- path.replaceWith(buildExportCall("default", declar));
246
- }
247
- } else if (path.isExportNamedDeclaration()) {
248
- const declar = path.node.declaration;
249
- if (declar) {
250
- path.replaceWith(declar);
251
- if (_core.types.isFunction(declar)) {
252
- const name = declar.id.name;
253
- addExportName(name, name);
254
- beforeBody.push(declar);
255
- exportNames.push(name);
256
- exportValues.push(_core.types.cloneNode(declar.id));
257
- removedPaths.push(path);
258
- } else if (_core.types.isClass(declar)) {
259
- const name = declar.id.name;
260
- exportNames.push(name);
261
- exportValues.push(scope.buildUndefinedNode());
262
- variableIds.push(_core.types.cloneNode(declar.id));
263
- path.replaceWith(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(declar.id), _core.types.toExpression(declar))));
264
- addExportName(name, name);
265
- } else {
266
- if (_core.types.isVariableDeclaration(declar)) {
267
- declar.kind = "var";
268
- }
269
- for (const name of Object.keys(_core.types.getBindingIdentifiers(declar))) {
270
- addExportName(name, name);
271
- }
272
- }
273
- } else {
274
- const specifiers = path.node.specifiers;
275
- if (specifiers != null && specifiers.length) {
276
- if (path.node.source) {
277
- pushModule(path.node.source.value, "exports", specifiers);
278
- path.remove();
279
- } else {
280
- const nodes = [];
281
- for (const specifier of specifiers) {
282
- const {
283
- local,
284
- exported
285
- } = specifier;
286
- const binding = scope.getBinding(local.name);
287
- const exportedName = getExportSpecifierName(exported, stringSpecifiers);
288
- if (binding && _core.types.isFunctionDeclaration(binding.path.node)) {
289
- exportNames.push(exportedName);
290
- exportValues.push(_core.types.cloneNode(local));
291
- } else if (!binding) {
292
- nodes.push(buildExportCall(exportedName, local));
293
- }
294
- addExportName(local.name, exportedName);
295
- }
296
- path.replaceWithMultiple(nodes);
297
- }
298
- } else {
299
- path.remove();
300
- }
301
- }
302
- }
303
- }
304
- modules.forEach(function (specifiers) {
305
- const setterBody = [];
306
- // --- START FORK CHANGES ---
307
- const targetHint = state.opts.generateIdentifierHint ? state.opts.generateIdentifierHint(specifiers.key) : specifiers.key;
308
- const target = scope.generateUid(targetHint);
309
- // --- END FORK CHANGES ---
310
- for (let specifier of specifiers.imports) {
311
- if (_core.types.isImportNamespaceSpecifier(specifier)) {
312
- setterBody.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", specifier.local, _core.types.identifier(target))));
313
- } else if (_core.types.isImportDefaultSpecifier(specifier)) {
314
- specifier = _core.types.importSpecifier(specifier.local, _core.types.identifier("default"));
315
- }
316
- if (_core.types.isImportSpecifier(specifier)) {
317
- const {
318
- imported
319
- } = specifier;
320
- setterBody.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", specifier.local, _core.types.memberExpression(_core.types.identifier(target), specifier.imported, imported.type === "StringLiteral"))));
321
- }
322
- }
323
- if (specifiers.exports.length) {
324
- const exportNames = [];
325
- const exportValues = [];
326
- let hasExportStar = false;
327
- for (const node of specifiers.exports) {
328
- if (_core.types.isExportAllDeclaration(node)) {
329
- hasExportStar = true;
330
- } else if (_core.types.isExportSpecifier(node)) {
331
- const exportedName = getExportSpecifierName(node.exported, stringSpecifiers);
332
- exportNames.push(exportedName);
333
- exportValues.push(_core.types.memberExpression(_core.types.identifier(target), node.local, _core.types.isStringLiteral(node.local)));
334
- } else ;
335
- }
336
- setterBody.push(...constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, hasExportStar ? _core.types.identifier(target) : null, stringSpecifiers));
337
- }
338
- sources.push(_core.types.stringLiteral(specifiers.key));
339
- setters.push(_core.types.functionExpression(null, [_core.types.identifier(target)], _core.types.blockStatement(setterBody)));
340
- });
341
- let moduleName = (0, _helperModuleTransforms.getModuleName)(this.file.opts, options);
342
- if (moduleName) moduleName = _core.types.stringLiteral(moduleName);
343
- (0, _helperHoistVariables.default)(path, (id, name, hasInit) => {
344
- variableIds.push(id);
345
- if (!hasInit && name in exportMap) {
346
- for (const exported of exportMap[name]) {
347
- exportNames.push(exported);
348
- exportValues.push(scope.buildUndefinedNode());
349
- }
350
- }
351
- });
352
- if (variableIds.length) {
353
- beforeBody.unshift(_core.types.variableDeclaration("var", variableIds.map(id => _core.types.variableDeclarator(id))));
354
- }
355
- if (exportNames.length) {
356
- beforeBody.push(...constructExportCall(path, _core.types.identifier(exportIdent), exportNames, exportValues, null, stringSpecifiers));
357
- }
358
- path.traverse(reassignmentVisitor, {
359
- exports: exportMap,
360
- buildCall: buildExportCall,
361
- scope
362
- });
363
- for (const path of removedPaths) {
364
- path.remove();
365
- }
366
- let hasTLA = false;
367
- path.traverse({
368
- AwaitExpression(path) {
369
- hasTLA = true;
370
- path.stop();
371
- },
372
- Function(path) {
373
- path.skip();
374
- },
375
- noScope: true
376
- });
377
- path.node.body = [buildTemplate({
378
- SYSTEM_REGISTER: _core.types.memberExpression(_core.types.identifier(systemGlobal), _core.types.identifier("register")),
379
- BEFORE_BODY: beforeBody,
380
- MODULE_NAME: moduleName,
381
- SETTERS: _core.types.arrayExpression(setters),
382
- EXECUTE: _core.types.functionExpression(null, [], _core.types.blockStatement(path.node.body), false, hasTLA),
383
- SOURCES: _core.types.arrayExpression(sources),
384
- EXPORT_IDENTIFIER: _core.types.identifier(exportIdent),
385
- CONTEXT_IDENTIFIER: _core.types.identifier(contextIdent)
386
- })];
387
- }
388
- }
389
- }
390
- };
391
- });
392
- exports.default = _default;
@@ -1,109 +0,0 @@
1
- // https://twitter.com/damienmaillard/status/1554752482273787906
2
- const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
3
- const superviseScriptTypeModule = async ({
4
- src,
5
- async
6
- }) => {
7
- const currentScript = document.querySelector(`script[type="module"][inlined-from-src="${src}"]`);
8
- const execute = isWebkitOrSafari ? createExecuteWithDynamicImport({
9
- src
10
- }) : createExecuteWithScript({
11
- currentScript,
12
- src
13
- });
14
- return window.__supervisor__.addExecution({
15
- src,
16
- async,
17
- type: "js_module",
18
- execute
19
- });
20
- };
21
- const createExecuteWithScript = ({
22
- currentScript,
23
- src
24
- }) => {
25
- const parentNode = currentScript.parentNode;
26
- let nodeToReplace;
27
- let currentScriptClone;
28
- return async ({
29
- isReload
30
- }) => {
31
- const urlObject = new URL(src, window.location);
32
- const loadPromise = new Promise((resolve, reject) => {
33
- currentScriptClone = document.createElement("script");
34
- // browsers set async by default when creating script(s)
35
- // we want an exact copy to preserves how code is executed
36
- currentScriptClone.async = false;
37
- Array.from(currentScript.attributes).forEach(attribute => {
38
- currentScriptClone.setAttribute(attribute.nodeName, attribute.nodeValue);
39
- });
40
- if (isReload) {
41
- urlObject.searchParams.set("hmr", Date.now());
42
- nodeToReplace = currentScriptClone;
43
- currentScriptClone.src = urlObject.href;
44
- } else {
45
- currentScriptClone.removeAttribute("jsenv-cooked-by");
46
- currentScriptClone.removeAttribute("jsenv-inlined-by");
47
- currentScriptClone.removeAttribute("jsenv-injected-by");
48
- currentScriptClone.removeAttribute("inlined-from-src");
49
- currentScriptClone.removeAttribute("original-position");
50
- currentScriptClone.removeAttribute("original-src-position");
51
- nodeToReplace = currentScript;
52
- currentScriptClone.src = src;
53
- }
54
- currentScriptClone.addEventListener("error", reject);
55
- currentScriptClone.addEventListener("load", resolve);
56
- parentNode.replaceChild(currentScriptClone, nodeToReplace);
57
- });
58
- try {
59
- await loadPromise;
60
- } catch (e) {
61
- // eslint-disable-next-line no-throw-literal
62
- throw {
63
- message: `Failed to fetch module: ${urlObject.href}`,
64
- reportedBy: "script_error_event",
65
- url: urlObject.href,
66
- // window.error won't be dispatched for this error
67
- needsReport: true
68
- };
69
- }
70
- try {
71
- return {
72
- executionPromise: import(urlObject.href)
73
- };
74
- } catch (e) {
75
- e.reportedBy = "dynamic_import";
76
- throw e;
77
- }
78
- };
79
- };
80
- const createExecuteWithDynamicImport = ({
81
- src
82
- }) => {
83
- return async ({
84
- isReload
85
- }) => {
86
- const urlObject = new URL(src, window.location);
87
- if (isReload) {
88
- urlObject.searchParams.set("hmr", Date.now());
89
- }
90
- try {
91
- const namespace = await import(urlObject.href);
92
- return {
93
- executionPromise: Promise.resolve(namespace)
94
- };
95
- } catch (e) {
96
- e.reportedBy = "dynamic_import";
97
- // dynamic import would hide the error to the browser
98
- // so it must be re-reported using window.reportError
99
- if (typeof window.reportError === "function") {
100
- window.reportError(e);
101
- } else {
102
- console.error(e);
103
- }
104
- throw e;
105
- }
106
- };
107
- };
108
-
109
- export { superviseScriptTypeModule };