@jsenv/core 27.0.0-alpha.63 → 27.0.0-alpha.64

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 (39) hide show
  1. package/dist/html_supervisor_installer.js +1 -1
  2. package/dist/html_supervisor_installer.js.map +2 -2
  3. package/dist/s.js +626 -0
  4. package/dist/s.js.map +207 -0
  5. package/main.js +1 -0
  6. package/package.json +6 -6
  7. package/src/build/build.js +23 -8
  8. package/src/build/inject_global_version_mappings.js +18 -5
  9. package/src/build/start_build_server.js +38 -29
  10. package/src/dev/start_dev_server.js +1 -1
  11. package/src/execute/runtimes/browsers/from_playwright.js +10 -0
  12. package/src/execute/runtimes/node/node_process.js +8 -0
  13. package/src/omega/kitchen.js +52 -134
  14. package/src/omega/server/file_service.js +34 -17
  15. package/src/omega/url_graph/url_graph_load.js +10 -17
  16. package/src/omega/url_graph/url_info_transformations.js +1 -4
  17. package/src/omega/url_graph.js +6 -2
  18. package/src/omega/url_specifier_encoding.js +59 -0
  19. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
  20. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
  21. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
  22. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
  23. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
  24. package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
  25. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
  26. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +4 -0
  27. package/src/plugins/plugins.js +4 -1
  28. package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
  29. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +28 -12
  30. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
  31. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +165 -133
  32. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
  33. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
  34. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -1
  35. package/src/test/execute_plan.js +32 -13
  36. package/src/test/execute_test_plan.js +2 -0
  37. package/src/test/logs_file_execution.js +47 -38
  38. package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
  39. package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
@@ -1,790 +1,103 @@
1
1
  /*
2
- * SJS 6.12.1
3
- * Minimal SystemJS Build
4
- */
5
- (function () {
6
-
7
- function errMsg(errCode, msg) {
8
- return (msg || "") + " (SystemJS https://git.io/JvFET#" + errCode + ")";
9
- }
10
-
11
- var hasSymbol = typeof Symbol !== 'undefined';
12
- var hasSelf = typeof self !== 'undefined';
13
- var hasDocument = typeof document !== 'undefined';
14
-
15
- var envGlobal = hasSelf ? self : global;
16
-
17
- var baseUrl;
18
-
19
- if (hasDocument) {
20
- var baseEl = document.querySelector('base[href]');
21
- if (baseEl)
22
- baseUrl = baseEl.href;
23
- }
24
-
25
- if (!baseUrl && typeof location !== 'undefined') {
26
- baseUrl = location.href.split('#')[0].split('?')[0];
27
- var lastSepIndex = baseUrl.lastIndexOf('/');
28
- if (lastSepIndex !== -1)
29
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
30
- }
31
-
32
- var backslashRegEx = /\\/g;
33
- function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
34
- if (relUrl.indexOf('\\') !== -1)
35
- relUrl = relUrl.replace(backslashRegEx, '/');
36
- // protocol-relative
37
- if (relUrl[0] === '/' && relUrl[1] === '/') {
38
- return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
39
- }
40
- // relative-url
41
- else if (relUrl[0] === '.' && (relUrl[1] === '/' || relUrl[1] === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) ||
42
- relUrl.length === 1 && (relUrl += '/')) ||
43
- relUrl[0] === '/') {
44
- var parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
45
- // Disabled, but these cases will give inconsistent results for deep backtracking
46
- //if (parentUrl[parentProtocol.length] !== '/')
47
- // throw Error('Cannot resolve');
48
- // read pathname from parent URL
49
- // pathname taken to be part after leading "/"
50
- var pathname;
51
- if (parentUrl[parentProtocol.length + 1] === '/') {
52
- // resolving to a :// so we need to read out the auth and host
53
- if (parentProtocol !== 'file:') {
54
- pathname = parentUrl.slice(parentProtocol.length + 2);
55
- pathname = pathname.slice(pathname.indexOf('/') + 1);
56
- }
57
- else {
58
- pathname = parentUrl.slice(8);
59
- }
60
- }
61
- else {
62
- // resolving to :/ so pathname is the /... part
63
- pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
64
- }
65
-
66
- if (relUrl[0] === '/')
67
- return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
68
-
69
- // join together and split for removal of .. and . segments
70
- // looping the string instead of anything fancy for perf reasons
71
- // '../../../../../z' resolved to 'x/y' is just 'z'
72
- var segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
73
-
74
- var output = [];
75
- var segmentIndex = -1;
76
- for (var i = 0; i < segmented.length; i++) {
77
- // busy reading a segment - only terminate on '/'
78
- if (segmentIndex !== -1) {
79
- if (segmented[i] === '/') {
80
- output.push(segmented.slice(segmentIndex, i + 1));
81
- segmentIndex = -1;
82
- }
83
- }
84
-
85
- // new segment - check if it is relative
86
- else if (segmented[i] === '.') {
87
- // ../ segment
88
- if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
89
- output.pop();
90
- i += 2;
91
- }
92
- // ./ segment
93
- else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
94
- i += 1;
95
- }
96
- else {
97
- // the start of a new segment as below
98
- segmentIndex = i;
99
- }
100
- }
101
- // it is the start of a new segment
102
- else {
103
- segmentIndex = i;
104
- }
105
- }
106
- // finish reading out the last segment
107
- if (segmentIndex !== -1)
108
- output.push(segmented.slice(segmentIndex));
109
- return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
110
- }
111
- }
112
-
113
- /*
114
- * Import maps implementation
115
- *
116
- * To make lookups fast we pre-resolve the entire import map
117
- * and then match based on backtracked hash lookups
118
- *
119
- */
120
-
121
- function resolveUrl (relUrl, parentUrl) {
122
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
123
- }
124
-
125
- function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap, parentUrl) {
126
- for (var p in packages) {
127
- var resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
128
- var rhs = packages[p];
129
- // package fallbacks not currently supported
130
- if (typeof rhs !== 'string')
131
- continue;
132
- var mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(rhs, baseUrl) || rhs, parentUrl);
133
- if (!mapped) {
134
- targetWarning('W1', p, rhs);
135
- }
136
- else
137
- outPackages[resolvedLhs] = mapped;
138
- }
139
- }
140
-
141
- function resolveAndComposeImportMap (json, baseUrl, outMap) {
142
- if (json.imports)
143
- resolveAndComposePackages(json.imports, outMap.imports, baseUrl, outMap, null);
144
-
145
- var u;
146
- for (u in json.scopes || {}) {
147
- var resolvedScope = resolveUrl(u, baseUrl);
148
- resolveAndComposePackages(json.scopes[u], outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}), baseUrl, outMap, resolvedScope);
149
- }
150
-
151
- for (u in json.depcache || {})
152
- outMap.depcache[resolveUrl(u, baseUrl)] = json.depcache[u];
153
-
154
- for (u in json.integrity || {})
155
- outMap.integrity[resolveUrl(u, baseUrl)] = json.integrity[u];
156
- }
157
-
158
- function getMatch (path, matchObj) {
159
- if (matchObj[path])
160
- return path;
161
- var sepIndex = path.length;
162
- do {
163
- var segment = path.slice(0, sepIndex + 1);
164
- if (segment in matchObj)
165
- return segment;
166
- } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1)
167
- }
168
-
169
- function applyPackages (id, packages) {
170
- var pkgName = getMatch(id, packages);
171
- if (pkgName) {
172
- var pkg = packages[pkgName];
173
- if (pkg === null) return;
174
- if (id.length > pkgName.length && pkg[pkg.length - 1] !== '/') {
175
- targetWarning('W2', pkgName, pkg);
176
- }
177
- else
178
- return pkg + id.slice(pkgName.length);
179
- }
180
- }
181
-
182
- function targetWarning (code, match, target, msg) {
183
- console.warn(errMsg(code, [target, match].join(', ') ));
184
- }
185
-
186
- function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
187
- var scopes = importMap.scopes;
188
- var scopeUrl = parentUrl && getMatch(parentUrl, scopes);
189
- while (scopeUrl) {
190
- var packageResolution = applyPackages(resolvedOrPlain, scopes[scopeUrl]);
191
- if (packageResolution)
192
- return packageResolution;
193
- scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), scopes);
194
- }
195
- return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
196
- }
197
-
198
- /*
199
- * SystemJS Core
200
- *
201
- * Provides
202
- * - System.import
203
- * - System.register support for
204
- * live bindings, function hoisting through circular references,
205
- * reexports, dynamic import, import.meta.url, top-level await
206
- * - System.getRegister to get the registration
207
- * - Symbol.toStringTag support in Module objects
208
- * - Hookable System.createContext to customize import.meta
209
- * - System.onload(err, id, deps) handler for tracing / hot-reloading
210
- *
211
- * Core comes with no System.prototype.resolve or
212
- * System.prototype.instantiate implementations
213
- */
214
-
215
- var toStringTag = hasSymbol && Symbol.toStringTag;
216
- var REGISTRY = hasSymbol ? Symbol() : '@';
217
-
218
- function SystemJS () {
219
- this[REGISTRY] = {};
220
- }
221
-
222
- var systemJSPrototype = SystemJS.prototype;
223
-
224
- systemJSPrototype.import = function (id, parentUrl) {
225
- var loader = this;
226
- return Promise.resolve(loader.prepareImport())
227
- .then(function() {
228
- return loader.resolve(String(id), parentUrl);
229
- })
230
- .then(function (id) {
231
- var load = getOrCreateLoad(loader, id);
232
- return load.C || topLevelLoad(loader, load);
233
- });
234
- };
235
-
236
- // Hookable createContext function -> allowing eg custom import meta
237
- systemJSPrototype.createContext = function (parentId) {
238
- var loader = this;
239
- return {
240
- url: parentId,
241
- resolve: function (id, parentUrl) {
242
- return Promise.resolve(loader.resolve(id, parentUrl || parentId));
243
- }
244
- };
245
- };
246
- function loadToId (load) {
247
- return load.id;
2
+ * This file is a modified version of https://github.com/systemjs/systemjs/blob/main/dist/s.js
3
+ * with the following changes:
4
+ *
5
+ * - Code can use aync/await, const, ... because an es5 version of this file is generated
6
+ * - Can use document.currentScript because we don't support IE
7
+ * - auto import inline System.register
8
+ * - auto import first System.register in web workers
9
+ * - queing events in web workers
10
+ * - no support for importmap because jsenv don't need it
11
+ */
12
+
13
+ ;(function () {
14
+ /* eslint-env browser */
15
+ /* globals self */
16
+
17
+ const loadRegistry = Object.create(null)
18
+ const registerRegistry = Object.create(null)
19
+ let inlineScriptCount = 0
20
+ const System = {}
21
+
22
+ const hasDocument = typeof document === "object"
23
+ const envGlobal = self
24
+ const isWorker =
25
+ !hasDocument &&
26
+ typeof envGlobal.WorkerGlobalScope === "function" &&
27
+ envGlobal instanceof envGlobal.WorkerGlobalScope
28
+ const isServiceWorker = isWorker && typeof self.skipWaiting === "function"
29
+ envGlobal.System = System
30
+
31
+ let baseUrl = envGlobal.location.href.split("#")[0].split("?")[0]
32
+ const lastSlashIndex = baseUrl.lastIndexOf("/")
33
+ if (lastSlashIndex !== -1) {
34
+ baseUrl = baseUrl.slice(0, lastSlashIndex + 1)
248
35
  }
249
- function triggerOnload (loader, load, err, isErrSource) {
250
- loader.onload(err, load.id, load.d && load.d.map(loadToId), !!isErrSource);
251
- if (err)
252
- throw err;
253
- }
254
-
255
- var lastRegister;
256
- systemJSPrototype.register = function (deps, declare) {
257
- lastRegister = [deps, declare];
258
- };
259
-
260
- /*
261
- * getRegister provides the last anonymous System.register call
262
- */
263
- systemJSPrototype.getRegister = function () {
264
- var _lastRegister = lastRegister;
265
- lastRegister = undefined;
266
- return _lastRegister;
267
- };
268
-
269
- function getOrCreateLoad (loader, id, firstParentUrl) {
270
- var load = loader[REGISTRY][id];
271
- if (load)
272
- return load;
273
-
274
- var importerSetters = [];
275
- var ns = Object.create(null);
276
- if (toStringTag)
277
- Object.defineProperty(ns, toStringTag, { value: 'Module' });
278
-
279
- var instantiatePromise = Promise.resolve()
280
- .then(function () {
281
- return loader.instantiate(id, firstParentUrl);
282
- })
283
- .then(function (registration) {
284
- if (!registration)
285
- throw Error(errMsg(2, id ));
286
- function _export (name, value) {
287
- // note if we have hoisted exports (including reexports)
288
- load.h = true;
289
- var changed = false;
290
- if (typeof name === 'string') {
291
- if (!(name in ns) || ns[name] !== value) {
292
- ns[name] = value;
293
- changed = true;
294
- }
295
- }
296
- else {
297
- for (var p in name) {
298
- var value = name[p];
299
- if (!(p in ns) || ns[p] !== value) {
300
- ns[p] = value;
301
- changed = true;
302
- }
303
- }
304
-
305
- if (name && name.__esModule) {
306
- ns.__esModule = name.__esModule;
307
- }
308
- }
309
- if (changed)
310
- for (var i = 0; i < importerSetters.length; i++) {
311
- var setter = importerSetters[i];
312
- if (setter) setter(ns);
313
- }
314
- return value;
315
- }
316
- var declared = registration[1](_export, registration[1].length === 2 ? {
317
- import: function (importId) {
318
- return loader.import(importId, id);
319
- },
320
- meta: loader.createContext(id)
321
- } : undefined);
322
- load.e = declared.execute || function () {};
323
- return [registration[0], declared.setters || []];
324
- }, function (err) {
325
- load.e = null;
326
- load.er = err;
327
- throw err;
328
- });
329
-
330
- var linkPromise = instantiatePromise
331
- .then(function (instantiation) {
332
- return Promise.all(instantiation[0].map(function (dep, i) {
333
- var setter = instantiation[1][i];
334
- return Promise.resolve(loader.resolve(dep, id))
335
- .then(function (depId) {
336
- var depLoad = getOrCreateLoad(loader, depId, id);
337
- // depLoad.I may be undefined for already-evaluated
338
- return Promise.resolve(depLoad.I)
339
- .then(function () {
340
- if (setter) {
341
- depLoad.i.push(setter);
342
- // only run early setters when there are hoisted exports of that module
343
- // the timing works here as pending hoisted export calls will trigger through importerSetters
344
- if (depLoad.h || !depLoad.I)
345
- setter(depLoad.n);
346
- }
347
- return depLoad;
348
- });
349
- });
350
- }))
351
- .then(function (depLoads) {
352
- load.d = depLoads;
353
- });
354
- });
355
-
356
- // Capital letter = a promise function
357
- return load = loader[REGISTRY][id] = {
358
- id: id,
359
- // importerSetters, the setters functions registered to this dependency
360
- // we retain this to add more later
361
- i: importerSetters,
362
- // module namespace object
363
- n: ns,
364
-
365
- // instantiate
366
- I: instantiatePromise,
367
- // link
368
- L: linkPromise,
369
- // whether it has hoisted exports
370
- h: false,
371
36
 
372
- // On instantiate completion we have populated:
373
- // dependency load records
374
- d: undefined,
375
- // execution function
376
- e: undefined,
37
+ const resolveUrl = (specifier, baseUrl) => new URL(specifier, baseUrl).href
377
38
 
378
- // On execution we have populated:
379
- // the execution error if any
380
- er: undefined,
381
- // in the case of TLA, the execution promise
382
- E: undefined,
383
-
384
- // On execution, L, I, E cleared
385
-
386
- // Promise for top-level completion
387
- C: undefined,
388
-
389
- // parent instantiator / executor
390
- p: undefined
391
- };
392
- }
393
-
394
- function instantiateAll (loader, load, parent, loaded) {
395
- if (!loaded[load.id]) {
396
- loaded[load.id] = true;
397
- // load.L may be undefined for already-instantiated
398
- return Promise.resolve(load.L)
399
- .then(function () {
400
- if (!load.p || load.p.e === null)
401
- load.p = parent;
402
- return Promise.all(load.d.map(function (dep) {
403
- return instantiateAll(loader, dep, parent, loaded);
404
- }));
405
- })
406
- .catch(function (err) {
407
- if (load.er)
408
- throw err;
409
- load.e = null;
410
- throw err;
411
- });
412
- }
413
- }
414
-
415
- function topLevelLoad (loader, load) {
416
- return load.C = instantiateAll(loader, load, load, {})
417
- .then(function () {
418
- return postOrderExec(loader, load, {});
419
- })
420
- .then(function () {
421
- return load.n;
422
- });
423
- }
424
-
425
- // the closest we can get to call(undefined)
426
- var nullContext = Object.freeze(Object.create(null));
427
-
428
- // returns a promise if and only if a top-level await subgraph
429
- // throws on sync errors
430
- function postOrderExec (loader, load, seen) {
431
- if (seen[load.id])
432
- return;
433
- seen[load.id] = true;
434
-
435
- if (!load.e) {
436
- if (load.er)
437
- throw load.er;
438
- if (load.E)
439
- return load.E;
440
- return;
441
- }
442
-
443
- // deps execute first, unless circular
444
- var depLoadPromises;
445
- load.d.forEach(function (depLoad) {
446
- try {
447
- var depLoadPromise = postOrderExec(loader, depLoad, seen);
448
- if (depLoadPromise)
449
- (depLoadPromises = depLoadPromises || []).push(depLoadPromise);
450
- }
451
- catch (err) {
452
- load.e = null;
453
- load.er = err;
454
- throw err;
455
- }
456
- });
457
- if (depLoadPromises)
458
- return Promise.all(depLoadPromises).then(doExec);
459
-
460
- return doExec();
461
-
462
- function doExec () {
463
- try {
464
- var execPromise = load.e.call(nullContext);
465
- if (execPromise) {
466
- execPromise = execPromise.then(function () {
467
- load.C = load.n;
468
- load.E = null; // indicates completion
469
- if (!true) ;
470
- }, function (err) {
471
- load.er = err;
472
- load.E = null;
473
- if (!true) ;
474
- throw err;
475
- });
476
- return load.E = execPromise;
477
- }
478
- // (should be a promise, but a minify optimization to leave out Promise.resolve)
479
- load.C = load.n;
480
- load.L = load.I = undefined;
481
- }
482
- catch (err) {
483
- load.er = err;
484
- throw err;
485
- }
486
- finally {
487
- load.e = null;
488
- }
489
- }
490
- }
491
-
492
- envGlobal.System = new SystemJS();
493
-
494
- /*
495
- * SystemJS browser attachments for script and import map processing
496
- */
497
-
498
- var importMapPromise = Promise.resolve();
499
- var importMap = { imports: {}, scopes: {}, depcache: {}, integrity: {} };
500
- systemJSPrototype.importMap = importMap;
501
- systemJSPrototype.baseUrl = baseUrl;
502
-
503
- // Scripts are processed immediately, on the first System.import, and on DOMReady.
504
- // Import map scripts are processed only once (by being marked) and in order for each phase.
505
- // This is to avoid using DOM mutation observers in core, although that would be an alternative.
506
- var processFirst = hasDocument;
507
- systemJSPrototype.prepareImport = function (doProcessScripts) {
508
- if (processFirst || doProcessScripts) {
509
- processScripts();
510
- processFirst = false;
511
- }
512
- return importMapPromise;
513
- };
514
39
  if (hasDocument) {
515
- processScripts();
516
- window.addEventListener('DOMContentLoaded', processScripts);
517
- }
518
-
519
- function processScripts () {
520
- [].forEach.call(document.querySelectorAll('script'), function (script) {
521
- if (script.sp) // sp marker = systemjs processed
522
- return;
523
- // TODO: deprecate systemjs-module in next major now that we have auto import
524
- if (script.type === 'systemjs-module') {
525
- script.sp = true;
526
- if (!script.src)
527
- return;
528
- System.import(script.src.slice(0, 7) === 'import:' ? script.src.slice(7) : resolveUrl(script.src, baseUrl)).catch(function (e) {
529
- // if there is a script load error, dispatch an "error" event
530
- // on the script tag.
531
- if (e.message.indexOf('https://git.io/JvFET#3') > -1) {
532
- var event = document.createEvent('Event');
533
- event.initEvent('error', false, false);
534
- script.dispatchEvent(event);
535
- }
536
- return Promise.reject(e);
537
- });
538
- }
539
- else if (script.type === 'systemjs-importmap') {
540
- script.sp = true;
541
- // The passThrough property is for letting the module types fetch implementation know that this is not a SystemJS module.
542
- var fetchPromise = script.src ? (System.fetch || fetch)(script.src, { integrity: script.integrity, passThrough: true }).then(function (res) {
543
- if (!res.ok)
544
- throw Error(res.status );
545
- return res.text();
546
- }).catch(function (err) {
547
- err.message = errMsg('W4', script.src ) + '\n' + err.message;
548
- console.warn(err);
549
- if (typeof script.onerror === 'function') {
550
- script.onerror();
551
- }
552
- return '{}';
553
- }) : script.innerHTML;
554
- importMapPromise = importMapPromise.then(function () {
555
- return fetchPromise;
556
- }).then(function (text) {
557
- extendImportMap(importMap, text, script.src || baseUrl);
558
- return importMap
559
- });
560
- }
561
- });
562
- }
563
-
564
- function extendImportMap (importMap, newMapText, newMapUrl) {
565
- var newMap = {};
566
- try {
567
- newMap = JSON.parse(newMapText);
568
- } catch (err) {
569
- console.warn(Error((errMsg('W5') )));
40
+ const baseElement = document.querySelector("base[href]")
41
+ if (baseElement) {
42
+ baseUrl = baseElement.href
570
43
  }
571
- resolveAndComposeImportMap(newMap, newMapUrl, importMap);
572
- }
573
- System.extendImportMap = extendImportMap
574
-
575
- /*
576
- * Script instantiation loading
577
- */
578
-
579
- if (hasDocument) {
580
- window.addEventListener('error', function (evt) {
581
- lastWindowErrorUrl = evt.filename;
582
- lastWindowError = evt.error;
583
- });
584
- var baseOrigin = location.origin;
585
- }
586
-
587
- systemJSPrototype.createScript = function (url) {
588
- var script = document.createElement('script');
589
- script.async = true;
590
- // Only add cross origin for actual cross origin
591
- // this is because Safari triggers for all
592
- // - https://bugs.webkit.org/show_bug.cgi?id=171566
593
- if (url.indexOf(baseOrigin + '/'))
594
- script.crossOrigin = 'anonymous';
595
- var integrity = importMap.integrity[url];
596
- if (integrity)
597
- script.integrity = integrity;
598
- script.src = url;
599
- return script;
600
- };
601
-
602
- // Auto imports -> script tags can be inlined directly for load phase
603
- var lastAutoImportDeps, lastAutoImportTimeout;
604
- var autoImportCandidates = {};
605
- var systemRegister = systemJSPrototype.register;
606
- var inlineScriptCount = 0;
607
- systemJSPrototype.register = function (deps, declare, autoUrl) {
608
- if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
609
- var scripts = document.querySelectorAll('script');
610
- var lastScript = scripts[scripts.length - 1];
611
- var lastAutoImportUrl
612
- lastAutoImportDeps = deps;
613
- if (lastScript && lastScript.src) {
614
- lastAutoImportUrl = lastScript.src;
44
+ System.register = (deps, declare) => {
45
+ if (!document.currentScript) {
46
+ throw new Error("unexpected call")
615
47
  }
616
- else if (autoUrl) {
617
- lastAutoImportUrl = autoUrl
48
+ if (document.currentScript.__s__) {
49
+ registerRegistry[document.currentScript.src] = [deps, declare]
50
+ return null
618
51
  }
619
- else {
620
- inlineScriptCount++
621
- lastAutoImportUrl = document.location.href + "__inline_script__" + inlineScriptCount;
622
- }
623
- // if this is already a System load, then the instantiate has already begun
624
- // so this re-import has no consequence
625
- var loader = this;
626
- lastAutoImportTimeout = setTimeout(function () {
627
- autoImportCandidates[lastAutoImportUrl] = [deps, declare];
628
- loader.import(lastAutoImportUrl);
629
- });
630
- }
631
- else {
632
- lastAutoImportDeps = undefined;
633
- }
634
- return systemRegister.call(this, deps, declare);
635
- };
636
-
637
- var lastWindowErrorUrl, lastWindowError;
638
- systemJSPrototype.instantiate = function (url, firstParentUrl) {
639
- var autoImportRegistration = autoImportCandidates[url];
640
- if (autoImportRegistration) {
641
- delete autoImportCandidates[url];
642
- return autoImportRegistration;
52
+ const url =
53
+ document.currentScript.src ||
54
+ `${window.location.href}__inline_script__${++inlineScriptCount}`
55
+ registerRegistry[url] = [deps, declare]
56
+ return _import(url)
643
57
  }
644
- var loader = this;
645
- return Promise.resolve(systemJSPrototype.createScript(url)).then(function (script) {
58
+ System.instantiate = (url) => {
59
+ const script = createScript(url)
646
60
  return new Promise(function (resolve, reject) {
647
- script.addEventListener('error', function () {
648
- reject(Error(errMsg(3, [url, firstParentUrl].join(', ') )));
649
- });
650
- script.addEventListener('load', function () {
651
- document.head.removeChild(script);
61
+ let lastWindowErrorUrl
62
+ let lastWindowError
63
+ const windowErrorCallback = (event) => {
64
+ lastWindowErrorUrl = event.filename
65
+ lastWindowError = event.error
66
+ }
67
+ window.addEventListener("error", windowErrorCallback)
68
+ script.addEventListener("error", () => {
69
+ window.removeEventListener("error", windowErrorCallback)
70
+ reject(`An error occured while loading url with <script> for ${url}`)
71
+ })
72
+ script.addEventListener("load", () => {
73
+ window.removeEventListener("error", windowErrorCallback)
74
+ document.head.removeChild(script)
652
75
  // Note that if an error occurs that isn't caught by this if statement,
653
76
  // that getRegister will return null and a "did not instantiate" error will be thrown.
654
77
  if (lastWindowErrorUrl === url) {
655
- reject(lastWindowError);
78
+ reject(lastWindowError)
79
+ } else {
80
+ resolve()
656
81
  }
657
- else {
658
- var register = loader.getRegister(url);
659
- // Clear any auto import registration for dynamic import scripts during load
660
- if (register && register[0] === lastAutoImportDeps)
661
- clearTimeout(lastAutoImportTimeout);
662
- resolve(register);
663
- }
664
- });
665
- document.head.appendChild(script);
666
- });
667
- });
668
- };
669
-
670
- /*
671
- * Fetch loader, sets up shouldFetch and fetch hooks
672
- */
673
- systemJSPrototype.shouldFetch = function () {
674
- return false;
675
- };
676
- if (typeof fetch !== 'undefined')
677
- systemJSPrototype.fetch = fetch;
678
-
679
- var instantiate = systemJSPrototype.instantiate;
680
- var jsContentTypeRegEx = /^(text|application)\/(x-)?javascript(;|$)/;
681
- systemJSPrototype.instantiate = function (url, parent) {
682
- var loader = this;
683
- if (!this.shouldFetch(url))
684
- return instantiate.apply(this, arguments);
685
- return this.fetch(url, {
686
- credentials: 'same-origin',
687
- integrity: importMap.integrity[url]
688
- })
689
- .then(function (res) {
690
- if (!res.ok)
691
- throw Error(errMsg(7, [res.status, res.statusText, url, parent].join(', ') ));
692
- var contentType = res.headers.get('content-type');
693
- if (!contentType || !jsContentTypeRegEx.test(contentType))
694
- throw Error(errMsg(4, contentType ));
695
- return res.text().then(function (source) {
696
- if (source.indexOf('//# sourceURL=') < 0)
697
- source += '\n//# sourceURL=' + url;
698
- (0, eval)(source);
699
- return loader.getRegister(url);
700
- });
701
- });
702
- };
703
-
704
- systemJSPrototype.resolve = function (id, parentUrl) {
705
- parentUrl = parentUrl || !true || baseUrl;
706
- return resolveImportMap((importMap), resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) || throwUnresolved(id, parentUrl);
707
- };
708
-
709
- function throwUnresolved (id, parentUrl) {
710
- throw Error(errMsg(8, [id, parentUrl].join(', ') ));
711
- }
712
-
713
- var systemInstantiate = systemJSPrototype.instantiate;
714
- systemJSPrototype.instantiate = function (url, firstParentUrl) {
715
- var preloads = (importMap).depcache[url];
716
- if (preloads) {
717
- for (var i = 0; i < preloads.length; i++)
718
- getOrCreateLoad(this, this.resolve(preloads[i], url), url);
719
- }
720
- return systemInstantiate.call(this, url, firstParentUrl);
721
- };
722
-
723
- /*
724
- * Supports loading System.register in workers
725
- */
726
-
727
- if (hasSelf && typeof importScripts === 'function') {
728
- systemJSPrototype.instantiate = function (url) {
729
- var loader = this;
730
- return self.fetch(url, {
731
- credentials: 'same-origin',
732
- }).then(function (response) {
733
- if (!response.ok) {
734
- throw Error(errMsg(7, [response.status, response.statusText, url].join(', ') ));
735
- }
736
- return response.text()
737
- }).then(function (source) {
738
- if (source.indexOf('//# sourceURL=') < 0) source += '\n//# sourceURL=' + url;
739
- (0, eval)(source);
740
- return loader.getRegister(url);
82
+ })
83
+ document.head.appendChild(script)
741
84
  })
742
- };
743
- }
744
-
745
- }());
746
-
747
- (function(){
748
- var envGlobal = typeof self !== 'undefined' ? self : global;
749
- var System = envGlobal.System;
750
-
751
- var registerRegistry = Object.create(null)
752
- var register = System.register;
753
- System.registerRegistry = registerRegistry;
754
- System.register = function (name, deps, declare) {
755
- if (typeof name !== 'string') return register.apply(this, arguments);
756
- var define = [deps, declare];
757
- return System.prepareImport().then(function () {
758
- var url = System.resolve(`./${name}`);
759
- registerRegistry[url] = define;
760
- return register.call(System, deps, declare, url);
761
- })
762
- };
763
-
764
- var instantiate = System.instantiate;
765
- System.instantiate = function (url, firstParentUrl) {
766
- var result = registerRegistry[url];
767
-
768
- if (result) {
769
- registerRegistry[url] = null;
770
- return result;
771
- } else {
772
- return instantiate.call(this, url, firstParentUrl);
773
85
  }
774
- };
775
-
776
- var getRegister = System.getRegister;
777
- System.getRegister = function (url) {
778
- // Calling getRegister() because other extras need to know it was called so they can perform side effects
779
- var register = getRegister.call(this, url);
780
- var result = registerRegistry[url] || register;
781
- return result;
782
- };
783
- }());
784
-
785
- (function () {
786
- // worker or service worker
787
- if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
86
+ const createScript = (url) => {
87
+ const script = document.createElement("script")
88
+ script.async = true
89
+ // Only add cross origin for actual cross origin
90
+ // this is because Safari triggers for all
91
+ // - https://bugs.webkit.org/show_bug.cgi?id=171566
92
+ if (url.indexOf(`${self.location.origin}/`)) {
93
+ script.crossOrigin = "anonymous"
94
+ }
95
+ script.__s__ = true
96
+ script.src = url
97
+ return script
98
+ }
99
+ }
100
+ if (isWorker) {
788
101
  /*
789
102
  * SystemJs loads X files before executing the worker/service worker main file
790
103
  * It mean events dispatched during this phase could be missed
@@ -792,35 +105,34 @@
792
105
  * "Event handler of 'install' event must be added on the initial evaluation of worker script"
793
106
  * To fix that code below listen for these events early and redispatch them later
794
107
  * once the worker file is executed (the listeners are installed)
795
- */
796
- var firstRegisterCallbacks = []
797
- var isServiceWorker = typeof self.skipWaiting === 'function'
108
+ */
109
+ const firstImportCallbacks = []
798
110
  if (isServiceWorker) {
799
111
  // for service worker there is more events to listen
800
112
  // and, to get rid of the warning, we override self.addEventListener
801
- var eventsToCatch = ['message', 'install', 'activate', 'fetch']
802
- var eventCallbackProxies = {}
803
- var firstRegisterPromise = new Promise((resolve) => {
804
- firstRegisterCallbacks.push(resolve)
113
+ const eventsToCatch = ["message", "install", "activate", "fetch"]
114
+ const eventCallbackProxies = {}
115
+ const firstImportPromise = new Promise((resolve) => {
116
+ firstImportCallbacks.push(resolve)
805
117
  })
806
- eventsToCatch.forEach(function(eventName) {
807
- var eventsToDispatch = []
808
- var eventCallback = function (event) {
118
+ eventsToCatch.forEach((eventName) => {
119
+ const eventsToDispatch = []
120
+ const eventCallback = (event) => {
809
121
  const eventCallbackProxy = eventCallbackProxies[event.type]
810
122
  if (eventCallbackProxy) {
811
123
  eventCallbackProxy(event)
812
- }
813
- else {
124
+ } else {
814
125
  eventsToDispatch.push(event)
815
- event.waitUntil(firstRegisterPromise)
126
+ event.waitUntil(firstImportPromise)
816
127
  }
817
128
  }
818
129
  self.addEventListener(eventName, eventCallback)
819
- firstRegisterCallbacks.push(function() {
130
+ firstImportCallbacks.push(() => {
820
131
  if (eventsToDispatch.length) {
821
- const eventCallbackProxy = eventCallbackProxies[eventsToDispatch[0].type]
132
+ const eventCallbackProxy =
133
+ eventCallbackProxies[eventsToDispatch[0].type]
822
134
  if (eventCallbackProxy) {
823
- eventsToDispatch.forEach(function (event) {
135
+ eventsToDispatch.forEach((event) => {
824
136
  eventCallbackProxy(event)
825
137
  })
826
138
  }
@@ -828,25 +140,24 @@
828
140
  }
829
141
  })
830
142
  })
831
-
832
- var addEventListener = self.addEventListener
143
+
144
+ const addEventListener = self.addEventListener
833
145
  self.addEventListener = function (eventName, callback, options) {
834
146
  if (eventsToCatch.indexOf(eventName) > -1) {
835
147
  eventCallbackProxies[eventName] = callback
836
- return
148
+ return null
837
149
  }
838
150
  return addEventListener.call(self, eventName, callback, options)
839
151
  }
840
- }
841
- else {
842
- var eventsToCatch = ['message']
843
- eventsToCatch.forEach(function (eventName) {
152
+ } else {
153
+ const eventsToCatch = ["message"]
154
+ eventsToCatch.forEach((eventName) => {
844
155
  var eventQueue = []
845
156
  var eventCallback = (event) => {
846
157
  eventQueue.push(event)
847
158
  }
848
159
  self.addEventListener(eventName, eventCallback)
849
- firstRegisterCallbacks.push(function() {
160
+ firstImportCallbacks.push(() => {
850
161
  self.removeEventListener(eventName, eventCallback)
851
162
  eventQueue.forEach(function (event) {
852
163
  self.dispatchEvent(event)
@@ -856,19 +167,263 @@
856
167
  })
857
168
  }
858
169
 
170
+ System.register = async (deps, declare) => {
171
+ System.register = () => {
172
+ throw new Error("unexpected call")
173
+ }
174
+ const url = self.location.href
175
+ registerRegistry[url] = [deps, declare]
176
+ const namespace = await _import(url)
177
+ firstImportCallbacks.forEach((firstImportCallback) => {
178
+ firstImportCallback()
179
+ })
180
+ firstImportCallbacks.length = 0
181
+ return namespace
182
+ }
183
+ System.instantiate = async (url) => {
184
+ const response = await self.fetch(url, {
185
+ credentials: "same-origin",
186
+ })
187
+ if (!response.ok) {
188
+ throw Error(`Failed to fetch module at ${url}`)
189
+ }
190
+ let source = await response.text()
191
+ if (source.indexOf("//# sourceURL=") < 0) {
192
+ source += `\n//# sourceURL=${url}`
193
+ }
194
+ const register = System.register
195
+ System.register = (deps, declare) => {
196
+ registerRegistry[url] = [deps, declare]
197
+ }
198
+ ;(0, self.eval)(source)
199
+ System.register = register
200
+ }
201
+ }
202
+
203
+ const _import = (specifier, parentUrl) => {
204
+ const url = resolveUrl(specifier, parentUrl)
205
+ const load = getOrCreateLoad(url, parentUrl)
206
+ return load.completionPromise || startExecution(load)
207
+ }
208
+
209
+ const getOrCreateLoad = (url, firstParentUrl) => {
210
+ const existingLoad = loadRegistry[url]
211
+ if (existingLoad) {
212
+ return existingLoad
213
+ }
214
+
215
+ const load = {
216
+ url,
217
+ }
218
+ loadRegistry[url] = load
219
+
220
+ const importerSetters = []
221
+ load.importerSetters = importerSetters
859
222
 
860
- // auto import first register
861
- var register = System.register;
862
- System.register = function(deps, declare) {
863
- System.register = register;
864
- System.registerRegistry[self.location.href] = [deps, declare];
865
- return System.import(self.location.href).then((result) => {
866
- firstRegisterCallbacks.forEach(firstRegisterCallback => {
867
- firstRegisterCallback()
223
+ const namespace = createNamespace()
224
+ load.namespace = namespace
225
+
226
+ load.instantiatePromise = (async () => {
227
+ try {
228
+ let registration = registerRegistry[url]
229
+ if (!registration) {
230
+ const instantiateReturnValue = System.instantiate(url, firstParentUrl)
231
+ if (instantiateReturnValue) {
232
+ await instantiateReturnValue
233
+ }
234
+ registration = registerRegistry[url]
235
+ }
236
+ if (!registration) {
237
+ throw new Error(`System.register() not called after executing ${url}`)
238
+ }
239
+
240
+ const _export = (firstArg, secondArg) => {
241
+ load.hoistedExports = true
242
+ let changed = false
243
+ if (typeof firstArg === "string") {
244
+ const name = firstArg
245
+ const value = secondArg
246
+ if (!(name in namespace) || namespace[name] !== value) {
247
+ namespace[name] = value
248
+ changed = true
249
+ }
250
+ } else {
251
+ Object.keys(firstArg).forEach((name) => {
252
+ const value = firstArg[name]
253
+ if (!(name in namespace) || namespace[name] !== value) {
254
+ namespace[name] = value
255
+ changed = true
256
+ }
257
+ })
258
+ if (firstArg && firstArg.__esModule) {
259
+ namespace.__esModule = firstArg.__esModule
260
+ }
261
+ }
262
+ if (changed) {
263
+ importerSetters.forEach((importerSetter) => {
264
+ if (importerSetter) {
265
+ importerSetter(namespace)
266
+ }
267
+ })
268
+ }
269
+ return secondArg
270
+ }
271
+ const [deps, declare] = registration
272
+ const { setters, execute = () => {} } = declare(_export, {
273
+ import: (importId) => _import(importId, url),
274
+ meta: createMeta(url),
868
275
  })
869
- firstRegisterCallbacks.length = 0
870
- return result
871
- })
276
+ load.deps = deps
277
+ load.setters = setters
278
+ load.execute = execute
279
+ } catch (e) {
280
+ load.error = e
281
+ load.execute = null
282
+ }
283
+ })()
284
+
285
+ load.linkPromise = (async () => {
286
+ await load.instantiatePromise
287
+ const dependencyLoads = await Promise.all(
288
+ load.deps.map(async (dep, index) => {
289
+ const setter = load.setters[index]
290
+ const dependencyUrl = resolveUrl(dep, url)
291
+ const dependencyLoad = getOrCreateLoad(dependencyUrl, url)
292
+ if (dependencyLoad.instantiatePromise) {
293
+ await dependencyLoad.instantiatePromise
294
+ }
295
+ if (setter) {
296
+ dependencyLoad.importerSetters.push(setter)
297
+ if (
298
+ dependencyLoad.hoistedExports ||
299
+ !dependencyLoad.instantiatePromise
300
+ ) {
301
+ setter(dependencyLoad.namespace)
302
+ }
303
+ }
304
+ return dependencyLoad
305
+ }),
306
+ )
307
+ load.dependencyLoads = dependencyLoads
308
+ })()
309
+
310
+ return load
311
+ }
312
+
313
+ const startExecution = async (load) => {
314
+ load.completionPromise = (async () => {
315
+ await instantiateAll(load, load, {})
316
+ await postOrderExec(load, {})
317
+ return load.namespace
318
+ })()
319
+ return load.completionPromise
320
+ }
321
+
322
+ const instantiateAll = async (load, parent, loaded) => {
323
+ if (loaded[load.url]) {
324
+ return
325
+ }
326
+ loaded[load.url] = true
327
+ try {
328
+ if (load.linkPromise) {
329
+ // load.linkPromise is null once instantiated
330
+ await load.linkPromise
331
+ }
332
+ // if (!load.parent || !load.parent.execute) {
333
+ // load.parent = parent
334
+ // }
335
+ await Promise.all(
336
+ load.dependencyLoads.map((dependencyLoad) => {
337
+ return instantiateAll(dependencyLoad, parent, loaded)
338
+ }),
339
+ )
340
+ } catch (error) {
341
+ if (load.error) {
342
+ throw error
343
+ }
344
+ load.execute = null
345
+ throw error
872
346
  }
873
347
  }
874
- }());
348
+
349
+ const postOrderExec = async (load, seen) => {
350
+ if (seen[load.url]) {
351
+ return
352
+ }
353
+ seen[load.url] = true
354
+ if (!load.execute) {
355
+ if (load.error) {
356
+ throw load.error
357
+ }
358
+ if (load.executePromise) {
359
+ await load.executePromise
360
+ }
361
+ return
362
+ }
363
+
364
+ // deps execute first, unless circular
365
+ const depLoadPromises = []
366
+ load.dependencyLoads.forEach((dependencyLoad) => {
367
+ try {
368
+ const depLoadPromise = postOrderExec(dependencyLoad, seen)
369
+ if (depLoadPromise) {
370
+ depLoadPromises.push(depLoadPromise)
371
+ }
372
+ } catch (err) {
373
+ load.execute = null
374
+ load.error = err
375
+ throw err
376
+ }
377
+ })
378
+ if (depLoadPromises.length) {
379
+ await Promise.all(depLoadPromises)
380
+ }
381
+
382
+ try {
383
+ const executeReturnValue = load.execute.call(nullContext)
384
+ if (executeReturnValue) {
385
+ load.executePromise = executeReturnValue.then(
386
+ () => {
387
+ load.executePromise = null
388
+ load.completionPromise = load.namespace
389
+ },
390
+ (error) => {
391
+ load.executePromise = null
392
+ load.error = error
393
+ throw error
394
+ },
395
+ )
396
+ return
397
+ }
398
+ load.instantiatePromise = null
399
+ load.linkPromise = null
400
+ load.completionPromise = load.namespace
401
+ } catch (error) {
402
+ load.error = error
403
+ throw error
404
+ } finally {
405
+ load.execute = null
406
+ }
407
+ }
408
+
409
+ // the closest we can get to call(undefined)
410
+ const nullContext = Object.freeze(Object.create(null))
411
+
412
+ const createMeta = (url) => {
413
+ return {
414
+ url,
415
+ resolve: (id, parentUrl) => resolveUrl(id, parentUrl),
416
+ }
417
+ }
418
+
419
+ const createNamespace =
420
+ typeof Symbol !== "undefined" && Symbol.toStringTag
421
+ ? () => {
422
+ const namespace = Object.create(null)
423
+ Object.defineProperty(namespace, Symbol.toStringTag, {
424
+ value: "Module",
425
+ })
426
+ return namespace
427
+ }
428
+ : () => Object.create(null)
429
+ })();