es-module-shims 1.7.0 → 1.7.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/index.d.ts CHANGED
@@ -1,212 +1,212 @@
1
- interface ESMSInitOptions {
2
- /**
3
- * Enable Shim Mode
4
- */
5
- shimMode?: boolean;
6
-
7
- /**
8
- * Enable polyfill features.
9
- * Currently supports ['css-modules', 'json-modules']
10
- */
11
- polyfillEnable?: string[];
12
-
13
- /**
14
- * #### Enforce Integrity
15
- *
16
- * Set to *true* to enable secure mode to not support loading modules without integrity (integrity is always verified though).
17
- *
18
- */
19
- enforceIntegrity: boolean;
20
-
21
- /**
22
- * Nonce for CSP build
23
- */
24
- nonce?: boolean;
25
-
26
- /**
27
- * Disable retriggering of document readystate
28
- */
29
- noLoadEventRetriggers: true;
30
-
31
- /**
32
- * #### Skip Processing Stability
33
- *
34
- * > Non-spec feature
35
- *
36
- * When loading modules that you know will only use baseline modules
37
- * features, it is possible to set a rule to explicitly opt-out modules
38
- * from rewriting. This improves performance because those modules then do
39
- * not need to be processed or transformed at all, so that only local
40
- * application code is handled and not library code.
41
- *
42
- * This can be configured by setting the importShim.skip URL regular
43
- * expression:
44
- *
45
- * ```js
46
- * importShim.skip = /^https:\/\/cdn\.com/;
47
- * ```
48
- *
49
- * By default, this expression supports jspm.dev, dev.jspm.io and
50
- * cdn.pika.dev.
51
- */
52
- skip: RegExp;
53
-
54
- /**
55
- * #### Error hook
56
- *
57
- * Register a callback for any ES Module Shims module errors.
58
- *
59
- */
60
- onerror: (e: any) => any;
61
-
62
- /**
63
- * #### Polyfill hook
64
- *
65
- * Register a callback invoked when polyfill mode first engages.
66
- *
67
- */
68
- onpolyfill: () => void;
69
-
70
- /**
71
- * #### Resolve Hook
72
- *
73
- * Only supported in Shim Mode.
74
- *
75
- * Provide a custom resolver function.
76
- */
77
- resolve: (
78
- id: string,
79
- parentUrl: string,
80
- resolve: (id: string, parentUrl: string) => string
81
- ) => string | Promise<string>;
82
-
83
- /**
84
- * #### Fetch Hook
85
- *
86
- * Only supported in Shim Mode.
87
- *
88
- * > Stability: Non-spec feature
89
- *
90
- * This is provided as a convenience feature since the pipeline handles
91
- * the same data URL rewriting and circular handling of the module graph
92
- * that applies when trying to implement any module transform system.
93
- *
94
- * The ES Module Shims fetch hook can be used to implement transform
95
- * plugins.
96
- *
97
- * For example:
98
- *
99
- * ```js
100
- * importShim.fetch = async function (url) {
101
- * const response = await fetch(url);
102
- * if (response.url.endsWith('.ts')) {
103
- * const source = await response.body();
104
- * const transformed = tsCompile(source);
105
- * return new Response(new Blob([transformed], { type: 'application/javascript' }));
106
- * }
107
- * return response;
108
- * };
109
- * ```
110
- *
111
- * Because the dependency analysis applies by ES Module Shims takes care
112
- * of ensuring all dependencies run through the same fetch hook, the above
113
- * is all that is needed to implement custom plugins.
114
- *
115
- * Streaming support is also provided, for example here is a hook with
116
- * streaming support for JSON:
117
- *
118
- * ```js
119
- * importShim.fetch = async function (url) {
120
- * const response = await fetch(url);
121
- * if (!response.ok)
122
- * throw new Error(`${response.status} ${response.statusText} ${response.url}`);
123
- * const contentType = response.headers.get('content-type');
124
- * if (!/^application\/json($|;)/.test(contentType))
125
- * return response;
126
- * const reader = response.body.getReader();
127
- * return new Response(new ReadableStream({
128
- * async start (controller) {
129
- * let done, value;
130
- * controller.enqueue(new Uint8Array([...'export default '].map(c => c.charCodeAt(0))));
131
- * while (({ done, value } = await reader.read()) && !done) {
132
- * controller.enqueue(value);
133
- * }
134
- * controller.close();
135
- * }
136
- * }), {
137
- * status: 200,
138
- * headers: {
139
- * "Content-Type": "application/javascript"
140
- * }
141
- * });
142
- * }
143
- * ```
144
- */
145
- fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
146
-
147
- /**
148
- * #### Revoke Blob URLs
149
- *
150
- * Set to *true* to cleanup blob URLs from memory after execution.
151
- * Can cost some compute time for large loads.
152
- *
153
- */
154
- revokeBlobURLs: boolean;
155
-
156
- /**
157
- * #### Map Overrides
158
- *
159
- * Set to *true* to permit overrides to import maps.
160
- *
161
- */
162
- mapOverrides: boolean;
163
-
164
- /**
165
- * #### Meta hook
166
- *
167
- * Register a callback for import.meta construction.
168
- *
169
- */
170
- meta: (meta: any, url: string) => void;
171
-
172
- /**
173
- * #### On import hook
174
- *
175
- * Register a callback for top-level imports.
176
- *
177
- */
178
- onimport: (url: string, options: any, parentUrl: string) => void;
179
- }
180
-
181
- interface ImportMap {
182
- imports: Record<string, string>;
183
- scopes: Record<string, Record<string, string>>;
184
- }
185
-
186
- /**
187
- * Dynamic import(...) within any modules loaded will be rewritten as
188
- * importShim(...) automatically providing full support for all es-module-shims
189
- * features through dynamic import.
190
- *
191
- * To load code dynamically (say from the browser console), importShim can be
192
- * called similarly:
193
- *
194
- * ```js
195
- * importShim('/path/to/module.js').then(x => console.log(x));
196
- * ```
197
- */
198
- declare function importShim<Default, Exports extends object>(
199
- specifier: string,
200
- parentUrl?: string
201
- ): Promise<{ default: Default } & Exports>;
202
-
203
- declare namespace importShim {
204
- const resolve: (id: string, parentURL?: string) => string;
205
- const addImportMap: (importMap: Partial<ImportMap>) => void;
206
- const getImportMap: () => ImportMap;
207
- }
208
-
209
- interface Window {
210
- esmsInitOptions?: ESMSInitOptions;
211
- importShim: typeof importShim;
212
- }
1
+ interface ESMSInitOptions {
2
+ /**
3
+ * Enable Shim Mode
4
+ */
5
+ shimMode?: boolean;
6
+
7
+ /**
8
+ * Enable polyfill features.
9
+ * Currently supports ['css-modules', 'json-modules']
10
+ */
11
+ polyfillEnable?: string[];
12
+
13
+ /**
14
+ * #### Enforce Integrity
15
+ *
16
+ * Set to *true* to enable secure mode to not support loading modules without integrity (integrity is always verified though).
17
+ *
18
+ */
19
+ enforceIntegrity: boolean;
20
+
21
+ /**
22
+ * Nonce for CSP build
23
+ */
24
+ nonce?: boolean;
25
+
26
+ /**
27
+ * Disable retriggering of document readystate
28
+ */
29
+ noLoadEventRetriggers: true;
30
+
31
+ /**
32
+ * #### Skip Processing Stability
33
+ *
34
+ * > Non-spec feature
35
+ *
36
+ * When loading modules that you know will only use baseline modules
37
+ * features, it is possible to set a rule to explicitly opt-out modules
38
+ * from rewriting. This improves performance because those modules then do
39
+ * not need to be processed or transformed at all, so that only local
40
+ * application code is handled and not library code.
41
+ *
42
+ * This can be configured by setting the importShim.skip URL regular
43
+ * expression:
44
+ *
45
+ * ```js
46
+ * importShim.skip = /^https:\/\/cdn\.com/;
47
+ * ```
48
+ *
49
+ * By default, this expression supports jspm.dev, dev.jspm.io and
50
+ * cdn.pika.dev.
51
+ */
52
+ skip: RegExp;
53
+
54
+ /**
55
+ * #### Error hook
56
+ *
57
+ * Register a callback for any ES Module Shims module errors.
58
+ *
59
+ */
60
+ onerror: (e: any) => any;
61
+
62
+ /**
63
+ * #### Polyfill hook
64
+ *
65
+ * Register a callback invoked when polyfill mode first engages.
66
+ *
67
+ */
68
+ onpolyfill: () => void;
69
+
70
+ /**
71
+ * #### Resolve Hook
72
+ *
73
+ * Only supported in Shim Mode.
74
+ *
75
+ * Provide a custom resolver function.
76
+ */
77
+ resolve: (
78
+ id: string,
79
+ parentUrl: string,
80
+ resolve: (id: string, parentUrl: string) => string
81
+ ) => string | Promise<string>;
82
+
83
+ /**
84
+ * #### Fetch Hook
85
+ *
86
+ * Only supported in Shim Mode.
87
+ *
88
+ * > Stability: Non-spec feature
89
+ *
90
+ * This is provided as a convenience feature since the pipeline handles
91
+ * the same data URL rewriting and circular handling of the module graph
92
+ * that applies when trying to implement any module transform system.
93
+ *
94
+ * The ES Module Shims fetch hook can be used to implement transform
95
+ * plugins.
96
+ *
97
+ * For example:
98
+ *
99
+ * ```js
100
+ * importShim.fetch = async function (url) {
101
+ * const response = await fetch(url);
102
+ * if (response.url.endsWith('.ts')) {
103
+ * const source = await response.body();
104
+ * const transformed = tsCompile(source);
105
+ * return new Response(new Blob([transformed], { type: 'application/javascript' }));
106
+ * }
107
+ * return response;
108
+ * };
109
+ * ```
110
+ *
111
+ * Because the dependency analysis applies by ES Module Shims takes care
112
+ * of ensuring all dependencies run through the same fetch hook, the above
113
+ * is all that is needed to implement custom plugins.
114
+ *
115
+ * Streaming support is also provided, for example here is a hook with
116
+ * streaming support for JSON:
117
+ *
118
+ * ```js
119
+ * importShim.fetch = async function (url) {
120
+ * const response = await fetch(url);
121
+ * if (!response.ok)
122
+ * throw new Error(`${response.status} ${response.statusText} ${response.url}`);
123
+ * const contentType = response.headers.get('content-type');
124
+ * if (!/^application\/json($|;)/.test(contentType))
125
+ * return response;
126
+ * const reader = response.body.getReader();
127
+ * return new Response(new ReadableStream({
128
+ * async start (controller) {
129
+ * let done, value;
130
+ * controller.enqueue(new Uint8Array([...'export default '].map(c => c.charCodeAt(0))));
131
+ * while (({ done, value } = await reader.read()) && !done) {
132
+ * controller.enqueue(value);
133
+ * }
134
+ * controller.close();
135
+ * }
136
+ * }), {
137
+ * status: 200,
138
+ * headers: {
139
+ * "Content-Type": "application/javascript"
140
+ * }
141
+ * });
142
+ * }
143
+ * ```
144
+ */
145
+ fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
146
+
147
+ /**
148
+ * #### Revoke Blob URLs
149
+ *
150
+ * Set to *true* to cleanup blob URLs from memory after execution.
151
+ * Can cost some compute time for large loads.
152
+ *
153
+ */
154
+ revokeBlobURLs: boolean;
155
+
156
+ /**
157
+ * #### Map Overrides
158
+ *
159
+ * Set to *true* to permit overrides to import maps.
160
+ *
161
+ */
162
+ mapOverrides: boolean;
163
+
164
+ /**
165
+ * #### Meta hook
166
+ *
167
+ * Register a callback for import.meta construction.
168
+ *
169
+ */
170
+ meta: (meta: any, url: string) => void;
171
+
172
+ /**
173
+ * #### On import hook
174
+ *
175
+ * Register a callback for top-level imports.
176
+ *
177
+ */
178
+ onimport: (url: string, options: any, parentUrl: string) => void;
179
+ }
180
+
181
+ interface ImportMap {
182
+ imports: Record<string, string>;
183
+ scopes: Record<string, Record<string, string>>;
184
+ }
185
+
186
+ /**
187
+ * Dynamic import(...) within any modules loaded will be rewritten as
188
+ * importShim(...) automatically providing full support for all es-module-shims
189
+ * features through dynamic import.
190
+ *
191
+ * To load code dynamically (say from the browser console), importShim can be
192
+ * called similarly:
193
+ *
194
+ * ```js
195
+ * importShim('/path/to/module.js').then(x => console.log(x));
196
+ * ```
197
+ */
198
+ declare function importShim<Default, Exports extends object>(
199
+ specifier: string,
200
+ parentUrl?: string
201
+ ): Promise<{ default: Default } & Exports>;
202
+
203
+ declare namespace importShim {
204
+ const resolve: (id: string, parentURL?: string) => string;
205
+ const addImportMap: (importMap: Partial<ImportMap>) => void;
206
+ const getImportMap: () => ImportMap;
207
+ }
208
+
209
+ interface Window {
210
+ esmsInitOptions?: ESMSInitOptions;
211
+ importShim: typeof importShim;
212
+ }
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "es-module-shims",
3
- "version": "1.7.0",
4
- "description": "Shims for the latest ES module features",
5
- "main": "dist/es-module-shims.js",
6
- "exports": {
7
- ".": "./dist/es-module-shims.js",
8
- "./wasm": "./dist/es-module-shims.wasm.js"
9
- },
10
- "types": "index.d.ts",
11
- "type": "module",
12
- "files": [
13
- "CHANGELOG.md",
14
- "dist",
15
- "index.d.ts"
16
- ],
17
- "author": "Guy Bedford",
18
- "license": "MIT",
19
- "devDependencies": {
20
- "@rollup/plugin-replace": "^2.4.2",
21
- "es-module-lexer": "1.2.0",
22
- "esm": "^3.2.25",
23
- "kleur": "^4.1.4",
24
- "mime-types": "^2.1.33",
25
- "mocha": "^9.1.1",
26
- "npm-run-all": "^4.1.5",
27
- "open": "^8.0.8",
28
- "preact": "^10.5.14",
29
- "pretty-ms": "^3.2.0",
30
- "rimraf": "^3.0.2",
31
- "rollup": "^2.58.0",
32
- "tachometer": "^0.5.10",
33
- "terser": "^5.10.0"
34
- },
35
- "directories": {
36
- "test": "test"
37
- },
38
- "scripts": {
39
- "build": "npm install -g chomp ; chomp build",
40
- "test": "npm install -g chomp ; chomp test"
41
- },
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/guybedford/es-module-shims.git"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/guybedford/es-module-shims/issues"
48
- },
49
- "homepage": "https://github.com/guybedford/es-module-shims#readme"
50
- }
1
+ {
2
+ "name": "es-module-shims",
3
+ "version": "1.7.1",
4
+ "description": "Shims for the latest ES module features",
5
+ "main": "dist/es-module-shims.js",
6
+ "exports": {
7
+ ".": "./dist/es-module-shims.js",
8
+ "./wasm": "./dist/es-module-shims.wasm.js"
9
+ },
10
+ "types": "index.d.ts",
11
+ "type": "module",
12
+ "files": [
13
+ "CHANGELOG.md",
14
+ "dist",
15
+ "index.d.ts"
16
+ ],
17
+ "author": "Guy Bedford",
18
+ "license": "MIT",
19
+ "devDependencies": {
20
+ "@rollup/plugin-replace": "^2.4.2",
21
+ "es-module-lexer": "1.2.1",
22
+ "esm": "^3.2.25",
23
+ "kleur": "^4.1.4",
24
+ "mime-types": "^2.1.33",
25
+ "mocha": "^9.1.1",
26
+ "npm-run-all": "^4.1.5",
27
+ "open": "^8.0.8",
28
+ "preact": "^10.5.14",
29
+ "pretty-ms": "^3.2.0",
30
+ "rimraf": "^3.0.2",
31
+ "rollup": "^2.58.0",
32
+ "tachometer": "^0.5.10",
33
+ "terser": "^5.10.0"
34
+ },
35
+ "directories": {
36
+ "test": "test"
37
+ },
38
+ "scripts": {
39
+ "build": "npm install -g chomp ; chomp build",
40
+ "test": "npm install -g chomp ; chomp test"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/guybedford/es-module-shims.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/guybedford/es-module-shims/issues"
48
+ },
49
+ "homepage": "https://github.com/guybedford/es-module-shims#readme"
50
+ }