es-module-shims 1.7.3 → 1.8.1
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 +1 -1
- package/dist/es-module-shims.debug.js +27 -3
- package/dist/es-module-shims.js +27 -3
- package/dist/es-module-shims.wasm.js +27 -3
- package/index.d.ts +12 -12
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
29
29
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@1.
|
|
32
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@1.8.1/dist/es-module-shims.js"></script>
|
|
33
33
|
|
|
34
34
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
35
35
|
<script type="importmap">
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims DEBUG BUILD 1.
|
|
1
|
+
/* ES Module Shims DEBUG BUILD 1.8.1 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -127,6 +127,9 @@
|
|
|
127
127
|
relUrl.length === 1 && (relUrl += '/')) ||
|
|
128
128
|
relUrl[0] === '/') {
|
|
129
129
|
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
130
|
+
if (parentProtocol === 'blob:') {
|
|
131
|
+
throw new TypeError(`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`);
|
|
132
|
+
}
|
|
130
133
|
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
131
134
|
//if (parentUrl[parentProtocol.length] !== '/')
|
|
132
135
|
// throw new Error('Cannot resolve');
|
|
@@ -463,6 +466,7 @@
|
|
|
463
466
|
};
|
|
464
467
|
|
|
465
468
|
const registry = importShim._r = {};
|
|
469
|
+
importShim._w = {};
|
|
466
470
|
|
|
467
471
|
async function loadAll (load, seen) {
|
|
468
472
|
if (load.b || seen[load.u])
|
|
@@ -708,6 +712,7 @@
|
|
|
708
712
|
const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
|
|
709
713
|
|
|
710
714
|
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
715
|
+
const wasmContentType = /^(application)\/wasm(;|$)/;
|
|
711
716
|
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
712
717
|
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
713
718
|
|
|
@@ -741,8 +746,12 @@
|
|
|
741
746
|
finally {
|
|
742
747
|
popFetchPool();
|
|
743
748
|
}
|
|
744
|
-
|
|
745
|
-
|
|
749
|
+
|
|
750
|
+
if (!res.ok) {
|
|
751
|
+
const error = new TypeError(`${res.status} ${res.statusText} ${res.url}${fromParent(parent)}`);
|
|
752
|
+
error.response = res;
|
|
753
|
+
throw error;
|
|
754
|
+
}
|
|
746
755
|
return res;
|
|
747
756
|
}
|
|
748
757
|
|
|
@@ -751,6 +760,21 @@
|
|
|
751
760
|
const contentType = res.headers.get('content-type');
|
|
752
761
|
if (jsContentType.test(contentType))
|
|
753
762
|
return { r: res.url, s: await res.text(), t: 'js' };
|
|
763
|
+
else if (wasmContentType.test(contentType)) {
|
|
764
|
+
const module = importShim._w[url] = await WebAssembly.compileStreaming(res);
|
|
765
|
+
let s = '', i = 0, importObj = '';
|
|
766
|
+
for (const impt of WebAssembly.Module.imports(module)) {
|
|
767
|
+
s += `import * as impt${i} from '${impt.module}';\n`;
|
|
768
|
+
importObj += `'${impt.module}':impt${i++},`;
|
|
769
|
+
}
|
|
770
|
+
i = 0;
|
|
771
|
+
s += `const instance = await WebAssembly.instantiate(importShim._w['${url}'], {${importObj}});\n`;
|
|
772
|
+
for (const expt of WebAssembly.Module.exports(module)) {
|
|
773
|
+
s += `const expt${i} = instance['${expt.name}'];\n`;
|
|
774
|
+
s += `export { expt${i++} as "${expt.name}" };\n`;
|
|
775
|
+
}
|
|
776
|
+
return { r: res.url, s, t: 'wasm' };
|
|
777
|
+
}
|
|
754
778
|
else if (jsonContentType.test(contentType))
|
|
755
779
|
return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
|
|
756
780
|
else if (cssContentType.test(contentType)) {
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims 1.
|
|
1
|
+
/* ES Module Shims 1.8.1 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -127,6 +127,9 @@
|
|
|
127
127
|
relUrl.length === 1 && (relUrl += '/')) ||
|
|
128
128
|
relUrl[0] === '/') {
|
|
129
129
|
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
130
|
+
if (parentProtocol === 'blob:') {
|
|
131
|
+
throw new TypeError(`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`);
|
|
132
|
+
}
|
|
130
133
|
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
131
134
|
//if (parentUrl[parentProtocol.length] !== '/')
|
|
132
135
|
// throw new Error('Cannot resolve');
|
|
@@ -458,6 +461,7 @@
|
|
|
458
461
|
};
|
|
459
462
|
|
|
460
463
|
const registry = importShim._r = {};
|
|
464
|
+
importShim._w = {};
|
|
461
465
|
|
|
462
466
|
async function loadAll (load, seen) {
|
|
463
467
|
if (load.b || seen[load.u])
|
|
@@ -701,6 +705,7 @@
|
|
|
701
705
|
const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
|
|
702
706
|
|
|
703
707
|
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
708
|
+
const wasmContentType = /^(application)\/wasm(;|$)/;
|
|
704
709
|
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
705
710
|
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
706
711
|
|
|
@@ -734,8 +739,12 @@
|
|
|
734
739
|
finally {
|
|
735
740
|
popFetchPool();
|
|
736
741
|
}
|
|
737
|
-
|
|
738
|
-
|
|
742
|
+
|
|
743
|
+
if (!res.ok) {
|
|
744
|
+
const error = new TypeError(`${res.status} ${res.statusText} ${res.url}${fromParent(parent)}`);
|
|
745
|
+
error.response = res;
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
739
748
|
return res;
|
|
740
749
|
}
|
|
741
750
|
|
|
@@ -744,6 +753,21 @@
|
|
|
744
753
|
const contentType = res.headers.get('content-type');
|
|
745
754
|
if (jsContentType.test(contentType))
|
|
746
755
|
return { r: res.url, s: await res.text(), t: 'js' };
|
|
756
|
+
else if (wasmContentType.test(contentType)) {
|
|
757
|
+
const module = importShim._w[url] = await WebAssembly.compileStreaming(res);
|
|
758
|
+
let s = '', i = 0, importObj = '';
|
|
759
|
+
for (const impt of WebAssembly.Module.imports(module)) {
|
|
760
|
+
s += `import * as impt${i} from '${impt.module}';\n`;
|
|
761
|
+
importObj += `'${impt.module}':impt${i++},`;
|
|
762
|
+
}
|
|
763
|
+
i = 0;
|
|
764
|
+
s += `const instance = await WebAssembly.instantiate(importShim._w['${url}'], {${importObj}});\n`;
|
|
765
|
+
for (const expt of WebAssembly.Module.exports(module)) {
|
|
766
|
+
s += `const expt${i} = instance['${expt.name}'];\n`;
|
|
767
|
+
s += `export { expt${i++} as "${expt.name}" };\n`;
|
|
768
|
+
}
|
|
769
|
+
return { r: res.url, s, t: 'wasm' };
|
|
770
|
+
}
|
|
747
771
|
else if (jsonContentType.test(contentType))
|
|
748
772
|
return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
|
|
749
773
|
else if (cssContentType.test(contentType)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 1.
|
|
1
|
+
/* ES Module Shims Wasm 1.8.1 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -127,6 +127,9 @@
|
|
|
127
127
|
relUrl.length === 1 && (relUrl += '/')) ||
|
|
128
128
|
relUrl[0] === '/') {
|
|
129
129
|
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
130
|
+
if (parentProtocol === 'blob:') {
|
|
131
|
+
throw new TypeError(`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`);
|
|
132
|
+
}
|
|
130
133
|
// Disabled, but these cases will give inconsistent results for deep backtracking
|
|
131
134
|
//if (parentUrl[parentProtocol.length] !== '/')
|
|
132
135
|
// throw new Error('Cannot resolve');
|
|
@@ -458,6 +461,7 @@
|
|
|
458
461
|
};
|
|
459
462
|
|
|
460
463
|
const registry = importShim._r = {};
|
|
464
|
+
importShim._w = {};
|
|
461
465
|
|
|
462
466
|
async function loadAll (load, seen) {
|
|
463
467
|
if (load.b || seen[load.u])
|
|
@@ -701,6 +705,7 @@
|
|
|
701
705
|
const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
|
|
702
706
|
|
|
703
707
|
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
708
|
+
const wasmContentType = /^(application)\/wasm(;|$)/;
|
|
704
709
|
const jsonContentType = /^(text|application)\/json(;|$)/;
|
|
705
710
|
const cssContentType = /^(text|application)\/css(;|$)/;
|
|
706
711
|
|
|
@@ -734,8 +739,12 @@
|
|
|
734
739
|
finally {
|
|
735
740
|
popFetchPool();
|
|
736
741
|
}
|
|
737
|
-
|
|
738
|
-
|
|
742
|
+
|
|
743
|
+
if (!res.ok) {
|
|
744
|
+
const error = new TypeError(`${res.status} ${res.statusText} ${res.url}${fromParent(parent)}`);
|
|
745
|
+
error.response = res;
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
739
748
|
return res;
|
|
740
749
|
}
|
|
741
750
|
|
|
@@ -744,6 +753,21 @@
|
|
|
744
753
|
const contentType = res.headers.get('content-type');
|
|
745
754
|
if (jsContentType.test(contentType))
|
|
746
755
|
return { r: res.url, s: await res.text(), t: 'js' };
|
|
756
|
+
else if (wasmContentType.test(contentType)) {
|
|
757
|
+
const module = importShim._w[url] = await WebAssembly.compileStreaming(res);
|
|
758
|
+
let s = '', i = 0, importObj = '';
|
|
759
|
+
for (const impt of WebAssembly.Module.imports(module)) {
|
|
760
|
+
s += `import * as impt${i} from '${impt.module}';\n`;
|
|
761
|
+
importObj += `'${impt.module}':impt${i++},`;
|
|
762
|
+
}
|
|
763
|
+
i = 0;
|
|
764
|
+
s += `const instance = await WebAssembly.instantiate(importShim._w['${url}'], {${importObj}});\n`;
|
|
765
|
+
for (const expt of WebAssembly.Module.exports(module)) {
|
|
766
|
+
s += `const expt${i} = instance['${expt.name}'];\n`;
|
|
767
|
+
s += `export { expt${i++} as "${expt.name}" };\n`;
|
|
768
|
+
}
|
|
769
|
+
return { r: res.url, s, t: 'wasm' };
|
|
770
|
+
}
|
|
747
771
|
else if (jsonContentType.test(contentType))
|
|
748
772
|
return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
|
|
749
773
|
else if (cssContentType.test(contentType)) {
|
package/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface ESMSInitOptions {
|
|
|
8
8
|
* Enable polyfill features.
|
|
9
9
|
* Currently supports ['css-modules', 'json-modules']
|
|
10
10
|
*/
|
|
11
|
-
polyfillEnable?:
|
|
11
|
+
polyfillEnable?: Array<'css-modules' | 'json-modules'>
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* #### Enforce Integrity
|
|
@@ -16,7 +16,7 @@ interface ESMSInitOptions {
|
|
|
16
16
|
* Set to *true* to enable secure mode to not support loading modules without integrity (integrity is always verified though).
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
-
enforceIntegrity
|
|
19
|
+
enforceIntegrity?: boolean;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Nonce for CSP build
|
|
@@ -26,7 +26,7 @@ interface ESMSInitOptions {
|
|
|
26
26
|
/**
|
|
27
27
|
* Disable retriggering of document readystate
|
|
28
28
|
*/
|
|
29
|
-
noLoadEventRetriggers
|
|
29
|
+
noLoadEventRetriggers?: true;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* #### Skip Processing Stability
|
|
@@ -49,7 +49,7 @@ interface ESMSInitOptions {
|
|
|
49
49
|
* By default, this expression supports jspm.dev, dev.jspm.io and
|
|
50
50
|
* cdn.pika.dev.
|
|
51
51
|
*/
|
|
52
|
-
skip
|
|
52
|
+
skip?: RegExp;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* #### Error hook
|
|
@@ -57,7 +57,7 @@ interface ESMSInitOptions {
|
|
|
57
57
|
* Register a callback for any ES Module Shims module errors.
|
|
58
58
|
*
|
|
59
59
|
*/
|
|
60
|
-
onerror
|
|
60
|
+
onerror?: (e: any) => any;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* #### Polyfill hook
|
|
@@ -65,7 +65,7 @@ interface ESMSInitOptions {
|
|
|
65
65
|
* Register a callback invoked when polyfill mode first engages.
|
|
66
66
|
*
|
|
67
67
|
*/
|
|
68
|
-
onpolyfill
|
|
68
|
+
onpolyfill?: () => void;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* #### Resolve Hook
|
|
@@ -74,7 +74,7 @@ interface ESMSInitOptions {
|
|
|
74
74
|
*
|
|
75
75
|
* Provide a custom resolver function.
|
|
76
76
|
*/
|
|
77
|
-
resolve
|
|
77
|
+
resolve?: (
|
|
78
78
|
id: string,
|
|
79
79
|
parentUrl: string,
|
|
80
80
|
resolve: (id: string, parentUrl: string) => string
|
|
@@ -142,7 +142,7 @@ interface ESMSInitOptions {
|
|
|
142
142
|
* }
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
|
-
fetch
|
|
145
|
+
fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* #### Revoke Blob URLs
|
|
@@ -151,7 +151,7 @@ interface ESMSInitOptions {
|
|
|
151
151
|
* Can cost some compute time for large loads.
|
|
152
152
|
*
|
|
153
153
|
*/
|
|
154
|
-
revokeBlobURLs
|
|
154
|
+
revokeBlobURLs?: boolean;
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
157
|
* #### Map Overrides
|
|
@@ -159,7 +159,7 @@ interface ESMSInitOptions {
|
|
|
159
159
|
* Set to *true* to permit overrides to import maps.
|
|
160
160
|
*
|
|
161
161
|
*/
|
|
162
|
-
mapOverrides
|
|
162
|
+
mapOverrides?: boolean;
|
|
163
163
|
|
|
164
164
|
/**
|
|
165
165
|
* #### Meta hook
|
|
@@ -167,7 +167,7 @@ interface ESMSInitOptions {
|
|
|
167
167
|
* Register a callback for import.meta construction.
|
|
168
168
|
*
|
|
169
169
|
*/
|
|
170
|
-
meta
|
|
170
|
+
meta?: (meta: any, url: string) => void;
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* #### On import hook
|
|
@@ -175,7 +175,7 @@ interface ESMSInitOptions {
|
|
|
175
175
|
* Register a callback for top-level imports.
|
|
176
176
|
*
|
|
177
177
|
*/
|
|
178
|
-
onimport
|
|
178
|
+
onimport?: (url: string, options: any, parentUrl: string) => void;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
interface ImportMap {
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-module-shims",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Shims for the latest ES module features",
|
|
5
5
|
"main": "dist/es-module-shims.js",
|
|
6
6
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"default": "./dist/es-module-shims.js"
|
|
10
|
+
},
|
|
11
|
+
"./debug": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"default": "./dist/es-module-shims.debug.js"
|
|
14
|
+
},
|
|
15
|
+
"./wasm": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"default": "./dist/es-module-shims.wasm.js"
|
|
18
|
+
}
|
|
10
19
|
},
|
|
11
20
|
"types": "index.d.ts",
|
|
12
21
|
"type": "module",
|