es-module-shims 1.5.4 → 1.5.5
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 +3 -1
- package/dist/es-module-shims.js +28 -18
- package/dist/es-module-shims.wasm.js +28 -18
- package/package.json +1 -1
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.
|
|
32
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.5/dist/es-module-shims.js"></script>
|
|
33
33
|
|
|
34
34
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
35
35
|
<script type="importmap">
|
|
@@ -675,6 +675,8 @@ window.polyfilling = () => console.log('The polyfill is actively applying');
|
|
|
675
675
|
|
|
676
676
|
The default hook will log a message to the console with `console.info` noting that polyfill mode is enabled and that the native error can be ignored.
|
|
677
677
|
|
|
678
|
+
Overriding this hook with an empty function will disable the default polyfill log output.
|
|
679
|
+
|
|
678
680
|
In the above, running in latest Chromium browsers, nothing will be logged, while running in an older browser that does not support newer features like import maps the console log will be output.
|
|
679
681
|
|
|
680
682
|
#### Error hook
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims 1.5.
|
|
1
|
+
/* ES Module Shims 1.5.5 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const noop = () => {};
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
31
|
-
const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () =>
|
|
31
|
+
const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => {
|
|
32
|
+
console.log('%c^^ Module TypeError above is polyfilled and can be ignored ^^', 'font-weight:900;color:#391');
|
|
33
|
+
};
|
|
32
34
|
|
|
33
35
|
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
34
36
|
|
|
@@ -285,7 +287,7 @@
|
|
|
285
287
|
dynamicImport(createBlob('import.meta')).then(() => supportsImportMeta = true, noop),
|
|
286
288
|
cssModulesEnabled && dynamicImport(createBlob('import"data:text/css,{}"assert{type:"css"}')).then(() => supportsCssAssertions = true, noop),
|
|
287
289
|
jsonModulesEnabled && dynamicImport(createBlob('import"data:text/json,{}"assert{type:"json"}')).then(() => supportsJsonAssertions = true, noop),
|
|
288
|
-
new Promise(resolve => {
|
|
290
|
+
HTMLScriptElement.supports ? supportsImportMaps = HTMLScriptElement.supports('importmap') : new Promise(resolve => {
|
|
289
291
|
self._$s = v => {
|
|
290
292
|
document.head.removeChild(iframe);
|
|
291
293
|
if (v) supportsImportMaps = true;
|
|
@@ -294,6 +296,7 @@
|
|
|
294
296
|
};
|
|
295
297
|
const iframe = document.createElement('iframe');
|
|
296
298
|
iframe.style.display = 'none';
|
|
299
|
+
iframe.setAttribute('nonce', nonce);
|
|
297
300
|
iframe.srcdoc = `<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>`;
|
|
298
301
|
document.head.appendChild(iframe);
|
|
299
302
|
})
|
|
@@ -401,6 +404,10 @@
|
|
|
401
404
|
}
|
|
402
405
|
}
|
|
403
406
|
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
|
+
}
|
|
404
411
|
if (shimMode || !baselinePassthrough) {
|
|
405
412
|
new MutationObserver(mutations => {
|
|
406
413
|
for (const mutation of mutations) {
|
|
@@ -419,6 +426,20 @@
|
|
|
419
426
|
}).observe(document, { childList: true, subtree: true });
|
|
420
427
|
processImportMaps();
|
|
421
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);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
document.addEventListener('readystatechange', readyListener);
|
|
442
|
+
}
|
|
422
443
|
return undefined;
|
|
423
444
|
}
|
|
424
445
|
});
|
|
@@ -760,16 +781,6 @@
|
|
|
760
781
|
});
|
|
761
782
|
|
|
762
783
|
let readyStateCompleteCnt = 1;
|
|
763
|
-
if (document.readyState === 'complete') {
|
|
764
|
-
readyStateCompleteCheck();
|
|
765
|
-
}
|
|
766
|
-
else {
|
|
767
|
-
document.addEventListener('readystatechange', async () => {
|
|
768
|
-
processImportMaps();
|
|
769
|
-
await initPromise;
|
|
770
|
-
readyStateCompleteCheck();
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
784
|
function readyStateCompleteCheck () {
|
|
774
785
|
if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers)
|
|
775
786
|
document.dispatchEvent(new Event('readystatechange'));
|
|
@@ -809,14 +820,13 @@
|
|
|
809
820
|
return;
|
|
810
821
|
script.ep = true;
|
|
811
822
|
// does this load block readystate complete
|
|
812
|
-
const
|
|
823
|
+
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
813
824
|
// does this load block DOMContentLoaded
|
|
814
825
|
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
|
815
|
-
if (
|
|
826
|
+
if (isBlockingReadyScript) readyStateCompleteCnt++;
|
|
816
827
|
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
if (blocks)
|
|
828
|
+
const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isBlockingReadyScript && lastStaticLoadPromise).catch(throwError);
|
|
829
|
+
if (isBlockingReadyScript)
|
|
820
830
|
lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
|
|
821
831
|
if (isDomContentLoadedScript)
|
|
822
832
|
loadPromise.then(domContentLoadedCheck);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 1.5.
|
|
1
|
+
/* ES Module Shims Wasm 1.5.5 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const noop = () => {};
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
31
|
-
const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () =>
|
|
31
|
+
const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => {
|
|
32
|
+
console.log('%c^^ Module TypeError above is polyfilled and can be ignored ^^', 'font-weight:900;color:#391');
|
|
33
|
+
};
|
|
32
34
|
|
|
33
35
|
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
34
36
|
|
|
@@ -283,7 +285,7 @@
|
|
|
283
285
|
dynamicImport(createBlob('import.meta')).then(() => supportsImportMeta = true, noop),
|
|
284
286
|
cssModulesEnabled && dynamicImport(createBlob('import"data:text/css,{}"assert{type:"css"}')).then(() => supportsCssAssertions = true, noop),
|
|
285
287
|
jsonModulesEnabled && dynamicImport(createBlob('import"data:text/json,{}"assert{type:"json"}')).then(() => supportsJsonAssertions = true, noop),
|
|
286
|
-
new Promise(resolve => {
|
|
288
|
+
HTMLScriptElement.supports ? supportsImportMaps = HTMLScriptElement.supports('importmap') : new Promise(resolve => {
|
|
287
289
|
self._$s = v => {
|
|
288
290
|
document.head.removeChild(iframe);
|
|
289
291
|
if (v) supportsImportMaps = true;
|
|
@@ -292,6 +294,7 @@
|
|
|
292
294
|
};
|
|
293
295
|
const iframe = document.createElement('iframe');
|
|
294
296
|
iframe.style.display = 'none';
|
|
297
|
+
iframe.setAttribute('nonce', nonce);
|
|
295
298
|
iframe.srcdoc = `<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>`;
|
|
296
299
|
document.head.appendChild(iframe);
|
|
297
300
|
})
|
|
@@ -399,6 +402,10 @@
|
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
404
|
baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
|
|
405
|
+
if (!supportsImportMaps) {
|
|
406
|
+
const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
|
|
407
|
+
HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
|
|
408
|
+
}
|
|
402
409
|
if (shimMode || !baselinePassthrough) {
|
|
403
410
|
new MutationObserver(mutations => {
|
|
404
411
|
for (const mutation of mutations) {
|
|
@@ -417,6 +424,20 @@
|
|
|
417
424
|
}).observe(document, { childList: true, subtree: true });
|
|
418
425
|
processImportMaps();
|
|
419
426
|
processScriptsAndPreloads();
|
|
427
|
+
if (document.readyState === 'complete') {
|
|
428
|
+
readyStateCompleteCheck();
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
async function readyListener () {
|
|
432
|
+
await initPromise;
|
|
433
|
+
processImportMaps();
|
|
434
|
+
if (document.readyState === 'complete') {
|
|
435
|
+
readyStateCompleteCheck();
|
|
436
|
+
document.removeEventListener('readystatechange', readyListener);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
document.addEventListener('readystatechange', readyListener);
|
|
440
|
+
}
|
|
420
441
|
return init;
|
|
421
442
|
}
|
|
422
443
|
});
|
|
@@ -758,16 +779,6 @@
|
|
|
758
779
|
});
|
|
759
780
|
|
|
760
781
|
let readyStateCompleteCnt = 1;
|
|
761
|
-
if (document.readyState === 'complete') {
|
|
762
|
-
readyStateCompleteCheck();
|
|
763
|
-
}
|
|
764
|
-
else {
|
|
765
|
-
document.addEventListener('readystatechange', async () => {
|
|
766
|
-
processImportMaps();
|
|
767
|
-
await initPromise;
|
|
768
|
-
readyStateCompleteCheck();
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
782
|
function readyStateCompleteCheck () {
|
|
772
783
|
if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers)
|
|
773
784
|
document.dispatchEvent(new Event('readystatechange'));
|
|
@@ -807,14 +818,13 @@
|
|
|
807
818
|
return;
|
|
808
819
|
script.ep = true;
|
|
809
820
|
// does this load block readystate complete
|
|
810
|
-
const
|
|
821
|
+
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
811
822
|
// does this load block DOMContentLoaded
|
|
812
823
|
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
|
813
|
-
if (
|
|
824
|
+
if (isBlockingReadyScript) readyStateCompleteCnt++;
|
|
814
825
|
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
if (blocks)
|
|
826
|
+
const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isBlockingReadyScript && lastStaticLoadPromise).catch(throwError);
|
|
827
|
+
if (isBlockingReadyScript)
|
|
818
828
|
lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
|
|
819
829
|
if (isDomContentLoadedScript)
|
|
820
830
|
loadPromise.then(domContentLoadedCheck);
|