es-module-shims 1.4.1 → 1.4.5

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,157 +1,157 @@
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
- * Nonce for CSP build
15
- */
16
- nonce?: boolean;
17
-
18
- /**
19
- * Disable retriggering of document readystate
20
- */
21
- noLoadEventRetriggers: true,
22
-
23
- /**
24
- * #### Skip Processing Stability
25
- *
26
- * > Non-spec feature
27
- *
28
- * When loading modules that you know will only use baseline modules
29
- * features, it is possible to set a rule to explicitly opt-out modules
30
- * from rewriting. This improves performance because those modules then do
31
- * not need to be processed or transformed at all, so that only local
32
- * application code is handled and not library code.
33
- *
34
- * This can be configured by setting the importShim.skip URL regular
35
- * expression:
36
- *
37
- * ```js
38
- * importShim.skip = /^https:\/\/cdn\.com/;
39
- * ```
40
- *
41
- * By default, this expression supports jspm.dev, dev.jspm.io and
42
- * cdn.pika.dev.
43
- */
44
- skip: RegExp;
45
-
46
- /**
47
- * #### Error hook
48
- *
49
- * Register a callback for any ES Module Shims module errors.
50
- *
51
- */
52
- onerror: (e: any) => any;
53
-
54
- /**
55
- * #### Resolve Hook
56
- *
57
- * Only supported in Shim Mode.
58
- *
59
- * Provide a custom resolver function.
60
- */
61
- resolve: (id: string, parentUrl: string, resolve: (id: string, parentUrl: string) => string) => string | Promise<string>;
62
-
63
- /**
64
- * #### Fetch Hook
65
- *
66
- * Only supported in Shim Mode.
67
- *
68
- * > Stability: Non-spec feature
69
- *
70
- * This is provided as a convenience feature since the pipeline handles
71
- * the same data URL rewriting and circular handling of the module graph
72
- * that applies when trying to implement any module transform system.
73
- *
74
- * The ES Module Shims fetch hook can be used to implement transform
75
- * plugins.
76
- *
77
- * For example:
78
- *
79
- * ```js
80
- * importShim.fetch = async function (url) {
81
- * const response = await fetch(url);
82
- * if (response.url.endsWith('.ts')) {
83
- * const source = await response.body();
84
- * const transformed = tsCompile(source);
85
- * return new Response(new Blob([transformed], { type: 'application/javascript' }));
86
- * }
87
- * return response;
88
- * };
89
- * ```
90
- *
91
- * Because the dependency analysis applies by ES Module Shims takes care
92
- * of ensuring all dependencies run through the same fetch hook, the above
93
- * is all that is needed to implement custom plugins.
94
- *
95
- * Streaming support is also provided, for example here is a hook with
96
- * streaming support for JSON:
97
- *
98
- * ```js
99
- * importShim.fetch = async function (url) {
100
- * const response = await fetch(url);
101
- * if (!response.ok)
102
- * throw new Error(`${response.status} ${response.statusText} ${response.url}`);
103
- * const contentType = response.headers.get('content-type');
104
- * if (!/^application\/json($|;)/.test(contentType))
105
- * return response;
106
- * const reader = response.body.getReader();
107
- * return new Response(new ReadableStream({
108
- * async start (controller) {
109
- * let done, value;
110
- * controller.enqueue(new Uint8Array([...'export default '].map(c => c.charCodeAt(0))));
111
- * while (({ done, value } = await reader.read()) && !done) {
112
- * controller.enqueue(value);
113
- * }
114
- * controller.close();
115
- * }
116
- * }), {
117
- * status: 200,
118
- * headers: {
119
- * "Content-Type": "application/javascript"
120
- * }
121
- * });
122
- * }
123
- * ```
124
- */
125
- fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
126
-
127
- /**
128
- * #### Revoke Blob URLs
129
- *
130
- * Set to *true* to cleanup blob URLs from memory after execution.
131
- * Can cost some compute time for large loads.
132
- *
133
- */
134
- revokeBlobURLs: boolean;
135
- }
136
-
137
- /**
138
- * Dynamic import(...) within any modules loaded will be rewritten as
139
- * importShim(...) automatically providing full support for all es-module-shims
140
- * features through dynamic import.
141
- *
142
- * To load code dynamically (say from the browser console), importShim can be
143
- * called similarly:
144
- *
145
- * ```js
146
- * importShim('/path/to/module.js').then(x => console.log(x));
147
- * ```
148
- */
149
- declare function importShim<Default, Exports extends object>(
150
- specifier: string,
151
- parentUrl?: string
152
- ): Promise<{ default: Default } & Exports>;
153
-
154
- interface Window {
155
- esmsInitOptions?: ESMSInitOptions;
156
- importShim: typeof importShim;
157
- }
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
+ * Nonce for CSP build
15
+ */
16
+ nonce?: boolean;
17
+
18
+ /**
19
+ * Disable retriggering of document readystate
20
+ */
21
+ noLoadEventRetriggers: true,
22
+
23
+ /**
24
+ * #### Skip Processing Stability
25
+ *
26
+ * > Non-spec feature
27
+ *
28
+ * When loading modules that you know will only use baseline modules
29
+ * features, it is possible to set a rule to explicitly opt-out modules
30
+ * from rewriting. This improves performance because those modules then do
31
+ * not need to be processed or transformed at all, so that only local
32
+ * application code is handled and not library code.
33
+ *
34
+ * This can be configured by setting the importShim.skip URL regular
35
+ * expression:
36
+ *
37
+ * ```js
38
+ * importShim.skip = /^https:\/\/cdn\.com/;
39
+ * ```
40
+ *
41
+ * By default, this expression supports jspm.dev, dev.jspm.io and
42
+ * cdn.pika.dev.
43
+ */
44
+ skip: RegExp;
45
+
46
+ /**
47
+ * #### Error hook
48
+ *
49
+ * Register a callback for any ES Module Shims module errors.
50
+ *
51
+ */
52
+ onerror: (e: any) => any;
53
+
54
+ /**
55
+ * #### Resolve Hook
56
+ *
57
+ * Only supported in Shim Mode.
58
+ *
59
+ * Provide a custom resolver function.
60
+ */
61
+ resolve: (id: string, parentUrl: string, resolve: (id: string, parentUrl: string) => string) => string | Promise<string>;
62
+
63
+ /**
64
+ * #### Fetch Hook
65
+ *
66
+ * Only supported in Shim Mode.
67
+ *
68
+ * > Stability: Non-spec feature
69
+ *
70
+ * This is provided as a convenience feature since the pipeline handles
71
+ * the same data URL rewriting and circular handling of the module graph
72
+ * that applies when trying to implement any module transform system.
73
+ *
74
+ * The ES Module Shims fetch hook can be used to implement transform
75
+ * plugins.
76
+ *
77
+ * For example:
78
+ *
79
+ * ```js
80
+ * importShim.fetch = async function (url) {
81
+ * const response = await fetch(url);
82
+ * if (response.url.endsWith('.ts')) {
83
+ * const source = await response.body();
84
+ * const transformed = tsCompile(source);
85
+ * return new Response(new Blob([transformed], { type: 'application/javascript' }));
86
+ * }
87
+ * return response;
88
+ * };
89
+ * ```
90
+ *
91
+ * Because the dependency analysis applies by ES Module Shims takes care
92
+ * of ensuring all dependencies run through the same fetch hook, the above
93
+ * is all that is needed to implement custom plugins.
94
+ *
95
+ * Streaming support is also provided, for example here is a hook with
96
+ * streaming support for JSON:
97
+ *
98
+ * ```js
99
+ * importShim.fetch = async function (url) {
100
+ * const response = await fetch(url);
101
+ * if (!response.ok)
102
+ * throw new Error(`${response.status} ${response.statusText} ${response.url}`);
103
+ * const contentType = response.headers.get('content-type');
104
+ * if (!/^application\/json($|;)/.test(contentType))
105
+ * return response;
106
+ * const reader = response.body.getReader();
107
+ * return new Response(new ReadableStream({
108
+ * async start (controller) {
109
+ * let done, value;
110
+ * controller.enqueue(new Uint8Array([...'export default '].map(c => c.charCodeAt(0))));
111
+ * while (({ done, value } = await reader.read()) && !done) {
112
+ * controller.enqueue(value);
113
+ * }
114
+ * controller.close();
115
+ * }
116
+ * }), {
117
+ * status: 200,
118
+ * headers: {
119
+ * "Content-Type": "application/javascript"
120
+ * }
121
+ * });
122
+ * }
123
+ * ```
124
+ */
125
+ fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
126
+
127
+ /**
128
+ * #### Revoke Blob URLs
129
+ *
130
+ * Set to *true* to cleanup blob URLs from memory after execution.
131
+ * Can cost some compute time for large loads.
132
+ *
133
+ */
134
+ revokeBlobURLs: boolean;
135
+ }
136
+
137
+ /**
138
+ * Dynamic import(...) within any modules loaded will be rewritten as
139
+ * importShim(...) automatically providing full support for all es-module-shims
140
+ * features through dynamic import.
141
+ *
142
+ * To load code dynamically (say from the browser console), importShim can be
143
+ * called similarly:
144
+ *
145
+ * ```js
146
+ * importShim('/path/to/module.js').then(x => console.log(x));
147
+ * ```
148
+ */
149
+ declare function importShim<Default, Exports extends object>(
150
+ specifier: string,
151
+ parentUrl?: string
152
+ ): Promise<{ default: Default } & Exports>;
153
+
154
+ interface Window {
155
+ esmsInitOptions?: ESMSInitOptions;
156
+ importShim: typeof importShim;
157
+ }
package/package.json CHANGED
@@ -1,65 +1,67 @@
1
- {
2
- "name": "es-module-shims",
3
- "version": "1.4.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
- "scripts": {
11
- "build": "rollup -c",
12
- "bench": "bash bench/bench.sh",
13
- "bench:clear": "rm -rf bench/results",
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
- "prepublishOnly": "npm run build",
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
- "test:test-base-href": "cross-env TEST_NAME=test-base-href node test/server.mjs",
19
- "test:test-csp": "cross-env TEST_NAME=test-csp node test/server.mjs",
20
- "test:test-dom-order": "cross-env TEST_NAME=test-dom-order node test/server.mjs",
21
- "test:test-early-module-load": "cross-env TEST_NAME=test-early-module-load node test/server.mjs",
22
- "test:test-polyfill": "cross-env TEST_NAME=test-polyfill node test/server.mjs",
23
- "test:test-polyfill-wasm": "cross-env TEST_NAME=test-polyfill-wasm node test/server.mjs",
24
- "test:test-preload-case": "cross-env TEST_NAME=test-preload-case node test/server.mjs",
25
- "test:test-revoke-blob-urls": "cross-env TEST_NAME=test-revoke-blob-urls node test/server.mjs",
26
- "test:test-shim": "cross-env TEST_NAME=test-shim node test/server.mjs"
27
- },
28
- "types": "index.d.ts",
29
- "type": "module",
30
- "files": [
31
- "CHANGELOG.md",
32
- "dist",
33
- "index.d.ts"
34
- ],
35
- "author": "Guy Bedford",
36
- "license": "MIT",
37
- "devDependencies": {
38
- "@rollup/plugin-replace": "^2.4.2",
39
- "cross-env": "^7.0.3",
40
- "es-module-lexer": "^0.9.3",
41
- "esm": "^3.2.25",
42
- "kleur": "^4.1.4",
43
- "mime-types": "^2.1.33",
44
- "mocha": "^9.1.1",
45
- "npm-run-all": "^4.1.5",
46
- "open": "^8.0.8",
47
- "preact": "^10.5.14",
48
- "pretty-ms": "^3.2.0",
49
- "rimraf": "^3.0.2",
50
- "rollup": "^2.58.0",
51
- "speed-limiter": "^1.0.2",
52
- "tachometer": "^0.5.10"
53
- },
54
- "directories": {
55
- "test": "test"
56
- },
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/guybedford/es-module-shims.git"
60
- },
61
- "bugs": {
62
- "url": "https://github.com/guybedford/es-module-shims/issues"
63
- },
64
- "homepage": "https://github.com/guybedford/es-module-shims#readme"
65
- }
1
+ {
2
+ "name": "es-module-shims",
3
+ "version": "1.4.5",
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
+ "scripts": {
11
+ "build": "rollup -c",
12
+ "bench": "bash bench/bench.sh",
13
+ "bench:clear": "rm -rf bench/results",
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
+ "prepublishOnly": "npm run build",
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 ; npm run test:test-shim-map-overrides",
18
+ "test:test-base-href": "cross-env TEST_NAME=test-base-href node test/server.mjs",
19
+ "test:test-csp": "cross-env TEST_NAME=test-csp node test/server.mjs",
20
+ "test:test-dom-order": "cross-env TEST_NAME=test-dom-order node test/server.mjs",
21
+ "test:test-early-module-load": "cross-env TEST_NAME=test-early-module-load node test/server.mjs",
22
+ "test:test-polyfill": "cross-env TEST_NAME=test-polyfill node test/server.mjs",
23
+ "test:test-polyfill-wasm": "cross-env TEST_NAME=test-polyfill-wasm node test/server.mjs",
24
+ "test:test-preload-case": "cross-env TEST_NAME=test-preload-case node test/server.mjs",
25
+ "test:test-revoke-blob-urls": "cross-env TEST_NAME=test-revoke-blob-urls node test/server.mjs",
26
+ "test:test-shim": "cross-env TEST_NAME=test-shim node test/server.mjs",
27
+ "test:test-shim-map-overrides": "cross-env TEST_NAME=test-shim-map-overrides node test/server.mjs"
28
+ },
29
+ "types": "index.d.ts",
30
+ "type": "module",
31
+ "files": [
32
+ "CHANGELOG.md",
33
+ "dist",
34
+ "index.d.ts"
35
+ ],
36
+ "author": "Guy Bedford",
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@rollup/plugin-replace": "^2.4.2",
40
+ "cross-env": "^7.0.3",
41
+ "es-module-lexer": "^0.9.3",
42
+ "esm": "^3.2.25",
43
+ "kleur": "^4.1.4",
44
+ "mime-types": "^2.1.33",
45
+ "mocha": "^9.1.1",
46
+ "npm-run-all": "^4.1.5",
47
+ "open": "^8.0.8",
48
+ "preact": "^10.5.14",
49
+ "pretty-ms": "^3.2.0",
50
+ "rimraf": "^3.0.2",
51
+ "rollup": "^2.58.0",
52
+ "speed-limiter": "^1.0.2",
53
+ "tachometer": "^0.5.10",
54
+ "terser": "^5.10.0"
55
+ },
56
+ "directories": {
57
+ "test": "test"
58
+ },
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+https://github.com/guybedford/es-module-shims.git"
62
+ },
63
+ "bugs": {
64
+ "url": "https://github.com/guybedford/es-module-shims/issues"
65
+ },
66
+ "homepage": "https://github.com/guybedford/es-module-shims#readme"
67
+ }