es-module-shims 1.5.6 → 1.5.9

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/README.md CHANGED
@@ -29,7 +29,7 @@ Because we are still using the native module loader the edge cases work out comp
29
29
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
30
30
 
31
31
  ```html
32
- <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.6/dist/es-module-shims.js"></script>
32
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.9/dist/es-module-shims.js"></script>
33
33
 
34
34
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
35
35
  <script type="importmap">
@@ -292,11 +292,22 @@ While in polyfill mode the same restrictions apply that multiple import maps, im
292
292
  To make it easy to keep track of import map state, es-module-shims provides a `importShim.getImportMap` utility function, available only in shim mode.
293
293
 
294
294
  ```js
295
- const importMap = importShim.getImportMap()
295
+ const importMap = importShim.getImportMap();
296
296
 
297
297
  // importMap will be an object in the same shape as the json in a importmap script
298
298
  ```
299
299
 
300
+ #### Setting current import map state
301
+ To make it easy to set the import map state, es-module-shims provides a `importShim.addImportMap` utility function, available only in shim mode.
302
+
303
+ ```js
304
+ // importMap will be an object in the same shape as the json in a importmap script
305
+ const importMap = { imports: {/*...*/}, scopes: {/*...*/} };
306
+
307
+ importShim.addImportMap(importMap);
308
+ ```
309
+
310
+
300
311
  ### Dynamic Import
301
312
 
302
313
  > Stability: Stable browser standard
@@ -423,6 +434,34 @@ var resolvedUrl = import.meta.resolve('dep', 'https://site.com/another/scope');
423
434
 
424
435
  Node.js also implements a similar API, although it's in the process of shifting to a synchronous resolver.
425
436
 
437
+ ### Module Workers
438
+ ES Module Shims can be used in module workers in browsers that provide dynamic import in worker environments, which at the moment are Chrome(80+), Edge(80+), Safari(15+).
439
+
440
+ An example of ES Module Shims usage in web workers is provided below:
441
+ ```js
442
+ /**
443
+ *
444
+ * @param {string} aURL a string representing the URL of the module script the worker will execute.
445
+ * @returns {string} The string representing the URL of the script the worker will execute.
446
+ */
447
+ function getWorkerScriptURL(aURL) {
448
+ // baseURL, esModuleShimsURL are considered to be known in advance
449
+ // esModuleShimsURL - must point to the non-CSP build of ES Module Shims,
450
+ // namely the `es-module-shim.wasm.js` output: es-module-shims/dist/es-module-shims.wasm.js
451
+
452
+ return URL.createObjectURL(new Blob(
453
+ [
454
+ `importScripts('${new URL(esModuleShimsURL, baseURL).href}');
455
+ importShim.addImportMap(${JSON.stringify(importShim.getImportMap())});
456
+ importShim('${new URL(aURL, baseURL).href}').catch(e => setTimeout(() => { throw e; }))`
457
+ ],
458
+ { type: 'application/javascript' }))
459
+ }
460
+
461
+ const worker = new Worker(getWorkerScriptURL('myEsModule.js'));
462
+ ```
463
+ > For now, in web workers must be used the non-CSP build of ES Module Shims, namely the `es-module-shim.wasm.js` output: es-module-shims/dist/es-module-shims.wasm.js.
464
+
426
465
  ## Init Options
427
466
 
428
467
  Provide a `esmsInitOptions` on the global scope before `es-module-shims` is loaded to configure various aspects of the module loading process:
@@ -1,27 +1,29 @@
1
- /* ES Module Shims 1.5.6 */
1
+ /* ES Module Shims 1.5.9 */
2
2
  (function () {
3
3
 
4
+ const hasWindow = typeof window !== 'undefined';
5
+ const hasDocument = typeof document !== 'undefined';
6
+
4
7
  const noop = () => {};
5
8
 
6
- const optionsScript = document.querySelector('script[type=esms-options]');
9
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
7
10
 
8
11
  const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
9
12
  Object.assign(esmsInitOptions, self.esmsInitOptions || {});
10
13
 
11
- let shimMode = !!esmsInitOptions.shimMode;
14
+ let shimMode = hasDocument ? !!esmsInitOptions.shimMode : true;
12
15
 
13
16
  const importHook = globalHook(shimMode && esmsInitOptions.onimport);
14
17
  const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
15
18
  let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
16
- const metaHook = esmsInitOptions.meta ? globalHook(shimModule && esmsInitOptions.meta) : noop;
19
+ const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
17
20
 
18
21
  const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
19
22
 
20
- let nonce = esmsInitOptions.nonce;
21
-
22
23
  const mapOverrides = esmsInitOptions.mapOverrides;
23
24
 
24
- if (!nonce) {
25
+ let nonce = esmsInitOptions.nonce;
26
+ if (!nonce && hasDocument) {
25
27
  const nonceElement = document.querySelector('script[nonce]');
26
28
  if (nonceElement)
27
29
  nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
@@ -42,13 +44,13 @@
42
44
  const cssModulesEnabled = enable.includes('css-modules');
43
45
  const jsonModulesEnabled = enable.includes('json-modules');
44
46
 
45
- function setShimMode () {
46
- shimMode = true;
47
- }
48
-
49
47
  const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
50
48
 
51
- const baseUrl = document.baseURI;
49
+ const baseUrl = hasDocument
50
+ ? document.baseURI
51
+ : `${location.protocol}//${location.host}${location.pathname.includes('/')
52
+ ? location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
53
+ : location.pathname}`;
52
54
 
53
55
  function createBlob (source, type = 'text/javascript') {
54
56
  return URL.createObjectURL(new Blob([source], { type }));
@@ -56,10 +58,36 @@
56
58
 
57
59
  const eoop = err => setTimeout(() => { throw err });
58
60
 
59
- const throwError = err => { (window.reportError || window.safari && console.error || eoop)(err), void onerror(err); };
61
+ const throwError = err => { (self.reportError || hasWindow && window.safari && console.error || eoop)(err), void onerror(err); };
60
62
 
61
63
  function fromParent (parent) {
62
64
  return parent ? ` imported from ${parent}` : '';
65
+ }
66
+
67
+ let importMapSrcOrLazy = false;
68
+
69
+ function setImportMapSrcOrLazy () {
70
+ importMapSrcOrLazy = true;
71
+ }
72
+
73
+ // shim mode is determined on initialization, no late shim mode
74
+ if (!shimMode) {
75
+ if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
76
+ shimMode = true;
77
+ }
78
+ else {
79
+ let seenScript = false;
80
+ for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
81
+ if (!seenScript) {
82
+ if (script.type === 'module' && !script.ep)
83
+ seenScript = true;
84
+ }
85
+ else if (script.type === 'importmap' && seenScript) {
86
+ importMapSrcOrLazy = true;
87
+ break;
88
+ }
89
+ }
90
+ }
63
91
  }
64
92
 
65
93
  const backslashRegEx = /\\/g;
@@ -237,7 +265,7 @@
237
265
  function dynamicImportScript (url, { errUrl = url } = {}) {
238
266
  err = undefined;
239
267
  const src = createBlob(`import*as m from'${url}';self._esmsi=m`);
240
- const s = Object.assign(document.createElement('script'), { type: 'module', src });
268
+ const s = Object.assign(document.createElement('script'), { type: 'module', src, ep: true });
241
269
  s.setAttribute('nonce', nonce);
242
270
  s.setAttribute('noshim', '');
243
271
  const p = new Promise((resolve, reject) => {
@@ -273,7 +301,7 @@
273
301
  let supportsJsonAssertions = false;
274
302
  let supportsCssAssertions = false;
275
303
 
276
- let supportsImportMaps = HTMLScriptElement.supports ? HTMLScriptElement.supports('importmap') : false;
304
+ let supportsImportMaps = hasDocument && HTMLScriptElement.supports ? HTMLScriptElement.supports('importmap') : false;
277
305
  let supportsImportMeta = supportsImportMaps;
278
306
  let supportsDynamicImport = false;
279
307
 
@@ -284,24 +312,32 @@
284
312
 
285
313
  return Promise.all([
286
314
  supportsImportMaps || dynamicImport(createBlob('import.meta')).then(() => supportsImportMeta = true, noop),
287
- cssModulesEnabled && dynamicImport(createBlob('import"data:text/css,{}"assert{type:"css"}')).then(() => supportsCssAssertions = true, noop),
288
- jsonModulesEnabled && dynamicImport(createBlob('import"data:text/json,{}"assert{type:"json"}')).then(() => supportsJsonAssertions = true, noop),
289
- supportsImportMaps || new Promise(resolve => {
290
- self._$s = v => {
291
- document.head.removeChild(iframe);
292
- if (v) supportsImportMaps = true;
293
- delete self._$s;
294
- resolve();
295
- };
315
+ cssModulesEnabled && dynamicImport(createBlob(`import"${createBlob('', 'text/css')}"assert{type:"css"}`)).then(() => supportsCssAssertions = true, noop),
316
+ jsonModulesEnabled && dynamicImport(createBlob(`import"${createBlob('{}', 'text/json')}"assert{type:"json"}`)).then(() => supportsJsonAssertions = true, noop),
317
+ supportsImportMaps || hasDocument && (HTMLScriptElement.supports || new Promise(resolve => {
296
318
  const iframe = document.createElement('iframe');
297
319
  iframe.style.display = 'none';
298
320
  iframe.setAttribute('nonce', nonce);
299
- document.head.appendChild(iframe);
300
- // we use document.write here because eg Weixin built-in browser doesn't support setting srcdoc
301
321
  // setting src to a blob URL results in a navigation event in webviews
302
322
  // setting srcdoc is not supported in React native webviews on iOS
303
- iframe.contentWindow.document.write(`<script type=importmap nonce="${nonce}">{"imports":{"x":"data:text/javascript,"}}<${''}/script><script nonce="${nonce}">import('x').then(()=>1,()=>0).then(v=>parent._$s(v))<${''}/script>`);
304
- })
323
+ // therefore, we need to first feature detect srcdoc support
324
+ iframe.srcdoc = `<!doctype html><script nonce="${nonce}"><${''}/script>`;
325
+ document.head.appendChild(iframe);
326
+ iframe.onload = () => {
327
+ self._$s = v => {
328
+ document.head.removeChild(iframe);
329
+ supportsImportMaps = v;
330
+ delete self._$s;
331
+ resolve();
332
+ };
333
+ const supportsSrcDoc = iframe.contentDocument.head.childNodes.length > 0;
334
+ const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}<${''}/script><script nonce="${nonce}">import('x').catch(() => {}).then(v=>parent._$s(!!v))<${''}/script>`;
335
+ if (supportsSrcDoc)
336
+ iframe.srcdoc = importMapTest;
337
+ else
338
+ iframe.contentDocument.write(importMapTest);
339
+ };
340
+ }))
305
341
  ]);
306
342
  });
307
343
 
@@ -338,7 +374,9 @@
338
374
  await initPromise;
339
375
  if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
340
376
  if (acceptingImportMaps || shimMode || !baselinePassthrough) {
341
- processImportMaps();
377
+ if (hasDocument)
378
+ processImportMaps();
379
+
342
380
  if (!shimMode)
343
381
  acceptingImportMaps = false;
344
382
  }
@@ -368,6 +406,10 @@
368
406
 
369
407
  importShim.resolve = resolveSync;
370
408
  importShim.getImportMap = () => JSON.parse(JSON.stringify(importMap));
409
+ importShim.addImportMap = importMapIn => {
410
+ if (!shimMode) throw new Error('Unsupported in polyfill mode.');
411
+ importMap = resolveAndComposeImportMap(importMapIn, baseUrl, importMap);
412
+ };
371
413
 
372
414
  const registry = importShim._r = {};
373
415
 
@@ -382,68 +424,50 @@
382
424
  }
383
425
 
384
426
  let importMap = { imports: {}, scopes: {} };
385
- let importMapSrcOrLazy = false;
386
427
  let baselinePassthrough;
387
428
 
388
429
  const initPromise = featureDetectionPromise.then(() => {
389
- // shim mode is determined on initialization, no late shim mode
390
- if (!shimMode) {
391
- if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
392
- setShimMode();
393
- }
394
- else {
395
- let seenScript = false;
396
- for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
397
- if (!seenScript) {
398
- if (script.type === 'module')
399
- seenScript = true;
400
- }
401
- else if (script.type === 'importmap') {
402
- importMapSrcOrLazy = true;
403
- break;
404
- }
405
- }
406
- }
407
- }
408
430
  baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
409
- if (!supportsImportMaps) {
410
- const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
411
- HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
412
- }
413
- if (shimMode || !baselinePassthrough) {
414
- new MutationObserver(mutations => {
415
- for (const mutation of mutations) {
416
- if (mutation.type !== 'childList') continue;
417
- for (const node of mutation.addedNodes) {
418
- if (node.tagName === 'SCRIPT') {
419
- if (node.type === (shimMode ? 'module-shim' : 'module'))
420
- processScript(node);
421
- if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
422
- processImportMap(node);
431
+ if (hasDocument) {
432
+ if (!supportsImportMaps) {
433
+ const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
434
+ HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
435
+ }
436
+ if (shimMode || !baselinePassthrough) {
437
+ new MutationObserver(mutations => {
438
+ for (const mutation of mutations) {
439
+ if (mutation.type !== 'childList') continue;
440
+ for (const node of mutation.addedNodes) {
441
+ if (node.tagName === 'SCRIPT') {
442
+ if (node.type === (shimMode ? 'module-shim' : 'module'))
443
+ processScript(node);
444
+ if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
445
+ processImportMap(node);
446
+ }
447
+ else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
448
+ processPreload(node);
423
449
  }
424
- else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
425
- processPreload(node);
426
450
  }
451
+ }).observe(document, {childList: true, subtree: true});
452
+ processImportMaps();
453
+ processScriptsAndPreloads();
454
+ if (document.readyState === 'complete') {
455
+ readyStateCompleteCheck();
427
456
  }
428
- }).observe(document, { childList: true, subtree: true });
429
- processImportMaps();
430
- processScriptsAndPreloads();
431
- if (document.readyState === 'complete') {
432
- readyStateCompleteCheck();
433
- }
434
- else {
435
- async function readyListener () {
436
- await initPromise;
437
- processImportMaps();
438
- if (document.readyState === 'complete') {
439
- readyStateCompleteCheck();
440
- document.removeEventListener('readystatechange', readyListener);
457
+ else {
458
+ async function readyListener() {
459
+ await initPromise;
460
+ processImportMaps();
461
+ if (document.readyState === 'complete') {
462
+ readyStateCompleteCheck();
463
+ document.removeEventListener('readystatechange', readyListener);
464
+ }
441
465
  }
466
+ document.addEventListener('readystatechange', readyListener);
442
467
  }
443
- document.addEventListener('readystatechange', readyListener);
444
468
  }
445
- return undefined;
446
469
  }
470
+ return undefined;
447
471
  });
448
472
  let importMapPromise = initPromise;
449
473
  let firstPolyfillLoad = true;
@@ -453,7 +477,7 @@
453
477
  if (!shimMode)
454
478
  acceptingImportMaps = false;
455
479
  await importMapPromise;
456
- if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
480
+ if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
457
481
  // early analysis opt-out - no need to even fetch if we have feature support
458
482
  if (!shimMode && baselinePassthrough) {
459
483
  // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
@@ -523,7 +547,7 @@
523
547
  const source = load.S;
524
548
 
525
549
  // edge doesnt execute sibling in order, so we fix this up by ensuring all previous executions are explicit dependencies
526
- let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
550
+ let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
527
551
 
528
552
  if (!imports.length) {
529
553
  resolvedSource += source;
@@ -564,7 +588,7 @@
564
588
  resolvedSource += `/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
565
589
 
566
590
  // circular shell execution
567
- if (!cycleShell && depLoad.s) {
591
+ if (!cycleShell && depLoad.s) {
568
592
  resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
569
593
  depLoad.s = undefined;
570
594
  }
@@ -651,8 +675,8 @@
651
675
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
652
676
  else if (cssContentType.test(contentType)) {
653
677
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
654
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
655
- });export default s;`, t: 'css' };
678
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
679
+ });export default s;`, t: 'css' };
656
680
  }
657
681
  else
658
682
  throw Error(`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`);
@@ -773,14 +797,16 @@
773
797
  document.dispatchEvent(new Event('DOMContentLoaded'));
774
798
  }
775
799
  // this should always trigger because we assume es-module-shims is itself a domcontentloaded requirement
776
- document.addEventListener('DOMContentLoaded', async () => {
777
- await initPromise;
778
- domContentLoadedCheck();
779
- if (shimMode || !baselinePassthrough) {
780
- processImportMaps();
781
- processScriptsAndPreloads();
782
- }
783
- });
800
+ if (hasDocument) {
801
+ document.addEventListener('DOMContentLoaded', async () => {
802
+ await initPromise;
803
+ domContentLoadedCheck();
804
+ if (shimMode || !baselinePassthrough) {
805
+ processImportMaps();
806
+ processScriptsAndPreloads();
807
+ }
808
+ });
809
+ }
784
810
 
785
811
  let readyStateCompleteCnt = 1;
786
812
  function readyStateCompleteCheck () {
@@ -799,7 +825,7 @@
799
825
  if (script.src) {
800
826
  if (!shimMode)
801
827
  return;
802
- importMapSrcOrLazy = true;
828
+ setImportMapSrcOrLazy();
803
829
  }
804
830
  if (acceptingImportMaps) {
805
831
  importMapPromise = importMapPromise
@@ -1,27 +1,29 @@
1
- /* ES Module Shims Wasm 1.5.6 */
1
+ /* ES Module Shims Wasm 1.5.9 */
2
2
  (function () {
3
3
 
4
+ const hasWindow = typeof window !== 'undefined';
5
+ const hasDocument = typeof document !== 'undefined';
6
+
4
7
  const noop = () => {};
5
8
 
6
- const optionsScript = document.querySelector('script[type=esms-options]');
9
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
7
10
 
8
11
  const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
9
12
  Object.assign(esmsInitOptions, self.esmsInitOptions || {});
10
13
 
11
- let shimMode = !!esmsInitOptions.shimMode;
14
+ let shimMode = hasDocument ? !!esmsInitOptions.shimMode : true;
12
15
 
13
16
  const importHook = globalHook(shimMode && esmsInitOptions.onimport);
14
17
  const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
15
18
  let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
16
- const metaHook = esmsInitOptions.meta ? globalHook(shimModule && esmsInitOptions.meta) : noop;
19
+ const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
17
20
 
18
21
  const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
19
22
 
20
- let nonce = esmsInitOptions.nonce;
21
-
22
23
  const mapOverrides = esmsInitOptions.mapOverrides;
23
24
 
24
- if (!nonce) {
25
+ let nonce = esmsInitOptions.nonce;
26
+ if (!nonce && hasDocument) {
25
27
  const nonceElement = document.querySelector('script[nonce]');
26
28
  if (nonceElement)
27
29
  nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
@@ -42,13 +44,13 @@
42
44
  const cssModulesEnabled = enable.includes('css-modules');
43
45
  const jsonModulesEnabled = enable.includes('json-modules');
44
46
 
45
- function setShimMode () {
46
- shimMode = true;
47
- }
48
-
49
47
  const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
50
48
 
51
- const baseUrl = document.baseURI;
49
+ const baseUrl = hasDocument
50
+ ? document.baseURI
51
+ : `${location.protocol}//${location.host}${location.pathname.includes('/')
52
+ ? location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
53
+ : location.pathname}`;
52
54
 
53
55
  function createBlob (source, type = 'text/javascript') {
54
56
  return URL.createObjectURL(new Blob([source], { type }));
@@ -56,10 +58,36 @@
56
58
 
57
59
  const eoop = err => setTimeout(() => { throw err });
58
60
 
59
- const throwError = err => { (window.reportError || window.safari && console.error || eoop)(err), void onerror(err); };
61
+ const throwError = err => { (self.reportError || hasWindow && window.safari && console.error || eoop)(err), void onerror(err); };
60
62
 
61
63
  function fromParent (parent) {
62
64
  return parent ? ` imported from ${parent}` : '';
65
+ }
66
+
67
+ let importMapSrcOrLazy = false;
68
+
69
+ function setImportMapSrcOrLazy () {
70
+ importMapSrcOrLazy = true;
71
+ }
72
+
73
+ // shim mode is determined on initialization, no late shim mode
74
+ if (!shimMode) {
75
+ if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
76
+ shimMode = true;
77
+ }
78
+ else {
79
+ let seenScript = false;
80
+ for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
81
+ if (!seenScript) {
82
+ if (script.type === 'module' && !script.ep)
83
+ seenScript = true;
84
+ }
85
+ else if (script.type === 'importmap' && seenScript) {
86
+ importMapSrcOrLazy = true;
87
+ break;
88
+ }
89
+ }
90
+ }
63
91
  }
64
92
 
65
93
  const backslashRegEx = /\\/g;
@@ -234,6 +262,15 @@
234
262
 
235
263
  let supportsDynamicImportCheck = false;
236
264
 
265
+ // first check basic eval support
266
+ try {
267
+ eval('');
268
+ }
269
+ catch (e) {
270
+ throw new Error(`The ES Module Shims Wasm build will not work without eval support. Either use the alternative CSP-compatible build or make sure to add both the "unsafe-eval" and "unsafe-wasm-eval" CSP policies.`);
271
+ }
272
+
273
+ // polyfill dynamic import if not supported
237
274
  let dynamicImport;
238
275
  try {
239
276
  dynamicImport = (0, eval)('u=>import(u)');
@@ -241,7 +278,7 @@
241
278
  }
242
279
  catch (e) {}
243
280
 
244
- if (!supportsDynamicImportCheck) {
281
+ if (hasDocument && !supportsDynamicImportCheck) {
245
282
  let err;
246
283
  window.addEventListener('error', _err => err = _err);
247
284
  dynamicImport = (url, { errUrl = url }) => {
@@ -249,7 +286,6 @@
249
286
  const src = createBlob(`import*as m from'${url}';self._esmsi=m;`);
250
287
  const s = Object.assign(document.createElement('script'), { type: 'module', src });
251
288
  s.setAttribute('noshim', '');
252
- s.setAttribute('nonce', nonce);
253
289
  document.head.appendChild(s);
254
290
  return new Promise((resolve, reject) => {
255
291
  s.addEventListener('load', () => {
@@ -271,7 +307,7 @@
271
307
  let supportsJsonAssertions = false;
272
308
  let supportsCssAssertions = false;
273
309
 
274
- let supportsImportMaps = HTMLScriptElement.supports ? HTMLScriptElement.supports('importmap') : false;
310
+ let supportsImportMaps = hasDocument && HTMLScriptElement.supports ? HTMLScriptElement.supports('importmap') : false;
275
311
  let supportsImportMeta = supportsImportMaps;
276
312
  let supportsDynamicImport = false;
277
313
 
@@ -282,24 +318,32 @@
282
318
 
283
319
  return Promise.all([
284
320
  supportsImportMaps || dynamicImport(createBlob('import.meta')).then(() => supportsImportMeta = true, noop),
285
- cssModulesEnabled && dynamicImport(createBlob('import"data:text/css,{}"assert{type:"css"}')).then(() => supportsCssAssertions = true, noop),
286
- jsonModulesEnabled && dynamicImport(createBlob('import"data:text/json,{}"assert{type:"json"}')).then(() => supportsJsonAssertions = true, noop),
287
- supportsImportMaps || new Promise(resolve => {
288
- self._$s = v => {
289
- document.head.removeChild(iframe);
290
- if (v) supportsImportMaps = true;
291
- delete self._$s;
292
- resolve();
293
- };
321
+ cssModulesEnabled && dynamicImport(createBlob(`import"${createBlob('', 'text/css')}"assert{type:"css"}`)).then(() => supportsCssAssertions = true, noop),
322
+ jsonModulesEnabled && dynamicImport(createBlob(`import"${createBlob('{}', 'text/json')}"assert{type:"json"}`)).then(() => supportsJsonAssertions = true, noop),
323
+ supportsImportMaps || hasDocument && (HTMLScriptElement.supports || new Promise(resolve => {
294
324
  const iframe = document.createElement('iframe');
295
325
  iframe.style.display = 'none';
296
326
  iframe.setAttribute('nonce', nonce);
297
- document.head.appendChild(iframe);
298
- // we use document.write here because eg Weixin built-in browser doesn't support setting srcdoc
299
327
  // setting src to a blob URL results in a navigation event in webviews
300
328
  // setting srcdoc is not supported in React native webviews on iOS
301
- iframe.contentWindow.document.write(`<script type=importmap nonce="${nonce}">{"imports":{"x":"data:text/javascript,"}}<${''}/script><script nonce="${nonce}">import('x').then(()=>1,()=>0).then(v=>parent._$s(v))<${''}/script>`);
302
- })
329
+ // therefore, we need to first feature detect srcdoc support
330
+ iframe.srcdoc = `<!doctype html><script nonce="${nonce}"><${''}/script>`;
331
+ document.head.appendChild(iframe);
332
+ iframe.onload = () => {
333
+ self._$s = v => {
334
+ document.head.removeChild(iframe);
335
+ supportsImportMaps = v;
336
+ delete self._$s;
337
+ resolve();
338
+ };
339
+ const supportsSrcDoc = iframe.contentDocument.head.childNodes.length > 0;
340
+ const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}<${''}/script><script nonce="${nonce}">import('x').catch(() => {}).then(v=>parent._$s(!!v))<${''}/script>`;
341
+ if (supportsSrcDoc)
342
+ iframe.srcdoc = importMapTest;
343
+ else
344
+ iframe.contentDocument.write(importMapTest);
345
+ };
346
+ }))
303
347
  ]);
304
348
  });
305
349
 
@@ -336,7 +380,9 @@
336
380
  await initPromise;
337
381
  if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
338
382
  if (acceptingImportMaps || shimMode || !baselinePassthrough) {
339
- processImportMaps();
383
+ if (hasDocument)
384
+ processImportMaps();
385
+
340
386
  if (!shimMode)
341
387
  acceptingImportMaps = false;
342
388
  }
@@ -366,6 +412,10 @@
366
412
 
367
413
  importShim.resolve = resolveSync;
368
414
  importShim.getImportMap = () => JSON.parse(JSON.stringify(importMap));
415
+ importShim.addImportMap = importMapIn => {
416
+ if (!shimMode) throw new Error('Unsupported in polyfill mode.');
417
+ importMap = resolveAndComposeImportMap(importMapIn, baseUrl, importMap);
418
+ };
369
419
 
370
420
  const registry = importShim._r = {};
371
421
 
@@ -380,68 +430,50 @@
380
430
  }
381
431
 
382
432
  let importMap = { imports: {}, scopes: {} };
383
- let importMapSrcOrLazy = false;
384
433
  let baselinePassthrough;
385
434
 
386
435
  const initPromise = featureDetectionPromise.then(() => {
387
- // shim mode is determined on initialization, no late shim mode
388
- if (!shimMode) {
389
- if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
390
- setShimMode();
391
- }
392
- else {
393
- let seenScript = false;
394
- for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
395
- if (!seenScript) {
396
- if (script.type === 'module')
397
- seenScript = true;
398
- }
399
- else if (script.type === 'importmap') {
400
- importMapSrcOrLazy = true;
401
- break;
402
- }
403
- }
404
- }
405
- }
406
436
  baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
407
- if (!supportsImportMaps) {
408
- const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
409
- HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
410
- }
411
- if (shimMode || !baselinePassthrough) {
412
- new MutationObserver(mutations => {
413
- for (const mutation of mutations) {
414
- if (mutation.type !== 'childList') continue;
415
- for (const node of mutation.addedNodes) {
416
- if (node.tagName === 'SCRIPT') {
417
- if (node.type === (shimMode ? 'module-shim' : 'module'))
418
- processScript(node);
419
- if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
420
- processImportMap(node);
437
+ if (hasDocument) {
438
+ if (!supportsImportMaps) {
439
+ const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
440
+ HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
441
+ }
442
+ if (shimMode || !baselinePassthrough) {
443
+ new MutationObserver(mutations => {
444
+ for (const mutation of mutations) {
445
+ if (mutation.type !== 'childList') continue;
446
+ for (const node of mutation.addedNodes) {
447
+ if (node.tagName === 'SCRIPT') {
448
+ if (node.type === (shimMode ? 'module-shim' : 'module'))
449
+ processScript(node);
450
+ if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
451
+ processImportMap(node);
452
+ }
453
+ else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
454
+ processPreload(node);
421
455
  }
422
- else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
423
- processPreload(node);
424
456
  }
457
+ }).observe(document, {childList: true, subtree: true});
458
+ processImportMaps();
459
+ processScriptsAndPreloads();
460
+ if (document.readyState === 'complete') {
461
+ readyStateCompleteCheck();
425
462
  }
426
- }).observe(document, { childList: true, subtree: true });
427
- processImportMaps();
428
- processScriptsAndPreloads();
429
- if (document.readyState === 'complete') {
430
- readyStateCompleteCheck();
431
- }
432
- else {
433
- async function readyListener () {
434
- await initPromise;
435
- processImportMaps();
436
- if (document.readyState === 'complete') {
437
- readyStateCompleteCheck();
438
- document.removeEventListener('readystatechange', readyListener);
463
+ else {
464
+ async function readyListener() {
465
+ await initPromise;
466
+ processImportMaps();
467
+ if (document.readyState === 'complete') {
468
+ readyStateCompleteCheck();
469
+ document.removeEventListener('readystatechange', readyListener);
470
+ }
439
471
  }
472
+ document.addEventListener('readystatechange', readyListener);
440
473
  }
441
- document.addEventListener('readystatechange', readyListener);
442
474
  }
443
- return init;
444
475
  }
476
+ return init;
445
477
  });
446
478
  let importMapPromise = initPromise;
447
479
  let firstPolyfillLoad = true;
@@ -451,7 +483,7 @@
451
483
  if (!shimMode)
452
484
  acceptingImportMaps = false;
453
485
  await importMapPromise;
454
- if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
486
+ if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
455
487
  // early analysis opt-out - no need to even fetch if we have feature support
456
488
  if (!shimMode && baselinePassthrough) {
457
489
  // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
@@ -521,7 +553,7 @@
521
553
  const source = load.S;
522
554
 
523
555
  // edge doesnt execute sibling in order, so we fix this up by ensuring all previous executions are explicit dependencies
524
- let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
556
+ let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
525
557
 
526
558
  if (!imports.length) {
527
559
  resolvedSource += source;
@@ -562,7 +594,7 @@
562
594
  resolvedSource += `/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
563
595
 
564
596
  // circular shell execution
565
- if (!cycleShell && depLoad.s) {
597
+ if (!cycleShell && depLoad.s) {
566
598
  resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
567
599
  depLoad.s = undefined;
568
600
  }
@@ -649,8 +681,8 @@
649
681
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
650
682
  else if (cssContentType.test(contentType)) {
651
683
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
652
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
653
- });export default s;`, t: 'css' };
684
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
685
+ });export default s;`, t: 'css' };
654
686
  }
655
687
  else
656
688
  throw Error(`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`);
@@ -771,14 +803,16 @@
771
803
  document.dispatchEvent(new Event('DOMContentLoaded'));
772
804
  }
773
805
  // this should always trigger because we assume es-module-shims is itself a domcontentloaded requirement
774
- document.addEventListener('DOMContentLoaded', async () => {
775
- await initPromise;
776
- domContentLoadedCheck();
777
- if (shimMode || !baselinePassthrough) {
778
- processImportMaps();
779
- processScriptsAndPreloads();
780
- }
781
- });
806
+ if (hasDocument) {
807
+ document.addEventListener('DOMContentLoaded', async () => {
808
+ await initPromise;
809
+ domContentLoadedCheck();
810
+ if (shimMode || !baselinePassthrough) {
811
+ processImportMaps();
812
+ processScriptsAndPreloads();
813
+ }
814
+ });
815
+ }
782
816
 
783
817
  let readyStateCompleteCnt = 1;
784
818
  function readyStateCompleteCheck () {
@@ -797,7 +831,7 @@
797
831
  if (script.src) {
798
832
  if (!shimMode)
799
833
  return;
800
- importMapSrcOrLazy = true;
834
+ setImportMapSrcOrLazy();
801
835
  }
802
836
  if (acceptingImportMaps) {
803
837
  importMapPromise = importMapPromise
package/index.d.ts CHANGED
@@ -18,7 +18,7 @@ interface ESMSInitOptions {
18
18
  /**
19
19
  * Disable retriggering of document readystate
20
20
  */
21
- noLoadEventRetriggers: true,
21
+ noLoadEventRetriggers: true;
22
22
 
23
23
  /**
24
24
  * #### Skip Processing Stability
@@ -45,24 +45,28 @@ interface ESMSInitOptions {
45
45
 
46
46
  /**
47
47
  * #### Error hook
48
- *
48
+ *
49
49
  * Register a callback for any ES Module Shims module errors.
50
- *
50
+ *
51
51
  */
52
52
  onerror: (e: any) => any;
53
53
 
54
54
  /**
55
55
  * #### Resolve Hook
56
- *
56
+ *
57
57
  * Only supported in Shim Mode.
58
- *
58
+ *
59
59
  * Provide a custom resolver function.
60
60
  */
61
- resolve: (id: string, parentUrl: string, resolve: (id: string, parentUrl: string) => string) => string | Promise<string>;
61
+ resolve: (
62
+ id: string,
63
+ parentUrl: string,
64
+ resolve: (id: string, parentUrl: string) => string
65
+ ) => string | Promise<string>;
62
66
 
63
67
  /**
64
68
  * #### Fetch Hook
65
- *
69
+ *
66
70
  * Only supported in Shim Mode.
67
71
  *
68
72
  * > Stability: Non-spec feature
@@ -126,14 +130,19 @@ interface ESMSInitOptions {
126
130
 
127
131
  /**
128
132
  * #### Revoke Blob URLs
129
- *
133
+ *
130
134
  * Set to *true* to cleanup blob URLs from memory after execution.
131
135
  * Can cost some compute time for large loads.
132
- *
136
+ *
133
137
  */
134
138
  revokeBlobURLs: boolean;
135
139
  }
136
140
 
141
+ interface ImportMap {
142
+ imports: Record<string, string>;
143
+ scopes: Record<string, Record<string, string>>;
144
+ }
145
+
137
146
  /**
138
147
  * Dynamic import(...) within any modules loaded will be rewritten as
139
148
  * importShim(...) automatically providing full support for all es-module-shims
@@ -151,6 +160,12 @@ declare function importShim<Default, Exports extends object>(
151
160
  parentUrl?: string
152
161
  ): Promise<{ default: Default } & Exports>;
153
162
 
163
+ declare namespace importShim {
164
+ const resolve: (id: string, parentURL?: string) => string;
165
+ const addImportMap: (importMap: Partial<ImportMap>) => void;
166
+ const getImportMap: () => ImportMap;
167
+ }
168
+
154
169
  interface Window {
155
170
  esmsInitOptions?: ESMSInitOptions;
156
171
  importShim: typeof importShim;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.5.6",
3
+ "version": "1.5.9",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {
package/CHANGELOG.md DELETED
@@ -1,298 +0,0 @@
1
- ES Module Shims 1.5.1 (2022/03/17)
2
- * Deps: Update to es-module-lexer@0.10.4 (#273)
3
-
4
- ES Module Shims 1.5.0 (2022/03/17)
5
- * Feat: Import hook, meta hook, sync resolver implementation, deprecating async resolver (#268)
6
- * Deps: Update to es-module-lexer@0.10.3 (#272)
7
-
8
- ES Module Shims 1.4.7 (2022/02/23)
9
- * Feat: Alternative IFrame injection to avoid navigation event on Android (#265)
10
- * Deps: Update to es-module-lexer@0.10.0 (#266)
11
-
12
- ES Module Shims 1.4.6 (2022/02/15)
13
- * Feat: Improve fetch content type error failure context (https://github.com/guybedford/es-module-shims/pull/263)
14
- * Feat: Refactor error handling paths, use `reportError` when possible (https://github.com/guybedford/es-module-shims/pull/264)
15
-
16
- ES Module Shims 1.4.5 (2022/02/12)
17
- * Feat: Allow import map overrides with option (https://github.com/guybedford/es-module-shims/pull/257, @lewisl@9029)
18
- * Feat: Additional fetch error context (https://github.com/guybedford/es-module-shims/pull/256)
19
- * Fix: dynamic import context with import assertions (https://github.com/guybedford/es-module-shims/pull/260, @ICodeMyOwnLife)
20
- * Docs: Clarify modulepreload-shim (https://github.com/guybedford/es-module-shims/pull/261, @LarsDenBakker)
21
-
22
- ES Module Shims 1.4.4 (2022/02/03)
23
- * Fix: import.meta.resolve support for inline scripts (https://github.com/guybedford/es-module-shims/pull/251)
24
- * Fix: CSS imports unquoted URL normalization (https://github.com/guybedford/es-module-shims/pull/252)
25
- * Fix: Reword polyfill info message (https://github.com/guybedford/es-module-shims/pull/253)
26
-
27
- ES Module Shims 1.4.3 (2022/01/25)
28
- * Feature: Support import map overrides when existing resolution matches new resolution (https://github.com/guybedford/es-module-shims/pull/249, @vovacodes)
29
- * Fix: Import assertions support with dynamic imports (https://github.com/guybedford/es-module-shims/pull/248)
30
-
31
- ES Module Shims 1.4.2 (2022/01/24)
32
- * Fix: optional catch binding in `isUrl` function (@thepassle, https://github.com/guybedford/es-module-shims/pull/246)
33
-
34
- ES Module Shims 1.4.1 (2021/12/15)
35
- * Fix: Firefox parse error stacks (https://github.com/guybedford/es-module-shims/pull/239)
36
-
37
- ES Module Shims 1.4.0 (2021/12/14)
38
- * Feature: "enforceIntegrity" option and "modulepreload-shim" support for secure shim mode with integrity (https://github.com/guybedford/es-module-shims/pull/236)
39
- * Fix: Safari parse error stacks (https://github.com/guybedford/es-module-shims/pull/238)
40
- * Note: Polyfill mode console note when expected native errors are present (https://github.com/guybedford/es-module-shims/pull/237)
41
-
42
- ES Module Shims 1.3.6 (2021/12/07)
43
- * Fix resolve hook via esms options (#233, @ffortier)
44
-
45
- ES Module Shims 1.3.5 (2021/12/02)
46
- * Fix trailing comment regex for source mapping normalization with trailling comments (https://github.com/guybedford/es-module-shims/pull/231)
47
-
48
- ES Module Shims 1.3.4 (2021/12/02)
49
- * Support source mapping normalization with trailing comments (https://github.com/guybedford/es-module-shims/pull/229)
50
-
51
- ES Module Shims 1.3.3 (2021/11/30))
52
- * Remove use of document.write (https://github.com/guybedford/es-module-shims/pull/227, @lewisl9029)
53
-
54
- ES Module Shims 1.3.2 (2021/11/16)
55
- * Fix CSP nonce detection (https://github.com/guybedford/es-module-shims/pull/223, @MathiasWP)
56
-
57
- ES Module Shims 1.3.1 (2021/11/04)
58
- * Feature: Support "async" attribute ordering on polyfill and shim scripts (https://github.com/guybedford/es-module-shims/pull/221)
59
- * Fix: Sourcemap regex fix (https://github.com/guybedford/es-module-shims/pull/218)
60
- * Fix: Polyfill duplicate instance bug (https://github.com/guybedford/es-module-shims/pull/220)
61
-
62
- ES Module Shims 1.3.0 (2021/10/14)
63
- * Feature: Shim mode function to get import map, dynamic map overrides now throw (https://github.com/guybedford/es-module-shims/pull/213, @lewisl9029)
64
- * Feature: Upgrade to es-module-lexer@0.9.3 with import / export strings support (https://github.com/guybedford/es-module-shims/pull/210)
65
- * Performance: Disable subgraph passthrough (https://github.com/guybedford/es-module-shims/pull/208)
66
- * Fix: Undefined error callbacks for Safari (https://github.com/guybedford/es-module-shims/pull/209)
67
-
68
- ES Module Shims 1.2.0 (2021/10/04)
69
- * Fix: Bug where fetch hook was renamed to "fetchHook" instead of "fetch" (https://github.com/guybedford/es-module-shims/pull/205)
70
-
71
- ES Modules Shims 1.1.0 (2021/09/28)
72
- * Feature: Enable polyfill when loading a module before the import map. This resolves browser extension issues (https://github.com/WICG/import-maps/issues/248) (https://github.com/guybedford/es-module-shims/pull/203)
73
- * Fix: Upgrade to es-module-lexer@0.9.1 supporting large source analysis (https://github.com/guybedford/es-module-shims/pull/203)
74
-
75
- ES Module Shims 1.0.4 (2021/09/22)
76
- * Fix typo bug in import maps call (https://github.com/guybedford/es-module-shims/pull/198)
77
-
78
- ES Module Shims 1.0.3 (2021/09/22)
79
- * Lifecycle event polishing and fixes (https://github.com/guybedford/es-module-shims/pull/197)
80
-
81
- ES Module Shims 1.0.2 (2021/09/22)
82
- * Fix native passthrough for contextual `importShim` dynamic import to still full reconstruct top-level resolution by parsing import maps (https://github.com/guybedford/es-module-shims/pull/196)
83
- * Remove skip option default (https://github.com/guybedford/es-module-shims/pull/195)
84
-
85
- ES Module Shims 1.0.1 (2021/09/22)
86
- * Improved native passthrough performance, with some load event restrictions on unstable new features within release cutoff (https://github.com/guybedford/es-module-shims/pull/194)
87
-
88
- ES Module Shims 1.0.0 (2021/09/20)
89
- * CSP support build by default (https://github.com/guybedford/es-module-shims/pull/193)
90
-
91
- ES Module Shims 0.15.1 (2021/09/18)
92
- * Significant performance improvements to CSP build via asm.js (https://github.com/guybedford/es-module-shims/pull/190) and direct dynamic import (https://github.com/guybedford/es-module-shims/pull/191)
93
-
94
- ES Module Shims 0.15.0 (2021/09/17)
95
- * Various perf and behaviour polishing (https://github.com/guybedford/es-module-shims/pull/188)
96
- * Revert DOM mutator nested queryString checks (https://github.com/guybedford/es-module-shims/pull/189)
97
- * Fetch pooling (https://github.com/guybedford/es-module-shims/pull/184)
98
-
99
- ES Module Shims 0.14.0 (2021/09/13)
100
- * CSP compatible ES Module Shims build (https://github.com/guybedford/es-module-shims/pull/183)
101
-
102
- ES Module Shims 0.13.1 (2021/09/10)
103
- * Fix to ensure global script errors always propagate to the console (https://github.com/guybedford/es-module-shims/pull/182)
104
-
105
- ES Module Shims 0.13.0 (2021/09/07)
106
- * Breaking Change: Polyfill mode restricts behaviours to native baseline support (https://github.com/guybedford/es-module-shims/pull/173)
107
- * Breaking Change: JSON and CSS modules require explicit enabling (https://github.com/guybedford/es-module-shims/pull/172)
108
- * Breaking Change: Adds the "exports" field to encapsulate the package entry point (https://github.com/guybedford/es-module-shims/pull/177)
109
- * Feature: Support script DOM "load" events (https://github.com/guybedford/es-module-shims/pull/170)
110
- * Improve browser compatibility for Weixin browser (https://github.com/guybedford/es-module-shims/pull/165, @xxgjzftd)
111
- * Fix dynamic import polyfill recursion in Firefox 60 (https://github.com/guybedford/es-module-shims/pull/176)
112
- * Change compat to Edge 17+ (https://github.com/guybedford/es-module-shims/pull/178)
113
-
114
- ES Module Shims 0.12.8 (2021/08/24)
115
- * Fix preload deduping for re-injection of preloads (https://github.com/guybedford/es-module-shims/pull/164)
116
-
117
- ES Module Shims 0.12.7 (2021/08/23)
118
- * Support re-triggering DOM load events for static script executions (https://github.com/guybedford/es-module-shims/pull/162)
119
-
120
- ES Module Shims 0.12.6 (2021/08/20)
121
- * Fix regression where inline scripts in polyfill mode on supported browsers would throw an unnecessary error (https://github.com/guybedford/es-module-shims/pull/159)
122
-
123
- ES Module Shims 0.12.5 (2021/08/19)
124
- * Support CSS module scripts (https://github.com/guybedford/es-module-shims/pull/154)
125
-
126
- ES Module Shims 0.12.4 (2021/08/18)
127
- * Fix eager modulepreload preloading bug from 0.12.3 (https://github.com/guybedford/es-module-shims/pull/152)
128
-
129
- ES Module Shims 0.12.3 (2021/08/17)
130
- * Support resolve hook (https://github.com/guybedford/es-module-shims/pull/146, @zhoukekestar)
131
- * Internal preload cache to avoid double network requests (https://github.com/guybedford/es-module-shims/pull/149)
132
-
133
- ES Module Shims 0.12.2 (2021/07/23)
134
- * Support processing nested tags in mutaton observer (https://github.com/guybedford/es-module-shims/pull/144, @dbackeus)
135
-
136
- ES Module SHims 0.12.1 (2021/06/29)
137
- * Fixup dynamic injection of modulepreload (f231485)
138
-
139
- ES Module Shims 0.12.0 (2021/06/29)
140
- * Support modulepreload polyfilling (https://github.com/guybedford/es-module-shims/pull/141)
141
-
142
- ES Module Shims 0.11.1 (2021/06/17)
143
- * Fixup replacement offset regression (https://github.com/guybedford/es-module-shims/pull/140)
144
-
145
- ES Module Shims 0.11.0 (2021/06/15)
146
- * Support for JSON modules and import assertions (https://github.com/guybedford/es-module-shims/commit/2d7eb193986d51733fa6394ad699ee70e5060a13)
147
- * Fix dynamic import bug in Firefox <67 (https://github.com/guybedford/es-module-shims/commit/3f3d71fc3dd76ba1a965ae00285823672f34c138)
148
-
149
- ES Module Shims 0.10.7 (2021/06/10)
150
- * Fix import map feature detection in Safari (https://github.com/guybedford/es-module-shims/pull/131, @heypiotr)
151
-
152
- ES Module Shims 0.10.6 (2021/06/05)
153
- * Support for revoking blob URLs (https://github.com/guybedford/es-module-shims/pull/124, @vovacodes)
154
- * Include typescript types in published package (https://github.com/guybedford/es-module-shims/pull/125, @vovacodes)
155
- * Fix support for dynamic import in inline scripts (https://github.com/guybedford/es-module-shims/pull/128)
156
- * Polyfill bug fixes (https://github.com/guybedford/es-module-shims/pull/130)
157
-
158
- ES Module Shims 0.10.5 (2021/05/14)
159
- * Fix immediately added dynamic import maps (https://github.com/guybedford/es-module-shims/pull/123, @vovacodes)
160
- * Handle relative sourceURL and sourceMappingURL (https://github.com/guybedford/es-module-shims/pull/122, @vovacodes)
161
-
162
- ES Module Shims 0.10.4 (2021/04/11)
163
- * Fix cycle handling regression (https://github.com/guybedford/es-module-shims/issues/119)
164
-
165
- ES Module Shims 0.10.3 (2021/03/22)
166
- * Fix shim mode execution bug (https://github.com/guybedford/es-module-shims/issues/117)
167
-
168
- ES Module Shims 0.10.2 (2021/03/18)
169
- * Fix inline module-shim execution in non-polyfill mode (https://github.com/guybedford/es-module-shims/issues/115)
170
- * Bug fix for scope key resolution to be relative to baseURL not scopeURL (https://github.com/guybedford/es-module-shims/pull/116)
171
-
172
- ES Module Shims 0.10.1 (2021/02/27)
173
- * Various bug fixes for polyfill mode
174
-
175
- ES Module Shims 0.10.0 (2021/02/27)
176
- * Feature: Comprehensive polyfill mode (https://github.com/guybedford/es-module-shims/pull/113)
177
-
178
- ES Module Shims 0.9.0 (2021/01/23)
179
- * Breaking: New initialOptions global API instead of hooking importShims properties (https://github.com/guybedford/es-module-shims/pull/109, @lewisl9029)
180
- * Fix inline script double execution issue (https://github.com/guybedford/es-module-shims/pull/111)
181
-
182
- ES Module Shims 0.8.0 (2020/12/23)
183
- * Fix URL to URL import map mappings (https://github.com/guybedford/es-module-shims/pull/107, @vovacodes)
184
- * Include TypeScript types (https://github.com/guybedford/es-module-shims/pull/104, @ifiokjr)
185
- * Fix processScripts to permit dynamic additions (https://github.com/guybedford/es-module-shims/pull/102, @ifiokjr)
186
- * Remove unnecessary sourceMappingURL rebase (https://github.com/guybedford/es-module-shims/pull/98)
187
-
188
- ES Module Shims 0.7.1 (2020/10/30)
189
- * Update to es-module-shims@0.3.26
190
- * Fixup onerror hook to throw by default (#96)
191
-
192
- ES Module Shims 0.7.0 (2020/10/06)
193
- * Process scripts in order, global importShims.onerror hook (a3e3f639e835d6)
194
-
195
- ES Module Shims 0.6.0 (2020/09/17)
196
- * Resolve scopes to the baseURL not the scopeURL (d2893159e4b66c43)
197
-
198
- ES Module Shims 0.5.2 (2020/08/07)
199
- * import.meta.resolve (https://github.com/guybedford/es-module-shims/pull/89)
200
-
201
- ES Module Shims 0.5.0 (2020/07/24)
202
- * Dynamic import map support (https://github.com/guybedford/es-module-shims/pull/85)
203
- * Remove support for array fallbacks, builtin modules, workers, CSS modules, JSON modules, Wasm modules (https://github.com/guybedford/es-module-shims/pull/84)
204
- * Depcache implementation (https://github.com/guybedford/es-module-shims/pull/78)
205
-
206
- ES Module Shims 0.4.6 (2019/10/21)
207
- * Implement fetch hook (https://github.com/guybedford/es-module-shims/pull/73)
208
-
209
- ES Module Shims 0.4.5 (2019/09/18)
210
- * Fixup incorrect pageBaseUrl reference (7391880e836712)
211
- * Fixup hasDocument check for Firefox (https://github.com/guybedford/es-module-shims/issues/62)
212
-
213
- ES Module Shims 0.4.4 (2019/09/09)
214
- * Fix to ensure build against latest es-module-lexer
215
-
216
- ES Module Shims 0.4.3 (2019/09/08)
217
- * Remove unnecessary Object.assign polyfill (https://github.com/guybedford/es-module-shims/commit/6bc90c059377e254e71b6695368215ce6ebff7d7)
218
- * Rework standard module detection (https://github.com/guybedford/es-module-shims/pull/62)
219
-
220
- ES Module Shims 0.4.2 (2019/08/31)
221
- * Fixes a critical Edge bug with parallel execution using a graph inlining to ensure execution order (https://github.com/guybedford/es-module-shims/pull/57, https://github.com/microsoft/ChakraCore/issues/6261)
222
- * `x-javascript` MIME type support (https://github.com/guybedford/es-module-shims/pull/56)
223
-
224
- ES Module Shims 0.4.1 (2019/08/30)
225
- * Support text/javascript MIME type (https://github.com/guybedford/es-module-shims/pull/53)
226
-
227
- ES Module Shims 0.4.0 (2019/08/29)
228
- * Support for cascading import maps (https://github.com/guybedford/es-module-shims/pull/49)
229
- * Use strict Content-Type checks for modules (https://github.com/guybedford/es-module-shims/pull/47)
230
-
231
- ES Module Shims 0.3.2 (2019/08/29)
232
- * Update to ES module lexer 0.3.12
233
-
234
- ES Module Shims 0.3.1 (2019/08/28)
235
- * Updates to ES module lexer 0.3.11 including better errors and invalid syntax handling (https://github.com/guybedford/es-module-shims/pull/46)
236
-
237
- ES Module Shims 0.3.0 (2019/08/25)
238
- * Implement CSS modules (https://github.com/guybedford/es-module-shims/pull/41)
239
- * Upgrade to Wasm-based ES module lexer for performance (https://github.com/guybedford/es-module-shims/38)
240
- * Fix sourceMappingURL support in Firefox (https://github.com/guybedford/es-module-shims/pull/37, @MicahZoltu)
241
- * Separate ES module lexer into its own project (https://github.com/guybedford/es-module-shims/pull/36, @LarsDenBakker)
242
-
243
- ES Module Shims 0.2.15 (2019/07/28)
244
- * Early import map resolution (https://github.com/guybedford/es-module-shims/pull/32)
245
-
246
- ES Module Shims 0.2.14 (2019/07/17)
247
- * Support import map fallbacks by ignoring std modules (https://github.com/guybedford/es-module-shims/pull/28, @thepassle)
248
- * Support path separators in module URLs containing hashes and query strings (https://github.com/guybedford/es-module-shims/pull/30, @LarsDenBakker)
249
-
250
- ES Module Shims 0.2.13 (2019/06/29)
251
- * Support JSON module imports (https://github.com/guybedford/es-module-shims/pull/27)
252
-
253
- ES Module Shims 0.2.12 (2019/06/29)
254
- * Support `<base>` tag for baseURL (https://github.com/guybedford/es-module-shims/pull/26, @LarsDenBakker)
255
-
256
- ES Module Shims 0.2.11 (2019/06/26)
257
- * Fix use of object spread in Edge (https://github.com/guybedford/es-module-shims/pull/25, @LarsDenBakker)
258
-
259
- ES Module Shims 0.2.10 (2019/06/25)
260
- * Fix Worker constructor options bug (https://github.com/guybedford/es-module-shims/pull/23)
261
-
262
- ES Module Shims 0.2.9 (2019/06/24)
263
- * Fixup WorkerShim worker output
264
-
265
- ES Module Shims 0.2.8 (2019/06/24)
266
- * Support WorkerShim module workers (https://github.com/guybedford/es-module-shims/pull/17 by @costingeana)
267
-
268
- ES Module Shims 0.2.7 (2019/05/04)
269
- * Fix imports minification case (https://github.com/guybedford/es-module-shims/issues/11)
270
-
271
- ES Module Shims 0.2.6 (2019/04/30)
272
- * Fixup dynamic import regression
273
-
274
- ES Module Shims 0.2.5 (2019/04/30)
275
- * Fix various lexing edge cases around dynamic import
276
-
277
- ES Module Shims 0.2.4
278
- * Add "type": "module" to package.json
279
-
280
- ES Module Shims 0.2.3 (2019/03/29)
281
- * Fixup minification build
282
- * Further lexer adjustments (2ca2589b1)
283
-
284
- ES Module Shims 0.2.2 (2019/03/28)
285
- * Fixup export syntax parser bug (51396799)
286
-
287
- ES Module Shims 0.2.1 (2019/02/25)
288
- * Fix support for URL imports
289
-
290
- ES Module Shims 0.2.0 (2019/01/12)
291
- * Update to latest import maps spec (e6e64748)
292
-
293
- ES Module Shims 0.1.15 (2018/10/09)
294
- * Use responseURL for resolution for spec compliant redirects (689aed0)
295
-
296
- ES Module Shims 0.1.14 (2018/10/06)
297
- * Fix Safari WASM support (7cf31ac4)
298
- * add sourceURL to cycle shells for debugging (80438731)