es-module-shims 2.0.3 → 2.0.4
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 +39 -7
- package/dist/es-module-shims-typescript.js +546 -0
- package/dist/es-module-shims.debug.js +370 -351
- package/dist/es-module-shims.js +361 -339
- package/dist/es-module-shims.wasm.js +360 -338
- package/package.json +8 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 2.0.
|
|
1
|
+
/* ES Module Shims Wasm 2.0.4 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasDocument = typeof document !== 'undefined';
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
|
|
25
25
|
let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
|
26
26
|
const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
|
|
27
|
+
const tsTransform =
|
|
28
|
+
esmsInitOptions.tsTransform ||
|
|
29
|
+
(document.currentScript &&
|
|
30
|
+
document.currentScript.src.replace('.js', '-typescript.js')) ||
|
|
31
|
+
'./es-module-shims-typescript.js';
|
|
27
32
|
|
|
28
33
|
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
29
34
|
|
|
@@ -42,10 +47,13 @@
|
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
50
|
+
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
51
|
+
const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
|
|
52
|
+
const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
|
|
53
|
+
const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
|
|
54
|
+
const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
|
|
55
|
+
const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
|
|
56
|
+
const typescriptEnabled = enable.includes('typescript') || enableAll;
|
|
49
57
|
|
|
50
58
|
const onpolyfill =
|
|
51
59
|
esmsInitOptions.onpolyfill ?
|
|
@@ -85,309 +93,309 @@
|
|
|
85
93
|
return parent ? ` imported from ${parent}` : '';
|
|
86
94
|
}
|
|
87
95
|
|
|
88
|
-
const backslashRegEx = /\\/g;
|
|
89
|
-
|
|
90
|
-
function asURL(url) {
|
|
91
|
-
try {
|
|
92
|
-
if (url.indexOf(':') !== -1) return new URL(url).href;
|
|
93
|
-
} catch (_) {}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function resolveUrl(relUrl, parentUrl) {
|
|
97
|
-
return resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
101
|
-
const hIdx = parentUrl.indexOf('#'),
|
|
102
|
-
qIdx = parentUrl.indexOf('?');
|
|
103
|
-
if (hIdx + qIdx > -2)
|
|
104
|
-
parentUrl = parentUrl.slice(
|
|
105
|
-
0,
|
|
106
|
-
hIdx === -1 ? qIdx
|
|
107
|
-
: qIdx === -1 || qIdx > hIdx ? hIdx
|
|
108
|
-
: qIdx
|
|
109
|
-
);
|
|
110
|
-
if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
|
|
111
|
-
// protocol-relative
|
|
112
|
-
if (relUrl[0] === '/' && relUrl[1] === '/') {
|
|
113
|
-
return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
|
|
114
|
-
}
|
|
115
|
-
// relative-url
|
|
116
|
-
else if (
|
|
117
|
-
(relUrl[0] === '.' &&
|
|
118
|
-
(relUrl[1] === '/' ||
|
|
119
|
-
(relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
|
|
120
|
-
(relUrl.length === 1 && (relUrl += '/')))) ||
|
|
121
|
-
relUrl[0] === '/'
|
|
122
|
-
) {
|
|
123
|
-
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
124
|
-
if (parentProtocol === 'blob:') {
|
|
125
|
-
throw new TypeError(
|
|
126
|
-
`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
130
|
-
//if (parentUrl[parentProtocol.length] !== '/')
|
|
131
|
-
// throw new Error('Cannot resolve');
|
|
132
|
-
// read pathname from parent URL
|
|
133
|
-
// pathname taken to be part after leading "/"
|
|
134
|
-
let pathname;
|
|
135
|
-
if (parentUrl[parentProtocol.length + 1] === '/') {
|
|
136
|
-
// resolving to a :// so we need to read out the auth and host
|
|
137
|
-
if (parentProtocol !== 'file:') {
|
|
138
|
-
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
139
|
-
pathname = pathname.slice(pathname.indexOf('/') + 1);
|
|
140
|
-
} else {
|
|
141
|
-
pathname = parentUrl.slice(8);
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
// resolving to :/ so pathname is the /... part
|
|
145
|
-
pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
149
|
-
|
|
150
|
-
// join together and split for removal of .. and . segments
|
|
151
|
-
// looping the string instead of anything fancy for perf reasons
|
|
152
|
-
// '../../../../../z' resolved to 'x/y' is just 'z'
|
|
153
|
-
const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
|
|
154
|
-
|
|
155
|
-
const output = [];
|
|
156
|
-
let segmentIndex = -1;
|
|
157
|
-
for (let i = 0; i < segmented.length; i++) {
|
|
158
|
-
// busy reading a segment - only terminate on '/'
|
|
159
|
-
if (segmentIndex !== -1) {
|
|
160
|
-
if (segmented[i] === '/') {
|
|
161
|
-
output.push(segmented.slice(segmentIndex, i + 1));
|
|
162
|
-
segmentIndex = -1;
|
|
163
|
-
}
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
// new segment - check if it is relative
|
|
167
|
-
else if (segmented[i] === '.') {
|
|
168
|
-
// ../ segment
|
|
169
|
-
if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
|
|
170
|
-
output.pop();
|
|
171
|
-
i += 2;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
// ./ segment
|
|
175
|
-
else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
|
|
176
|
-
i += 1;
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// it is the start of a new segment
|
|
181
|
-
while (segmented[i] === '/') i++;
|
|
182
|
-
segmentIndex = i;
|
|
183
|
-
}
|
|
184
|
-
// finish reading out the last segment
|
|
185
|
-
if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
|
|
186
|
-
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function resolveAndComposeImportMap(json, baseUrl, parentMap) {
|
|
191
|
-
const outMap = {
|
|
192
|
-
imports: Object.assign({}, parentMap.imports),
|
|
193
|
-
scopes: Object.assign({}, parentMap.scopes),
|
|
194
|
-
integrity: Object.assign({}, parentMap.integrity)
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
|
|
198
|
-
|
|
199
|
-
if (json.scopes)
|
|
200
|
-
for (let s in json.scopes) {
|
|
201
|
-
const resolvedScope = resolveUrl(s, baseUrl);
|
|
202
|
-
resolveAndComposePackages(
|
|
203
|
-
json.scopes[s],
|
|
204
|
-
outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
|
|
205
|
-
baseUrl,
|
|
206
|
-
parentMap
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
|
|
211
|
-
|
|
212
|
-
return outMap;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function getMatch(path, matchObj) {
|
|
216
|
-
if (matchObj[path]) return path;
|
|
217
|
-
let sepIndex = path.length;
|
|
218
|
-
do {
|
|
219
|
-
const segment = path.slice(0, sepIndex + 1);
|
|
220
|
-
if (segment in matchObj) return segment;
|
|
221
|
-
} while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function applyPackages(id, packages) {
|
|
225
|
-
const pkgName = getMatch(id, packages);
|
|
226
|
-
if (pkgName) {
|
|
227
|
-
const pkg = packages[pkgName];
|
|
228
|
-
if (pkg === null) return;
|
|
229
|
-
return pkg + id.slice(pkgName.length);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
|
|
234
|
-
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
235
|
-
while (scopeUrl) {
|
|
236
|
-
const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
|
|
237
|
-
if (packageResolution) return packageResolution;
|
|
238
|
-
scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
|
|
239
|
-
}
|
|
240
|
-
return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
|
|
244
|
-
for (let p in packages) {
|
|
245
|
-
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
246
|
-
if (
|
|
247
|
-
(!shimMode || !mapOverrides) &&
|
|
248
|
-
outPackages[resolvedLhs] &&
|
|
249
|
-
outPackages[resolvedLhs] !== packages[resolvedLhs]
|
|
250
|
-
) {
|
|
251
|
-
console.warn(
|
|
252
|
-
`es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
|
|
253
|
-
);
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
let target = packages[p];
|
|
257
|
-
if (typeof target !== 'string') continue;
|
|
258
|
-
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
259
|
-
if (mapped) {
|
|
260
|
-
outPackages[resolvedLhs] = mapped;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function resolveAndComposeIntegrity(integrity, outIntegrity, baseUrl) {
|
|
268
|
-
for (let p in integrity) {
|
|
269
|
-
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
270
|
-
if (
|
|
271
|
-
(!shimMode || !mapOverrides) &&
|
|
272
|
-
outIntegrity[resolvedLhs] &&
|
|
273
|
-
outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
|
|
274
|
-
) {
|
|
275
|
-
console.warn(
|
|
276
|
-
`es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
outIntegrity[resolvedLhs] = integrity[p];
|
|
280
|
-
}
|
|
96
|
+
const backslashRegEx = /\\/g;
|
|
97
|
+
|
|
98
|
+
function asURL(url) {
|
|
99
|
+
try {
|
|
100
|
+
if (url.indexOf(':') !== -1) return new URL(url).href;
|
|
101
|
+
} catch (_) {}
|
|
281
102
|
}
|
|
282
103
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
104
|
+
function resolveUrl(relUrl, parentUrl) {
|
|
105
|
+
return resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
109
|
+
const hIdx = parentUrl.indexOf('#'),
|
|
110
|
+
qIdx = parentUrl.indexOf('?');
|
|
111
|
+
if (hIdx + qIdx > -2)
|
|
112
|
+
parentUrl = parentUrl.slice(
|
|
113
|
+
0,
|
|
114
|
+
hIdx === -1 ? qIdx
|
|
115
|
+
: qIdx === -1 || qIdx > hIdx ? hIdx
|
|
116
|
+
: qIdx
|
|
117
|
+
);
|
|
118
|
+
if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
|
|
119
|
+
// protocol-relative
|
|
120
|
+
if (relUrl[0] === '/' && relUrl[1] === '/') {
|
|
121
|
+
return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
|
|
122
|
+
}
|
|
123
|
+
// relative-url
|
|
124
|
+
else if (
|
|
125
|
+
(relUrl[0] === '.' &&
|
|
126
|
+
(relUrl[1] === '/' ||
|
|
127
|
+
(relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
|
|
128
|
+
(relUrl.length === 1 && (relUrl += '/')))) ||
|
|
129
|
+
relUrl[0] === '/'
|
|
130
|
+
) {
|
|
131
|
+
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
132
|
+
if (parentProtocol === 'blob:') {
|
|
133
|
+
throw new TypeError(
|
|
134
|
+
`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
138
|
+
//if (parentUrl[parentProtocol.length] !== '/')
|
|
139
|
+
// throw new Error('Cannot resolve');
|
|
140
|
+
// read pathname from parent URL
|
|
141
|
+
// pathname taken to be part after leading "/"
|
|
142
|
+
let pathname;
|
|
143
|
+
if (parentUrl[parentProtocol.length + 1] === '/') {
|
|
144
|
+
// resolving to a :// so we need to read out the auth and host
|
|
145
|
+
if (parentProtocol !== 'file:') {
|
|
146
|
+
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
147
|
+
pathname = pathname.slice(pathname.indexOf('/') + 1);
|
|
148
|
+
} else {
|
|
149
|
+
pathname = parentUrl.slice(8);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
// resolving to :/ so pathname is the /... part
|
|
153
|
+
pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
157
|
+
|
|
158
|
+
// join together and split for removal of .. and . segments
|
|
159
|
+
// looping the string instead of anything fancy for perf reasons
|
|
160
|
+
// '../../../../../z' resolved to 'x/y' is just 'z'
|
|
161
|
+
const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
|
|
162
|
+
|
|
163
|
+
const output = [];
|
|
164
|
+
let segmentIndex = -1;
|
|
165
|
+
for (let i = 0; i < segmented.length; i++) {
|
|
166
|
+
// busy reading a segment - only terminate on '/'
|
|
167
|
+
if (segmentIndex !== -1) {
|
|
168
|
+
if (segmented[i] === '/') {
|
|
169
|
+
output.push(segmented.slice(segmentIndex, i + 1));
|
|
170
|
+
segmentIndex = -1;
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
// new segment - check if it is relative
|
|
175
|
+
else if (segmented[i] === '.') {
|
|
176
|
+
// ../ segment
|
|
177
|
+
if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
|
|
178
|
+
output.pop();
|
|
179
|
+
i += 2;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// ./ segment
|
|
183
|
+
else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
|
|
184
|
+
i += 1;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// it is the start of a new segment
|
|
189
|
+
while (segmented[i] === '/') i++;
|
|
190
|
+
segmentIndex = i;
|
|
191
|
+
}
|
|
192
|
+
// finish reading out the last segment
|
|
193
|
+
if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
|
|
194
|
+
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function resolveAndComposeImportMap(json, baseUrl, parentMap) {
|
|
199
|
+
const outMap = {
|
|
200
|
+
imports: Object.assign({}, parentMap.imports),
|
|
201
|
+
scopes: Object.assign({}, parentMap.scopes),
|
|
202
|
+
integrity: Object.assign({}, parentMap.integrity)
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
|
|
206
|
+
|
|
207
|
+
if (json.scopes)
|
|
208
|
+
for (let s in json.scopes) {
|
|
209
|
+
const resolvedScope = resolveUrl(s, baseUrl);
|
|
210
|
+
resolveAndComposePackages(
|
|
211
|
+
json.scopes[s],
|
|
212
|
+
outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
|
|
213
|
+
baseUrl,
|
|
214
|
+
parentMap
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
|
|
219
|
+
|
|
220
|
+
return outMap;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function getMatch(path, matchObj) {
|
|
224
|
+
if (matchObj[path]) return path;
|
|
225
|
+
let sepIndex = path.length;
|
|
226
|
+
do {
|
|
227
|
+
const segment = path.slice(0, sepIndex + 1);
|
|
228
|
+
if (segment in matchObj) return segment;
|
|
229
|
+
} while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function applyPackages(id, packages) {
|
|
233
|
+
const pkgName = getMatch(id, packages);
|
|
234
|
+
if (pkgName) {
|
|
235
|
+
const pkg = packages[pkgName];
|
|
236
|
+
if (pkg === null) return;
|
|
237
|
+
return pkg + id.slice(pkgName.length);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
|
|
242
|
+
let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
|
243
|
+
while (scopeUrl) {
|
|
244
|
+
const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
|
|
245
|
+
if (packageResolution) return packageResolution;
|
|
246
|
+
scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
|
|
247
|
+
}
|
|
248
|
+
return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
|
|
252
|
+
for (let p in packages) {
|
|
253
|
+
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
254
|
+
if (
|
|
255
|
+
(!shimMode || !mapOverrides) &&
|
|
256
|
+
outPackages[resolvedLhs] &&
|
|
257
|
+
outPackages[resolvedLhs] !== packages[resolvedLhs]
|
|
258
|
+
) {
|
|
259
|
+
console.warn(
|
|
260
|
+
`es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
|
|
261
|
+
);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
let target = packages[p];
|
|
265
|
+
if (typeof target !== 'string') continue;
|
|
266
|
+
const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
|
267
|
+
if (mapped) {
|
|
268
|
+
outPackages[resolvedLhs] = mapped;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function resolveAndComposeIntegrity(integrity, outIntegrity, baseUrl) {
|
|
276
|
+
for (let p in integrity) {
|
|
277
|
+
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
|
278
|
+
if (
|
|
279
|
+
(!shimMode || !mapOverrides) &&
|
|
280
|
+
outIntegrity[resolvedLhs] &&
|
|
281
|
+
outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
|
|
282
|
+
) {
|
|
283
|
+
console.warn(
|
|
284
|
+
`es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
outIntegrity[resolvedLhs] = integrity[p];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// support browsers without dynamic import support (eg Firefox 6x)
|
|
292
|
+
let supportsJsonType = false;
|
|
293
|
+
let supportsCssType = false;
|
|
294
|
+
|
|
295
|
+
const supports = hasDocument && HTMLScriptElement.supports;
|
|
296
|
+
|
|
297
|
+
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
298
|
+
let supportsWasmModules = false;
|
|
299
|
+
let supportsSourcePhase = false;
|
|
300
|
+
let supportsMultipleImportMaps = false;
|
|
301
|
+
|
|
302
|
+
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
303
|
+
|
|
304
|
+
let featureDetectionPromise = (async function () {
|
|
305
|
+
if (!hasDocument)
|
|
306
|
+
return Promise.all([
|
|
307
|
+
cssModulesEnabled &&
|
|
308
|
+
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
309
|
+
() => (supportsCssType = true),
|
|
310
|
+
noop
|
|
311
|
+
),
|
|
312
|
+
jsonModulesEnabled &&
|
|
313
|
+
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
314
|
+
() => (supportsJsonType = true),
|
|
315
|
+
noop
|
|
316
|
+
),
|
|
317
|
+
wasmModulesEnabled &&
|
|
318
|
+
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
319
|
+
() => (supportsWasmModules = true),
|
|
320
|
+
noop
|
|
321
|
+
),
|
|
322
|
+
wasmModulesEnabled &&
|
|
323
|
+
sourcePhaseEnabled &&
|
|
324
|
+
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
325
|
+
() => (supportsSourcePhase = true),
|
|
326
|
+
noop
|
|
327
|
+
)
|
|
328
|
+
]);
|
|
329
|
+
|
|
330
|
+
return new Promise(resolve => {
|
|
331
|
+
const iframe = document.createElement('iframe');
|
|
332
|
+
iframe.style.display = 'none';
|
|
333
|
+
iframe.setAttribute('nonce', nonce);
|
|
334
|
+
function cb({ data }) {
|
|
335
|
+
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
|
|
336
|
+
if (!isFeatureDetectionMessage) return;
|
|
337
|
+
[
|
|
338
|
+
,
|
|
339
|
+
supportsImportMaps,
|
|
340
|
+
supportsMultipleImportMaps,
|
|
341
|
+
supportsCssType,
|
|
342
|
+
supportsJsonType,
|
|
343
|
+
supportsWasmModules,
|
|
344
|
+
supportsSourcePhase
|
|
345
|
+
] = data;
|
|
346
|
+
resolve();
|
|
347
|
+
document.head.removeChild(iframe);
|
|
348
|
+
window.removeEventListener('message', cb, false);
|
|
349
|
+
}
|
|
350
|
+
window.addEventListener('message', cb, false);
|
|
351
|
+
|
|
352
|
+
const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);Promise.all([${
|
|
353
|
+
supportsImportMaps ? 'true' : "'x'"
|
|
354
|
+
},${supportsImportMaps ? "'y'" : false},${supportsImportMaps && cssModulesEnabled ? `b(\`import"\${b('','text/css')}"with{type:"css"}\`)` : 'false'}, ${
|
|
355
|
+
supportsImportMaps && jsonModulesEnabled ? `b(\`import"\${b('{}','text/json')\}"with{type:"json"}\`)` : 'false'
|
|
356
|
+
},${
|
|
357
|
+
supportsImportMaps && wasmModulesEnabled ?
|
|
358
|
+
`b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`)`
|
|
359
|
+
: 'false'
|
|
360
|
+
},${
|
|
361
|
+
supportsImportMaps && wasmModulesEnabled && sourcePhaseEnabled ?
|
|
362
|
+
`b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`)`
|
|
363
|
+
: 'false'
|
|
364
|
+
}].map(x =>typeof x==='string'?import(x).then(()=>true,()=>false):x)).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
|
|
365
|
+
|
|
366
|
+
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
367
|
+
// path to trigger before setting srcdoc, therefore we track the timing
|
|
368
|
+
let readyForOnload = false,
|
|
369
|
+
onloadCalledWhileNotReady = false;
|
|
370
|
+
function doOnload() {
|
|
371
|
+
if (!readyForOnload) {
|
|
372
|
+
onloadCalledWhileNotReady = true;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
376
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
377
|
+
const doc = iframe.contentDocument;
|
|
378
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
379
|
+
const s = doc.createElement('script');
|
|
380
|
+
if (nonce) s.setAttribute('nonce', nonce);
|
|
381
|
+
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
382
|
+
doc.head.appendChild(s);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
iframe.onload = doOnload;
|
|
387
|
+
// WeChat browser requires append before setting srcdoc
|
|
388
|
+
document.head.appendChild(iframe);
|
|
389
|
+
|
|
390
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
391
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
392
|
+
// document.write gives usability warnings
|
|
393
|
+
readyForOnload = true;
|
|
394
|
+
if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
|
|
395
|
+
else iframe.contentDocument.write(importMapTest);
|
|
396
|
+
// retrigger onload for Safari only if necessary
|
|
397
|
+
if (onloadCalledWhileNotReady) doOnload();
|
|
398
|
+
});
|
|
391
399
|
})();
|
|
392
400
|
|
|
393
401
|
/* es-module-lexer 1.6.0 */
|
|
@@ -437,25 +445,20 @@
|
|
|
437
445
|
return resolve(id, parentUrl).r;
|
|
438
446
|
}
|
|
439
447
|
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
// import('mod', { opts });
|
|
443
|
-
// import('mod', { opts }, parentUrl);
|
|
444
|
-
// import('mod', parentUrl);
|
|
445
|
-
async function importShim(specifier, opts, parentUrl) {
|
|
448
|
+
// import()
|
|
449
|
+
async function importShim(id, opts, parentUrl) {
|
|
446
450
|
if (typeof opts === 'string') {
|
|
447
451
|
parentUrl = opts;
|
|
448
452
|
opts = undefined;
|
|
449
453
|
}
|
|
450
|
-
|
|
451
|
-
//
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
return topLevelLoad(url, { credentials: 'same-origin' });
|
|
454
|
+
// we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
|
|
455
|
+
// because we can't syntactically pass through to dynamic import with a second argument in this libarary
|
|
456
|
+
const url = await importHandler(id, opts, parentUrl);
|
|
457
|
+
const source =
|
|
458
|
+
typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string' ?
|
|
459
|
+
`export{default}from'${url}'with{type:"${opts.with.type}"}`
|
|
460
|
+
: null;
|
|
461
|
+
return topLevelLoad(url, { credentials: 'same-origin' }, source);
|
|
459
462
|
}
|
|
460
463
|
|
|
461
464
|
// import.source()
|
|
@@ -531,7 +534,8 @@
|
|
|
531
534
|
(!wasmModulesEnabled || supportsWasmModules) &&
|
|
532
535
|
(!sourcePhaseEnabled || supportsSourcePhase) &&
|
|
533
536
|
(!multipleImportMaps || supportsMultipleImportMaps) &&
|
|
534
|
-
!importMapSrc
|
|
537
|
+
!importMapSrc &&
|
|
538
|
+
!typescriptEnabled;
|
|
535
539
|
if (sourcePhaseEnabled && typeof WebAssembly !== 'undefined' && !Object.getPrototypeOf(WebAssembly.Module).name) {
|
|
536
540
|
const s = Symbol();
|
|
537
541
|
const brand = m =>
|
|
@@ -601,8 +605,8 @@
|
|
|
601
605
|
}
|
|
602
606
|
}
|
|
603
607
|
});
|
|
608
|
+
observer.observe(document, { childList: true });
|
|
604
609
|
observer.observe(document.head, { childList: true });
|
|
605
|
-
observer.observe(document.body, { childList: true });
|
|
606
610
|
processScriptsAndPreloads();
|
|
607
611
|
}
|
|
608
612
|
|
|
@@ -628,11 +632,13 @@
|
|
|
628
632
|
await loadAll(load, seen);
|
|
629
633
|
resolveDeps(load, seen);
|
|
630
634
|
await lastStaticLoadPromise;
|
|
631
|
-
if (!shimMode && !load.n
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
635
|
+
if (!shimMode && !load.n) {
|
|
636
|
+
if (nativelyLoaded) {
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (source) {
|
|
640
|
+
return await dynamicImport(createBlob(source));
|
|
641
|
+
}
|
|
636
642
|
}
|
|
637
643
|
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
638
644
|
onpolyfill();
|
|
@@ -709,7 +715,7 @@
|
|
|
709
715
|
lastIndex = originalIndex;
|
|
710
716
|
}
|
|
711
717
|
|
|
712
|
-
for (const { s: start, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t } of imports) {
|
|
718
|
+
for (const { s: start, e: end, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t, a } of imports) {
|
|
713
719
|
// source phase
|
|
714
720
|
if (t === 4) {
|
|
715
721
|
let { l: depLoad } = load.d[depIndex++];
|
|
@@ -717,8 +723,8 @@
|
|
|
717
723
|
resolvedSource += 'import ';
|
|
718
724
|
lastIndex = statementStart + 14;
|
|
719
725
|
pushStringTo(start - 1);
|
|
720
|
-
resolvedSource += `/*${source.slice(start - 1,
|
|
721
|
-
lastIndex =
|
|
726
|
+
resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${createBlob(`export default importShim._s[${urlJsString(depLoad.r)}]`)}'`;
|
|
727
|
+
lastIndex = end + 1;
|
|
722
728
|
}
|
|
723
729
|
// dependency source replacements
|
|
724
730
|
else if (dynamicImportIndex === -1) {
|
|
@@ -743,15 +749,18 @@
|
|
|
743
749
|
}
|
|
744
750
|
}
|
|
745
751
|
|
|
752
|
+
// strip import assertions unless we support them
|
|
753
|
+
const stripAssertion = (!supportsCssType && !supportsJsonType) || !(a > 0);
|
|
754
|
+
|
|
746
755
|
pushStringTo(start - 1);
|
|
747
|
-
resolvedSource += `/*${source.slice(start - 1,
|
|
756
|
+
resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${blobUrl}'`;
|
|
748
757
|
|
|
749
758
|
// circular shell execution
|
|
750
759
|
if (!cycleShell && depLoad.s) {
|
|
751
760
|
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
|
|
752
761
|
depLoad.s = undefined;
|
|
753
762
|
}
|
|
754
|
-
lastIndex = statementEnd;
|
|
763
|
+
lastIndex = stripAssertion ? statementEnd : end + 1;
|
|
755
764
|
}
|
|
756
765
|
// import.meta
|
|
757
766
|
else if (dynamicImportIndex === -2) {
|
|
@@ -824,9 +833,10 @@
|
|
|
824
833
|
const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
|
|
825
834
|
|
|
826
835
|
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
827
|
-
const wasmContentType = /^
|
|
836
|
+
const wasmContentType = /^application\/wasm(;|$)/;
|
|
828
837
|
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
829
838
|
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
839
|
+
const tsContentType = /^application\/typescript(;|$)|/;
|
|
830
840
|
|
|
831
841
|
const cssUrlRegEx = /url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;
|
|
832
842
|
|
|
@@ -862,6 +872,8 @@
|
|
|
862
872
|
return res;
|
|
863
873
|
}
|
|
864
874
|
|
|
875
|
+
let esmsTsTransform;
|
|
876
|
+
|
|
865
877
|
async function fetchModule(url, fetchOpts, parent) {
|
|
866
878
|
const mapIntegrity = composedImportMap.integrity[url];
|
|
867
879
|
const res = await doFetch(
|
|
@@ -901,6 +913,14 @@
|
|
|
901
913
|
)});export default s;`,
|
|
902
914
|
t: 'css'
|
|
903
915
|
};
|
|
916
|
+
} else if ((typescriptEnabled && tsContentType.test(contentType)) || url.endsWith('.ts') || url.endsWith('.mts')) {
|
|
917
|
+
const source = await res.text();
|
|
918
|
+
// if we don't have a ts transform hook, try to load it
|
|
919
|
+
if (!esmsTsTransform) {
|
|
920
|
+
({ transform: esmsTsTransform } = await import(tsTransform));
|
|
921
|
+
}
|
|
922
|
+
const transformed = esmsTsTransform(source, url);
|
|
923
|
+
return { r, s: transformed || source, t: transformed ? 'ts' : 'js' };
|
|
904
924
|
} else
|
|
905
925
|
throw Error(
|
|
906
926
|
`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
|
|
@@ -911,13 +931,15 @@
|
|
|
911
931
|
if (
|
|
912
932
|
(type === 'css' && !cssModulesEnabled) ||
|
|
913
933
|
(type === 'json' && !jsonModulesEnabled) ||
|
|
914
|
-
(type === 'wasm' && !wasmModulesEnabled)
|
|
934
|
+
(type === 'wasm' && !wasmModulesEnabled) ||
|
|
935
|
+
(type === 'ts' && !typescriptEnabled)
|
|
915
936
|
)
|
|
916
|
-
throw featErr(`${
|
|
937
|
+
throw featErr(`${type}-modules`);
|
|
917
938
|
return (
|
|
918
939
|
(type === 'css' && !supportsCssType) ||
|
|
919
940
|
(type === 'json' && !supportsJsonType) ||
|
|
920
|
-
(type === 'wasm' && !supportsWasmModules)
|
|
941
|
+
(type === 'wasm' && !supportsWasmModules) ||
|
|
942
|
+
type === 'ts'
|
|
921
943
|
);
|
|
922
944
|
}
|
|
923
945
|
|
|
@@ -961,7 +983,7 @@
|
|
|
961
983
|
if (!load.S) {
|
|
962
984
|
// preload fetch options override fetch options (race)
|
|
963
985
|
({ r: load.r, s: load.S, t: load.t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
|
|
964
|
-
if (load.t !== 'js' && !shimMode && isUnsupportedType(load.t)) {
|
|
986
|
+
if (!load.n && load.t !== 'js' && !shimMode && isUnsupportedType(load.t)) {
|
|
965
987
|
load.n = true;
|
|
966
988
|
}
|
|
967
989
|
}
|