es-module-shims 2.3.1 → 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 +12 -1
- package/dist/es-module-shims.debug.js +214 -206
- package/dist/es-module-shims.js +211 -203
- package/dist/es-module-shims.wasm.js +211 -203
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
30
30
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
31
31
|
|
|
32
32
|
```html
|
|
33
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@2.
|
|
33
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@2.4.0/dist/es-module-shims.js"></script>
|
|
34
34
|
|
|
35
35
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
36
36
|
<script type="importmap">
|
|
@@ -701,6 +701,7 @@ Provide a `esmsInitOptions` on the global scope before `es-module-shims` is load
|
|
|
701
701
|
* [revokeBlobURLs](#revoke-blob-urls)
|
|
702
702
|
* [shimMode](#shim-mode-option)
|
|
703
703
|
* [skip](#skip)
|
|
704
|
+
* [version](#version)
|
|
704
705
|
|
|
705
706
|
```html
|
|
706
707
|
<script>
|
|
@@ -739,6 +740,8 @@ window.esmsInitOptions = {
|
|
|
739
740
|
meta: (meta, url) => void // default is noop
|
|
740
741
|
// Hook top-level imports
|
|
741
742
|
onimport: (url, options, parentUrl, source) => void // default is noop
|
|
743
|
+
// Ensure only the exact provided version of es-module-shims registered
|
|
744
|
+
version: '2.4.0' // default is empty
|
|
742
745
|
}
|
|
743
746
|
</script>
|
|
744
747
|
<script async src="es-module-shims.js"></script>
|
|
@@ -888,6 +891,14 @@ When passing an array, relative URLs or paths ending in `/` can be provided:
|
|
|
888
891
|
<script async src="es-module-shims.js"></script>
|
|
889
892
|
```
|
|
890
893
|
|
|
894
|
+
### Version
|
|
895
|
+
|
|
896
|
+
When there is a risk of multiple versions of ES Module Shims on the same page, deconflicting is managed by logic that will opt-out of initializing ES Module Shims if it has already been initialized. In addition, ES Module Shims itself is frozen and locked from further mutations.
|
|
897
|
+
|
|
898
|
+
To better support cooporative multi-version cases, as of version 2.4.0, we support a `version` option, which when set will skip initialization if the current version of ES Module Shims does not match this exact expected version.
|
|
899
|
+
|
|
900
|
+
This way, any other old versions after version 2.4.0 running on the page can effectively be turned off, ensuring only the defined version of the polyfill initiates the polyfill.
|
|
901
|
+
|
|
891
902
|
### Revoke Blob URLs
|
|
892
903
|
|
|
893
904
|
When polyfilling the missing features `es-module-shims` would create in-memory blobs using `URL.createObjectURL()` for each processed module.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ES Module Shims 2.
|
|
1
|
+
/** ES Module Shims @version 2.4.0 */
|
|
2
2
|
(function (exports) {
|
|
3
3
|
|
|
4
4
|
let invalidate;
|
|
@@ -162,13 +162,6 @@
|
|
|
162
162
|
];
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
if (self.importShim) {
|
|
166
|
-
console.info(
|
|
167
|
-
`es-module-shims: skipping initialization as importShim was already registered by another polyfill instance`
|
|
168
|
-
);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
165
|
const hasDocument = typeof document !== 'undefined';
|
|
173
166
|
|
|
174
167
|
const noop = () => {};
|
|
@@ -181,11 +174,22 @@
|
|
|
181
174
|
|
|
182
175
|
const dynamicImport = (u, errUrl) => import(u);
|
|
183
176
|
|
|
177
|
+
const defineValue = (obj, prop, value) =>
|
|
178
|
+
Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
|
|
179
|
+
|
|
184
180
|
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
185
181
|
|
|
186
182
|
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
187
183
|
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
188
184
|
|
|
185
|
+
const r$1 = esmsInitOptions.version;
|
|
186
|
+
if (self.importShim || (r$1 && r$1 !== "2.4.0")) {
|
|
187
|
+
console.info(
|
|
188
|
+
`es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
|
|
189
|
+
);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
189
193
|
// shim mode is determined on initialization, no late shim mode
|
|
190
194
|
const shimMode =
|
|
191
195
|
esmsInitOptions.shimMode ||
|
|
@@ -276,198 +280,198 @@
|
|
|
276
280
|
|
|
277
281
|
const fromParent = parent => (parent ? ` imported from ${parent}` : '');
|
|
278
282
|
|
|
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:
|
|
383
|
-
scopes:
|
|
384
|
-
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
|
-
}
|
|
283
|
+
const backslashRegEx = /\\/g;
|
|
284
|
+
|
|
285
|
+
const asURL = url => {
|
|
286
|
+
try {
|
|
287
|
+
if (url.indexOf(':') !== -1) return new URL(url).href;
|
|
288
|
+
} catch (_) {}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const resolveUrl = (relUrl, parentUrl) =>
|
|
292
|
+
resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
|
|
293
|
+
|
|
294
|
+
const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
|
|
295
|
+
const hIdx = parentUrl.indexOf('#'),
|
|
296
|
+
qIdx = parentUrl.indexOf('?');
|
|
297
|
+
if (hIdx + qIdx > -2)
|
|
298
|
+
parentUrl = parentUrl.slice(
|
|
299
|
+
0,
|
|
300
|
+
hIdx === -1 ? qIdx
|
|
301
|
+
: qIdx === -1 || qIdx > hIdx ? hIdx
|
|
302
|
+
: qIdx
|
|
303
|
+
);
|
|
304
|
+
if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
|
|
305
|
+
// protocol-relative
|
|
306
|
+
if (relUrl[0] === '/' && relUrl[1] === '/') {
|
|
307
|
+
return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
|
|
308
|
+
}
|
|
309
|
+
// relative-url
|
|
310
|
+
else if (
|
|
311
|
+
(relUrl[0] === '.' &&
|
|
312
|
+
(relUrl[1] === '/' ||
|
|
313
|
+
(relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
|
|
314
|
+
(relUrl.length === 1 && (relUrl += '/')))) ||
|
|
315
|
+
relUrl[0] === '/'
|
|
316
|
+
) {
|
|
317
|
+
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
318
|
+
if (parentProtocol === 'blob:') {
|
|
319
|
+
throw new TypeError(
|
|
320
|
+
`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
324
|
+
//if (parentUrl[parentProtocol.length] !== '/')
|
|
325
|
+
// throw new Error('Cannot resolve');
|
|
326
|
+
// read pathname from parent URL
|
|
327
|
+
// pathname taken to be part after leading "/"
|
|
328
|
+
let pathname;
|
|
329
|
+
if (parentUrl[parentProtocol.length + 1] === '/') {
|
|
330
|
+
// resolving to a :// so we need to read out the auth and host
|
|
331
|
+
if (parentProtocol !== 'file:') {
|
|
332
|
+
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
333
|
+
pathname = pathname.slice(pathname.indexOf('/') + 1);
|
|
334
|
+
} else {
|
|
335
|
+
pathname = parentUrl.slice(8);
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
// resolving to :/ so pathname is the /... part
|
|
339
|
+
pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
343
|
+
|
|
344
|
+
// join together and split for removal of .. and . segments
|
|
345
|
+
// looping the string instead of anything fancy for perf reasons
|
|
346
|
+
// '../../../../../z' resolved to 'x/y' is just 'z'
|
|
347
|
+
const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
|
|
348
|
+
|
|
349
|
+
const output = [];
|
|
350
|
+
let segmentIndex = -1;
|
|
351
|
+
for (let i = 0; i < segmented.length; i++) {
|
|
352
|
+
// busy reading a segment - only terminate on '/'
|
|
353
|
+
if (segmentIndex !== -1) {
|
|
354
|
+
if (segmented[i] === '/') {
|
|
355
|
+
output.push(segmented.slice(segmentIndex, i + 1));
|
|
356
|
+
segmentIndex = -1;
|
|
357
|
+
}
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
// new segment - check if it is relative
|
|
361
|
+
else if (segmented[i] === '.') {
|
|
362
|
+
// ../ segment
|
|
363
|
+
if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
|
|
364
|
+
output.pop();
|
|
365
|
+
i += 2;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
// ./ segment
|
|
369
|
+
else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
|
|
370
|
+
i += 1;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// it is the start of a new segment
|
|
375
|
+
while (segmented[i] === '/') i++;
|
|
376
|
+
segmentIndex = i;
|
|
377
|
+
}
|
|
378
|
+
// finish reading out the last segment
|
|
379
|
+
if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
|
|
380
|
+
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
|
|
385
|
+
const outMap = {
|
|
386
|
+
imports: { ...parentMap.imports },
|
|
387
|
+
scopes: { ...parentMap.scopes },
|
|
388
|
+
integrity: { ...parentMap.integrity }
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
|
|
392
|
+
|
|
393
|
+
if (json.scopes)
|
|
394
|
+
for (let s in json.scopes) {
|
|
395
|
+
const resolvedScope = resolveUrl(s, baseUrl);
|
|
396
|
+
resolveAndComposePackages(
|
|
397
|
+
json.scopes[s],
|
|
398
|
+
outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
|
|
399
|
+
baseUrl,
|
|
400
|
+
parentMap
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
|
|
405
|
+
|
|
406
|
+
return outMap;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const getMatch = (path, matchObj) => {
|
|
410
|
+
if (matchObj[path]) return path;
|
|
411
|
+
let sepIndex = path.length;
|
|
412
|
+
do {
|
|
413
|
+
const segment = path.slice(0, sepIndex + 1);
|
|
414
|
+
if (segment in matchObj) return segment;
|
|
415
|
+
} while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const applyPackages = (id, packages) => {
|
|
419
|
+
const pkgName = getMatch(id, packages);
|
|
420
|
+
if (pkgName) {
|
|
421
|
+
const pkg = packages[pkgName];
|
|
422
|
+
if (pkg === null) return;
|
|
423
|
+
return pkg + id.slice(pkgName.length);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
|
|
428
|
+
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
429
|
+
while (scopeUrl) {
|
|
430
|
+
const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
|
|
431
|
+
if (packageResolution) return packageResolution;
|
|
432
|
+
scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
|
|
433
|
+
}
|
|
434
|
+
return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
|
|
438
|
+
for (let p in packages) {
|
|
439
|
+
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
440
|
+
if (
|
|
441
|
+
(!shimMode || !mapOverrides) &&
|
|
442
|
+
outPackages[resolvedLhs] &&
|
|
443
|
+
outPackages[resolvedLhs] !== packages[resolvedLhs]
|
|
444
|
+
) {
|
|
445
|
+
console.warn(
|
|
446
|
+
`es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
|
|
447
|
+
);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
let target = packages[p];
|
|
451
|
+
if (typeof target !== 'string') continue;
|
|
452
|
+
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
453
|
+
if (mapped) {
|
|
454
|
+
outPackages[resolvedLhs] = mapped;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
|
|
462
|
+
for (let p in integrity) {
|
|
463
|
+
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
464
|
+
if (
|
|
465
|
+
(!shimMode || !mapOverrides) &&
|
|
466
|
+
outIntegrity[resolvedLhs] &&
|
|
467
|
+
outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
|
|
468
|
+
) {
|
|
469
|
+
console.warn(
|
|
470
|
+
`es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
outIntegrity[resolvedLhs] = integrity[p];
|
|
474
|
+
}
|
|
471
475
|
};
|
|
472
476
|
|
|
473
477
|
// support browsers without dynamic import support (eg Firefox 6x)
|
|
@@ -673,8 +677,6 @@
|
|
|
673
677
|
|
|
674
678
|
if (hotReload) importShim$1.hotReload = hotReload$1;
|
|
675
679
|
|
|
676
|
-
self.importShim = importShim$1;
|
|
677
|
-
|
|
678
680
|
const defaultResolve = (id, parentUrl) => {
|
|
679
681
|
return (
|
|
680
682
|
resolveImportMap(composedImportMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) ||
|
|
@@ -702,6 +704,13 @@
|
|
|
702
704
|
const sourceCache = (importShim$1._s = {});
|
|
703
705
|
(importShim$1._i = new WeakMap());
|
|
704
706
|
|
|
707
|
+
// Ensure this version is the only version
|
|
708
|
+
defineValue(self, 'importShim', Object.freeze(importShim$1));
|
|
709
|
+
const shimModeOptions = { ...esmsInitOptions, shimMode: true };
|
|
710
|
+
if (optionsScript) optionsScript.innerHTML = JSON.stringify(shimModeOptions);
|
|
711
|
+
self.esmsInitOptions = shimModeOptions;
|
|
712
|
+
defineValue(self, '_d', undefined);
|
|
713
|
+
|
|
705
714
|
const loadAll = async (load, seen) => {
|
|
706
715
|
seen[load.u] = 1;
|
|
707
716
|
await load.L;
|
|
@@ -735,8 +744,7 @@
|
|
|
735
744
|
if (!shimMode && typeof WebAssembly !== 'undefined') {
|
|
736
745
|
if (wasmSourcePhaseEnabled && !Object.getPrototypeOf(WebAssembly.Module).name) {
|
|
737
746
|
const s = Symbol();
|
|
738
|
-
const brand = m =>
|
|
739
|
-
Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
|
|
747
|
+
const brand = m => defineValue(m, s, 'WebAssembly.Module');
|
|
740
748
|
class AbstractModuleSource {
|
|
741
749
|
get [Symbol.toStringTag]() {
|
|
742
750
|
if (this[s]) return this[s];
|
|
@@ -1098,7 +1106,7 @@
|
|
|
1098
1106
|
const mapIntegrity = composedImportMap.integrity[url];
|
|
1099
1107
|
const res = await doFetch(
|
|
1100
1108
|
url,
|
|
1101
|
-
mapIntegrity && !fetchOpts.integrity ?
|
|
1109
|
+
mapIntegrity && !fetchOpts.integrity ? { ...fetchOpts, integrity: mapIntegrity } : fetchOpts,
|
|
1102
1110
|
parent
|
|
1103
1111
|
);
|
|
1104
1112
|
const r = res.url;
|
|
@@ -1253,7 +1261,7 @@
|
|
|
1253
1261
|
if (d >= 0 || resolved.N) load.N = true;
|
|
1254
1262
|
if (d !== -1) return;
|
|
1255
1263
|
if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
|
|
1256
|
-
if (childFetchOpts.integrity) childFetchOpts =
|
|
1264
|
+
if (childFetchOpts.integrity) childFetchOpts = { ...childFetchOpts, integrity: undefined };
|
|
1257
1265
|
const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, source), s: sourcePhase };
|
|
1258
1266
|
// assertion case -> inline the CSS / JSON URL directly
|
|
1259
1267
|
if (source === '') child.l.b = child.l.u;
|