es-module-shims 2.3.0 → 2.4.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 +18 -4
- package/dist/es-module-shims.debug.js +362 -338
- package/dist/es-module-shims.js +359 -335
- package/dist/es-module-shims.wasm.js +359 -335
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** ES Module Shims Wasm 2.
|
|
2
|
-
(function () {
|
|
1
|
+
/** ES Module Shims Wasm @version 2.4.0 */
|
|
2
|
+
(function (exports) {
|
|
3
3
|
|
|
4
4
|
let invalidate;
|
|
5
5
|
const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
|
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
if (!parents.includes(originalParent)) parents.push(originalParent);
|
|
18
18
|
return toVersioned(url);
|
|
19
19
|
};
|
|
20
|
-
const hotImportHook = url => {
|
|
21
|
-
getHotState(url)
|
|
20
|
+
const hotImportHook = (url, _, __, source, sourceType) => {
|
|
21
|
+
const hotState = getHotState(url);
|
|
22
|
+
hotState.e = typeof source === 'string' ? source : true;
|
|
23
|
+
hotState.t = sourceType;
|
|
22
24
|
};
|
|
23
25
|
const hotMetaHook = (metaObj, url) => {
|
|
24
26
|
metaObj.hot = new Hot(url);
|
|
@@ -79,12 +81,14 @@
|
|
|
79
81
|
A: true,
|
|
80
82
|
// unload callback
|
|
81
83
|
u: null,
|
|
82
|
-
// entry point
|
|
84
|
+
// entry point or inline script source
|
|
83
85
|
e: false,
|
|
84
86
|
// hot data
|
|
85
87
|
d: {},
|
|
86
88
|
// parents
|
|
87
|
-
p: []
|
|
89
|
+
p: [],
|
|
90
|
+
// source type
|
|
91
|
+
t: undefined
|
|
88
92
|
});
|
|
89
93
|
|
|
90
94
|
invalidate = (url, fromUrl, seen = []) => {
|
|
@@ -111,7 +115,15 @@
|
|
|
111
115
|
const earlyRoots = new Set();
|
|
112
116
|
for (const root of curInvalidationRoots) {
|
|
113
117
|
const hotState = hotRegistry[root];
|
|
114
|
-
|
|
118
|
+
topLevelLoad(
|
|
119
|
+
toVersioned(root),
|
|
120
|
+
baseUrl,
|
|
121
|
+
defaultFetchOpts,
|
|
122
|
+
typeof hotState.e === 'string' ? hotState.e : undefined,
|
|
123
|
+
false,
|
|
124
|
+
undefined,
|
|
125
|
+
hotState.t
|
|
126
|
+
).then(m => {
|
|
115
127
|
if (hotState.a) {
|
|
116
128
|
hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
|
|
117
129
|
// unload should be the latest unload handler from the just loaded module
|
|
@@ -133,327 +145,329 @@
|
|
|
133
145
|
);
|
|
134
146
|
});
|
|
135
147
|
}
|
|
136
|
-
},
|
|
148
|
+
}, throwError);
|
|
137
149
|
}
|
|
138
150
|
curInvalidationRoots = new Set();
|
|
139
151
|
}, hotReloadInterval);
|
|
140
152
|
};
|
|
141
153
|
|
|
142
154
|
return [
|
|
143
|
-
_importHook ?
|
|
144
|
-
(url, opts, parentUrl) => {
|
|
145
|
-
_importHook(url, opts, parentUrl);
|
|
146
|
-
hotImportHook(url);
|
|
147
|
-
}
|
|
148
|
-
: hotImportHook,
|
|
155
|
+
_importHook ? chain(_importHook, hotImportHook) : hotImportHook,
|
|
149
156
|
_resolveHook ?
|
|
150
157
|
(id, parent, defaultResolve) =>
|
|
151
158
|
hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
|
|
152
159
|
: hotResolveHook,
|
|
153
|
-
_metaHook ?
|
|
154
|
-
(metaObj, url) => {
|
|
155
|
-
_metaHook(metaObj, url);
|
|
156
|
-
hotMetaHook(metaObj, url);
|
|
157
|
-
}
|
|
158
|
-
: hotMetaHook
|
|
160
|
+
_metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
|
|
159
161
|
];
|
|
160
162
|
};
|
|
161
163
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
const
|
|
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
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
(
|
|
261
|
-
|
|
262
|
-
|
|
164
|
+
const hasDocument = typeof document !== 'undefined';
|
|
165
|
+
|
|
166
|
+
const noop = () => {};
|
|
167
|
+
|
|
168
|
+
const chain = (a, b) =>
|
|
169
|
+
function () {
|
|
170
|
+
a.apply(this, arguments);
|
|
171
|
+
b.apply(this, arguments);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const dynamicImport = (u, errUrl) => import(u);
|
|
175
|
+
|
|
176
|
+
const defineValue = (obj, prop, value) =>
|
|
177
|
+
Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
|
|
178
|
+
|
|
179
|
+
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
180
|
+
|
|
181
|
+
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
182
|
+
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
183
|
+
|
|
184
|
+
const r = esmsInitOptions.version;
|
|
185
|
+
if (self.importShim || (r && r !== "2.4.0")) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// shim mode is determined on initialization, no late shim mode
|
|
190
|
+
const shimMode =
|
|
191
|
+
esmsInitOptions.shimMode ||
|
|
192
|
+
(hasDocument &&
|
|
193
|
+
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
194
|
+
.length > 0);
|
|
195
|
+
|
|
196
|
+
let importHook,
|
|
197
|
+
resolveHook,
|
|
198
|
+
fetchHook = fetch,
|
|
199
|
+
metaHook,
|
|
200
|
+
tsTransform =
|
|
201
|
+
esmsInitOptions.tsTransform ||
|
|
202
|
+
(hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
|
|
203
|
+
'./es-module-shims-typescript.js';
|
|
204
|
+
|
|
205
|
+
const defaultFetchOpts = { credentials: 'same-origin' };
|
|
206
|
+
|
|
207
|
+
const {
|
|
208
|
+
revokeBlobURLs,
|
|
209
|
+
noLoadEventRetriggers,
|
|
210
|
+
enforceIntegrity,
|
|
211
|
+
hotReload,
|
|
212
|
+
hotReloadInterval = 100,
|
|
213
|
+
nativePassthrough = !hotReload
|
|
214
|
+
} = esmsInitOptions;
|
|
215
|
+
|
|
216
|
+
const globalHook = name => (typeof name === 'string' ? self[name] : name);
|
|
217
|
+
|
|
218
|
+
if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
|
|
219
|
+
if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
|
|
220
|
+
if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
|
|
221
|
+
if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
|
|
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 enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
237
|
+
const wasmInstancePhaseEnabled =
|
|
238
|
+
enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
|
|
239
|
+
const wasmSourcePhaseEnabled =
|
|
240
|
+
enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
|
|
241
|
+
const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
|
|
242
|
+
|
|
243
|
+
const onpolyfill =
|
|
244
|
+
esmsInitOptions.onpolyfill ?
|
|
245
|
+
globalHook(esmsInitOptions.onpolyfill)
|
|
246
|
+
: () => {
|
|
247
|
+
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const baseUrl =
|
|
251
|
+
hasDocument ?
|
|
252
|
+
document.baseURI
|
|
253
|
+
: `${location.protocol}//${location.host}${
|
|
254
|
+
location.pathname.includes('/') ?
|
|
255
|
+
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
256
|
+
: location.pathname
|
|
257
|
+
}`;
|
|
258
|
+
|
|
259
|
+
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
260
|
+
let { skip } = esmsInitOptions;
|
|
261
|
+
if (Array.isArray(skip)) {
|
|
262
|
+
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
263
|
+
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
264
|
+
} else if (typeof skip === 'string') {
|
|
265
|
+
const r = new RegExp(skip);
|
|
266
|
+
skip = s => r.test(s);
|
|
267
|
+
} else if (skip instanceof RegExp) {
|
|
268
|
+
skip = s => skip.test(s);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
272
|
+
|
|
273
|
+
const throwError = err => {
|
|
274
|
+
(self.reportError || dispatchError)(err), void onerror(err);
|
|
275
|
+
};
|
|
276
|
+
|
|
263
277
|
const fromParent = parent => (parent ? ` imported from ${parent}` : '');
|
|
264
278
|
|
|
265
|
-
const backslashRegEx = /\\/g;
|
|
266
|
-
|
|
267
|
-
const asURL = url => {
|
|
268
|
-
try {
|
|
269
|
-
if (url.indexOf(':') !== -1) return new URL(url).href;
|
|
270
|
-
} catch (_) {}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const resolveUrl = (relUrl, parentUrl) =>
|
|
274
|
-
resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
|
|
275
|
-
|
|
276
|
-
const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
|
|
277
|
-
const hIdx = parentUrl.indexOf('#'),
|
|
278
|
-
qIdx = parentUrl.indexOf('?');
|
|
279
|
-
if (hIdx + qIdx > -2)
|
|
280
|
-
parentUrl = parentUrl.slice(
|
|
281
|
-
0,
|
|
282
|
-
hIdx === -1 ? qIdx
|
|
283
|
-
: qIdx === -1 || qIdx > hIdx ? hIdx
|
|
284
|
-
: qIdx
|
|
285
|
-
);
|
|
286
|
-
if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
|
|
287
|
-
// protocol-relative
|
|
288
|
-
if (relUrl[0] === '/' && relUrl[1] === '/') {
|
|
289
|
-
return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
|
|
290
|
-
}
|
|
291
|
-
// relative-url
|
|
292
|
-
else if (
|
|
293
|
-
(relUrl[0] === '.' &&
|
|
294
|
-
(relUrl[1] === '/' ||
|
|
295
|
-
(relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
|
|
296
|
-
(relUrl.length === 1 && (relUrl += '/')))) ||
|
|
297
|
-
relUrl[0] === '/'
|
|
298
|
-
) {
|
|
299
|
-
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
300
|
-
if (parentProtocol === 'blob:') {
|
|
301
|
-
throw new TypeError(
|
|
302
|
-
`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
306
|
-
//if (parentUrl[parentProtocol.length] !== '/')
|
|
307
|
-
// throw new Error('Cannot resolve');
|
|
308
|
-
// read pathname from parent URL
|
|
309
|
-
// pathname taken to be part after leading "/"
|
|
310
|
-
let pathname;
|
|
311
|
-
if (parentUrl[parentProtocol.length + 1] === '/') {
|
|
312
|
-
// resolving to a :// so we need to read out the auth and host
|
|
313
|
-
if (parentProtocol !== 'file:') {
|
|
314
|
-
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
315
|
-
pathname = pathname.slice(pathname.indexOf('/') + 1);
|
|
316
|
-
} else {
|
|
317
|
-
pathname = parentUrl.slice(8);
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
// resolving to :/ so pathname is the /... part
|
|
321
|
-
pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
325
|
-
|
|
326
|
-
// join together and split for removal of .. and . segments
|
|
327
|
-
// looping the string instead of anything fancy for perf reasons
|
|
328
|
-
// '../../../../../z' resolved to 'x/y' is just 'z'
|
|
329
|
-
const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
|
|
330
|
-
|
|
331
|
-
const output = [];
|
|
332
|
-
let segmentIndex = -1;
|
|
333
|
-
for (let i = 0; i < segmented.length; i++) {
|
|
334
|
-
// busy reading a segment - only terminate on '/'
|
|
335
|
-
if (segmentIndex !== -1) {
|
|
336
|
-
if (segmented[i] === '/') {
|
|
337
|
-
output.push(segmented.slice(segmentIndex, i + 1));
|
|
338
|
-
segmentIndex = -1;
|
|
339
|
-
}
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
// new segment - check if it is relative
|
|
343
|
-
else if (segmented[i] === '.') {
|
|
344
|
-
// ../ segment
|
|
345
|
-
if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
|
|
346
|
-
output.pop();
|
|
347
|
-
i += 2;
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
// ./ segment
|
|
351
|
-
else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
|
|
352
|
-
i += 1;
|
|
353
|
-
continue;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
// it is the start of a new segment
|
|
357
|
-
while (segmented[i] === '/') i++;
|
|
358
|
-
segmentIndex = i;
|
|
359
|
-
}
|
|
360
|
-
// finish reading out the last segment
|
|
361
|
-
if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
|
|
362
|
-
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
|
|
367
|
-
const outMap = {
|
|
368
|
-
imports:
|
|
369
|
-
scopes:
|
|
370
|
-
integrity:
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
|
|
374
|
-
|
|
375
|
-
if (json.scopes)
|
|
376
|
-
for (let s in json.scopes) {
|
|
377
|
-
const resolvedScope = resolveUrl(s, baseUrl);
|
|
378
|
-
resolveAndComposePackages(
|
|
379
|
-
json.scopes[s],
|
|
380
|
-
outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
|
|
381
|
-
baseUrl,
|
|
382
|
-
parentMap
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
|
|
387
|
-
|
|
388
|
-
return outMap;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const getMatch = (path, matchObj) => {
|
|
392
|
-
if (matchObj[path]) return path;
|
|
393
|
-
let sepIndex = path.length;
|
|
394
|
-
do {
|
|
395
|
-
const segment = path.slice(0, sepIndex + 1);
|
|
396
|
-
if (segment in matchObj) return segment;
|
|
397
|
-
} while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const applyPackages = (id, packages) => {
|
|
401
|
-
const pkgName = getMatch(id, packages);
|
|
402
|
-
if (pkgName) {
|
|
403
|
-
const pkg = packages[pkgName];
|
|
404
|
-
if (pkg === null) return;
|
|
405
|
-
return pkg + id.slice(pkgName.length);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
|
|
410
|
-
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
411
|
-
while (scopeUrl) {
|
|
412
|
-
const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
|
|
413
|
-
if (packageResolution) return packageResolution;
|
|
414
|
-
scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
|
|
415
|
-
}
|
|
416
|
-
return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
|
|
420
|
-
for (let p in packages) {
|
|
421
|
-
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
422
|
-
if (
|
|
423
|
-
(!shimMode || !mapOverrides) &&
|
|
424
|
-
outPackages[resolvedLhs] &&
|
|
425
|
-
outPackages[resolvedLhs] !== packages[resolvedLhs]
|
|
426
|
-
) {
|
|
427
|
-
console.warn(
|
|
428
|
-
`es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
|
|
429
|
-
);
|
|
430
|
-
continue;
|
|
431
|
-
}
|
|
432
|
-
let target = packages[p];
|
|
433
|
-
if (typeof target !== 'string') continue;
|
|
434
|
-
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
435
|
-
if (mapped) {
|
|
436
|
-
outPackages[resolvedLhs] = mapped;
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
|
|
444
|
-
for (let p in integrity) {
|
|
445
|
-
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
446
|
-
if (
|
|
447
|
-
(!shimMode || !mapOverrides) &&
|
|
448
|
-
outIntegrity[resolvedLhs] &&
|
|
449
|
-
outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
|
|
450
|
-
) {
|
|
451
|
-
console.warn(
|
|
452
|
-
`es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
outIntegrity[resolvedLhs] = integrity[p];
|
|
456
|
-
}
|
|
279
|
+
const backslashRegEx = /\\/g;
|
|
280
|
+
|
|
281
|
+
const asURL = url => {
|
|
282
|
+
try {
|
|
283
|
+
if (url.indexOf(':') !== -1) return new URL(url).href;
|
|
284
|
+
} catch (_) {}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const resolveUrl = (relUrl, parentUrl) =>
|
|
288
|
+
resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
|
|
289
|
+
|
|
290
|
+
const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
|
|
291
|
+
const hIdx = parentUrl.indexOf('#'),
|
|
292
|
+
qIdx = parentUrl.indexOf('?');
|
|
293
|
+
if (hIdx + qIdx > -2)
|
|
294
|
+
parentUrl = parentUrl.slice(
|
|
295
|
+
0,
|
|
296
|
+
hIdx === -1 ? qIdx
|
|
297
|
+
: qIdx === -1 || qIdx > hIdx ? hIdx
|
|
298
|
+
: qIdx
|
|
299
|
+
);
|
|
300
|
+
if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
|
|
301
|
+
// protocol-relative
|
|
302
|
+
if (relUrl[0] === '/' && relUrl[1] === '/') {
|
|
303
|
+
return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
|
|
304
|
+
}
|
|
305
|
+
// relative-url
|
|
306
|
+
else if (
|
|
307
|
+
(relUrl[0] === '.' &&
|
|
308
|
+
(relUrl[1] === '/' ||
|
|
309
|
+
(relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
|
|
310
|
+
(relUrl.length === 1 && (relUrl += '/')))) ||
|
|
311
|
+
relUrl[0] === '/'
|
|
312
|
+
) {
|
|
313
|
+
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
314
|
+
if (parentProtocol === 'blob:') {
|
|
315
|
+
throw new TypeError(
|
|
316
|
+
`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
320
|
+
//if (parentUrl[parentProtocol.length] !== '/')
|
|
321
|
+
// throw new Error('Cannot resolve');
|
|
322
|
+
// read pathname from parent URL
|
|
323
|
+
// pathname taken to be part after leading "/"
|
|
324
|
+
let pathname;
|
|
325
|
+
if (parentUrl[parentProtocol.length + 1] === '/') {
|
|
326
|
+
// resolving to a :// so we need to read out the auth and host
|
|
327
|
+
if (parentProtocol !== 'file:') {
|
|
328
|
+
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
329
|
+
pathname = pathname.slice(pathname.indexOf('/') + 1);
|
|
330
|
+
} else {
|
|
331
|
+
pathname = parentUrl.slice(8);
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
// resolving to :/ so pathname is the /... part
|
|
335
|
+
pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
339
|
+
|
|
340
|
+
// join together and split for removal of .. and . segments
|
|
341
|
+
// looping the string instead of anything fancy for perf reasons
|
|
342
|
+
// '../../../../../z' resolved to 'x/y' is just 'z'
|
|
343
|
+
const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
|
|
344
|
+
|
|
345
|
+
const output = [];
|
|
346
|
+
let segmentIndex = -1;
|
|
347
|
+
for (let i = 0; i < segmented.length; i++) {
|
|
348
|
+
// busy reading a segment - only terminate on '/'
|
|
349
|
+
if (segmentIndex !== -1) {
|
|
350
|
+
if (segmented[i] === '/') {
|
|
351
|
+
output.push(segmented.slice(segmentIndex, i + 1));
|
|
352
|
+
segmentIndex = -1;
|
|
353
|
+
}
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
// new segment - check if it is relative
|
|
357
|
+
else if (segmented[i] === '.') {
|
|
358
|
+
// ../ segment
|
|
359
|
+
if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
|
|
360
|
+
output.pop();
|
|
361
|
+
i += 2;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
// ./ segment
|
|
365
|
+
else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
|
|
366
|
+
i += 1;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// it is the start of a new segment
|
|
371
|
+
while (segmented[i] === '/') i++;
|
|
372
|
+
segmentIndex = i;
|
|
373
|
+
}
|
|
374
|
+
// finish reading out the last segment
|
|
375
|
+
if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
|
|
376
|
+
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
|
|
381
|
+
const outMap = {
|
|
382
|
+
imports: { ...parentMap.imports },
|
|
383
|
+
scopes: { ...parentMap.scopes },
|
|
384
|
+
integrity: { ...parentMap.integrity }
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
|
|
388
|
+
|
|
389
|
+
if (json.scopes)
|
|
390
|
+
for (let s in json.scopes) {
|
|
391
|
+
const resolvedScope = resolveUrl(s, baseUrl);
|
|
392
|
+
resolveAndComposePackages(
|
|
393
|
+
json.scopes[s],
|
|
394
|
+
outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
|
|
395
|
+
baseUrl,
|
|
396
|
+
parentMap
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
|
|
401
|
+
|
|
402
|
+
return outMap;
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const getMatch = (path, matchObj) => {
|
|
406
|
+
if (matchObj[path]) return path;
|
|
407
|
+
let sepIndex = path.length;
|
|
408
|
+
do {
|
|
409
|
+
const segment = path.slice(0, sepIndex + 1);
|
|
410
|
+
if (segment in matchObj) return segment;
|
|
411
|
+
} while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const applyPackages = (id, packages) => {
|
|
415
|
+
const pkgName = getMatch(id, packages);
|
|
416
|
+
if (pkgName) {
|
|
417
|
+
const pkg = packages[pkgName];
|
|
418
|
+
if (pkg === null) return;
|
|
419
|
+
return pkg + id.slice(pkgName.length);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
|
|
424
|
+
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
425
|
+
while (scopeUrl) {
|
|
426
|
+
const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
|
|
427
|
+
if (packageResolution) return packageResolution;
|
|
428
|
+
scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
|
|
429
|
+
}
|
|
430
|
+
return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
|
|
434
|
+
for (let p in packages) {
|
|
435
|
+
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
436
|
+
if (
|
|
437
|
+
(!shimMode || !mapOverrides) &&
|
|
438
|
+
outPackages[resolvedLhs] &&
|
|
439
|
+
outPackages[resolvedLhs] !== packages[resolvedLhs]
|
|
440
|
+
) {
|
|
441
|
+
console.warn(
|
|
442
|
+
`es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
|
|
443
|
+
);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
let target = packages[p];
|
|
447
|
+
if (typeof target !== 'string') continue;
|
|
448
|
+
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
449
|
+
if (mapped) {
|
|
450
|
+
outPackages[resolvedLhs] = mapped;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
|
|
458
|
+
for (let p in integrity) {
|
|
459
|
+
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
460
|
+
if (
|
|
461
|
+
(!shimMode || !mapOverrides) &&
|
|
462
|
+
outIntegrity[resolvedLhs] &&
|
|
463
|
+
outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
|
|
464
|
+
) {
|
|
465
|
+
console.warn(
|
|
466
|
+
`es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
outIntegrity[resolvedLhs] = integrity[p];
|
|
470
|
+
}
|
|
457
471
|
};
|
|
458
472
|
|
|
459
473
|
// support browsers without dynamic import support (eg Firefox 6x)
|
|
@@ -619,15 +633,7 @@
|
|
|
619
633
|
sourceType = opts.with.type;
|
|
620
634
|
}
|
|
621
635
|
}
|
|
622
|
-
return topLevelLoad(
|
|
623
|
-
id,
|
|
624
|
-
parentUrl || baseUrl,
|
|
625
|
-
{ credentials: 'same-origin' },
|
|
626
|
-
undefined,
|
|
627
|
-
undefined,
|
|
628
|
-
undefined,
|
|
629
|
-
sourceType
|
|
630
|
-
);
|
|
636
|
+
return topLevelLoad(id, parentUrl || baseUrl, defaultFetchOpts, undefined, undefined, undefined, sourceType);
|
|
631
637
|
}
|
|
632
638
|
|
|
633
639
|
// import.source()
|
|
@@ -645,7 +651,7 @@
|
|
|
645
651
|
}
|
|
646
652
|
await importMapPromise;
|
|
647
653
|
const url = resolve(id, parentUrl || baseUrl).r;
|
|
648
|
-
const load = getOrCreateLoad(url,
|
|
654
|
+
const load = getOrCreateLoad(url, defaultFetchOpts, undefined, undefined);
|
|
649
655
|
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
650
656
|
onpolyfill();
|
|
651
657
|
firstPolyfillLoad = false;
|
|
@@ -659,8 +665,6 @@
|
|
|
659
665
|
|
|
660
666
|
if (hotReload) importShim$1.hotReload = hotReload$1;
|
|
661
667
|
|
|
662
|
-
self.importShim = importShim$1;
|
|
663
|
-
|
|
664
668
|
const defaultResolve = (id, parentUrl) => {
|
|
665
669
|
return (
|
|
666
670
|
resolveImportMap(composedImportMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) ||
|
|
@@ -688,6 +692,13 @@
|
|
|
688
692
|
const sourceCache = (importShim$1._s = {});
|
|
689
693
|
(importShim$1._i = new WeakMap());
|
|
690
694
|
|
|
695
|
+
// Ensure this version is the only version
|
|
696
|
+
defineValue(self, 'importShim', Object.freeze(importShim$1));
|
|
697
|
+
const shimModeOptions = { ...esmsInitOptions, shimMode: true };
|
|
698
|
+
if (optionsScript) optionsScript.innerHTML = JSON.stringify(shimModeOptions);
|
|
699
|
+
self.esmsInitOptions = shimModeOptions;
|
|
700
|
+
defineValue(self, '_d', undefined);
|
|
701
|
+
|
|
691
702
|
const loadAll = async (load, seen) => {
|
|
692
703
|
seen[load.u] = 1;
|
|
693
704
|
await load.L;
|
|
@@ -721,8 +732,7 @@
|
|
|
721
732
|
if (!shimMode && typeof WebAssembly !== 'undefined') {
|
|
722
733
|
if (wasmSourcePhaseEnabled && !Object.getPrototypeOf(WebAssembly.Module).name) {
|
|
723
734
|
const s = Symbol();
|
|
724
|
-
const brand = m =>
|
|
725
|
-
Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
|
|
735
|
+
const brand = m => defineValue(m, s, 'WebAssembly.Module');
|
|
726
736
|
class AbstractModuleSource {
|
|
727
737
|
get [Symbol.toStringTag]() {
|
|
728
738
|
if (this[s]) return this[s];
|
|
@@ -790,7 +800,15 @@
|
|
|
790
800
|
let firstPolyfillLoad = true;
|
|
791
801
|
let legacyAcceptingImportMaps = true;
|
|
792
802
|
|
|
793
|
-
const topLevelLoad = async (
|
|
803
|
+
const topLevelLoad = async (
|
|
804
|
+
url,
|
|
805
|
+
parentUrl,
|
|
806
|
+
fetchOpts,
|
|
807
|
+
source,
|
|
808
|
+
nativelyLoaded,
|
|
809
|
+
lastStaticLoadPromise,
|
|
810
|
+
sourceType
|
|
811
|
+
) => {
|
|
794
812
|
await initPromise;
|
|
795
813
|
await importMapPromise;
|
|
796
814
|
url = (await resolve(url, parentUrl)).r;
|
|
@@ -802,7 +820,7 @@
|
|
|
802
820
|
url += '?entry';
|
|
803
821
|
}
|
|
804
822
|
|
|
805
|
-
if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, parentUrl);
|
|
823
|
+
if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, parentUrl, source, sourceType);
|
|
806
824
|
// early analysis opt-out - no need to even fetch if we have feature support
|
|
807
825
|
if (!shimMode && baselinePassthrough && nativePassthrough && sourceType !== 'ts') {
|
|
808
826
|
// for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
|
|
@@ -1070,7 +1088,7 @@
|
|
|
1070
1088
|
const mapIntegrity = composedImportMap.integrity[url];
|
|
1071
1089
|
const res = await doFetch(
|
|
1072
1090
|
url,
|
|
1073
|
-
mapIntegrity && !fetchOpts.integrity ?
|
|
1091
|
+
mapIntegrity && !fetchOpts.integrity ? { ...fetchOpts, integrity: mapIntegrity } : fetchOpts,
|
|
1074
1092
|
parent
|
|
1075
1093
|
);
|
|
1076
1094
|
const r = res.url;
|
|
@@ -1137,8 +1155,8 @@
|
|
|
1137
1155
|
const getOrCreateLoad = (url, fetchOpts, parent, source) => {
|
|
1138
1156
|
if (source && registry[url]) {
|
|
1139
1157
|
let i = 0;
|
|
1140
|
-
while (registry[url + '
|
|
1141
|
-
url += '
|
|
1158
|
+
while (registry[url + '#' + ++i]);
|
|
1159
|
+
url += '#' + i;
|
|
1142
1160
|
}
|
|
1143
1161
|
let load = registry[url];
|
|
1144
1162
|
if (load) return load;
|
|
@@ -1225,7 +1243,7 @@
|
|
|
1225
1243
|
if (d >= 0 || resolved.N) load.N = true;
|
|
1226
1244
|
if (d !== -1) return;
|
|
1227
1245
|
if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
|
|
1228
|
-
if (childFetchOpts.integrity) childFetchOpts =
|
|
1246
|
+
if (childFetchOpts.integrity) childFetchOpts = { ...childFetchOpts, integrity: undefined };
|
|
1229
1247
|
const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, source), s: sourcePhase };
|
|
1230
1248
|
// assertion case -> inline the CSS / JSON URL directly
|
|
1231
1249
|
if (source === '') child.l.b = child.l.u;
|
|
@@ -1397,7 +1415,7 @@
|
|
|
1397
1415
|
!script.src ? script.innerHTML : undefined,
|
|
1398
1416
|
!shimMode,
|
|
1399
1417
|
isBlockingReadyScript && lastStaticLoadPromise,
|
|
1400
|
-
'ts'
|
|
1418
|
+
ts ? 'ts' : undefined
|
|
1401
1419
|
).catch(throwError);
|
|
1402
1420
|
}
|
|
1403
1421
|
if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
|
|
@@ -1415,4 +1433,10 @@
|
|
|
1415
1433
|
fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
|
|
1416
1434
|
};
|
|
1417
1435
|
|
|
1418
|
-
|
|
1436
|
+
exports.topLevelLoad = topLevelLoad;
|
|
1437
|
+
|
|
1438
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1439
|
+
|
|
1440
|
+
return exports;
|
|
1441
|
+
|
|
1442
|
+
})({});
|