es-module-shims 2.5.0 → 2.6.0
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 +89 -17
- package/dist/es-module-shims.debug.js +239 -248
- package/dist/es-module-shims.js +235 -244
- package/dist/es-module-shims.wasm.js +235 -244
- package/index.d.ts +186 -30
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** ES Module Shims @version 2.
|
|
2
|
-
(function (
|
|
1
|
+
/** ES Module Shims @version 2.6.0 */
|
|
2
|
+
(function () {
|
|
3
3
|
|
|
4
4
|
let invalidate;
|
|
5
5
|
const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
|
|
@@ -23,9 +23,7 @@
|
|
|
23
23
|
hotState.e = typeof source === 'string' ? source : true;
|
|
24
24
|
hotState.t = sourceType;
|
|
25
25
|
};
|
|
26
|
-
const hotMetaHook = (metaObj, url) =>
|
|
27
|
-
metaObj.hot = new Hot(url);
|
|
28
|
-
};
|
|
26
|
+
const hotMetaHook = (metaObj, url) => (metaObj.hot = new Hot(url));
|
|
29
27
|
|
|
30
28
|
const Hot = class Hot {
|
|
31
29
|
constructor(url) {
|
|
@@ -50,10 +48,9 @@
|
|
|
50
48
|
}
|
|
51
49
|
invalidate() {
|
|
52
50
|
const hotState = getHotState(this.url);
|
|
53
|
-
hotState.a = null;
|
|
54
|
-
hotState.A = true;
|
|
51
|
+
hotState.a = hotState.A = null;
|
|
55
52
|
const seen = [this.url];
|
|
56
|
-
|
|
53
|
+
hotState.p.forEach(p => invalidate(p, this.url, seen));
|
|
57
54
|
}
|
|
58
55
|
};
|
|
59
56
|
|
|
@@ -93,26 +90,24 @@
|
|
|
93
90
|
});
|
|
94
91
|
|
|
95
92
|
invalidate = (url, fromUrl, seen = []) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
|
|
93
|
+
const hotState = hotRegistry[url];
|
|
94
|
+
if (!hotState || seen.includes(url)) return false;
|
|
95
|
+
seen.push(url);
|
|
96
|
+
console.info(`es-module-shims: hot reload ${url}`);
|
|
97
|
+
hotState.A = false;
|
|
98
|
+
if (
|
|
99
|
+
fromUrl &&
|
|
100
|
+
hotState.a &&
|
|
101
|
+
hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
|
|
102
|
+
) {
|
|
103
|
+
curInvalidationRoots.add(fromUrl);
|
|
104
|
+
} else {
|
|
105
|
+
if (hotState.e || hotState.a) curInvalidationRoots.add(url);
|
|
106
|
+
hotState.v++;
|
|
107
|
+
if (!hotState.a) hotState.p.forEach(p => invalidate(p, url, seen));
|
|
115
108
|
}
|
|
109
|
+
if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
|
|
110
|
+
return true;
|
|
116
111
|
};
|
|
117
112
|
|
|
118
113
|
const handleInvalidations = () => {
|
|
@@ -130,26 +125,25 @@
|
|
|
130
125
|
hotState.t
|
|
131
126
|
).then(m => {
|
|
132
127
|
if (hotState.a) {
|
|
133
|
-
hotState.a.
|
|
128
|
+
hotState.a.forEach(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
|
|
134
129
|
// unload should be the latest unload handler from the just loaded module
|
|
135
130
|
if (hotState.u) {
|
|
136
131
|
hotState.u(hotState.d);
|
|
137
132
|
hotState.u = null;
|
|
138
133
|
}
|
|
139
134
|
}
|
|
140
|
-
|
|
141
|
-
const hotState = hotRegistry[
|
|
135
|
+
hotState.p.forEach(p => {
|
|
136
|
+
const hotState = hotRegistry[p];
|
|
142
137
|
if (hotState && hotState.a)
|
|
143
|
-
hotState.a.
|
|
144
|
-
|
|
138
|
+
hotState.a.forEach(
|
|
139
|
+
async ([d, c]) =>
|
|
145
140
|
d &&
|
|
146
141
|
!earlyRoots.has(c) &&
|
|
147
142
|
(typeof d === 'string' ?
|
|
148
143
|
d === root && c(m)
|
|
149
144
|
: c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d, getHotState(d))))))))
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
145
|
+
);
|
|
146
|
+
});
|
|
153
147
|
}, throwError);
|
|
154
148
|
}
|
|
155
149
|
curInvalidationRoots = new Set();
|
|
@@ -165,124 +159,125 @@
|
|
|
165
159
|
];
|
|
166
160
|
};
|
|
167
161
|
|
|
168
|
-
const hasDocument = typeof document !== 'undefined';
|
|
169
|
-
|
|
170
|
-
const noop = () => {};
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
162
|
+
const hasDocument = typeof document !== 'undefined';
|
|
163
|
+
|
|
164
|
+
const noop = () => {};
|
|
165
|
+
|
|
166
|
+
const dynamicImport = (u, errUrl) => import(u);
|
|
167
|
+
|
|
168
|
+
const defineValue = (obj, prop, value) =>
|
|
169
|
+
Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
|
|
170
|
+
|
|
171
|
+
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
172
|
+
|
|
173
|
+
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
174
|
+
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
175
|
+
|
|
176
|
+
const version = "2.6.0";
|
|
177
|
+
|
|
178
|
+
const r$1 = esmsInitOptions.version;
|
|
179
|
+
if (self.importShim || (r$1 && r$1 !== version)) {
|
|
180
|
+
console.info(
|
|
181
|
+
`es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
|
|
182
|
+
);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// shim mode is determined on initialization, no late shim mode
|
|
187
|
+
const shimMode =
|
|
188
|
+
esmsInitOptions.shimMode ||
|
|
189
|
+
(hasDocument &&
|
|
190
|
+
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
191
|
+
.length > 0);
|
|
192
|
+
|
|
193
|
+
let importHook,
|
|
194
|
+
resolveHook,
|
|
195
|
+
fetchHook = fetch,
|
|
196
|
+
sourceHook,
|
|
197
|
+
metaHook,
|
|
198
|
+
tsTransform =
|
|
199
|
+
esmsInitOptions.tsTransform ||
|
|
200
|
+
(hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
|
|
201
|
+
'./es-module-shims-typescript.js';
|
|
202
|
+
|
|
203
|
+
const defaultFetchOpts = { credentials: 'same-origin' };
|
|
204
|
+
|
|
205
|
+
const globalHook = name => (typeof name === 'string' ? self[name] : name);
|
|
206
|
+
|
|
207
|
+
if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
|
|
208
|
+
if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
|
|
209
|
+
if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
|
|
210
|
+
if (esmsInitOptions.source) sourceHook = globalHook(esmsInitOptions.source);
|
|
211
|
+
if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
|
|
212
|
+
|
|
213
|
+
const hasCustomizationHooks = importHook || resolveHook || fetchHook !== fetch || sourceHook || metaHook;
|
|
214
|
+
|
|
215
|
+
const {
|
|
216
|
+
noLoadEventRetriggers,
|
|
217
|
+
enforceIntegrity,
|
|
218
|
+
hotReload,
|
|
219
|
+
hotReloadInterval = 100,
|
|
220
|
+
nativePassthrough = !hasCustomizationHooks && !hotReload
|
|
221
|
+
} = esmsInitOptions;
|
|
222
|
+
|
|
223
|
+
if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
|
|
224
|
+
|
|
225
|
+
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
226
|
+
|
|
227
|
+
let nonce = esmsInitOptions.nonce;
|
|
228
|
+
if (!nonce && hasDocument) {
|
|
229
|
+
const nonceElement = document.querySelector('script[nonce]');
|
|
230
|
+
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const onerror = globalHook(esmsInitOptions.onerror || console.error.bind(console));
|
|
234
|
+
|
|
235
|
+
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
236
|
+
const disable = Array.isArray(esmsInitOptions.polyfillDisable) ? esmsInitOptions.polyfillDisable : [];
|
|
237
|
+
|
|
238
|
+
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
239
|
+
const wasmInstancePhaseEnabled =
|
|
240
|
+
enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
|
|
241
|
+
const wasmSourcePhaseEnabled =
|
|
242
|
+
enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
|
|
243
|
+
const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
|
|
244
|
+
const cssModulesEnabled = !disable.includes('css-modules');
|
|
245
|
+
const jsonModulesEnabled = !disable.includes('json-modules');
|
|
246
|
+
|
|
247
|
+
const onpolyfill =
|
|
248
|
+
esmsInitOptions.onpolyfill ?
|
|
249
|
+
globalHook(esmsInitOptions.onpolyfill)
|
|
250
|
+
: () => {
|
|
251
|
+
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const baseUrl =
|
|
255
|
+
hasDocument ?
|
|
256
|
+
document.baseURI
|
|
257
|
+
: `${location.protocol}//${location.host}${
|
|
258
|
+
location.pathname.includes('/') ?
|
|
259
|
+
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
260
|
+
: location.pathname
|
|
261
|
+
}`;
|
|
262
|
+
|
|
263
|
+
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
264
|
+
let { skip } = esmsInitOptions;
|
|
265
|
+
if (Array.isArray(skip)) {
|
|
266
|
+
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
267
|
+
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
268
|
+
} else if (typeof skip === 'string') {
|
|
269
|
+
const r = new RegExp(skip);
|
|
270
|
+
skip = s => r.test(s);
|
|
271
|
+
} else if (skip instanceof RegExp) {
|
|
272
|
+
skip = s => skip.test(s);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
276
|
+
|
|
277
|
+
const throwError = err => {
|
|
278
|
+
(self.reportError || dispatchError)(err), void onerror(err);
|
|
279
|
+
};
|
|
280
|
+
|
|
286
281
|
const fromParent = parent => (parent ? ` imported from ${parent}` : '');
|
|
287
282
|
|
|
288
283
|
const backslashRegEx = /\\/g;
|
|
@@ -542,13 +537,15 @@
|
|
|
542
537
|
|
|
543
538
|
// Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
|
|
544
539
|
const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
|
|
545
|
-
supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
540
|
+
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
546
541
|
};sp=${
|
|
547
542
|
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
548
543
|
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
549
544
|
: 'false'
|
|
550
545
|
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
551
|
-
supportsImportMaps
|
|
546
|
+
supportsImportMaps && cssModulesEnabled ?
|
|
547
|
+
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
548
|
+
: 'false'
|
|
552
549
|
},sp,${
|
|
553
550
|
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
554
551
|
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
@@ -639,7 +636,7 @@
|
|
|
639
636
|
}
|
|
640
637
|
await initPromise; // needed for shim check
|
|
641
638
|
console.info(`es-module-shims: importShim("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`);
|
|
642
|
-
if (shimMode || !
|
|
639
|
+
if (shimMode || !baselineSupport) {
|
|
643
640
|
if (hasDocument) processScriptsAndPreloads();
|
|
644
641
|
legacyAcceptingImportMaps = false;
|
|
645
642
|
}
|
|
@@ -663,7 +660,7 @@
|
|
|
663
660
|
}
|
|
664
661
|
await initPromise; // needed for shim check
|
|
665
662
|
console.info(`es-module-shims: importShim.source("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`);
|
|
666
|
-
if (shimMode || !
|
|
663
|
+
if (shimMode || !baselineSupport) {
|
|
667
664
|
if (hasDocument) processScriptsAndPreloads();
|
|
668
665
|
legacyAcceptingImportMaps = false;
|
|
669
666
|
}
|
|
@@ -734,19 +731,19 @@
|
|
|
734
731
|
let firstImportMap = null;
|
|
735
732
|
// To support polyfilling multiple import maps, we separately track the composed import map from the first import map
|
|
736
733
|
let composedImportMap = { imports: {}, scopes: {}, integrity: {} };
|
|
737
|
-
let
|
|
734
|
+
let baselineSupport;
|
|
738
735
|
|
|
739
736
|
const initPromise = featureDetectionPromise.then(() => {
|
|
740
|
-
|
|
741
|
-
esmsInitOptions.polyfillEnable !== true &&
|
|
737
|
+
baselineSupport =
|
|
742
738
|
supportsImportMaps &&
|
|
743
|
-
supportsJsonType &&
|
|
744
|
-
supportsCssType &&
|
|
739
|
+
(!jsonModulesEnabled || supportsJsonType) &&
|
|
740
|
+
(!cssModulesEnabled || supportsCssType) &&
|
|
745
741
|
(!wasmInstancePhaseEnabled || supportsWasmInstancePhase) &&
|
|
746
742
|
(!wasmSourcePhaseEnabled || supportsWasmSourcePhase) &&
|
|
747
743
|
!deferPhaseEnabled &&
|
|
748
744
|
(!multipleImportMaps || supportsMultipleImportMaps) &&
|
|
749
|
-
!importMapSrc
|
|
745
|
+
!importMapSrc &&
|
|
746
|
+
!hasCustomizationHooks;
|
|
750
747
|
if (!shimMode && typeof WebAssembly !== 'undefined') {
|
|
751
748
|
if (wasmSourcePhaseEnabled && !Object.getPrototypeOf(WebAssembly.Module).name) {
|
|
752
749
|
const s = Symbol();
|
|
@@ -778,7 +775,7 @@
|
|
|
778
775
|
const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
|
|
779
776
|
HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
|
|
780
777
|
}
|
|
781
|
-
if (shimMode || !
|
|
778
|
+
if (shimMode || !baselineSupport) {
|
|
782
779
|
attachMutationObserver();
|
|
783
780
|
if (document.readyState === 'complete') {
|
|
784
781
|
readyStateCompleteCheck();
|
|
@@ -841,7 +838,7 @@
|
|
|
841
838
|
|
|
842
839
|
if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, parentUrl, source, sourceType);
|
|
843
840
|
// early analysis opt-out - no need to even fetch if we have feature support
|
|
844
|
-
if (!shimMode &&
|
|
841
|
+
if (!shimMode && baselineSupport && nativePassthrough && sourceType !== 'ts') {
|
|
845
842
|
console.info(`es-module-shims: early exit for ${url} due to baseline modules support`);
|
|
846
843
|
// for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
|
|
847
844
|
if (nativelyLoaded) return null;
|
|
@@ -874,7 +871,7 @@
|
|
|
874
871
|
: import(load.u));
|
|
875
872
|
// if the top-level load is a shell, run its update function
|
|
876
873
|
if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
|
|
877
|
-
|
|
874
|
+
revokeObjectURLs(Object.keys(seen));
|
|
878
875
|
return module;
|
|
879
876
|
};
|
|
880
877
|
|
|
@@ -1061,13 +1058,6 @@
|
|
|
1061
1058
|
|
|
1062
1059
|
const sourceURLCommentPrefix = '\n//# sourceURL=';
|
|
1063
1060
|
const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
|
|
1064
|
-
|
|
1065
|
-
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
1066
|
-
const wasmContentType = /^application\/wasm(;|$)/;
|
|
1067
|
-
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
1068
|
-
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
1069
|
-
const tsContentType = /^application\/typescript(;|$)|/;
|
|
1070
|
-
|
|
1071
1061
|
const cssUrlRegEx = /url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;
|
|
1072
1062
|
|
|
1073
1063
|
// restrict in-flight fetches to a pool of 100
|
|
@@ -1108,78 +1098,74 @@
|
|
|
1108
1098
|
if (!esmsTsTransform) esmsTsTransform = m.transform;
|
|
1109
1099
|
};
|
|
1110
1100
|
|
|
1101
|
+
const contentTypeRegEx = /^(text|application)\/((x-)?javascript|wasm|json|css|typescript)(;|$)/;
|
|
1102
|
+
async function defaultSourceHook(url, fetchOpts, parent) {
|
|
1103
|
+
const res = await doFetch(url, fetchOpts, parent);
|
|
1104
|
+
let [, , t] = (res.headers.get('content-type') || '').match(contentTypeRegEx) || [];
|
|
1105
|
+
if (!t) {
|
|
1106
|
+
if (url.endsWith('.ts') || url.endsWith('.mts')) t = 'ts';
|
|
1107
|
+
else
|
|
1108
|
+
throw Error(
|
|
1109
|
+
`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
return {
|
|
1113
|
+
url: res.url,
|
|
1114
|
+
source: t === 'wasm' ? await WebAssembly.compileStreaming(res) : await res.text(),
|
|
1115
|
+
type:
|
|
1116
|
+
t[0] === 'x' || (t[0] === 'j' && t[1] === 'a') ? 'js'
|
|
1117
|
+
: t[0] === 't' ? 'ts'
|
|
1118
|
+
: t
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1111
1122
|
const hotPrefix = 'var h=import.meta.hot,';
|
|
1112
|
-
const fetchModule = async (
|
|
1113
|
-
const mapIntegrity = composedImportMap.integrity[
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
const rStr = urlJsString(r);
|
|
1127
|
-
let s = `import*as $_ns from${rStr};`,
|
|
1128
|
-
i = 0,
|
|
1123
|
+
const fetchModule = async (reqUrl, fetchOpts, parent) => {
|
|
1124
|
+
const mapIntegrity = composedImportMap.integrity[reqUrl];
|
|
1125
|
+
fetchOpts = mapIntegrity && !fetchOpts.integrity ? { ...fetchOpts, integrity: mapIntegrity } : fetchOpts;
|
|
1126
|
+
let {
|
|
1127
|
+
url = reqUrl,
|
|
1128
|
+
source,
|
|
1129
|
+
type
|
|
1130
|
+
} = (await (sourceHook || defaultSourceHook)(reqUrl, fetchOpts, parent, defaultSourceHook)) || {};
|
|
1131
|
+
if (type === 'wasm') {
|
|
1132
|
+
const exports = WebAssembly.Module.exports((sourceCache[url] = source));
|
|
1133
|
+
const imports = WebAssembly.Module.imports(source);
|
|
1134
|
+
const rStr = urlJsString(url);
|
|
1135
|
+
source = `import*as $_ns from${rStr};`;
|
|
1136
|
+
let i = 0,
|
|
1129
1137
|
obj = '';
|
|
1130
|
-
for (const { module, kind } of
|
|
1138
|
+
for (const { module, kind } of imports) {
|
|
1131
1139
|
const specifier = urlJsString(module);
|
|
1132
|
-
|
|
1140
|
+
source += `import*as impt${i} from${specifier};\n`;
|
|
1133
1141
|
obj += `${specifier}:${kind === 'global' ? `importShim._i.get(impt${i})||impt${i++}` : `impt${i++}`},`;
|
|
1134
1142
|
}
|
|
1135
|
-
|
|
1143
|
+
source += `${hotPrefix}i=await WebAssembly.instantiate(importShim._s[${rStr}],{${obj}});importShim._i.set($_ns,i);`;
|
|
1136
1144
|
obj = '';
|
|
1137
1145
|
for (const { name, kind } of exports) {
|
|
1138
|
-
|
|
1139
|
-
if (kind === 'global')
|
|
1146
|
+
source += `export let ${name}=i.exports['${name}'];`;
|
|
1147
|
+
if (kind === 'global') source += `try{${name}=${name}.value}catch{${name}=undefined}`;
|
|
1140
1148
|
obj += `${name},`;
|
|
1141
1149
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
s: `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
|
|
1154
|
-
(await res.text()).replace(
|
|
1155
|
-
cssUrlRegEx,
|
|
1156
|
-
(_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`
|
|
1157
|
-
)
|
|
1158
|
-
)});if(h){h.data.s=s;h.accept(()=>{})}export default s`,
|
|
1159
|
-
t: 'css'
|
|
1160
|
-
};
|
|
1161
|
-
} else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
|
|
1162
|
-
const source = await res.text();
|
|
1150
|
+
source += `if(h)h.accept(m=>({${obj}}=m))`;
|
|
1151
|
+
} else if (type === 'json') {
|
|
1152
|
+
source = `${hotPrefix}j=${source};export{j as default};if(h)h.accept(m=>j=m.default)`;
|
|
1153
|
+
} else if (type === 'css') {
|
|
1154
|
+
source = `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
|
|
1155
|
+
source.replace(
|
|
1156
|
+
cssUrlRegEx,
|
|
1157
|
+
(_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`
|
|
1158
|
+
)
|
|
1159
|
+
)});if(h){h.data.s=s;h.accept(()=>{})}export default s`;
|
|
1160
|
+
} else if (type === 'ts') {
|
|
1163
1161
|
if (!esmsTsTransform) await initTs();
|
|
1164
1162
|
console.info(`es-module-shims: Compiling TypeScript file ${url}`);
|
|
1165
1163
|
const transformed = esmsTsTransform(source, url);
|
|
1166
1164
|
// even if the TypeScript is valid JavaScript, unless it was a top-level inline source, it wasn't served with
|
|
1167
1165
|
// a valid JS MIME here, so we must still polyfill it
|
|
1168
|
-
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
|
|
1172
|
-
);
|
|
1173
|
-
};
|
|
1174
|
-
|
|
1175
|
-
const isUnsupportedType = type => {
|
|
1176
|
-
if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
|
|
1177
|
-
return (
|
|
1178
|
-
(type === 'css' && !supportsCssType) ||
|
|
1179
|
-
(type === 'json' && !supportsJsonType) ||
|
|
1180
|
-
(type === 'wasm' && !supportsWasmInstancePhase && !supportsWasmSourcePhase) ||
|
|
1181
|
-
type === 'ts'
|
|
1182
|
-
);
|
|
1166
|
+
source = transformed === undefined ? source : transformed;
|
|
1167
|
+
}
|
|
1168
|
+
return { url, source, type };
|
|
1183
1169
|
};
|
|
1184
1170
|
|
|
1185
1171
|
const getOrCreateLoad = (url, fetchOpts, parent, source) => {
|
|
@@ -1221,8 +1207,16 @@
|
|
|
1221
1207
|
load.f = (async () => {
|
|
1222
1208
|
if (load.S === undefined) {
|
|
1223
1209
|
// preload fetch options override fetch options (race)
|
|
1224
|
-
({
|
|
1225
|
-
if (
|
|
1210
|
+
({ url: load.r, source: load.S, type: load.t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
|
|
1211
|
+
if (
|
|
1212
|
+
!load.n &&
|
|
1213
|
+
load.t !== 'js' &&
|
|
1214
|
+
!shimMode &&
|
|
1215
|
+
((load.t === 'css' && !supportsCssType) ||
|
|
1216
|
+
(load.t === 'json' && !supportsJsonType) ||
|
|
1217
|
+
(load.t === 'wasm' && !supportsWasmInstancePhase && !supportsWasmSourcePhase) ||
|
|
1218
|
+
load.t === 'ts')
|
|
1219
|
+
) {
|
|
1226
1220
|
load.n = true;
|
|
1227
1221
|
}
|
|
1228
1222
|
}
|
|
@@ -1269,7 +1263,7 @@
|
|
|
1269
1263
|
}
|
|
1270
1264
|
if (d !== -1 || !n) return;
|
|
1271
1265
|
const resolved = resolve(n, load.r || load.u);
|
|
1272
|
-
if (resolved.n) load.n = true;
|
|
1266
|
+
if (resolved.n || hasCustomizationHooks) load.n = true;
|
|
1273
1267
|
if (d >= 0 || resolved.N) load.N = true;
|
|
1274
1268
|
if (d !== -1) return;
|
|
1275
1269
|
if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
|
|
@@ -1320,7 +1314,7 @@
|
|
|
1320
1314
|
domContentLoaded = true;
|
|
1321
1315
|
domContentLoadedCnt--;
|
|
1322
1316
|
}
|
|
1323
|
-
if (--domContentLoadedCnt === 0 && !noLoadEventRetriggers && (shimMode || !
|
|
1317
|
+
if (--domContentLoadedCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselineSupport)) {
|
|
1324
1318
|
console.info(`es-module-shims: DOMContentLoaded refire`);
|
|
1325
1319
|
document.removeEventListener('DOMContentLoaded', domContentLoadedEvent);
|
|
1326
1320
|
document.dispatchEvent(new Event('DOMContentLoaded'));
|
|
@@ -1328,7 +1322,7 @@
|
|
|
1328
1322
|
};
|
|
1329
1323
|
let loadCnt = 1;
|
|
1330
1324
|
const loadCheck = () => {
|
|
1331
|
-
if (--loadCnt === 0 && !noLoadEventRetriggers && (shimMode || !
|
|
1325
|
+
if (--loadCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselineSupport)) {
|
|
1332
1326
|
console.info(`es-module-shims: load refire`);
|
|
1333
1327
|
window.removeEventListener('load', loadEvent);
|
|
1334
1328
|
window.dispatchEvent(new Event('load'));
|
|
@@ -1363,7 +1357,7 @@
|
|
|
1363
1357
|
const readyStateCompleteCheck = () => {
|
|
1364
1358
|
if (--readyStateCompleteCnt === 0) {
|
|
1365
1359
|
domContentLoadedCheck();
|
|
1366
|
-
if (!noLoadEventRetriggers && (shimMode || !
|
|
1360
|
+
if (!noLoadEventRetriggers && (shimMode || !baselineSupport)) {
|
|
1367
1361
|
console.info(`es-module-shims: readystatechange complete refire`);
|
|
1368
1362
|
document.removeEventListener('readystatechange', readyListener);
|
|
1369
1363
|
document.dispatchEvent(new Event('readystatechange'));
|
|
@@ -1402,9 +1396,9 @@
|
|
|
1402
1396
|
if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
|
|
1403
1397
|
if (!legacyAcceptingImportMaps && !multipleImportMaps) {
|
|
1404
1398
|
multipleImportMaps = true;
|
|
1405
|
-
if (!shimMode &&
|
|
1399
|
+
if (!shimMode && baselineSupport && !supportsMultipleImportMaps) {
|
|
1406
1400
|
console.info(`es-module-shims: disabling baseline passthrough due to multiple import maps`);
|
|
1407
|
-
|
|
1401
|
+
baselineSupport = false;
|
|
1408
1402
|
if (hasDocument) attachMutationObserver();
|
|
1409
1403
|
}
|
|
1410
1404
|
}
|
|
@@ -1466,14 +1460,11 @@
|
|
|
1466
1460
|
const fetchCache = {};
|
|
1467
1461
|
const processPreload = link => {
|
|
1468
1462
|
link.ep = true;
|
|
1469
|
-
|
|
1470
|
-
|
|
1463
|
+
initPromise.then(() => {
|
|
1464
|
+
if (baselineSupport && !shimMode) return;
|
|
1465
|
+
if (fetchCache[link.href]) return;
|
|
1466
|
+
fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
|
|
1467
|
+
});
|
|
1471
1468
|
};
|
|
1472
1469
|
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1476
|
-
|
|
1477
|
-
return exports;
|
|
1478
|
-
|
|
1479
|
-
})({});
|
|
1470
|
+
})();
|