es-module-shims 1.8.2 → 1.8.3

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 CHANGED
@@ -12,6 +12,7 @@ The following modules features are polyfilled:
12
12
  * Dynamic `import()` shimming when necessary in eg older Firefox versions.
13
13
  * `import.meta` and `import.meta.url`.
14
14
  * [JSON](#json-modules) and [CSS modules](#css-modules) with import assertions (when enabled).
15
+ * [Wasm modules](#wasm-modules) when enabled.
15
16
  * [`<link rel="modulepreload">` is shimmed](#modulepreload) in browsers without import maps support.
16
17
 
17
18
  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.
@@ -29,7 +30,7 @@ Because we are still using the native module loader the edge cases work out comp
29
30
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
30
31
 
31
32
  ```html
32
- <script async src="https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js"></script>
33
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.8.3/dist/es-module-shims.js"></script>
33
34
 
34
35
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
35
36
  <script type="importmap">
@@ -182,7 +183,7 @@ If using more modern features like CSS Modules or JSON Modules, these need to be
182
183
 
183
184
  ```html
184
185
  <script>
185
- window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules'] }
186
+ window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules', 'wasm-modules'] }
186
187
  </script>
187
188
  ```
188
189
 
@@ -222,6 +223,7 @@ Browser Compatibility on baseline ES modules support **with** ES Module Shims:
222
223
  | [Import Maps](#import-maps) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
223
224
  | [JSON Modules](#json-modules) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
224
225
  | [CSS Modules](#css-modules) | :heavy_check_mark:<sup>1</sup> | :heavy_check_mark:<sup>1</sup> | :heavy_check_mark:<sup>1</sup> |
226
+ | [Wasm Modules](#wasm-modules) | 89+ | 89+ | 15+ |
225
227
  | [import.meta.resolve](#resolve) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
226
228
  | [Module Workers](#module-workers) (via wrapper) | 63+ | :x:<sup>2</sup> | 15+ |
227
229
  | Top-Level Await (unpolyfilled<sup>3</sup>) | 89+ | 89+ | 15+ |
@@ -240,6 +242,7 @@ Browser compatibility **without** ES Module Shims:
240
242
  | [Import Maps](#import-maps) | 89+ | 108+ | 16.4+ |
241
243
  | [JSON Modules](#json-modules) | 91+ | :x: | :x: |
242
244
  | [CSS Modules](#css-modules) | 95+ | :x: | :x: |
245
+ | [Wasm Modules](#wasm-modules) | :x: | :x: | :x: |
243
246
  | [import.meta.resolve](#resolve) | :x: | :x: | :x: |
244
247
  | [Module Workers](#module-workers) | ~68+ | :x: | :x: |
245
248
  | Top-Level Await | 89+ | 89+ | 15+ |
@@ -436,6 +439,26 @@ In addition CSS modules need to be served with a valid CSS content type.
436
439
 
437
440
  Checks for assertion failures are not currently included.
438
441
 
442
+ ### Wasm Modules
443
+
444
+ > Stability: WebAssembly Standard, Unimplemented
445
+
446
+ Implements the [WebAssembly ESM Integration](https://github.com/WebAssembly/esm-integration) spec (source phase imports omitted currently, tracking in https://github.com/guybedford/es-module-shims/issues/410).
447
+
448
+ In shim mode, Wasm modules are always supported. In polyfill mode, Wasm modules require the `polyfillEnable: ['wasm-modules']` [init option](#polyfill-enable-option).
449
+
450
+ WebAssembly module exports are made available as module exports and WebAssembly module imports will be resolved using the browser module loader.
451
+
452
+ WebAssembly modules require native top-level await support to be polyfilled, see the [compatibility table](#browser-support) above.
453
+
454
+ ```html
455
+ <script type="module">
456
+ import { fn } from './app.wasm';
457
+ </script>
458
+ ```
459
+
460
+ If using CSP, make sure to add `'unsafe-wasm-eval'` to `script-src` which is needed when the shim or polyfill engages, note this policy is much much safer than eval due to the Wasm secure sandbox. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution.
461
+
439
462
  ### Resolve
440
463
 
441
464
  > Stability: Draft HTML PR
@@ -1,4 +1,4 @@
1
- /* ES Module Shims DEBUG BUILD 1.8.2 */
1
+ /* ES Module Shims DEBUG BUILD 1.8.3 */
2
2
  (function () {
3
3
 
4
4
  const hasWindow = typeof window !== 'undefined';
@@ -41,6 +41,7 @@
41
41
  const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
42
42
  const cssModulesEnabled = enable.includes('css-modules');
43
43
  const jsonModulesEnabled = enable.includes('json-modules');
44
+ const wasmModulesEnabled = enable.includes('wasm-modules');
44
45
 
45
46
  const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
46
47
 
@@ -314,20 +315,22 @@
314
315
 
315
316
  let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
316
317
  let supportsImportMeta = supportsDynamicImport;
318
+ let supportsWasmModules = false;
317
319
 
318
320
  const importMetaCheck = 'import.meta';
319
- const cssModulesCheck = `import"x"assert{type:"css"}`;
320
- const jsonModulesCheck = `import"x"assert{type:"json"}`;
321
+ const moduleCheck = 'import"x"';
322
+ const cssModulesCheck = `assert{type:"css"}`;
323
+ const jsonModulesCheck = `assert{type:"json"}`;
321
324
 
322
325
  let featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
323
326
  if (!supportsDynamicImport)
324
327
  return;
325
-
326
328
  if (!hasDocument)
327
329
  return Promise.all([
328
330
  supportsImportMaps || dynamicImport(createBlob(importMetaCheck)).then(() => supportsImportMeta = true, noop),
329
- cssModulesEnabled && dynamicImport(createBlob(cssModulesCheck.replace('x', createBlob('', 'text/css')))).then(() => supportsCssAssertions = true, noop),
330
- jsonModulesEnabled && dynamicImport(createBlob(jsonModulescheck.replace('x', createBlob('{}', 'text/json')))).then(() => supportsJsonAssertions = true, noop),
331
+ cssModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob('', 'text/css')) + cssModulesCheck)).then(() => supportsCssAssertions = true, noop),
332
+ jsonModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob('{}', 'text/json')) + jsonModulesCheck)).then(() => supportsJsonAssertions = true, noop),
333
+ wasmModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob(new Uint8Array([0,97,115,109,1,0,0,0]), 'application/wasm')))).then(() => supportsWasmModules = true, noop),
331
334
  ]);
332
335
 
333
336
  return new Promise(resolve => {
@@ -481,7 +484,7 @@
481
484
  let baselinePassthrough;
482
485
 
483
486
  const initPromise = featureDetectionPromise.then(() => {
484
- baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy;
487
+ baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && (!wasmModulesEnabled || supportsWasmModules) && !importMapSrcOrLazy;
485
488
  console.info(`es-module-shims: init ${shimMode ? 'shim mode' : 'polyfill mode'}, ${baselinePassthrough ? 'baseline passthrough' : 'polyfill engaged'}`);
486
489
  if (hasDocument) {
487
490
  if (!supportsImportMaps) {
@@ -769,8 +772,7 @@
769
772
  i = 0;
770
773
  s += `const instance = await WebAssembly.instantiate(importShim._w['${url}'], {${importObj}});\n`;
771
774
  for (const expt of WebAssembly.Module.exports(module)) {
772
- s += `const expt${i} = instance['${expt.name}'];\n`;
773
- s += `export { expt${i++} as "${expt.name}" };\n`;
775
+ s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
774
776
  }
775
777
  return { r: res.url, s, t: 'wasm' };
776
778
  }
@@ -829,9 +831,9 @@
829
831
  let t;
830
832
  ({ r: load.r, s: source, t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
831
833
  if (t && !shimMode) {
832
- if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
834
+ if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled || t === 'wasm' && !wasmModulesEnabled)
833
835
  throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
834
- if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
836
+ if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions || t === 'wasm' && !supportsWasmModules)
835
837
  load.n = true;
836
838
  }
837
839
  }
@@ -884,6 +886,8 @@
884
886
  fetchOpts.integrity = script.integrity;
885
887
  if (script.referrerPolicy)
886
888
  fetchOpts.referrerPolicy = script.referrerPolicy;
889
+ if (script.fetchPriority)
890
+ fetchOpts.priority = script.fetchPriority;
887
891
  if (script.crossOrigin === 'use-credentials')
888
892
  fetchOpts.credentials = 'include';
889
893
  else if (script.crossOrigin === 'anonymous')
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 1.8.2 */
1
+ /* ES Module Shims 1.8.3 */
2
2
  (function () {
3
3
 
4
4
  const hasWindow = typeof window !== 'undefined';
@@ -41,6 +41,7 @@
41
41
  const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
42
42
  const cssModulesEnabled = enable.includes('css-modules');
43
43
  const jsonModulesEnabled = enable.includes('json-modules');
44
+ const wasmModulesEnabled = enable.includes('wasm-modules');
44
45
 
45
46
  const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
46
47
 
@@ -314,20 +315,22 @@
314
315
 
315
316
  let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
316
317
  let supportsImportMeta = supportsDynamicImport;
318
+ let supportsWasmModules = false;
317
319
 
318
320
  const importMetaCheck = 'import.meta';
319
- const cssModulesCheck = `import"x"assert{type:"css"}`;
320
- const jsonModulesCheck = `import"x"assert{type:"json"}`;
321
+ const moduleCheck = 'import"x"';
322
+ const cssModulesCheck = `assert{type:"css"}`;
323
+ const jsonModulesCheck = `assert{type:"json"}`;
321
324
 
322
325
  let featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
323
326
  if (!supportsDynamicImport)
324
327
  return;
325
-
326
328
  if (!hasDocument)
327
329
  return Promise.all([
328
330
  supportsImportMaps || dynamicImport(createBlob(importMetaCheck)).then(() => supportsImportMeta = true, noop),
329
- cssModulesEnabled && dynamicImport(createBlob(cssModulesCheck.replace('x', createBlob('', 'text/css')))).then(() => supportsCssAssertions = true, noop),
330
- jsonModulesEnabled && dynamicImport(createBlob(jsonModulescheck.replace('x', createBlob('{}', 'text/json')))).then(() => supportsJsonAssertions = true, noop),
331
+ cssModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob('', 'text/css')) + cssModulesCheck)).then(() => supportsCssAssertions = true, noop),
332
+ jsonModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob('{}', 'text/json')) + jsonModulesCheck)).then(() => supportsJsonAssertions = true, noop),
333
+ wasmModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob(new Uint8Array([0,97,115,109,1,0,0,0]), 'application/wasm')))).then(() => supportsWasmModules = true, noop),
331
334
  ]);
332
335
 
333
336
  return new Promise(resolve => {
@@ -476,7 +479,7 @@
476
479
  let baselinePassthrough;
477
480
 
478
481
  const initPromise = featureDetectionPromise.then(() => {
479
- baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy;
482
+ baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && (!wasmModulesEnabled || supportsWasmModules) && !importMapSrcOrLazy;
480
483
  if (hasDocument) {
481
484
  if (!supportsImportMaps) {
482
485
  const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
@@ -762,8 +765,7 @@
762
765
  i = 0;
763
766
  s += `const instance = await WebAssembly.instantiate(importShim._w['${url}'], {${importObj}});\n`;
764
767
  for (const expt of WebAssembly.Module.exports(module)) {
765
- s += `const expt${i} = instance['${expt.name}'];\n`;
766
- s += `export { expt${i++} as "${expt.name}" };\n`;
768
+ s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
767
769
  }
768
770
  return { r: res.url, s, t: 'wasm' };
769
771
  }
@@ -822,9 +824,9 @@
822
824
  let t;
823
825
  ({ r: load.r, s: source, t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
824
826
  if (t && !shimMode) {
825
- if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
827
+ if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled || t === 'wasm' && !wasmModulesEnabled)
826
828
  throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
827
- if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
829
+ if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions || t === 'wasm' && !supportsWasmModules)
828
830
  load.n = true;
829
831
  }
830
832
  }
@@ -876,6 +878,8 @@
876
878
  fetchOpts.integrity = script.integrity;
877
879
  if (script.referrerPolicy)
878
880
  fetchOpts.referrerPolicy = script.referrerPolicy;
881
+ if (script.fetchPriority)
882
+ fetchOpts.priority = script.fetchPriority;
879
883
  if (script.crossOrigin === 'use-credentials')
880
884
  fetchOpts.credentials = 'include';
881
885
  else if (script.crossOrigin === 'anonymous')
@@ -1,4 +1,4 @@
1
- /* ES Module Shims Wasm 1.8.2 */
1
+ /* ES Module Shims Wasm 1.8.3 */
2
2
  (function () {
3
3
 
4
4
  const hasWindow = typeof window !== 'undefined';
@@ -41,6 +41,7 @@
41
41
  const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
42
42
  const cssModulesEnabled = enable.includes('css-modules');
43
43
  const jsonModulesEnabled = enable.includes('json-modules');
44
+ const wasmModulesEnabled = enable.includes('wasm-modules');
44
45
 
45
46
  const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
46
47
 
@@ -314,20 +315,22 @@
314
315
 
315
316
  let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
316
317
  let supportsImportMeta = supportsDynamicImport;
318
+ let supportsWasmModules = false;
317
319
 
318
320
  const importMetaCheck = 'import.meta';
319
- const cssModulesCheck = `import"x"assert{type:"css"}`;
320
- const jsonModulesCheck = `import"x"assert{type:"json"}`;
321
+ const moduleCheck = 'import"x"';
322
+ const cssModulesCheck = `assert{type:"css"}`;
323
+ const jsonModulesCheck = `assert{type:"json"}`;
321
324
 
322
325
  let featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
323
326
  if (!supportsDynamicImport)
324
327
  return;
325
-
326
328
  if (!hasDocument)
327
329
  return Promise.all([
328
330
  supportsImportMaps || dynamicImport(createBlob(importMetaCheck)).then(() => supportsImportMeta = true, noop),
329
- cssModulesEnabled && dynamicImport(createBlob(cssModulesCheck.replace('x', createBlob('', 'text/css')))).then(() => supportsCssAssertions = true, noop),
330
- jsonModulesEnabled && dynamicImport(createBlob(jsonModulescheck.replace('x', createBlob('{}', 'text/json')))).then(() => supportsJsonAssertions = true, noop),
331
+ cssModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob('', 'text/css')) + cssModulesCheck)).then(() => supportsCssAssertions = true, noop),
332
+ jsonModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob('{}', 'text/json')) + jsonModulesCheck)).then(() => supportsJsonAssertions = true, noop),
333
+ wasmModulesEnabled && dynamicImport(createBlob(moduleCheck.replace('x', createBlob(new Uint8Array([0,97,115,109,1,0,0,0]), 'application/wasm')))).then(() => supportsWasmModules = true, noop),
331
334
  ]);
332
335
 
333
336
  return new Promise(resolve => {
@@ -476,7 +479,7 @@
476
479
  let baselinePassthrough;
477
480
 
478
481
  const initPromise = featureDetectionPromise.then(() => {
479
- baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy;
482
+ baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && (!wasmModulesEnabled || supportsWasmModules) && !importMapSrcOrLazy;
480
483
  if (hasDocument) {
481
484
  if (!supportsImportMaps) {
482
485
  const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
@@ -762,8 +765,7 @@
762
765
  i = 0;
763
766
  s += `const instance = await WebAssembly.instantiate(importShim._w['${url}'], {${importObj}});\n`;
764
767
  for (const expt of WebAssembly.Module.exports(module)) {
765
- s += `const expt${i} = instance['${expt.name}'];\n`;
766
- s += `export { expt${i++} as "${expt.name}" };\n`;
768
+ s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
767
769
  }
768
770
  return { r: res.url, s, t: 'wasm' };
769
771
  }
@@ -822,9 +824,9 @@
822
824
  let t;
823
825
  ({ r: load.r, s: source, t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
824
826
  if (t && !shimMode) {
825
- if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
827
+ if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled || t === 'wasm' && !wasmModulesEnabled)
826
828
  throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
827
- if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
829
+ if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions || t === 'wasm' && !supportsWasmModules)
828
830
  load.n = true;
829
831
  }
830
832
  }
@@ -876,6 +878,8 @@
876
878
  fetchOpts.integrity = script.integrity;
877
879
  if (script.referrerPolicy)
878
880
  fetchOpts.referrerPolicy = script.referrerPolicy;
881
+ if (script.fetchPriority)
882
+ fetchOpts.priority = script.fetchPriority;
879
883
  if (script.crossOrigin === 'use-credentials')
880
884
  fetchOpts.credentials = 'include';
881
885
  else if (script.crossOrigin === 'anonymous')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {