es-module-shims 1.3.2 → 1.3.6

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,15 @@
1
+ ES Module Shims 1.3.6 (2021/12/07)
2
+ * Fix resolve hook via esms options (#233, @ffortier)
3
+
4
+ ES Module Shims 1.3.5 (2021/12/02)
5
+ * Fix trailing comment regex for source mapping normalization with trailling comments (https://github.com/guybedford/es-module-shims/pull/231)
6
+
7
+ ES Module Shims 1.3.4 (2021/12/02)
8
+ * Support source mapping normalization with trailing comments (https://github.com/guybedford/es-module-shims/pull/229)
9
+
10
+ ES Module Shims 1.3.3 (2021/11/30))
11
+ * Remove use of document.write (https://github.com/guybedford/es-module-shims/pull/227, @lewisl9029)
12
+
1
13
  ES Module Shims 1.3.2 (2021/11/16)
2
14
  * Fix CSP nonce detection (https://github.com/guybedford/es-module-shims/pull/223, @MathiasWP)
3
15
 
package/README.md CHANGED
@@ -85,7 +85,7 @@ If using CSS modules or JSON modules, since these features are relatively new, t
85
85
 
86
86
  ```html
87
87
  <script>
88
- window.esmsInitOptions = { enable: ['css-modules', 'json-modules'] }
88
+ window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules'] }
89
89
  </script>
90
90
  ```
91
91
 
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 1.3.2 */
1
+ /* ES Module Shims 1.3.6 */
2
2
  (function () {
3
3
 
4
4
  const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
@@ -199,14 +199,14 @@
199
199
 
200
200
  const optionsScript = document.querySelector('script[type=esms-options]');
201
201
 
202
- const esmsInitOptions$1 = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
202
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
203
203
 
204
- let shimMode = !!esmsInitOptions$1.shimMode;
205
- const resolveHook = globalHook(shimMode && esmsInitOptions$1.resolve);
204
+ let shimMode = !!esmsInitOptions.shimMode;
205
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
206
206
 
207
- const skip = esmsInitOptions$1.skip ? new RegExp(esmsInitOptions$1.skip) : null;
207
+ const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
208
208
 
209
- let nonce = esmsInitOptions$1.nonce;
209
+ let nonce = esmsInitOptions.nonce;
210
210
 
211
211
  if (!nonce) {
212
212
  const nonceElement = document.querySelector('script[nonce]');
@@ -214,18 +214,18 @@
214
214
  nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
215
215
  }
216
216
 
217
- const onerror = globalHook(esmsInitOptions$1.onerror || noop);
218
- const onpolyfill = globalHook(esmsInitOptions$1.onpolyfill || noop);
217
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
218
+ const onpolyfill = globalHook(esmsInitOptions.onpolyfill || noop);
219
219
 
220
- const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions$1;
220
+ const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions;
221
221
 
222
- const fetchHook = esmsInitOptions$1.fetch ? globalHook(esmsInitOptions$1.fetch) : fetch;
222
+ const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
223
223
 
224
224
  function globalHook (name) {
225
225
  return typeof name === 'string' ? self[name] : name;
226
226
  }
227
227
 
228
- const enable = Array.isArray(esmsInitOptions$1.polyfillEnable) ? esmsInitOptions$1.polyfillEnable : [];
228
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
229
229
  const cssModulesEnabled = enable.includes('css-modules');
230
230
  const jsonModulesEnabled = enable.includes('json-modules');
231
231
 
@@ -298,8 +298,7 @@
298
298
  const iframe = document.createElement('iframe');
299
299
  iframe.style.display = 'none';
300
300
  document.head.appendChild(iframe);
301
- // we use document.write here because eg Weixin built-in browser doesn't support setting srcdoc
302
- iframe.contentWindow.document.write(`<script type=importmap nonce="${nonce}">{"imports":{"x":"data:text/javascript,"}}<${''}/script><script nonce="${nonce}">import('x').then(()=>1,()=>0).then(v=>parent._$s(v))<${''}/script>`);
301
+ iframe.src = createBlob(`<script type=importmap nonce="${nonce}">{"imports":{"x":"data:text/javascript,"}}<${''}/script><script nonce="${nonce}">import('x').then(()=>1,()=>0).then(v=>parent._$s(v))<${''}/script>`, 'text/html');
303
302
  })
304
303
  ]);
305
304
  });
@@ -319,7 +318,7 @@
319
318
  };
320
319
  }
321
320
 
322
- const resolve = resolveHook ? async (id, parentUrl) => ({ r: await esmsInitOptions.resolve(id, parentUrl, defaultResolve), b: false }) : _resolve;
321
+ const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
323
322
 
324
323
  let id = 0;
325
324
  const registry = {};
@@ -530,9 +529,9 @@
530
529
  resolvedSource += source.slice(lastIndex);
531
530
  }
532
531
 
533
- resolvedSource = resolvedSource.replace(/\n\/\/# sourceMappingURL=([^\n]+)\s*$/, (match, url) => match.replace(url, () => new URL(url, load.r)));
532
+ // ; and // trailer support added for Ruby 7 source maps compatibility
534
533
  let hasSourceURL = false;
535
- resolvedSource = resolvedSource.replace(/\n\/\/# sourceURL=([^\n]+)\s*$/, (match, url) => (hasSourceURL = true, match.replace(url, () => new URL(url, load.r))));
534
+ resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
536
535
  if (!hasSourceURL)
537
536
  resolvedSource += '\n//# sourceURL=' + load.r;
538
537
 
@@ -540,6 +539,8 @@
540
539
  load.S = undefined;
541
540
  }
542
541
 
542
+ const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
543
+
543
544
  const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
544
545
  const jsonContentType = /^(text|application)\/json(;|$)/;
545
546
  const cssContentType = /^(text|application)\/css(;|$)/;
@@ -1,4 +1,4 @@
1
- /* ES Module Shims Wasm 1.3.2 */
1
+ /* ES Module Shims Wasm 1.3.6 */
2
2
  (function () {
3
3
 
4
4
  const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
@@ -199,14 +199,14 @@
199
199
 
200
200
  const optionsScript = document.querySelector('script[type=esms-options]');
201
201
 
202
- const esmsInitOptions$1 = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
202
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
203
203
 
204
- let shimMode = !!esmsInitOptions$1.shimMode;
205
- const resolveHook = globalHook(shimMode && esmsInitOptions$1.resolve);
204
+ let shimMode = !!esmsInitOptions.shimMode;
205
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
206
206
 
207
- const skip = esmsInitOptions$1.skip ? new RegExp(esmsInitOptions$1.skip) : null;
207
+ const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
208
208
 
209
- let nonce = esmsInitOptions$1.nonce;
209
+ let nonce = esmsInitOptions.nonce;
210
210
 
211
211
  if (!nonce) {
212
212
  const nonceElement = document.querySelector('script[nonce]');
@@ -214,18 +214,18 @@
214
214
  nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
215
215
  }
216
216
 
217
- const onerror = globalHook(esmsInitOptions$1.onerror || noop);
218
- const onpolyfill = globalHook(esmsInitOptions$1.onpolyfill || noop);
217
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
218
+ const onpolyfill = globalHook(esmsInitOptions.onpolyfill || noop);
219
219
 
220
- const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions$1;
220
+ const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions;
221
221
 
222
- const fetchHook = esmsInitOptions$1.fetch ? globalHook(esmsInitOptions$1.fetch) : fetch;
222
+ const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
223
223
 
224
224
  function globalHook (name) {
225
225
  return typeof name === 'string' ? self[name] : name;
226
226
  }
227
227
 
228
- const enable = Array.isArray(esmsInitOptions$1.polyfillEnable) ? esmsInitOptions$1.polyfillEnable : [];
228
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
229
229
  const cssModulesEnabled = enable.includes('css-modules');
230
230
  const jsonModulesEnabled = enable.includes('json-modules');
231
231
 
@@ -295,8 +295,7 @@
295
295
  const iframe = document.createElement('iframe');
296
296
  iframe.style.display = 'none';
297
297
  document.head.appendChild(iframe);
298
- // we use document.write here because eg Weixin built-in browser doesn't support setting srcdoc
299
- iframe.contentWindow.document.write(`<script type=importmap nonce="${nonce}">{"imports":{"x":"data:text/javascript,"}}<${''}/script><script nonce="${nonce}">import('x').then(()=>1,()=>0).then(v=>parent._$s(v))<${''}/script>`);
298
+ iframe.src = createBlob(`<script type=importmap nonce="${nonce}">{"imports":{"x":"data:text/javascript,"}}<${''}/script><script nonce="${nonce}">import('x').then(()=>1,()=>0).then(v=>parent._$s(v))<${''}/script>`, 'text/html');
300
299
  })
301
300
  ]);
302
301
  });
@@ -317,7 +316,7 @@
317
316
  };
318
317
  }
319
318
 
320
- const resolve = resolveHook ? async (id, parentUrl) => ({ r: await esmsInitOptions.resolve(id, parentUrl, defaultResolve), b: false }) : _resolve;
319
+ const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
321
320
 
322
321
  let id = 0;
323
322
  const registry = {};
@@ -528,9 +527,9 @@
528
527
  resolvedSource += source.slice(lastIndex);
529
528
  }
530
529
 
531
- resolvedSource = resolvedSource.replace(/\n\/\/# sourceMappingURL=([^\n]+)\s*$/, (match, url) => match.replace(url, () => new URL(url, load.r)));
530
+ // ; and // trailer support added for Ruby 7 source maps compatibility
532
531
  let hasSourceURL = false;
533
- resolvedSource = resolvedSource.replace(/\n\/\/# sourceURL=([^\n]+)\s*$/, (match, url) => (hasSourceURL = true, match.replace(url, () => new URL(url, load.r))));
532
+ resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
534
533
  if (!hasSourceURL)
535
534
  resolvedSource += '\n//# sourceURL=' + load.r;
536
535
 
@@ -538,6 +537,8 @@
538
537
  load.S = undefined;
539
538
  }
540
539
 
540
+ const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
541
+
541
542
  const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
542
543
  const jsonContentType = /^(text|application)\/json(;|$)/;
543
544
  const cssContentType = /^(text|application)\/css(;|$)/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.3.2",
3
+ "version": "1.3.6",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {
@@ -11,10 +11,10 @@
11
11
  "build": "rollup -c",
12
12
  "bench": "bash bench/bench.sh",
13
13
  "bench:clear": "rm -rf bench/results",
14
- "footprint": "npm run build && cat dist/es-module-shims.js | brotli | wc -c",
15
- "footprint:csp": "npm run build && cat dist/es-module-shims.csp.js | brotli | wc -c",
14
+ "footprint": "npm run build ; cat dist/es-module-shims.js | brotli | wc -c",
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-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",
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
20
  "test:test-dom-order": "cross-env TEST_NAME=test-dom-order node test/server.mjs",