es-module-shims 2.0.5 → 2.0.7
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 +2 -2
- package/dist/es-module-shims-typescript.js +246 -272
- package/dist/es-module-shims.debug.js +135 -107
- package/dist/es-module-shims.js +135 -107
- package/dist/es-module-shims.wasm.js +135 -107
- package/package.json +2 -2
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
/* ES Module Shims 2.0.
|
|
1
|
+
/* ES Module Shims 2.0.7 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
|
-
const hasDocument = typeof document !== 'undefined';
|
|
5
|
-
|
|
6
|
-
const noop = () => {};
|
|
7
|
-
|
|
8
|
-
const dynamicImport = (u, errUrl) => import(u);
|
|
9
|
-
|
|
10
|
-
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
11
|
-
|
|
12
|
-
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
13
|
-
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
14
|
-
|
|
15
|
-
// shim mode is determined on initialization, no late shim mode
|
|
16
|
-
const shimMode =
|
|
17
|
-
hasDocument ?
|
|
18
|
-
esmsInitOptions.shimMode ||
|
|
19
|
-
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
20
|
-
.length > 0
|
|
21
|
-
: true;
|
|
22
|
-
|
|
23
|
-
const importHook = globalHook(shimMode && esmsInitOptions.onimport);
|
|
24
|
-
const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
|
|
25
|
-
let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
26
|
-
const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
|
|
27
|
-
const tsTransform =
|
|
28
|
-
esmsInitOptions.tsTransform ||
|
|
29
|
-
(document.currentScript &&
|
|
30
|
-
document.currentScript.src.replace(/\.debug\.js$/ , '-typescript.js')) ||
|
|
31
|
-
'./es-module-shims-typescript.js';
|
|
32
|
-
|
|
33
|
-
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
34
|
-
|
|
35
|
-
let nonce = esmsInitOptions.nonce;
|
|
36
|
-
if (!nonce && hasDocument) {
|
|
37
|
-
const nonceElement = document.querySelector('script[nonce]');
|
|
38
|
-
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
42
|
-
|
|
43
|
-
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
44
|
-
|
|
45
|
-
function globalHook(name) {
|
|
46
|
-
return typeof name === 'string' ? self[name] : name;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
50
|
-
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
51
|
-
const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
|
|
52
|
-
const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
|
|
53
|
-
const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
|
|
54
|
-
const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
|
|
55
|
-
const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
|
|
56
|
-
const typescriptEnabled = enable.includes('typescript') || enableAll;
|
|
57
|
-
|
|
58
|
-
const onpolyfill =
|
|
59
|
-
esmsInitOptions.onpolyfill ?
|
|
60
|
-
globalHook(esmsInitOptions.onpolyfill)
|
|
61
|
-
: () => {
|
|
62
|
-
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const baseUrl =
|
|
66
|
-
hasDocument ?
|
|
67
|
-
document.baseURI
|
|
68
|
-
: `${location.protocol}//${location.host}${
|
|
69
|
-
location.pathname.includes('/') ?
|
|
70
|
-
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
71
|
-
: location.pathname
|
|
72
|
-
}`;
|
|
73
|
-
|
|
74
|
-
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
75
|
-
let { skip } = esmsInitOptions;
|
|
76
|
-
if (Array.isArray(skip)) {
|
|
77
|
-
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
78
|
-
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
79
|
-
} else if (typeof skip === 'string') {
|
|
80
|
-
const r = new RegExp(skip);
|
|
81
|
-
skip = s => r.test(s);
|
|
82
|
-
} else if (skip instanceof RegExp) {
|
|
83
|
-
skip = s => skip.test(s);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
87
|
-
|
|
88
|
-
const throwError = err => {
|
|
89
|
-
(self.reportError || dispatchError)(err), void onerror(err);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
function fromParent(parent) {
|
|
93
|
-
return parent ? ` imported from ${parent}` : '';
|
|
4
|
+
const hasDocument = typeof document !== 'undefined';
|
|
5
|
+
|
|
6
|
+
const noop = () => {};
|
|
7
|
+
|
|
8
|
+
const dynamicImport = (u, errUrl) => import(u);
|
|
9
|
+
|
|
10
|
+
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
11
|
+
|
|
12
|
+
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
13
|
+
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
14
|
+
|
|
15
|
+
// shim mode is determined on initialization, no late shim mode
|
|
16
|
+
const shimMode =
|
|
17
|
+
hasDocument ?
|
|
18
|
+
esmsInitOptions.shimMode ||
|
|
19
|
+
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
20
|
+
.length > 0
|
|
21
|
+
: true;
|
|
22
|
+
|
|
23
|
+
const importHook = globalHook(shimMode && esmsInitOptions.onimport);
|
|
24
|
+
const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
|
|
25
|
+
let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
26
|
+
const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
|
|
27
|
+
const tsTransform =
|
|
28
|
+
esmsInitOptions.tsTransform ||
|
|
29
|
+
(document.currentScript &&
|
|
30
|
+
document.currentScript.src.replace(/\.debug\.js$/ , '-typescript.js')) ||
|
|
31
|
+
'./es-module-shims-typescript.js';
|
|
32
|
+
|
|
33
|
+
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
34
|
+
|
|
35
|
+
let nonce = esmsInitOptions.nonce;
|
|
36
|
+
if (!nonce && hasDocument) {
|
|
37
|
+
const nonceElement = document.querySelector('script[nonce]');
|
|
38
|
+
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
42
|
+
|
|
43
|
+
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
44
|
+
|
|
45
|
+
function globalHook(name) {
|
|
46
|
+
return typeof name === 'string' ? self[name] : name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
50
|
+
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
51
|
+
const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
|
|
52
|
+
const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
|
|
53
|
+
const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
|
|
54
|
+
const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
|
|
55
|
+
const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
|
|
56
|
+
const typescriptEnabled = enable.includes('typescript') || enableAll;
|
|
57
|
+
|
|
58
|
+
const onpolyfill =
|
|
59
|
+
esmsInitOptions.onpolyfill ?
|
|
60
|
+
globalHook(esmsInitOptions.onpolyfill)
|
|
61
|
+
: () => {
|
|
62
|
+
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const baseUrl =
|
|
66
|
+
hasDocument ?
|
|
67
|
+
document.baseURI
|
|
68
|
+
: `${location.protocol}//${location.host}${
|
|
69
|
+
location.pathname.includes('/') ?
|
|
70
|
+
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
71
|
+
: location.pathname
|
|
72
|
+
}`;
|
|
73
|
+
|
|
74
|
+
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
75
|
+
let { skip } = esmsInitOptions;
|
|
76
|
+
if (Array.isArray(skip)) {
|
|
77
|
+
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
78
|
+
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
79
|
+
} else if (typeof skip === 'string') {
|
|
80
|
+
const r = new RegExp(skip);
|
|
81
|
+
skip = s => r.test(s);
|
|
82
|
+
} else if (skip instanceof RegExp) {
|
|
83
|
+
skip = s => skip.test(s);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
87
|
+
|
|
88
|
+
const throwError = err => {
|
|
89
|
+
(self.reportError || dispatchError)(err), void onerror(err);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function fromParent(parent) {
|
|
93
|
+
return parent ? ` imported from ${parent}` : '';
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const backslashRegEx = /\\/g;
|
|
@@ -462,17 +462,18 @@
|
|
|
462
462
|
}
|
|
463
463
|
// we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
|
|
464
464
|
// because we can't syntactically pass through to dynamic import with a second argument in this libarary
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
465
|
+
let url = await importHandler(id, opts, parentUrl, false);
|
|
466
|
+
let source = null;
|
|
467
|
+
if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
|
|
468
|
+
source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
|
|
469
|
+
url += '?entry';
|
|
470
|
+
}
|
|
471
|
+
return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
|
|
471
472
|
}
|
|
472
473
|
|
|
473
474
|
// import.source()
|
|
474
475
|
// (opts not currently supported as no use cases yet)
|
|
475
|
-
if (sourcePhaseEnabled)
|
|
476
|
+
if (shimMode || sourcePhaseEnabled)
|
|
476
477
|
importShim.source = async function importShimSource(specifier, opts, parentUrl) {
|
|
477
478
|
if (typeof opts === 'string') {
|
|
478
479
|
parentUrl = opts;
|
|
@@ -545,7 +546,12 @@
|
|
|
545
546
|
(!multipleImportMaps || supportsMultipleImportMaps) &&
|
|
546
547
|
!importMapSrc &&
|
|
547
548
|
!typescriptEnabled;
|
|
548
|
-
if (
|
|
549
|
+
if (
|
|
550
|
+
!shimMode &&
|
|
551
|
+
sourcePhaseEnabled &&
|
|
552
|
+
typeof WebAssembly !== 'undefined' &&
|
|
553
|
+
!Object.getPrototypeOf(WebAssembly.Module).name
|
|
554
|
+
) {
|
|
549
555
|
const s = Symbol();
|
|
550
556
|
const brand = m =>
|
|
551
557
|
Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
|
|
@@ -888,6 +894,10 @@
|
|
|
888
894
|
}
|
|
889
895
|
|
|
890
896
|
let esmsTsTransform;
|
|
897
|
+
async function initTs() {
|
|
898
|
+
const m = await import(tsTransform);
|
|
899
|
+
if (!esmsTsTransform) esmsTsTransform = m.transform;
|
|
900
|
+
}
|
|
891
901
|
|
|
892
902
|
async function fetchModule(url, fetchOpts, parent) {
|
|
893
903
|
const mapIntegrity = composedImportMap.integrity[url];
|
|
@@ -928,12 +938,12 @@
|
|
|
928
938
|
)});export default s;`,
|
|
929
939
|
t: 'css'
|
|
930
940
|
};
|
|
931
|
-
} else if (
|
|
941
|
+
} else if (
|
|
942
|
+
(shimMode || typescriptEnabled) &&
|
|
943
|
+
(tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
|
|
944
|
+
) {
|
|
932
945
|
const source = await res.text();
|
|
933
|
-
|
|
934
|
-
if (!esmsTsTransform) {
|
|
935
|
-
({ transform: esmsTsTransform } = await import(tsTransform));
|
|
936
|
-
}
|
|
946
|
+
if (!esmsTsTransform) await initTs();
|
|
937
947
|
const transformed = esmsTsTransform(source, url);
|
|
938
948
|
return { r, s: transformed || source, t: transformed ? 'ts' : 'js' };
|
|
939
949
|
} else
|
|
@@ -1023,12 +1033,16 @@
|
|
|
1023
1033
|
load.L = load.f.then(async () => {
|
|
1024
1034
|
let childFetchOpts = fetchOpts;
|
|
1025
1035
|
load.d = load.a[0]
|
|
1026
|
-
.map(({ n, d, t }) => {
|
|
1036
|
+
.map(({ n, d, t, a }) => {
|
|
1027
1037
|
const sourcePhase = t >= 4;
|
|
1028
1038
|
if (sourcePhase) {
|
|
1029
|
-
if (!sourcePhaseEnabled) throw featErr('source-phase');
|
|
1039
|
+
if (!shimMode && !sourcePhaseEnabled) throw featErr('source-phase');
|
|
1030
1040
|
if (!supportsSourcePhase) load.n = true;
|
|
1031
1041
|
}
|
|
1042
|
+
if (a > 0) {
|
|
1043
|
+
if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
|
|
1044
|
+
if (!supportsCssType && !supportsJsonType) load.n = true;
|
|
1045
|
+
}
|
|
1032
1046
|
if (d !== -1 || !n) return;
|
|
1033
1047
|
const resolved = resolve(n, load.r || load.u);
|
|
1034
1048
|
if (resolved.n) load.n = true;
|
|
@@ -1137,7 +1151,7 @@
|
|
|
1137
1151
|
if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
|
|
1138
1152
|
if (!legacyAcceptingImportMaps && !multipleImportMaps) {
|
|
1139
1153
|
multipleImportMaps = true;
|
|
1140
|
-
if (baselinePassthrough && !supportsMultipleImportMaps) {
|
|
1154
|
+
if (!shimMode && baselinePassthrough && !supportsMultipleImportMaps) {
|
|
1141
1155
|
console.info(`es-module-shims: disabling baseline passthrough due to multiple import maps`);
|
|
1142
1156
|
baselinePassthrough = false;
|
|
1143
1157
|
if (hasDocument) attachMutationObserver();
|
|
@@ -1148,6 +1162,20 @@
|
|
|
1148
1162
|
|
|
1149
1163
|
function processScript(script, ready = readyStateCompleteCnt > 0) {
|
|
1150
1164
|
if (epCheck(script, ready)) return;
|
|
1165
|
+
if (script.lang === 'ts' && !script.src) {
|
|
1166
|
+
const source = script.innerHTML;
|
|
1167
|
+
return initTs()
|
|
1168
|
+
.then(() =>
|
|
1169
|
+
topLevelLoad(
|
|
1170
|
+
baseUrl,
|
|
1171
|
+
getFetchOpts(script),
|
|
1172
|
+
esmsTsTransform(source, baseUrl) || source,
|
|
1173
|
+
undefined,
|
|
1174
|
+
undefined
|
|
1175
|
+
)
|
|
1176
|
+
)
|
|
1177
|
+
.catch(throwError);
|
|
1178
|
+
}
|
|
1151
1179
|
console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
|
|
1152
1180
|
// does this load block readystate complete
|
|
1153
1181
|
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
/* ES Module Shims 2.0.
|
|
1
|
+
/* ES Module Shims 2.0.7 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
|
-
const hasDocument = typeof document !== 'undefined';
|
|
5
|
-
|
|
6
|
-
const noop = () => {};
|
|
7
|
-
|
|
8
|
-
const dynamicImport = (u, errUrl) => import(u);
|
|
9
|
-
|
|
10
|
-
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
11
|
-
|
|
12
|
-
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
13
|
-
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
14
|
-
|
|
15
|
-
// shim mode is determined on initialization, no late shim mode
|
|
16
|
-
const shimMode =
|
|
17
|
-
hasDocument ?
|
|
18
|
-
esmsInitOptions.shimMode ||
|
|
19
|
-
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
20
|
-
.length > 0
|
|
21
|
-
: true;
|
|
22
|
-
|
|
23
|
-
const importHook = globalHook(shimMode && esmsInitOptions.onimport);
|
|
24
|
-
const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
|
|
25
|
-
let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
26
|
-
const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
|
|
27
|
-
const tsTransform =
|
|
28
|
-
esmsInitOptions.tsTransform ||
|
|
29
|
-
(document.currentScript &&
|
|
30
|
-
document.currentScript.src.replace(/\.js$/, '-typescript.js')) ||
|
|
31
|
-
'./es-module-shims-typescript.js';
|
|
32
|
-
|
|
33
|
-
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
34
|
-
|
|
35
|
-
let nonce = esmsInitOptions.nonce;
|
|
36
|
-
if (!nonce && hasDocument) {
|
|
37
|
-
const nonceElement = document.querySelector('script[nonce]');
|
|
38
|
-
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
42
|
-
|
|
43
|
-
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
44
|
-
|
|
45
|
-
function globalHook(name) {
|
|
46
|
-
return typeof name === 'string' ? self[name] : name;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
50
|
-
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
51
|
-
const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
|
|
52
|
-
const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
|
|
53
|
-
const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
|
|
54
|
-
const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
|
|
55
|
-
const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
|
|
56
|
-
const typescriptEnabled = enable.includes('typescript') || enableAll;
|
|
57
|
-
|
|
58
|
-
const onpolyfill =
|
|
59
|
-
esmsInitOptions.onpolyfill ?
|
|
60
|
-
globalHook(esmsInitOptions.onpolyfill)
|
|
61
|
-
: () => {
|
|
62
|
-
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const baseUrl =
|
|
66
|
-
hasDocument ?
|
|
67
|
-
document.baseURI
|
|
68
|
-
: `${location.protocol}//${location.host}${
|
|
69
|
-
location.pathname.includes('/') ?
|
|
70
|
-
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
71
|
-
: location.pathname
|
|
72
|
-
}`;
|
|
73
|
-
|
|
74
|
-
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
75
|
-
let { skip } = esmsInitOptions;
|
|
76
|
-
if (Array.isArray(skip)) {
|
|
77
|
-
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
78
|
-
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
79
|
-
} else if (typeof skip === 'string') {
|
|
80
|
-
const r = new RegExp(skip);
|
|
81
|
-
skip = s => r.test(s);
|
|
82
|
-
} else if (skip instanceof RegExp) {
|
|
83
|
-
skip = s => skip.test(s);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
87
|
-
|
|
88
|
-
const throwError = err => {
|
|
89
|
-
(self.reportError || dispatchError)(err), void onerror(err);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
function fromParent(parent) {
|
|
93
|
-
return parent ? ` imported from ${parent}` : '';
|
|
4
|
+
const hasDocument = typeof document !== 'undefined';
|
|
5
|
+
|
|
6
|
+
const noop = () => {};
|
|
7
|
+
|
|
8
|
+
const dynamicImport = (u, errUrl) => import(u);
|
|
9
|
+
|
|
10
|
+
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
11
|
+
|
|
12
|
+
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
13
|
+
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
14
|
+
|
|
15
|
+
// shim mode is determined on initialization, no late shim mode
|
|
16
|
+
const shimMode =
|
|
17
|
+
hasDocument ?
|
|
18
|
+
esmsInitOptions.shimMode ||
|
|
19
|
+
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
20
|
+
.length > 0
|
|
21
|
+
: true;
|
|
22
|
+
|
|
23
|
+
const importHook = globalHook(shimMode && esmsInitOptions.onimport);
|
|
24
|
+
const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
|
|
25
|
+
let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
26
|
+
const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
|
|
27
|
+
const tsTransform =
|
|
28
|
+
esmsInitOptions.tsTransform ||
|
|
29
|
+
(document.currentScript &&
|
|
30
|
+
document.currentScript.src.replace(/\.js$/, '-typescript.js')) ||
|
|
31
|
+
'./es-module-shims-typescript.js';
|
|
32
|
+
|
|
33
|
+
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
34
|
+
|
|
35
|
+
let nonce = esmsInitOptions.nonce;
|
|
36
|
+
if (!nonce && hasDocument) {
|
|
37
|
+
const nonceElement = document.querySelector('script[nonce]');
|
|
38
|
+
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
42
|
+
|
|
43
|
+
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
44
|
+
|
|
45
|
+
function globalHook(name) {
|
|
46
|
+
return typeof name === 'string' ? self[name] : name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
50
|
+
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
51
|
+
const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
|
|
52
|
+
const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
|
|
53
|
+
const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
|
|
54
|
+
const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
|
|
55
|
+
const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
|
|
56
|
+
const typescriptEnabled = enable.includes('typescript') || enableAll;
|
|
57
|
+
|
|
58
|
+
const onpolyfill =
|
|
59
|
+
esmsInitOptions.onpolyfill ?
|
|
60
|
+
globalHook(esmsInitOptions.onpolyfill)
|
|
61
|
+
: () => {
|
|
62
|
+
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const baseUrl =
|
|
66
|
+
hasDocument ?
|
|
67
|
+
document.baseURI
|
|
68
|
+
: `${location.protocol}//${location.host}${
|
|
69
|
+
location.pathname.includes('/') ?
|
|
70
|
+
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
71
|
+
: location.pathname
|
|
72
|
+
}`;
|
|
73
|
+
|
|
74
|
+
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
75
|
+
let { skip } = esmsInitOptions;
|
|
76
|
+
if (Array.isArray(skip)) {
|
|
77
|
+
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
78
|
+
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
79
|
+
} else if (typeof skip === 'string') {
|
|
80
|
+
const r = new RegExp(skip);
|
|
81
|
+
skip = s => r.test(s);
|
|
82
|
+
} else if (skip instanceof RegExp) {
|
|
83
|
+
skip = s => skip.test(s);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
87
|
+
|
|
88
|
+
const throwError = err => {
|
|
89
|
+
(self.reportError || dispatchError)(err), void onerror(err);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function fromParent(parent) {
|
|
93
|
+
return parent ? ` imported from ${parent}` : '';
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const backslashRegEx = /\\/g;
|
|
@@ -453,17 +453,18 @@
|
|
|
453
453
|
}
|
|
454
454
|
// we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
|
|
455
455
|
// because we can't syntactically pass through to dynamic import with a second argument in this libarary
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
456
|
+
let url = await importHandler(id, opts, parentUrl);
|
|
457
|
+
let source = null;
|
|
458
|
+
if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
|
|
459
|
+
source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
|
|
460
|
+
url += '?entry';
|
|
461
|
+
}
|
|
462
|
+
return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
|
|
462
463
|
}
|
|
463
464
|
|
|
464
465
|
// import.source()
|
|
465
466
|
// (opts not currently supported as no use cases yet)
|
|
466
|
-
if (sourcePhaseEnabled)
|
|
467
|
+
if (shimMode || sourcePhaseEnabled)
|
|
467
468
|
importShim.source = async function importShimSource(specifier, opts, parentUrl) {
|
|
468
469
|
if (typeof opts === 'string') {
|
|
469
470
|
parentUrl = opts;
|
|
@@ -536,7 +537,12 @@
|
|
|
536
537
|
(!multipleImportMaps || supportsMultipleImportMaps) &&
|
|
537
538
|
!importMapSrc &&
|
|
538
539
|
!typescriptEnabled;
|
|
539
|
-
if (
|
|
540
|
+
if (
|
|
541
|
+
!shimMode &&
|
|
542
|
+
sourcePhaseEnabled &&
|
|
543
|
+
typeof WebAssembly !== 'undefined' &&
|
|
544
|
+
!Object.getPrototypeOf(WebAssembly.Module).name
|
|
545
|
+
) {
|
|
540
546
|
const s = Symbol();
|
|
541
547
|
const brand = m =>
|
|
542
548
|
Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
|
|
@@ -873,6 +879,10 @@
|
|
|
873
879
|
}
|
|
874
880
|
|
|
875
881
|
let esmsTsTransform;
|
|
882
|
+
async function initTs() {
|
|
883
|
+
const m = await import(tsTransform);
|
|
884
|
+
if (!esmsTsTransform) esmsTsTransform = m.transform;
|
|
885
|
+
}
|
|
876
886
|
|
|
877
887
|
async function fetchModule(url, fetchOpts, parent) {
|
|
878
888
|
const mapIntegrity = composedImportMap.integrity[url];
|
|
@@ -913,12 +923,12 @@
|
|
|
913
923
|
)});export default s;`,
|
|
914
924
|
t: 'css'
|
|
915
925
|
};
|
|
916
|
-
} else if (
|
|
926
|
+
} else if (
|
|
927
|
+
(shimMode || typescriptEnabled) &&
|
|
928
|
+
(tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
|
|
929
|
+
) {
|
|
917
930
|
const source = await res.text();
|
|
918
|
-
|
|
919
|
-
if (!esmsTsTransform) {
|
|
920
|
-
({ transform: esmsTsTransform } = await import(tsTransform));
|
|
921
|
-
}
|
|
931
|
+
if (!esmsTsTransform) await initTs();
|
|
922
932
|
const transformed = esmsTsTransform(source, url);
|
|
923
933
|
return { r, s: transformed || source, t: transformed ? 'ts' : 'js' };
|
|
924
934
|
} else
|
|
@@ -1008,12 +1018,16 @@
|
|
|
1008
1018
|
load.L = load.f.then(async () => {
|
|
1009
1019
|
let childFetchOpts = fetchOpts;
|
|
1010
1020
|
load.d = load.a[0]
|
|
1011
|
-
.map(({ n, d, t }) => {
|
|
1021
|
+
.map(({ n, d, t, a }) => {
|
|
1012
1022
|
const sourcePhase = t >= 4;
|
|
1013
1023
|
if (sourcePhase) {
|
|
1014
|
-
if (!sourcePhaseEnabled) throw featErr('source-phase');
|
|
1024
|
+
if (!shimMode && !sourcePhaseEnabled) throw featErr('source-phase');
|
|
1015
1025
|
if (!supportsSourcePhase) load.n = true;
|
|
1016
1026
|
}
|
|
1027
|
+
if (a > 0) {
|
|
1028
|
+
if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
|
|
1029
|
+
if (!supportsCssType && !supportsJsonType) load.n = true;
|
|
1030
|
+
}
|
|
1017
1031
|
if (d !== -1 || !n) return;
|
|
1018
1032
|
const resolved = resolve(n, load.r || load.u);
|
|
1019
1033
|
if (resolved.n) load.n = true;
|
|
@@ -1118,7 +1132,7 @@
|
|
|
1118
1132
|
if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
|
|
1119
1133
|
if (!legacyAcceptingImportMaps && !multipleImportMaps) {
|
|
1120
1134
|
multipleImportMaps = true;
|
|
1121
|
-
if (baselinePassthrough && !supportsMultipleImportMaps) {
|
|
1135
|
+
if (!shimMode && baselinePassthrough && !supportsMultipleImportMaps) {
|
|
1122
1136
|
baselinePassthrough = false;
|
|
1123
1137
|
if (hasDocument) attachMutationObserver();
|
|
1124
1138
|
}
|
|
@@ -1128,6 +1142,20 @@
|
|
|
1128
1142
|
|
|
1129
1143
|
function processScript(script, ready = readyStateCompleteCnt > 0) {
|
|
1130
1144
|
if (epCheck(script, ready)) return;
|
|
1145
|
+
if (script.lang === 'ts' && !script.src) {
|
|
1146
|
+
const source = script.innerHTML;
|
|
1147
|
+
return initTs()
|
|
1148
|
+
.then(() =>
|
|
1149
|
+
topLevelLoad(
|
|
1150
|
+
baseUrl,
|
|
1151
|
+
getFetchOpts(script),
|
|
1152
|
+
esmsTsTransform(source, baseUrl) || source,
|
|
1153
|
+
undefined,
|
|
1154
|
+
undefined
|
|
1155
|
+
)
|
|
1156
|
+
)
|
|
1157
|
+
.catch(throwError);
|
|
1158
|
+
}
|
|
1131
1159
|
// does this load block readystate complete
|
|
1132
1160
|
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
1133
1161
|
// does this load block DOMContentLoaded
|