es-module-shims 1.3.0 → 1.3.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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ES Module Shims 1.3.1 (2021/11/04)
2
+ * Feature: Support "async" attribute ordering on polyfill and shim scripts (https://github.com/guybedford/es-module-shims/pull/221)
3
+ * Fix: Sourcemap regex fix (https://github.com/guybedford/es-module-shims/pull/218)
4
+ * Fix: Polyfill duplicate instance bug (https://github.com/guybedford/es-module-shims/pull/220)
5
+
1
6
  ES Module Shims 1.3.0 (2021/10/14)
2
7
  * Feature: Shim mode function to get import map, dynamic map overrides now throw (https://github.com/guybedford/es-module-shims/pull/213, @lewisl9029)
3
8
  * Feature: Upgrade to es-module-lexer@0.9.3 with import / export strings support (https://github.com/guybedford/es-module-shims/pull/210)
package/README.md CHANGED
@@ -47,8 +47,8 @@ ES Module Shims is designed for production performance. A [comprehensive benchma
47
47
 
48
48
  Benchmark summary:
49
49
 
50
- * [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
51
- * [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
50
+ * [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [70% of users](https://caniuse.com/import-maps)) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
51
+ * [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [30% of users](https://caniuse.com/import-maps)) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
52
52
  * [Very large import maps](bench/README.md#large-import-maps-performance) (100s of entries) cost only a few extra milliseconds upfront for the additional loading cost.
53
53
 
54
54
  ### Polyfill Mode
@@ -120,10 +120,12 @@ Works in all browsers with [baseline ES module support](https://caniuse.com/#fea
120
120
  | [JSON Modules](#json-modules) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
121
121
  | [CSS Modules](#css-modules) | :heavy_check_mark:<sup>3</sup> | :heavy_check_mark:<sup>3</sup> | :heavy_check_mark:<sup>3</sup> | :heavy_check_mark:<sup>3</sup> |
122
122
  | [import.meta.resolve](#resolve) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
123
+ | [Top-Level Await](#tla) | :heavy_check_mark: 89+ | :heavy_check_mark: 89+ | :x:<sup>4</sup> | :x:<sup>4</sup> |
123
124
 
124
125
  * 1: _The Edge parallel execution ordering bug is corrected by ES Module Shims with an execution chain inlining approach._
125
126
  * 2: _Module worker support cannot be implemented without dynamic import support in web workers._
126
127
  * 3: _CSS module support requires a separate [Constructable Stylesheets polyfill](https://github.com/calebdwilliams/construct-style-sheets#readme)._
128
+ * 4: _Top-level await support is possible for ES Module Shims to implement, with the feature request tracking in https://github.com/guybedford/es-module-shims/issues/5._
127
129
 
128
130
  #### Current browser compatibility of modules features without ES module shims:
129
131
 
@@ -138,6 +140,7 @@ Works in all browsers with [baseline ES module support](https://caniuse.com/#fea
138
140
  | [JSON Modules](#json-modules) | :heavy_check_mark: 91+ | :x: | :x: | :x: |
139
141
  | [CSS Modules](#css-modules) | :heavy_check_mark: 95+ | :x: | :x: | :x: |
140
142
  | [import.meta.resolve](#resolve) | :x: | :x: | :x: | :x: |
143
+ | [Top-Level Await](#tla) | :heavy_check_mark: 89+ | :heavy_check_mark: 89+ | :x: | :x: |
141
144
 
142
145
  * 1: _Edge executes parallel dependencies in non-deterministic order. ([ChakraCore bug](https://github.com/microsoft/ChakraCore/issues/6261))._
143
146
  * ~: _Indicates the exact first version support has not yet been determined (PR's welcome!)._
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 1.3.0 */
1
+ /* ES Module Shims 1.3.1 */
2
2
  (function () {
3
3
 
4
4
  const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
@@ -404,7 +404,7 @@
404
404
  if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
405
405
  return module;
406
406
  }
407
- const module = await dynamicImport((shimMode || load.n) ? load.b : load.u, { errUrl: load.u });
407
+ const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
408
408
  // if the top-level load is a shell, run its update function
409
409
  if (load.s)
410
410
  (await dynamicImport(load.s)).u$_(module);
@@ -530,9 +530,9 @@
530
530
  resolvedSource += source.slice(lastIndex);
531
531
  }
532
532
 
533
- resolvedSource = resolvedSource.replace(/\/\/# sourceMappingURL=(.*)\s*$/, (match, url) => match.replace(url, () => new URL(url, load.r)));
533
+ resolvedSource = resolvedSource.replace(/\n\/\/# sourceMappingURL=([^\n]+)\s*$/, (match, url) => match.replace(url, () => new URL(url, load.r)));
534
534
  let hasSourceURL = false;
535
- resolvedSource = resolvedSource.replace(/\/\/# sourceURL=(.*)\s*$/, (match, url) => (hasSourceURL = true, match.replace(url, () => new URL(url, load.r))));
535
+ resolvedSource = resolvedSource.replace(/\n\/\/# sourceURL=([^\n]+)\s*$/, (match, url) => (hasSourceURL = true, match.replace(url, () => new URL(url, load.r))));
536
536
  if (!hasSourceURL)
537
537
  resolvedSource += '\n//# sourceURL=' + load.r;
538
538
 
@@ -760,11 +760,12 @@
760
760
  const isDomContentLoadedScript = domContentLoadedCnt > 0;
761
761
  if (isReadyScript) readyStateCompleteCnt++;
762
762
  if (isDomContentLoadedScript) domContentLoadedCnt++;
763
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isReadyScript && lastStaticLoadPromise).catch(e => {
763
+ const blocks = script.getAttribute('async') === null && isReadyScript;
764
+ const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
764
765
  setTimeout(() => { throw e });
765
766
  onerror(e);
766
767
  });
767
- if (isReadyScript)
768
+ if (blocks)
768
769
  lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
769
770
  if (isDomContentLoadedScript)
770
771
  loadPromise.then(domContentLoadedCheck);
@@ -1,4 +1,4 @@
1
- /* ES Module Shims Wasm 1.3.0 */
1
+ /* ES Module Shims Wasm 1.3.1 */
2
2
  (function () {
3
3
 
4
4
  const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
@@ -402,7 +402,7 @@
402
402
  if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
403
403
  return module;
404
404
  }
405
- const module = await dynamicImport((shimMode || load.n) ? load.b : load.u, { errUrl: load.u });
405
+ const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
406
406
  // if the top-level load is a shell, run its update function
407
407
  if (load.s)
408
408
  (await dynamicImport(load.s)).u$_(module);
@@ -528,9 +528,9 @@
528
528
  resolvedSource += source.slice(lastIndex);
529
529
  }
530
530
 
531
- resolvedSource = resolvedSource.replace(/\/\/# sourceMappingURL=(.*)\s*$/, (match, url) => match.replace(url, () => new URL(url, load.r)));
531
+ resolvedSource = resolvedSource.replace(/\n\/\/# sourceMappingURL=([^\n]+)\s*$/, (match, url) => match.replace(url, () => new URL(url, load.r)));
532
532
  let hasSourceURL = false;
533
- resolvedSource = resolvedSource.replace(/\/\/# sourceURL=(.*)\s*$/, (match, url) => (hasSourceURL = true, match.replace(url, () => new URL(url, load.r))));
533
+ resolvedSource = resolvedSource.replace(/\n\/\/# sourceURL=([^\n]+)\s*$/, (match, url) => (hasSourceURL = true, match.replace(url, () => new URL(url, load.r))));
534
534
  if (!hasSourceURL)
535
535
  resolvedSource += '\n//# sourceURL=' + load.r;
536
536
 
@@ -758,11 +758,12 @@
758
758
  const isDomContentLoadedScript = domContentLoadedCnt > 0;
759
759
  if (isReadyScript) readyStateCompleteCnt++;
760
760
  if (isDomContentLoadedScript) domContentLoadedCnt++;
761
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isReadyScript && lastStaticLoadPromise).catch(e => {
761
+ const blocks = script.getAttribute('async') === null && isReadyScript;
762
+ const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
762
763
  setTimeout(() => { throw e });
763
764
  onerror(e);
764
765
  });
765
- if (isReadyScript)
766
+ if (blocks)
766
767
  lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
767
768
  if (isDomContentLoadedScript)
768
769
  loadPromise.then(domContentLoadedCheck);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {
@@ -14,9 +14,10 @@
14
14
  "footprint": "npm run build && cat dist/es-module-shims.js | brotli | wc -c",
15
15
  "footprint:csp": "npm run build && cat dist/es-module-shims.csp.js | brotli | wc -c",
16
16
  "prepublishOnly": "npm run build",
17
- "test": "npm run test:test-base-href && npm run test:test-csp && 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",
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
18
  "test:test-base-href": "cross-env TEST_NAME=test-base-href node test/server.mjs",
19
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",
20
21
  "test:test-early-module-load": "cross-env TEST_NAME=test-early-module-load node test/server.mjs",
21
22
  "test:test-polyfill": "cross-env TEST_NAME=test-polyfill node test/server.mjs",
22
23
  "test:test-polyfill-wasm": "cross-env TEST_NAME=test-polyfill-wasm node test/server.mjs",