es-module-shims 1.3.6 → 1.4.3
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/CHANGELOG.md +15 -0
- package/README.md +78 -58
- package/dist/es-module-shims.js +58 -51
- package/dist/es-module-shims.wasm.js +58 -51
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
ES Module Shims 1.4.3 (2022/01/25)
|
|
2
|
+
* Feature: Support import map overrides when existing resolution matches new resolution (https://github.com/guybedford/es-module-shims/pull/249, @vovacodes)
|
|
3
|
+
* Fix: Import assertions support with dynamic imports (https://github.com/guybedford/es-module-shims/pull/248)
|
|
4
|
+
|
|
5
|
+
ES Module Shims 1.4.2 (2022/01/24)
|
|
6
|
+
* Fix: optional catch binding in `isUrl` function (@thepassle, https://github.com/guybedford/es-module-shims/pull/246)
|
|
7
|
+
|
|
8
|
+
ES Module Shims 1.4.1 (2021/12/15)
|
|
9
|
+
* Fix: Firefox parse error stacks (https://github.com/guybedford/es-module-shims/pull/239)
|
|
10
|
+
|
|
11
|
+
ES Module Shims 1.4.0 (2021/12/14)
|
|
12
|
+
* Feature: "enforceIntegrity" option and "modulepreload-shim" support for secure shim mode with integrity (https://github.com/guybedford/es-module-shims/pull/236)
|
|
13
|
+
* Fix: Safari parse error stacks (https://github.com/guybedford/es-module-shims/pull/238)
|
|
14
|
+
* Note: Polyfill mode console note when expected native errors are present (https://github.com/guybedford/es-module-shims/pull/237)
|
|
15
|
+
|
|
1
16
|
ES Module Shims 1.3.6 (2021/12/07)
|
|
2
17
|
* Fix resolve hook via esms options (#233, @ffortier)
|
|
3
18
|
|
package/README.md
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
# ES Module Shims
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
Shims modern ES Modules features like import maps on top of the baseline modules support in browsers supported by [95% of users](https://caniuse.com/#feat=es6-module).
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
When running in polyfill mode, [the 67% of users](https://caniuse.com/import-maps) with import maps entirely bypass the shim code entirely.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
For the remaining 30% of users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The following modules features are polyfilled:
|
|
10
10
|
|
|
11
11
|
* [Import Maps](#import-maps) support.
|
|
12
12
|
* Dynamic `import()` shimming when necessary in eg older Firefox versions.
|
|
13
13
|
* `import.meta` and `import.meta.url`.
|
|
14
|
-
* [JSON](#json-modules) and [CSS modules](#css-modules) with import assertions.
|
|
14
|
+
* [JSON](#json-modules) and [CSS modules](#css-modules) with import assertions (when enabled).
|
|
15
15
|
* [`<link rel="modulepreload">` polyfill](#modulepreload) in non Chromium browsers for both shimmed and unshimmed preloading scenarios.
|
|
16
|
-
* Comprehensive [CSP support](#csp-support) using nonces, no `unsafe-eval` or `blob:` policy being necessary.
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
When running in shim mode, module rewriting is applied for all users and custom [resolve](#resolve-hook) and [fetch](#fetch-hook) hooks can be implemented allowing for custom resolution and streaming in-browser transform workflows.
|
|
19
18
|
|
|
20
19
|
Because we are still using the native module loader the edge cases work out comprehensively, including:
|
|
21
20
|
|
|
@@ -23,54 +22,34 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
23
22
|
* Dynamic import expressions (`import('src/' + varname')`)
|
|
24
23
|
* Circular references, with the execption that live bindings are disabled for the first unexecuted circular parent.
|
|
25
24
|
|
|
26
|
-
Due to the use of a tiny [JS tokenizer for ES module syntax only](https://github.com/guybedford/es-module-lexer), with very simple rewriting rules, transformation is very fast.
|
|
27
|
-
|
|
28
25
|
## Usage
|
|
29
26
|
|
|
30
|
-
Include ES Module Shims with a `async` attribute on the script:
|
|
31
|
-
|
|
32
|
-
For example, from CDN:
|
|
27
|
+
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
33
28
|
|
|
34
29
|
```html
|
|
35
|
-
|
|
36
|
-
<script async src="https://unpkg.com/es-module-shims@1.3.0/dist/es-module-shims.js"></script>
|
|
37
|
-
|
|
38
|
-
<!-- JSPM.IO -->
|
|
39
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@1.3.0/dist/es-module-shims.js"></script>
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Then there are two ways to use ES Module Shims: Polyfill Mode and [Shim Mode](#shim-mode).
|
|
43
|
-
|
|
44
|
-
### Benchmarks
|
|
45
|
-
|
|
46
|
-
ES Module Shims is designed for production performance. A [comprehensive benchmark suite](bench/README.md) tracks multiple loading scenarios for the project.
|
|
47
|
-
|
|
48
|
-
Benchmark summary:
|
|
49
|
-
|
|
50
|
-
* [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [70% of users](https://caniuse.com/import-maps)) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
|
|
51
|
-
* [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [30% of users](https://caniuse.com/import-maps)) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
|
|
52
|
-
* [Very large import maps](bench/README.md#large-import-maps-performance) (100s of entries) cost only a few extra milliseconds upfront for the additional loading cost.
|
|
53
|
-
|
|
54
|
-
### Polyfill Mode
|
|
30
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@1.4.3/dist/es-module-shims.js"></script>
|
|
55
31
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```html
|
|
32
|
+
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
59
33
|
<script type="importmap">
|
|
60
34
|
{
|
|
61
35
|
"imports": {
|
|
62
|
-
"
|
|
36
|
+
"react": "https://ga.jspm.io/npm:react@18.0.0-rc.0/index.js"
|
|
37
|
+
},
|
|
38
|
+
"scopes": {
|
|
39
|
+
"https://ga.jspm.io/npm:react@18.0.0-rc.0/": {
|
|
40
|
+
"object-assign": "https://ga.jspm.io/npm:object-assign@4.1.1/index.js"
|
|
41
|
+
}
|
|
63
42
|
}
|
|
64
43
|
}
|
|
65
44
|
</script>
|
|
66
|
-
<script type="module">import 'app'</script>
|
|
67
|
-
```
|
|
68
45
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
46
|
+
<script type="module">
|
|
47
|
+
import react from 'react';
|
|
48
|
+
console.log(react);
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
72
51
|
|
|
73
|
-
|
|
52
|
+
In browsers without import maps support, a console error will be given:
|
|
74
53
|
|
|
75
54
|
```
|
|
76
55
|
Uncaught TypeError: Failed to resolve module specifier "app". Relative references must start with either "/", "./", or "../".
|
|
@@ -81,25 +60,23 @@ This execution failure is a feature - it avoids the polyfill causing double exec
|
|
|
81
60
|
|
|
82
61
|
This is because the polyfill cannot disable the native loader - instead it will only execute modules that would otherwise fail resolving or parsing to avoid duplicate fetches or executions that would cause performance and reliability issues.
|
|
83
62
|
|
|
84
|
-
|
|
63
|
+
### Shim Mode
|
|
85
64
|
|
|
86
|
-
|
|
87
|
-
<script>
|
|
88
|
-
window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules'] }
|
|
89
|
-
</script>
|
|
90
|
-
```
|
|
65
|
+
Shim mode is an alternative to polyfill mode and doesn't rely on native modules erroring - instead it is triggered by the existence of any `<script type="importmap-shim">` or `<script type="module-shim">`, or when explicitly setting the [`shimMode` init option](#shim-mode-option).
|
|
91
66
|
|
|
92
|
-
|
|
67
|
+
In shim mode, only the above `importmap-shim` and `module-shim` tags will be parsed and executed by ES Module Shims.
|
|
93
68
|
|
|
94
|
-
|
|
69
|
+
Shim mode also provides some additional features that aren't yet natively supported such as supporting multiple import maps, [external import maps](#external-import-maps) with a `"src"` attribute, [dynamically injecting import maps](#dynamic-import-maps), and [reading current import map state](#reading-current-import-map-state), which can be useful in certain applications.
|
|
95
70
|
|
|
96
|
-
|
|
71
|
+
## Benchmarks
|
|
97
72
|
|
|
98
|
-
|
|
73
|
+
ES Module Shims is designed for production performance. A [comprehensive benchmark suite](bench/README.md) tracks multiple loading scenarios for the project.
|
|
99
74
|
|
|
100
|
-
|
|
75
|
+
Benchmark summary:
|
|
101
76
|
|
|
102
|
-
|
|
77
|
+
* [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [70% of users](https://caniuse.com/import-maps)) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
|
|
78
|
+
* [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [30% of users](https://caniuse.com/import-maps)) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
|
|
79
|
+
* [Very large import maps](bench/README.md#large-import-maps-performance) (100s of entries) cost only a few extra milliseconds upfront for the additional loading cost.
|
|
103
80
|
|
|
104
81
|
## Features
|
|
105
82
|
|
|
@@ -107,7 +84,7 @@ Shim mode also provides some additional features that aren't yet natively suppor
|
|
|
107
84
|
|
|
108
85
|
Works in all browsers with [baseline ES module support](https://caniuse.com/#feat=es6-module).
|
|
109
86
|
|
|
110
|
-
|
|
87
|
+
Browser Compatibility **with ES Module Shims**:
|
|
111
88
|
|
|
112
89
|
| ES Modules Features | Chrome (61+) | Firefox (60+) | Safari (10.1+) | Edge (17+) |
|
|
113
90
|
| ---------------------------------- | ------------------------------------ | ------------------------------------ | ------------------------------------ | ------------------------------------ |
|
|
@@ -127,7 +104,7 @@ Works in all browsers with [baseline ES module support](https://caniuse.com/#fea
|
|
|
127
104
|
* 3: _CSS module support requires a separate [Constructable Stylesheets polyfill](https://github.com/calebdwilliams/construct-style-sheets#readme)._
|
|
128
105
|
* 4: _Top-level await support is possible for ES Module Shims to implement, with the feature request tracking in https://github.com/guybedford/es-module-shims/issues/5._
|
|
129
106
|
|
|
130
|
-
|
|
107
|
+
Browser compatibility **without ES module shims**:
|
|
131
108
|
|
|
132
109
|
| ES Modules Features | Chrome (61+) | Firefox (60+) | Safari (10.1+) | Edge (17+) |
|
|
133
110
|
| ---------------------------------- | ------------------------------------ | ------------------------------------ | ------------------------------------ | ------------------------------------ |
|
|
@@ -351,7 +328,15 @@ In browsers with variable feature support, sources are analyzed with module spec
|
|
|
351
328
|
|
|
352
329
|
The current default native baseline for the ES module shims polyfill mode is browsers supporting import maps.
|
|
353
330
|
|
|
354
|
-
If using more modern features like CSS Modules or JSON Modules, these need to be manually enabled via the [`polyfillEnable` init option](#polyfill-enable-option) to raise the native baseline to only browsers supporting these features
|
|
331
|
+
If using more modern features like CSS Modules or JSON Modules, these need to be manually enabled via the [`polyfillEnable` init option](#polyfill-enable-option) to raise the native baseline to only browsers supporting these features:
|
|
332
|
+
|
|
333
|
+
```html
|
|
334
|
+
<script>
|
|
335
|
+
window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules'] }
|
|
336
|
+
</script>
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
To verify when the polyfill is actively engaging as opposed to relying on the native loader, [a `polyfill` hook](#polyfill-hook) is also provided.
|
|
355
340
|
|
|
356
341
|
#### Polyfill Edge Case: Dynamic Import
|
|
357
342
|
|
|
@@ -421,6 +406,18 @@ Adding the `"noshim"` attribute to the script tag will also ensure that ES Modul
|
|
|
421
406
|
|
|
422
407
|
Provide a `esmsInitOptions` on the global scope before `es-module-shims` is loaded to configure various aspects of the module loading process:
|
|
423
408
|
|
|
409
|
+
* [shimMode](#shim-mode-option)
|
|
410
|
+
* [polyfillEnable](#polyfill-enable-option)
|
|
411
|
+
* [enforceIntegrity](#enforce-integrity)
|
|
412
|
+
* [nonce](#nonce)
|
|
413
|
+
* [noLoadEventRetriggers](#no-load-event-retriggers)
|
|
414
|
+
* [skip](#skip-processing)
|
|
415
|
+
* [onerror](#error-hook)
|
|
416
|
+
* [onpolyfill](#polyfill-hook)
|
|
417
|
+
* [resolve](#resolve-hook)
|
|
418
|
+
* [fetch](#fetch-hook)
|
|
419
|
+
* [revokeBlobURLs](#revoke-blob-urls)
|
|
420
|
+
|
|
424
421
|
```html
|
|
425
422
|
<script>
|
|
426
423
|
window.esmsInitOptions = {
|
|
@@ -430,10 +427,11 @@ window.esmsInitOptions = {
|
|
|
430
427
|
noLoadEventRetriggers: true, // default false
|
|
431
428
|
skip: /^https:\/\/cdn\.com/, // defaults to null
|
|
432
429
|
onerror: (e) => { /*...*/ }, // default noop
|
|
433
|
-
onpolyfill: () => {},
|
|
430
|
+
onpolyfill: () => {}, // default logs to the console
|
|
434
431
|
resolve: (id, parentUrl, resolve) => resolve(id, parentUrl), // default is spec resolution
|
|
435
432
|
fetch: (url, options) => fetch(url, options), // default is native
|
|
436
433
|
revokeBlobURLs: true, // default false
|
|
434
|
+
enforceIntegrity: true, // default false
|
|
437
435
|
}
|
|
438
436
|
</script>
|
|
439
437
|
<script async src="es-module-shims.js"></script>
|
|
@@ -488,6 +486,26 @@ Currently this option supports just `"css-modules"` and `"json-modules"`.
|
|
|
488
486
|
</script>
|
|
489
487
|
```
|
|
490
488
|
|
|
489
|
+
### Enforce Integrity
|
|
490
|
+
|
|
491
|
+
When enabled, `enforceIntegrity` will ensure that all modules loaded through ES Module Shims must have integrity defined either on a `<link rel="modulepreload" integrity="...">` or on
|
|
492
|
+
a `<link rel="modulepreload-shim" integrity="...">` preload tag in shim mode. Modules without integrity will throw at fetch time.
|
|
493
|
+
|
|
494
|
+
For example in the following, only the listed `app.js` and `dep.js` modules will be able to execute with the provided integrity:
|
|
495
|
+
|
|
496
|
+
```html
|
|
497
|
+
<script type="esms-options">{ "enforceIntegrity": true }</script>
|
|
498
|
+
<link rel="modulepreload-shim" href="/app.js" integrity="sha384-..." />\
|
|
499
|
+
<link rel="modulepreload-shim" href="/dep.js" integrity="sha384-..." />
|
|
500
|
+
<script type="module-shim">
|
|
501
|
+
import '/app.js';
|
|
502
|
+
</script>
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
Strong execution guarantees are only possible in shim mode since in polyfill mode it is not possible to stop the native loader from executing code without an integrity.
|
|
506
|
+
|
|
507
|
+
Future versions of this option may provide support for origin-specific allow lists.
|
|
508
|
+
|
|
491
509
|
### Nonce
|
|
492
510
|
|
|
493
511
|
The `nonce` option allows setting a CSP nonce to be used with all script injections for full CSP compatibility supported by the [CSP build](#csp-build) of ES Module Shims.
|
|
@@ -552,6 +570,8 @@ window.polyfilling = () => console.log('The polyfill is actively applying');
|
|
|
552
570
|
</script>
|
|
553
571
|
```
|
|
554
572
|
|
|
573
|
+
The default hook will log a message to the console with `console.info` noting that polyfill mode is enabled and that the native error can be ignored.
|
|
574
|
+
|
|
555
575
|
In the above, running in latest Chromium browsers, nothing will be logged, while running in an older browser that does not support newer features
|
|
556
576
|
like import maps the console log will be output.
|
|
557
577
|
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
/* ES Module Shims 1.3
|
|
1
|
+
/* ES Module Shims 1.4.3 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const uaMatch = navigator.userAgent.match(/(Edge|Safari)\/\d+\.\d+/);
|
|
5
|
+
const edge = uaMatch && uaMatch[1] === 'Edge';
|
|
6
|
+
const safari = uaMatch && uaMatch[1] === 'Safari';
|
|
5
7
|
|
|
6
8
|
let baseUrl;
|
|
7
9
|
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
new URL(url);
|
|
28
30
|
return true;
|
|
29
31
|
}
|
|
30
|
-
catch {
|
|
32
|
+
catch(_) {
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -129,18 +131,18 @@
|
|
|
129
131
|
function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
|
|
130
132
|
for (let p in packages) {
|
|
131
133
|
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
132
|
-
if (outPackages[resolvedLhs]) {
|
|
133
|
-
throw
|
|
134
|
+
if (outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
|
|
135
|
+
throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
|
|
134
136
|
}
|
|
135
137
|
let target = packages[p];
|
|
136
|
-
if (typeof target !== 'string')
|
|
138
|
+
if (typeof target !== 'string')
|
|
137
139
|
continue;
|
|
138
140
|
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
139
141
|
if (mapped) {
|
|
140
142
|
outPackages[resolvedLhs] = mapped;
|
|
141
143
|
continue;
|
|
142
144
|
}
|
|
143
|
-
|
|
145
|
+
console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
|
|
@@ -175,17 +177,10 @@
|
|
|
175
177
|
if (pkgName) {
|
|
176
178
|
const pkg = packages[pkgName];
|
|
177
179
|
if (pkg === null) return;
|
|
178
|
-
|
|
179
|
-
targetWarning(pkgName, pkg, "should have a trailing '/'");
|
|
180
|
-
else
|
|
181
|
-
return pkg + id.slice(pkgName.length);
|
|
180
|
+
return pkg + id.slice(pkgName.length);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
183
|
|
|
185
|
-
function targetWarning (match, target, msg) {
|
|
186
|
-
console.warn("Package target " + msg + ", resolving target '" + target + "' for " + match);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
184
|
function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
|
|
190
185
|
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
191
186
|
while (scopeUrl) {
|
|
@@ -215,9 +210,9 @@
|
|
|
215
210
|
}
|
|
216
211
|
|
|
217
212
|
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
218
|
-
const onpolyfill = globalHook(esmsInitOptions.onpolyfill
|
|
213
|
+
const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
|
|
219
214
|
|
|
220
|
-
const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions;
|
|
215
|
+
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
221
216
|
|
|
222
217
|
const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
223
218
|
|
|
@@ -340,34 +335,36 @@
|
|
|
340
335
|
const initPromise = featureDetectionPromise.then(() => {
|
|
341
336
|
// shim mode is determined on initialization, no late shim mode
|
|
342
337
|
if (!shimMode) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
338
|
+
if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
|
|
339
|
+
setShimMode();
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
let seenScript = false;
|
|
343
|
+
for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
|
|
344
|
+
if (!seenScript) {
|
|
345
|
+
if (script.type === 'module')
|
|
346
|
+
seenScript = true;
|
|
347
|
+
}
|
|
348
|
+
else if (script.type === 'importmap') {
|
|
349
|
+
importMapSrcOrLazy = true;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
354
352
|
}
|
|
355
353
|
}
|
|
356
354
|
}
|
|
357
355
|
baselinePassthrough = supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
|
|
358
|
-
if (!baselinePassthrough) onpolyfill();
|
|
359
356
|
if (shimMode || !baselinePassthrough) {
|
|
360
357
|
new MutationObserver(mutations => {
|
|
361
358
|
for (const mutation of mutations) {
|
|
362
359
|
if (mutation.type !== 'childList') continue;
|
|
363
360
|
for (const node of mutation.addedNodes) {
|
|
364
361
|
if (node.tagName === 'SCRIPT') {
|
|
365
|
-
if (
|
|
362
|
+
if (node.type === (shimMode ? 'module-shim' : 'module'))
|
|
366
363
|
processScript(node);
|
|
367
|
-
if (
|
|
364
|
+
if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
|
|
368
365
|
processImportMap(node);
|
|
369
366
|
}
|
|
370
|
-
else if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
|
367
|
+
else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
|
|
371
368
|
processPreload(node);
|
|
372
369
|
}
|
|
373
370
|
}
|
|
@@ -378,8 +375,9 @@
|
|
|
378
375
|
}
|
|
379
376
|
});
|
|
380
377
|
let importMapPromise = initPromise;
|
|
381
|
-
|
|
378
|
+
let firstPolyfillLoad = true;
|
|
382
379
|
let acceptingImportMaps = true;
|
|
380
|
+
|
|
383
381
|
async function topLevelLoad (url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
|
|
384
382
|
if (!shimMode)
|
|
385
383
|
acceptingImportMaps = false;
|
|
@@ -403,6 +401,10 @@
|
|
|
403
401
|
if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
|
|
404
402
|
return module;
|
|
405
403
|
}
|
|
404
|
+
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
405
|
+
onpolyfill();
|
|
406
|
+
firstPolyfillLoad = false;
|
|
407
|
+
}
|
|
406
408
|
const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
|
|
407
409
|
// if the top-level load is a shell, run its update function
|
|
408
410
|
if (load.s)
|
|
@@ -484,7 +486,7 @@
|
|
|
484
486
|
// once all deps have loaded we can inline the dependency resolution blobs
|
|
485
487
|
// and define this blob
|
|
486
488
|
let lastIndex = 0, depIndex = 0;
|
|
487
|
-
for (const { s: start,
|
|
489
|
+
for (const { s: start, e: end, se: statementEnd, d: dynamicImportIndex } of imports) {
|
|
488
490
|
// dependency source replacements
|
|
489
491
|
if (dynamicImportIndex === -1) {
|
|
490
492
|
const depLoad = load.d[depIndex++];
|
|
@@ -505,31 +507,30 @@
|
|
|
505
507
|
}
|
|
506
508
|
// circular shell execution
|
|
507
509
|
else if (depLoad.s) {
|
|
508
|
-
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1,
|
|
509
|
-
lastIndex =
|
|
510
|
+
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)};import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
|
|
511
|
+
lastIndex = statementEnd;
|
|
510
512
|
depLoad.s = undefined;
|
|
511
513
|
continue;
|
|
512
514
|
}
|
|
513
|
-
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1,
|
|
514
|
-
lastIndex =
|
|
515
|
+
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
|
|
516
|
+
lastIndex = statementEnd;
|
|
515
517
|
}
|
|
516
518
|
// import.meta
|
|
517
519
|
else if (dynamicImportIndex === -2) {
|
|
518
520
|
meta[load.r] = { url: load.r, resolve: importMetaResolve };
|
|
519
521
|
resolvedSource += `${source.slice(lastIndex, start)}self._esmsm[${urlJsString(load.r)}]`;
|
|
520
|
-
lastIndex =
|
|
522
|
+
lastIndex = statementEnd;
|
|
521
523
|
}
|
|
522
524
|
// dynamic import
|
|
523
525
|
else {
|
|
524
|
-
resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}`;
|
|
525
|
-
lastIndex =
|
|
526
|
+
resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}${source.slice(end, statementEnd)}`;
|
|
527
|
+
lastIndex = statementEnd;
|
|
526
528
|
}
|
|
527
529
|
}
|
|
528
530
|
|
|
529
531
|
resolvedSource += source.slice(lastIndex);
|
|
530
532
|
}
|
|
531
533
|
|
|
532
|
-
// ; and // trailer support added for Ruby 7 source maps compatibility
|
|
533
534
|
let hasSourceURL = false;
|
|
534
535
|
resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
|
|
535
536
|
if (!hasSourceURL)
|
|
@@ -539,12 +540,13 @@
|
|
|
539
540
|
load.S = undefined;
|
|
540
541
|
}
|
|
541
542
|
|
|
543
|
+
// ; and // trailer support added for Ruby on Rails 7 source maps compatibility
|
|
544
|
+
// https://github.com/guybedford/es-module-shims/issues/228
|
|
542
545
|
const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
|
|
543
546
|
|
|
544
547
|
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
545
548
|
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
546
549
|
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
547
|
-
const wasmContentType = /^application\/wasm(;|$)/;
|
|
548
550
|
|
|
549
551
|
const cssUrlRegEx = /url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;
|
|
550
552
|
|
|
@@ -562,6 +564,8 @@
|
|
|
562
564
|
}
|
|
563
565
|
|
|
564
566
|
async function doFetch (url, fetchOpts) {
|
|
567
|
+
if (enforceIntegrity && !fetchOpts.integrity)
|
|
568
|
+
throw Error(`No integrity for ${url}`);
|
|
565
569
|
const poolQueue = pushFetchPool();
|
|
566
570
|
if (poolQueue) await poolQueue;
|
|
567
571
|
try {
|
|
@@ -571,7 +575,7 @@
|
|
|
571
575
|
popFetchPool();
|
|
572
576
|
}
|
|
573
577
|
if (!res.ok)
|
|
574
|
-
throw
|
|
578
|
+
throw Error(`${res.status} ${res.statusText} ${res.url}`);
|
|
575
579
|
const contentType = res.headers.get('content-type');
|
|
576
580
|
if (jsContentType.test(contentType))
|
|
577
581
|
return { r: res.url, s: await res.text(), t: 'js' };
|
|
@@ -581,10 +585,8 @@
|
|
|
581
585
|
return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
|
|
582
586
|
JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
|
|
583
587
|
});export default s;`, t: 'css' };
|
|
584
|
-
else if (wasmContentType.test(contentType))
|
|
585
|
-
throw new Error('WASM modules not supported');
|
|
586
588
|
else
|
|
587
|
-
throw
|
|
589
|
+
throw Error(`Unsupported Content-Type "${contentType}"`);
|
|
588
590
|
}
|
|
589
591
|
|
|
590
592
|
function getOrCreateLoad (url, fetchOpts, source) {
|
|
@@ -624,7 +626,7 @@
|
|
|
624
626
|
({ r: load.r, s: source, t } = await (fetchCache[url] || doFetch(url, fetchOpts)));
|
|
625
627
|
if (t && !shimMode) {
|
|
626
628
|
if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
|
|
627
|
-
throw
|
|
629
|
+
throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
|
|
628
630
|
if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
|
|
629
631
|
load.n = true;
|
|
630
632
|
}
|
|
@@ -663,9 +665,9 @@
|
|
|
663
665
|
}
|
|
664
666
|
|
|
665
667
|
function processScriptsAndPreloads () {
|
|
666
|
-
for (const script of document.querySelectorAll(shimMode ? 'script[type=
|
|
668
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
|
|
667
669
|
processScript(script);
|
|
668
|
-
for (const link of document.querySelectorAll('link[rel=
|
|
670
|
+
for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
|
|
669
671
|
processPreload(link);
|
|
670
672
|
}
|
|
671
673
|
|
|
@@ -763,7 +765,12 @@
|
|
|
763
765
|
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
764
766
|
const blocks = script.getAttribute('async') === null && isReadyScript;
|
|
765
767
|
const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
|
|
766
|
-
|
|
768
|
+
// Safari only gives error via console.error
|
|
769
|
+
if (safari)
|
|
770
|
+
console.error(e);
|
|
771
|
+
// Firefox only gives error stack via setTimeout
|
|
772
|
+
else
|
|
773
|
+
setTimeout(() => { throw e});
|
|
767
774
|
onerror(e);
|
|
768
775
|
});
|
|
769
776
|
if (blocks)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 1.3
|
|
1
|
+
/* ES Module Shims Wasm 1.4.3 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const uaMatch = navigator.userAgent.match(/(Edge|Safari)\/\d+\.\d+/);
|
|
5
|
+
const edge = uaMatch && uaMatch[1] === 'Edge';
|
|
6
|
+
const safari = uaMatch && uaMatch[1] === 'Safari';
|
|
5
7
|
|
|
6
8
|
let baseUrl;
|
|
7
9
|
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
new URL(url);
|
|
28
30
|
return true;
|
|
29
31
|
}
|
|
30
|
-
catch {
|
|
32
|
+
catch(_) {
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -129,18 +131,18 @@
|
|
|
129
131
|
function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
|
|
130
132
|
for (let p in packages) {
|
|
131
133
|
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
132
|
-
if (outPackages[resolvedLhs]) {
|
|
133
|
-
throw
|
|
134
|
+
if (outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
|
|
135
|
+
throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
|
|
134
136
|
}
|
|
135
137
|
let target = packages[p];
|
|
136
|
-
if (typeof target !== 'string')
|
|
138
|
+
if (typeof target !== 'string')
|
|
137
139
|
continue;
|
|
138
140
|
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
139
141
|
if (mapped) {
|
|
140
142
|
outPackages[resolvedLhs] = mapped;
|
|
141
143
|
continue;
|
|
142
144
|
}
|
|
143
|
-
|
|
145
|
+
console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
|
|
@@ -175,17 +177,10 @@
|
|
|
175
177
|
if (pkgName) {
|
|
176
178
|
const pkg = packages[pkgName];
|
|
177
179
|
if (pkg === null) return;
|
|
178
|
-
|
|
179
|
-
targetWarning(pkgName, pkg, "should have a trailing '/'");
|
|
180
|
-
else
|
|
181
|
-
return pkg + id.slice(pkgName.length);
|
|
180
|
+
return pkg + id.slice(pkgName.length);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
183
|
|
|
185
|
-
function targetWarning (match, target, msg) {
|
|
186
|
-
console.warn("Package target " + msg + ", resolving target '" + target + "' for " + match);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
184
|
function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
|
|
190
185
|
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
191
186
|
while (scopeUrl) {
|
|
@@ -215,9 +210,9 @@
|
|
|
215
210
|
}
|
|
216
211
|
|
|
217
212
|
const onerror = globalHook(esmsInitOptions.onerror || noop);
|
|
218
|
-
const onpolyfill = globalHook(esmsInitOptions.onpolyfill
|
|
213
|
+
const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
|
|
219
214
|
|
|
220
|
-
const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions;
|
|
215
|
+
const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
|
|
221
216
|
|
|
222
217
|
const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
223
218
|
|
|
@@ -338,34 +333,36 @@
|
|
|
338
333
|
const initPromise = featureDetectionPromise.then(() => {
|
|
339
334
|
// shim mode is determined on initialization, no late shim mode
|
|
340
335
|
if (!shimMode) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
336
|
+
if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
|
|
337
|
+
setShimMode();
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
let seenScript = false;
|
|
341
|
+
for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
|
|
342
|
+
if (!seenScript) {
|
|
343
|
+
if (script.type === 'module')
|
|
344
|
+
seenScript = true;
|
|
345
|
+
}
|
|
346
|
+
else if (script.type === 'importmap') {
|
|
347
|
+
importMapSrcOrLazy = true;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
352
350
|
}
|
|
353
351
|
}
|
|
354
352
|
}
|
|
355
353
|
baselinePassthrough = supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
|
|
356
|
-
if (!baselinePassthrough) onpolyfill();
|
|
357
354
|
if (shimMode || !baselinePassthrough) {
|
|
358
355
|
new MutationObserver(mutations => {
|
|
359
356
|
for (const mutation of mutations) {
|
|
360
357
|
if (mutation.type !== 'childList') continue;
|
|
361
358
|
for (const node of mutation.addedNodes) {
|
|
362
359
|
if (node.tagName === 'SCRIPT') {
|
|
363
|
-
if (
|
|
360
|
+
if (node.type === (shimMode ? 'module-shim' : 'module'))
|
|
364
361
|
processScript(node);
|
|
365
|
-
if (
|
|
362
|
+
if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
|
|
366
363
|
processImportMap(node);
|
|
367
364
|
}
|
|
368
|
-
else if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
|
365
|
+
else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
|
|
369
366
|
processPreload(node);
|
|
370
367
|
}
|
|
371
368
|
}
|
|
@@ -376,8 +373,9 @@
|
|
|
376
373
|
}
|
|
377
374
|
});
|
|
378
375
|
let importMapPromise = initPromise;
|
|
379
|
-
|
|
376
|
+
let firstPolyfillLoad = true;
|
|
380
377
|
let acceptingImportMaps = true;
|
|
378
|
+
|
|
381
379
|
async function topLevelLoad (url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
|
|
382
380
|
if (!shimMode)
|
|
383
381
|
acceptingImportMaps = false;
|
|
@@ -401,6 +399,10 @@
|
|
|
401
399
|
if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
|
|
402
400
|
return module;
|
|
403
401
|
}
|
|
402
|
+
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
403
|
+
onpolyfill();
|
|
404
|
+
firstPolyfillLoad = false;
|
|
405
|
+
}
|
|
404
406
|
const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
|
|
405
407
|
// if the top-level load is a shell, run its update function
|
|
406
408
|
if (load.s)
|
|
@@ -482,7 +484,7 @@
|
|
|
482
484
|
// once all deps have loaded we can inline the dependency resolution blobs
|
|
483
485
|
// and define this blob
|
|
484
486
|
let lastIndex = 0, depIndex = 0;
|
|
485
|
-
for (const { s: start,
|
|
487
|
+
for (const { s: start, e: end, se: statementEnd, d: dynamicImportIndex } of imports) {
|
|
486
488
|
// dependency source replacements
|
|
487
489
|
if (dynamicImportIndex === -1) {
|
|
488
490
|
const depLoad = load.d[depIndex++];
|
|
@@ -503,31 +505,30 @@
|
|
|
503
505
|
}
|
|
504
506
|
// circular shell execution
|
|
505
507
|
else if (depLoad.s) {
|
|
506
|
-
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1,
|
|
507
|
-
lastIndex =
|
|
508
|
+
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)};import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
|
|
509
|
+
lastIndex = statementEnd;
|
|
508
510
|
depLoad.s = undefined;
|
|
509
511
|
continue;
|
|
510
512
|
}
|
|
511
|
-
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1,
|
|
512
|
-
lastIndex =
|
|
513
|
+
resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
|
|
514
|
+
lastIndex = statementEnd;
|
|
513
515
|
}
|
|
514
516
|
// import.meta
|
|
515
517
|
else if (dynamicImportIndex === -2) {
|
|
516
518
|
meta[load.r] = { url: load.r, resolve: importMetaResolve };
|
|
517
519
|
resolvedSource += `${source.slice(lastIndex, start)}self._esmsm[${urlJsString(load.r)}]`;
|
|
518
|
-
lastIndex =
|
|
520
|
+
lastIndex = statementEnd;
|
|
519
521
|
}
|
|
520
522
|
// dynamic import
|
|
521
523
|
else {
|
|
522
|
-
resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}`;
|
|
523
|
-
lastIndex =
|
|
524
|
+
resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}${source.slice(end, statementEnd)}`;
|
|
525
|
+
lastIndex = statementEnd;
|
|
524
526
|
}
|
|
525
527
|
}
|
|
526
528
|
|
|
527
529
|
resolvedSource += source.slice(lastIndex);
|
|
528
530
|
}
|
|
529
531
|
|
|
530
|
-
// ; and // trailer support added for Ruby 7 source maps compatibility
|
|
531
532
|
let hasSourceURL = false;
|
|
532
533
|
resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
|
|
533
534
|
if (!hasSourceURL)
|
|
@@ -537,12 +538,13 @@
|
|
|
537
538
|
load.S = undefined;
|
|
538
539
|
}
|
|
539
540
|
|
|
541
|
+
// ; and // trailer support added for Ruby on Rails 7 source maps compatibility
|
|
542
|
+
// https://github.com/guybedford/es-module-shims/issues/228
|
|
540
543
|
const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
|
|
541
544
|
|
|
542
545
|
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
543
546
|
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
544
547
|
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
545
|
-
const wasmContentType = /^application\/wasm(;|$)/;
|
|
546
548
|
|
|
547
549
|
const cssUrlRegEx = /url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;
|
|
548
550
|
|
|
@@ -560,6 +562,8 @@
|
|
|
560
562
|
}
|
|
561
563
|
|
|
562
564
|
async function doFetch (url, fetchOpts) {
|
|
565
|
+
if (enforceIntegrity && !fetchOpts.integrity)
|
|
566
|
+
throw Error(`No integrity for ${url}`);
|
|
563
567
|
const poolQueue = pushFetchPool();
|
|
564
568
|
if (poolQueue) await poolQueue;
|
|
565
569
|
try {
|
|
@@ -569,7 +573,7 @@
|
|
|
569
573
|
popFetchPool();
|
|
570
574
|
}
|
|
571
575
|
if (!res.ok)
|
|
572
|
-
throw
|
|
576
|
+
throw Error(`${res.status} ${res.statusText} ${res.url}`);
|
|
573
577
|
const contentType = res.headers.get('content-type');
|
|
574
578
|
if (jsContentType.test(contentType))
|
|
575
579
|
return { r: res.url, s: await res.text(), t: 'js' };
|
|
@@ -579,10 +583,8 @@
|
|
|
579
583
|
return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
|
|
580
584
|
JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
|
|
581
585
|
});export default s;`, t: 'css' };
|
|
582
|
-
else if (wasmContentType.test(contentType))
|
|
583
|
-
throw new Error('WASM modules not supported');
|
|
584
586
|
else
|
|
585
|
-
throw
|
|
587
|
+
throw Error(`Unsupported Content-Type "${contentType}"`);
|
|
586
588
|
}
|
|
587
589
|
|
|
588
590
|
function getOrCreateLoad (url, fetchOpts, source) {
|
|
@@ -622,7 +624,7 @@
|
|
|
622
624
|
({ r: load.r, s: source, t } = await (fetchCache[url] || doFetch(url, fetchOpts)));
|
|
623
625
|
if (t && !shimMode) {
|
|
624
626
|
if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
|
|
625
|
-
throw
|
|
627
|
+
throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
|
|
626
628
|
if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
|
|
627
629
|
load.n = true;
|
|
628
630
|
}
|
|
@@ -661,9 +663,9 @@
|
|
|
661
663
|
}
|
|
662
664
|
|
|
663
665
|
function processScriptsAndPreloads () {
|
|
664
|
-
for (const script of document.querySelectorAll(shimMode ? 'script[type=
|
|
666
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
|
|
665
667
|
processScript(script);
|
|
666
|
-
for (const link of document.querySelectorAll('link[rel=
|
|
668
|
+
for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
|
|
667
669
|
processPreload(link);
|
|
668
670
|
}
|
|
669
671
|
|
|
@@ -761,7 +763,12 @@
|
|
|
761
763
|
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
762
764
|
const blocks = script.getAttribute('async') === null && isReadyScript;
|
|
763
765
|
const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
|
|
764
|
-
|
|
766
|
+
// Safari only gives error via console.error
|
|
767
|
+
if (safari)
|
|
768
|
+
console.error(e);
|
|
769
|
+
// Firefox only gives error stack via setTimeout
|
|
770
|
+
else
|
|
771
|
+
setTimeout(() => { throw e});
|
|
765
772
|
onerror(e);
|
|
766
773
|
});
|
|
767
774
|
if (blocks)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-module-shims",
|
|
3
|
-
"version": "1.3
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Shims for the latest ES module features",
|
|
5
5
|
"main": "dist/es-module-shims.js",
|
|
6
6
|
"exports": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"build": "rollup -c",
|
|
12
12
|
"bench": "bash bench/bench.sh",
|
|
13
13
|
"bench:clear": "rm -rf bench/results",
|
|
14
|
-
"footprint": "npm run build ; cat dist/es-module-shims.js | brotli | wc -c",
|
|
15
|
-
"footprint:
|
|
14
|
+
"footprint": "npm run build ; cat dist/es-module-shims.js | terser -mc | brotli | wc -c",
|
|
15
|
+
"footprint:wasm": "npm run build ; cat dist/es-module-shims.wasm.js | terser -mc | brotli | wc -c",
|
|
16
16
|
"prepublishOnly": "npm run build",
|
|
17
17
|
"test": "npm run test:test-base-href ; npm run test:test-csp ; npm run test:test-dom-order ; npm run test:test-early-module-load ; npm run test:test-polyfill ; npm run test:test-polyfill-wasm ; npm run test:test-preload-case ; npm run test:test-revoke-blob-urls ; npm run test:test-shim",
|
|
18
18
|
"test:test-base-href": "cross-env TEST_NAME=test-base-href node test/server.mjs",
|