es-module-shims 2.6.0 → 2.6.2
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 +6 -5
- package/dist/es-module-shims.debug.js +227 -212
- package/dist/es-module-shims.js +226 -211
- package/dist/es-module-shims.wasm.js +226 -211
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ The following modules features are polyfilled:
|
|
|
14
14
|
* [Import defer](#import-defer) via syntax stripping to allow usage in modern browsers with a polyfill fallback, when enabled.
|
|
15
15
|
* [TypeScript](#typescript-type-stripping) type stripping.
|
|
16
16
|
* [Hot Reloading](#hot-reloading) with a Vite-style `import.meta.hot` API.
|
|
17
|
+
* [Loader Hooks](#hooks) custom loader hooks for customizing module resolution and sources, including support for [virtual module sources](#source-hook).
|
|
17
18
|
|
|
18
19
|
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
20
|
|
|
@@ -30,7 +31,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
30
31
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
31
32
|
|
|
32
33
|
```html
|
|
33
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@2.6.
|
|
34
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@2.6.2/dist/es-module-shims.js"></script>
|
|
34
35
|
|
|
35
36
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
36
37
|
<script type="importmap">
|
|
@@ -215,7 +216,7 @@ Shim mode is an alternative to polyfill mode and doesn't rely on native modules
|
|
|
215
216
|
|
|
216
217
|
In shim mode, only the above `importmap-shim` and `module-shim` tags will be parsed and executed by ES Module Shims.
|
|
217
218
|
|
|
218
|
-
Shim mode also provides some additional features that aren't yet natively supported such as
|
|
219
|
+
Shim mode also provides some additional features that aren't yet natively supported such as [external import maps](#external-import-maps) with a `"src"` attribute and [reading current import map state](#reading-current-import-map-state), which can be useful in certain applications.
|
|
219
220
|
|
|
220
221
|
## Benchmarks
|
|
221
222
|
|
|
@@ -231,7 +232,7 @@ Benchmark summary:
|
|
|
231
232
|
|
|
232
233
|
### Browser Support
|
|
233
234
|
|
|
234
|
-
Works in all browsers with [
|
|
235
|
+
Works in all browsers with [ES module dynamic import support](https://caniuse.com/es6-module-dynamic-import).
|
|
235
236
|
|
|
236
237
|
Browser Compatibility on baseline ES modules support **with** ES Module Shims:
|
|
237
238
|
|
|
@@ -252,8 +253,8 @@ Browser compatibility **without** ES Module Shims:
|
|
|
252
253
|
| --------------------------------------------- | ------------------ | ------------------ | ------------------ |
|
|
253
254
|
| [modulepreload](#modulepreload) | 66+ | 115+ | 17.5+ |
|
|
254
255
|
| [Import Maps](#import-maps) | 89+ | 108+ | 16.4+ |
|
|
255
|
-
| [Import Map Integrity](#import-map-integrity) | 127+ |
|
|
256
|
-
| [Multiple Import Maps](#multiple-import-maps) | 135+ | :x: |
|
|
256
|
+
| [Import Map Integrity](#import-map-integrity) | 127+ | 138+ | 18+ |
|
|
257
|
+
| [Multiple Import Maps](#multiple-import-maps) | 135+ | :x: | 18.4+ |
|
|
257
258
|
| [JSON Modules](#json-modules) | 123+ | :x: | 17.2+ |
|
|
258
259
|
| [CSS Modules](#css-modules) | 123+ | :x: | :x: |
|
|
259
260
|
| [Wasm Modules](#wasm-modules) | Pending | :x: | :x: |
|
|
@@ -1,169 +1,177 @@
|
|
|
1
|
-
/** ES Module Shims @version 2.6.
|
|
1
|
+
/** ES Module Shims @version 2.6.2 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
hotState
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
hotState.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
undefined,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
4
|
+
const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
5
|
+
|
|
6
|
+
let invalidate;
|
|
7
|
+
const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
|
|
8
|
+
const initHotReload = (topLevelLoad, importShim) => {
|
|
9
|
+
let _importHook = importHook,
|
|
10
|
+
_resolveHook = resolveHook,
|
|
11
|
+
_metaHook = metaHook;
|
|
12
|
+
|
|
13
|
+
let defaultResolve;
|
|
14
|
+
let hotResolveHook = (id, parent, _defaultResolve) => {
|
|
15
|
+
if (!defaultResolve) defaultResolve = _defaultResolve;
|
|
16
|
+
const originalParent = stripVersion(parent);
|
|
17
|
+
const url = stripVersion(defaultResolve(id, originalParent));
|
|
18
|
+
const hotState = getHotState(url);
|
|
19
|
+
const parents = hotState.p;
|
|
20
|
+
if (!parents.includes(originalParent)) parents.push(originalParent);
|
|
21
|
+
return toVersioned(url, hotState);
|
|
22
|
+
};
|
|
23
|
+
const hotImportHook = (url, _, __, source, sourceType) => {
|
|
24
|
+
const hotState = getHotState(url);
|
|
25
|
+
hotState.e = typeof source === 'string' ? source : true;
|
|
26
|
+
hotState.t = sourceType;
|
|
27
|
+
};
|
|
28
|
+
const hotMetaHook = (metaObj, url) => (metaObj.hot = new Hot(url));
|
|
29
|
+
|
|
30
|
+
const Hot = class Hot {
|
|
31
|
+
constructor(url) {
|
|
32
|
+
this.data = getHotState((this.url = stripVersion(url))).d;
|
|
33
|
+
}
|
|
34
|
+
accept(deps, cb) {
|
|
35
|
+
if (typeof deps === 'function') {
|
|
36
|
+
cb = deps;
|
|
37
|
+
deps = null;
|
|
38
|
+
}
|
|
39
|
+
const hotState = getHotState(this.url);
|
|
40
|
+
if (!hotState.A) return;
|
|
41
|
+
(hotState.a = hotState.a || []).push([
|
|
42
|
+
typeof deps === 'string' ? defaultResolve(deps, this.url)
|
|
43
|
+
: deps ? deps.map(d => defaultResolve(d, this.url))
|
|
44
|
+
: null,
|
|
45
|
+
cb
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
dispose(cb) {
|
|
49
|
+
getHotState(this.url).u = cb;
|
|
50
|
+
}
|
|
51
|
+
invalidate() {
|
|
52
|
+
const hotState = getHotState(this.url);
|
|
53
|
+
hotState.a = hotState.A = null;
|
|
54
|
+
const seen = [this.url];
|
|
55
|
+
hotState.p.forEach(p => invalidate(p, this.url, seen));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const versionedRegEx = /\?v=\d+$/;
|
|
60
|
+
const stripVersion = url => {
|
|
61
|
+
const versionMatch = url.match(versionedRegEx);
|
|
62
|
+
return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const toVersioned = (url, hotState) => {
|
|
66
|
+
const { v } = hotState;
|
|
67
|
+
return url + (v ? '?v=' + v : '');
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let hotRegistry = {},
|
|
71
|
+
curInvalidationRoots = new Set(),
|
|
72
|
+
curInvalidationInterval;
|
|
73
|
+
const getHotState = url =>
|
|
74
|
+
hotRegistry[url] ||
|
|
75
|
+
(hotRegistry[url] = {
|
|
76
|
+
// version
|
|
77
|
+
v: 0,
|
|
78
|
+
// accept list ([deps, cb] pairs)
|
|
79
|
+
a: null,
|
|
80
|
+
// accepting acceptors
|
|
81
|
+
A: true,
|
|
82
|
+
// unload callback
|
|
83
|
+
u: null,
|
|
84
|
+
// entry point or inline script source
|
|
85
|
+
e: false,
|
|
86
|
+
// hot data
|
|
87
|
+
d: {},
|
|
88
|
+
// parents
|
|
89
|
+
p: [],
|
|
90
|
+
// source type
|
|
91
|
+
t: undefined
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
invalidate = (url, fromUrl, seen = []) => {
|
|
95
|
+
const hotState = hotRegistry[url];
|
|
96
|
+
if (!hotState || seen.includes(url)) return false;
|
|
97
|
+
seen.push(url);
|
|
98
|
+
console.info(`es-module-shims: hot reload ${url}`);
|
|
99
|
+
hotState.A = false;
|
|
100
|
+
if (
|
|
101
|
+
fromUrl &&
|
|
102
|
+
hotState.a &&
|
|
103
|
+
hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
|
|
104
|
+
) {
|
|
105
|
+
curInvalidationRoots.add(fromUrl);
|
|
106
|
+
} else {
|
|
107
|
+
if (hotState.e || hotState.a) curInvalidationRoots.add(url);
|
|
108
|
+
hotState.v++;
|
|
109
|
+
if (!hotState.a) hotState.p.forEach(p => invalidate(p, url, seen));
|
|
110
|
+
}
|
|
111
|
+
if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const handleInvalidations = () => {
|
|
116
|
+
curInvalidationInterval = null;
|
|
117
|
+
const earlyRoots = new Set();
|
|
118
|
+
for (const root of curInvalidationRoots) {
|
|
119
|
+
const hotState = hotRegistry[root];
|
|
120
|
+
topLevelLoad(
|
|
121
|
+
toVersioned(root, hotState),
|
|
122
|
+
baseUrl,
|
|
123
|
+
defaultFetchOpts,
|
|
124
|
+
typeof hotState.e === 'string' ? hotState.e : undefined,
|
|
125
|
+
false,
|
|
126
|
+
undefined,
|
|
127
|
+
hotState.t
|
|
128
|
+
).then(m => {
|
|
129
|
+
if (hotState.a) {
|
|
130
|
+
hotState.a.forEach(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
|
|
131
|
+
// unload should be the latest unload handler from the just loaded module
|
|
132
|
+
if (hotState.u) {
|
|
133
|
+
hotState.u(hotState.d);
|
|
134
|
+
hotState.u = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
hotState.p.forEach(p => {
|
|
138
|
+
const hotState = hotRegistry[p];
|
|
139
|
+
if (hotState && hotState.a)
|
|
140
|
+
hotState.a.forEach(
|
|
141
|
+
async ([d, c]) =>
|
|
142
|
+
d &&
|
|
143
|
+
!earlyRoots.has(c) &&
|
|
144
|
+
(typeof d === 'string' ?
|
|
145
|
+
d === root && c(m)
|
|
146
|
+
: c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d, getHotState(d))))))))
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
}, throwError);
|
|
150
|
+
}
|
|
151
|
+
curInvalidationRoots = new Set();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
setHooks(
|
|
155
|
+
_importHook ? chain(_importHook, hotImportHook) : hotImportHook,
|
|
156
|
+
_resolveHook ?
|
|
157
|
+
(id, parent, defaultResolve) =>
|
|
158
|
+
hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
|
|
159
|
+
: hotResolveHook,
|
|
160
|
+
_metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
|
|
161
|
+
);
|
|
160
162
|
};
|
|
161
163
|
|
|
162
164
|
const hasDocument = typeof document !== 'undefined';
|
|
163
165
|
|
|
164
166
|
const noop = () => {};
|
|
165
167
|
|
|
166
|
-
const
|
|
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);
|
|
167
175
|
|
|
168
176
|
const defineValue = (obj, prop, value) =>
|
|
169
177
|
Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
|
|
@@ -171,12 +179,12 @@
|
|
|
171
179
|
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
172
180
|
|
|
173
181
|
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
174
|
-
Object.assign(esmsInitOptions,
|
|
182
|
+
Object.assign(esmsInitOptions, self_.esmsInitOptions || {});
|
|
175
183
|
|
|
176
|
-
const version = "2.6.
|
|
184
|
+
const version = "2.6.2";
|
|
177
185
|
|
|
178
186
|
const r$1 = esmsInitOptions.version;
|
|
179
|
-
if (
|
|
187
|
+
if (self_.importShim || (r$1 && r$1 !== version)) {
|
|
180
188
|
console.info(
|
|
181
189
|
`es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
|
|
182
190
|
);
|
|
@@ -186,9 +194,11 @@
|
|
|
186
194
|
// shim mode is determined on initialization, no late shim mode
|
|
187
195
|
const shimMode =
|
|
188
196
|
esmsInitOptions.shimMode ||
|
|
189
|
-
(hasDocument
|
|
197
|
+
(hasDocument ?
|
|
190
198
|
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
191
|
-
.length > 0
|
|
199
|
+
.length > 0
|
|
200
|
+
// Without a document, shim mode is always true as we cannot polyfill
|
|
201
|
+
: true);
|
|
192
202
|
|
|
193
203
|
let importHook,
|
|
194
204
|
resolveHook,
|
|
@@ -202,7 +212,7 @@
|
|
|
202
212
|
|
|
203
213
|
const defaultFetchOpts = { credentials: 'same-origin' };
|
|
204
214
|
|
|
205
|
-
const globalHook = name => (typeof name === 'string' ?
|
|
215
|
+
const globalHook = name => (typeof name === 'string' ? self_[name] : name);
|
|
206
216
|
|
|
207
217
|
if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
|
|
208
218
|
if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
|
|
@@ -220,7 +230,11 @@
|
|
|
220
230
|
nativePassthrough = !hasCustomizationHooks && !hotReload
|
|
221
231
|
} = esmsInitOptions;
|
|
222
232
|
|
|
223
|
-
|
|
233
|
+
const setHooks = (importHook_, resolveHook_, metaHook_) => (
|
|
234
|
+
(importHook = importHook_),
|
|
235
|
+
(resolveHook = resolveHook_),
|
|
236
|
+
(metaHook = metaHook_)
|
|
237
|
+
);
|
|
224
238
|
|
|
225
239
|
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
226
240
|
|
|
@@ -252,13 +266,14 @@
|
|
|
252
266
|
};
|
|
253
267
|
|
|
254
268
|
const baseUrl =
|
|
255
|
-
hasDocument ?
|
|
256
|
-
|
|
257
|
-
|
|
269
|
+
hasDocument ? document.baseURI
|
|
270
|
+
: typeof location !== 'undefined' ?
|
|
271
|
+
`${location.protocol}//${location.host}${
|
|
258
272
|
location.pathname.includes('/') ?
|
|
259
273
|
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
260
274
|
: location.pathname
|
|
261
|
-
}
|
|
275
|
+
}`
|
|
276
|
+
: 'about:blank';
|
|
262
277
|
|
|
263
278
|
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
264
279
|
let { skip } = esmsInitOptions;
|
|
@@ -272,10 +287,11 @@
|
|
|
272
287
|
skip = s => skip.test(s);
|
|
273
288
|
}
|
|
274
289
|
|
|
275
|
-
const dispatchError = error =>
|
|
290
|
+
const dispatchError = error => self_.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
276
291
|
|
|
277
292
|
const throwError = err => {
|
|
278
|
-
(
|
|
293
|
+
(self_.reportError || dispatchError)(err);
|
|
294
|
+
onerror(err);
|
|
279
295
|
};
|
|
280
296
|
|
|
281
297
|
const fromParent = parent => (parent ? ` imported from ${parent}` : '');
|
|
@@ -629,7 +645,7 @@
|
|
|
629
645
|
};
|
|
630
646
|
|
|
631
647
|
// import()
|
|
632
|
-
async function importShim
|
|
648
|
+
async function importShim(id, opts, parentUrl) {
|
|
633
649
|
if (typeof opts === 'string') {
|
|
634
650
|
parentUrl = opts;
|
|
635
651
|
opts = undefined;
|
|
@@ -653,7 +669,7 @@
|
|
|
653
669
|
// import.source()
|
|
654
670
|
// (opts not currently supported as no use cases yet)
|
|
655
671
|
if (shimMode || wasmSourcePhaseEnabled)
|
|
656
|
-
importShim
|
|
672
|
+
importShim.source = async (id, opts, parentUrl) => {
|
|
657
673
|
if (typeof opts === 'string') {
|
|
658
674
|
parentUrl = opts;
|
|
659
675
|
opts = undefined;
|
|
@@ -667,18 +683,17 @@
|
|
|
667
683
|
await importMapPromise;
|
|
668
684
|
const url = resolve(id, parentUrl || baseUrl).r;
|
|
669
685
|
const load = getOrCreateLoad(url, defaultFetchOpts, undefined, undefined);
|
|
670
|
-
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
671
|
-
onpolyfill();
|
|
672
|
-
firstPolyfillLoad = false;
|
|
673
|
-
}
|
|
674
686
|
await load.f;
|
|
675
|
-
return importShim
|
|
687
|
+
return importShim._s[load.r];
|
|
676
688
|
};
|
|
677
689
|
|
|
678
690
|
// import.defer() is just a proxy for import(), since we can't actually defer
|
|
679
|
-
if (shimMode || deferPhaseEnabled) importShim
|
|
691
|
+
if (shimMode || deferPhaseEnabled) importShim.defer = importShim;
|
|
680
692
|
|
|
681
|
-
if (hotReload)
|
|
693
|
+
if (hotReload) {
|
|
694
|
+
initHotReload(topLevelLoad, importShim);
|
|
695
|
+
importShim.hotReload = hotReload$1;
|
|
696
|
+
}
|
|
682
697
|
|
|
683
698
|
const defaultResolve = (id, parentUrl) => {
|
|
684
699
|
return (
|
|
@@ -695,24 +710,24 @@
|
|
|
695
710
|
return resolve(id, `${parentUrl}`).r;
|
|
696
711
|
};
|
|
697
712
|
|
|
698
|
-
importShim
|
|
699
|
-
importShim
|
|
700
|
-
importShim
|
|
713
|
+
importShim.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
|
|
714
|
+
importShim.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
|
|
715
|
+
importShim.addImportMap = importMapIn => {
|
|
701
716
|
if (!shimMode) throw new Error('Unsupported in polyfill mode.');
|
|
702
717
|
composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
|
|
703
718
|
};
|
|
704
|
-
importShim
|
|
719
|
+
importShim.version = version;
|
|
705
720
|
|
|
706
|
-
const registry = (importShim
|
|
721
|
+
const registry = (importShim._r = {});
|
|
707
722
|
// Wasm caches
|
|
708
|
-
const sourceCache = (importShim
|
|
709
|
-
|
|
723
|
+
const sourceCache = (importShim._s = {});
|
|
724
|
+
/* const instanceCache = */ importShim._i = new WeakMap();
|
|
710
725
|
|
|
711
726
|
// Ensure this version is the only version
|
|
712
|
-
defineValue(
|
|
727
|
+
defineValue(self_, 'importShim', Object.freeze(importShim));
|
|
713
728
|
const shimModeOptions = { ...esmsInitOptions, shimMode: true };
|
|
714
729
|
if (optionsScript) optionsScript.innerHTML = JSON.stringify(shimModeOptions);
|
|
715
|
-
|
|
730
|
+
self_.esmsInitOptions = shimModeOptions;
|
|
716
731
|
|
|
717
732
|
const loadAll = async (load, seen) => {
|
|
718
733
|
seen[load.u] = 1;
|
|
@@ -815,7 +830,7 @@
|
|
|
815
830
|
let firstPolyfillLoad = true;
|
|
816
831
|
let legacyAcceptingImportMaps = true;
|
|
817
832
|
|
|
818
|
-
|
|
833
|
+
async function topLevelLoad(
|
|
819
834
|
url,
|
|
820
835
|
parentUrl,
|
|
821
836
|
fetchOpts,
|
|
@@ -823,7 +838,7 @@
|
|
|
823
838
|
nativelyLoaded,
|
|
824
839
|
lastStaticLoadPromise,
|
|
825
840
|
sourceType
|
|
826
|
-
)
|
|
841
|
+
) {
|
|
827
842
|
await initPromise;
|
|
828
843
|
await importMapPromise;
|
|
829
844
|
url = (await resolve(url, parentUrl)).r;
|
|
@@ -873,11 +888,11 @@
|
|
|
873
888
|
if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
|
|
874
889
|
revokeObjectURLs(Object.keys(seen));
|
|
875
890
|
return module;
|
|
876
|
-
}
|
|
891
|
+
}
|
|
877
892
|
|
|
878
893
|
const revokeObjectURLs = registryKeys => {
|
|
879
894
|
let curIdx = 0;
|
|
880
|
-
const handler =
|
|
895
|
+
const handler = self_.requestIdleCallback || self_.requestAnimationFrame || (fn => setTimeout(fn, 0));
|
|
881
896
|
handler(cleanup);
|
|
882
897
|
function cleanup() {
|
|
883
898
|
for (const key of registryKeys.slice(curIdx, (curIdx += 100))) {
|
|
@@ -944,7 +959,8 @@
|
|
|
944
959
|
|
|
945
960
|
// once all deps have loaded we can inline the dependency resolution blobs
|
|
946
961
|
// and define this blob
|
|
947
|
-
|
|
962
|
+
resolvedSource = '';
|
|
963
|
+
lastIndex = 0;
|
|
948
964
|
|
|
949
965
|
for (const { s: start, e: end, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t, a } of imports) {
|
|
950
966
|
// source phase
|
|
@@ -1073,10 +1089,11 @@
|
|
|
1073
1089
|
|
|
1074
1090
|
const doFetch = async (url, fetchOpts, parent) => {
|
|
1075
1091
|
if (enforceIntegrity && !fetchOpts.integrity) throw Error(`No integrity for ${url}${fromParent(parent)}.`);
|
|
1076
|
-
|
|
1092
|
+
let res,
|
|
1093
|
+
poolQueue = pushFetchPool();
|
|
1077
1094
|
if (poolQueue) await poolQueue;
|
|
1078
1095
|
try {
|
|
1079
|
-
|
|
1096
|
+
res = await fetchHook(url, fetchOpts);
|
|
1080
1097
|
} catch (e) {
|
|
1081
1098
|
e.message = `Unable to fetch ${url}${fromParent(parent)} - see network log for details.\n` + e.message;
|
|
1082
1099
|
throw e;
|
|
@@ -1098,24 +1115,22 @@
|
|
|
1098
1115
|
if (!esmsTsTransform) esmsTsTransform = m.transform;
|
|
1099
1116
|
};
|
|
1100
1117
|
|
|
1101
|
-
const contentTypeRegEx = /^(text|application)\/((x-)?javascript|wasm|json|css|typescript)(;|$)/;
|
|
1102
1118
|
async function defaultSourceHook(url, fetchOpts, parent) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1119
|
+
let res = await doFetch(url, fetchOpts, parent),
|
|
1120
|
+
contentType,
|
|
1121
|
+
[, json, type, jsts] =
|
|
1122
|
+
(contentType = res.headers.get('content-type') || '').match(
|
|
1123
|
+
/^(?:[^/;]+\/(?:[^/+;]+\+)?(json)|(?:text|application)\/(?:x-)?((java|type)script|wasm|css))(?:;|$)/
|
|
1124
|
+
) || [];
|
|
1125
|
+
if (!(type = json || (jsts ? jsts[0] + 's' : type || (/\.m?ts(\?|#|$)/.test(url) && 'ts')))) {
|
|
1126
|
+
throw Error(
|
|
1127
|
+
`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
|
|
1128
|
+
);
|
|
1111
1129
|
}
|
|
1112
1130
|
return {
|
|
1113
1131
|
url: res.url,
|
|
1114
|
-
source:
|
|
1115
|
-
type
|
|
1116
|
-
t[0] === 'x' || (t[0] === 'j' && t[1] === 'a') ? 'js'
|
|
1117
|
-
: t[0] === 't' ? 'ts'
|
|
1118
|
-
: t
|
|
1132
|
+
source: await (type > 'v' ? WebAssembly.compileStreaming(res) : res.text()),
|
|
1133
|
+
type
|
|
1119
1134
|
};
|
|
1120
1135
|
}
|
|
1121
1136
|
|
|
@@ -1149,7 +1164,7 @@
|
|
|
1149
1164
|
}
|
|
1150
1165
|
source += `if(h)h.accept(m=>({${obj}}=m))`;
|
|
1151
1166
|
} else if (type === 'json') {
|
|
1152
|
-
source = `${hotPrefix}j
|
|
1167
|
+
source = `${hotPrefix}j=JSON.parse(${JSON.stringify(source)});export{j as default};if(h)h.accept(m=>j=m.default)`;
|
|
1153
1168
|
} else if (type === 'css') {
|
|
1154
1169
|
source = `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
|
|
1155
1170
|
source.replace(
|
|
@@ -1238,7 +1253,7 @@
|
|
|
1238
1253
|
|
|
1239
1254
|
const linkLoad = (load, fetchOpts) => {
|
|
1240
1255
|
if (load.L) return;
|
|
1241
|
-
load.L = load.f.then(
|
|
1256
|
+
load.L = load.f.then(() => {
|
|
1242
1257
|
let childFetchOpts = fetchOpts;
|
|
1243
1258
|
load.d = load.a[0]
|
|
1244
1259
|
.map(({ n, d, t, a, se }) => {
|