es-module-shims 2.0.4 → 2.0.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/README.md CHANGED
@@ -28,7 +28,7 @@ Because we are still using the native module loader the edge cases work out comp
28
28
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
29
29
 
30
30
  ```html
31
- <script async src="https://ga.jspm.io/npm:es-module-shims@2.0.4/dist/es-module-shims.js"></script>
31
+ <script async src="https://ga.jspm.io/npm:es-module-shims@2.0.6/dist/es-module-shims.js"></script>
32
32
 
33
33
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
34
34
  <script type="importmap">
@@ -553,7 +553,7 @@ Once enabled, the separate `es-module-shims-typescript.js` extension must be ava
553
553
  Example:
554
554
 
555
555
  ```html
556
- <script async src="https://ga.jspm.io/npm:es-module-shims@2.0.4/dist/es-module-shims.js"></script>
556
+ <script async src="https://ga.jspm.io/npm:es-module-shims@2.0.6/dist/es-module-shims.js"></script>
557
557
  <script type="esms-options">
558
558
  {
559
559
  "polyfillEnable": "all"
@@ -1,96 +1,96 @@
1
- /* ES Module Shims 2.0.4 */
1
+ /* ES Module Shims 2.0.6 */
2
2
  (function () {
3
3
 
4
- const hasDocument = typeof document !== 'undefined';
5
-
6
- const noop = () => {};
7
-
8
- const dynamicImport = (u, errUrl) => import(u);
9
-
10
- const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
-
12
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
- Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
-
15
- // shim mode is determined on initialization, no late shim mode
16
- const shimMode =
17
- hasDocument ?
18
- esmsInitOptions.shimMode ||
19
- document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
- .length > 0
21
- : true;
22
-
23
- const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
- const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
- let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
- const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
- const tsTransform =
28
- esmsInitOptions.tsTransform ||
29
- (document.currentScript &&
30
- document.currentScript.src.replace('.debug.js' , '-typescript.js')) ||
31
- './es-module-shims-typescript.js';
32
-
33
- const mapOverrides = esmsInitOptions.mapOverrides;
34
-
35
- let nonce = esmsInitOptions.nonce;
36
- if (!nonce && hasDocument) {
37
- const nonceElement = document.querySelector('script[nonce]');
38
- if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
39
- }
40
-
41
- const onerror = globalHook(esmsInitOptions.onerror || noop);
42
-
43
- const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
44
-
45
- function globalHook(name) {
46
- return typeof name === 'string' ? self[name] : name;
47
- }
48
-
49
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
50
- const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
51
- const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
52
- const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
53
- const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
54
- const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
55
- const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
56
- const typescriptEnabled = enable.includes('typescript') || enableAll;
57
-
58
- const onpolyfill =
59
- esmsInitOptions.onpolyfill ?
60
- globalHook(esmsInitOptions.onpolyfill)
61
- : () => {
62
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
- };
64
-
65
- const baseUrl =
66
- hasDocument ?
67
- document.baseURI
68
- : `${location.protocol}//${location.host}${
69
- location.pathname.includes('/') ?
70
- location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
- : location.pathname
72
- }`;
73
-
74
- const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
- let { skip } = esmsInitOptions;
76
- if (Array.isArray(skip)) {
77
- const l = skip.map(s => new URL(s, baseUrl).href);
78
- skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
- } else if (typeof skip === 'string') {
80
- const r = new RegExp(skip);
81
- skip = s => r.test(s);
82
- } else if (skip instanceof RegExp) {
83
- skip = s => skip.test(s);
84
- }
85
-
86
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
-
88
- const throwError = err => {
89
- (self.reportError || dispatchError)(err), void onerror(err);
90
- };
91
-
92
- function fromParent(parent) {
93
- return parent ? ` imported from ${parent}` : '';
4
+ const hasDocument = typeof document !== 'undefined';
5
+
6
+ const noop = () => {};
7
+
8
+ const dynamicImport = (u, errUrl) => import(u);
9
+
10
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
+
12
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
+ Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
+
15
+ // shim mode is determined on initialization, no late shim mode
16
+ const shimMode =
17
+ hasDocument ?
18
+ esmsInitOptions.shimMode ||
19
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
+ .length > 0
21
+ : true;
22
+
23
+ const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
+ let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
+ const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
+ const tsTransform =
28
+ esmsInitOptions.tsTransform ||
29
+ (document.currentScript &&
30
+ document.currentScript.src.replace(/\.debug\.js$/ , '-typescript.js')) ||
31
+ './es-module-shims-typescript.js';
32
+
33
+ const mapOverrides = esmsInitOptions.mapOverrides;
34
+
35
+ let nonce = esmsInitOptions.nonce;
36
+ if (!nonce && hasDocument) {
37
+ const nonceElement = document.querySelector('script[nonce]');
38
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
39
+ }
40
+
41
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
42
+
43
+ const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
44
+
45
+ function globalHook(name) {
46
+ return typeof name === 'string' ? self[name] : name;
47
+ }
48
+
49
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
50
+ const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
51
+ const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
52
+ const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
53
+ const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
54
+ const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
55
+ const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
56
+ const typescriptEnabled = enable.includes('typescript') || enableAll;
57
+
58
+ const onpolyfill =
59
+ esmsInitOptions.onpolyfill ?
60
+ globalHook(esmsInitOptions.onpolyfill)
61
+ : () => {
62
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
+ };
64
+
65
+ const baseUrl =
66
+ hasDocument ?
67
+ document.baseURI
68
+ : `${location.protocol}//${location.host}${
69
+ location.pathname.includes('/') ?
70
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
+ : location.pathname
72
+ }`;
73
+
74
+ const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
+ let { skip } = esmsInitOptions;
76
+ if (Array.isArray(skip)) {
77
+ const l = skip.map(s => new URL(s, baseUrl).href);
78
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
+ } else if (typeof skip === 'string') {
80
+ const r = new RegExp(skip);
81
+ skip = s => r.test(s);
82
+ } else if (skip instanceof RegExp) {
83
+ skip = s => skip.test(s);
84
+ }
85
+
86
+ const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
+
88
+ const throwError = err => {
89
+ (self.reportError || dispatchError)(err), void onerror(err);
90
+ };
91
+
92
+ function fromParent(parent) {
93
+ return parent ? ` imported from ${parent}` : '';
94
94
  }
95
95
 
96
96
  const backslashRegEx = /\\/g;
@@ -462,17 +462,18 @@
462
462
  }
463
463
  // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
464
464
  // because we can't syntactically pass through to dynamic import with a second argument in this libarary
465
- const url = await importHandler(id, opts, parentUrl, false);
466
- const source =
467
- typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string' ?
468
- `export{default}from'${url}'with{type:"${opts.with.type}"}`
469
- : null;
465
+ let url = await importHandler(id, opts, parentUrl, false);
466
+ let source = null;
467
+ if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
468
+ source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
469
+ url += '?entry';
470
+ }
470
471
  return topLevelLoad(url, { credentials: 'same-origin' }, source);
471
472
  }
472
473
 
473
474
  // import.source()
474
475
  // (opts not currently supported as no use cases yet)
475
- if (sourcePhaseEnabled)
476
+ if (shimMode || sourcePhaseEnabled)
476
477
  importShim.source = async function importShimSource(specifier, opts, parentUrl) {
477
478
  if (typeof opts === 'string') {
478
479
  parentUrl = opts;
@@ -545,7 +546,12 @@
545
546
  (!multipleImportMaps || supportsMultipleImportMaps) &&
546
547
  !importMapSrc &&
547
548
  !typescriptEnabled;
548
- if (sourcePhaseEnabled && typeof WebAssembly !== 'undefined' && !Object.getPrototypeOf(WebAssembly.Module).name) {
549
+ if (
550
+ !shimMode &&
551
+ sourcePhaseEnabled &&
552
+ typeof WebAssembly !== 'undefined' &&
553
+ !Object.getPrototypeOf(WebAssembly.Module).name
554
+ ) {
549
555
  const s = Symbol();
550
556
  const brand = m =>
551
557
  Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
@@ -928,7 +934,10 @@
928
934
  )});export default s;`,
929
935
  t: 'css'
930
936
  };
931
- } else if ((typescriptEnabled && tsContentType.test(contentType)) || url.endsWith('.ts') || url.endsWith('.mts')) {
937
+ } else if (
938
+ (shimMode || typescriptEnabled) &&
939
+ (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
940
+ ) {
932
941
  const source = await res.text();
933
942
  // if we don't have a ts transform hook, try to load it
934
943
  if (!esmsTsTransform) {
@@ -1023,12 +1032,16 @@
1023
1032
  load.L = load.f.then(async () => {
1024
1033
  let childFetchOpts = fetchOpts;
1025
1034
  load.d = load.a[0]
1026
- .map(({ n, d, t }) => {
1035
+ .map(({ n, d, t, a }) => {
1027
1036
  const sourcePhase = t >= 4;
1028
1037
  if (sourcePhase) {
1029
- if (!sourcePhaseEnabled) throw featErr('source-phase');
1038
+ if (!shimMode && !sourcePhaseEnabled) throw featErr('source-phase');
1030
1039
  if (!supportsSourcePhase) load.n = true;
1031
1040
  }
1041
+ if (a > 0) {
1042
+ if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
1043
+ if (!supportsCssType && !supportsJsonType) load.n = true;
1044
+ }
1032
1045
  if (d !== -1 || !n) return;
1033
1046
  const resolved = resolve(n, load.r || load.u);
1034
1047
  if (resolved.n) load.n = true;
@@ -1137,7 +1150,7 @@
1137
1150
  if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
1138
1151
  if (!legacyAcceptingImportMaps && !multipleImportMaps) {
1139
1152
  multipleImportMaps = true;
1140
- if (baselinePassthrough && !supportsMultipleImportMaps) {
1153
+ if (!shimMode && baselinePassthrough && !supportsMultipleImportMaps) {
1141
1154
  console.info(`es-module-shims: disabling baseline passthrough due to multiple import maps`);
1142
1155
  baselinePassthrough = false;
1143
1156
  if (hasDocument) attachMutationObserver();
@@ -1,96 +1,96 @@
1
- /* ES Module Shims 2.0.4 */
1
+ /* ES Module Shims 2.0.6 */
2
2
  (function () {
3
3
 
4
- const hasDocument = typeof document !== 'undefined';
5
-
6
- const noop = () => {};
7
-
8
- const dynamicImport = (u, errUrl) => import(u);
9
-
10
- const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
-
12
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
- Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
-
15
- // shim mode is determined on initialization, no late shim mode
16
- const shimMode =
17
- hasDocument ?
18
- esmsInitOptions.shimMode ||
19
- document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
- .length > 0
21
- : true;
22
-
23
- const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
- const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
- let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
- const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
- const tsTransform =
28
- esmsInitOptions.tsTransform ||
29
- (document.currentScript &&
30
- document.currentScript.src.replace('.js', '-typescript.js')) ||
31
- './es-module-shims-typescript.js';
32
-
33
- const mapOverrides = esmsInitOptions.mapOverrides;
34
-
35
- let nonce = esmsInitOptions.nonce;
36
- if (!nonce && hasDocument) {
37
- const nonceElement = document.querySelector('script[nonce]');
38
- if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
39
- }
40
-
41
- const onerror = globalHook(esmsInitOptions.onerror || noop);
42
-
43
- const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
44
-
45
- function globalHook(name) {
46
- return typeof name === 'string' ? self[name] : name;
47
- }
48
-
49
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
50
- const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
51
- const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
52
- const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
53
- const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
54
- const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
55
- const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
56
- const typescriptEnabled = enable.includes('typescript') || enableAll;
57
-
58
- const onpolyfill =
59
- esmsInitOptions.onpolyfill ?
60
- globalHook(esmsInitOptions.onpolyfill)
61
- : () => {
62
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
- };
64
-
65
- const baseUrl =
66
- hasDocument ?
67
- document.baseURI
68
- : `${location.protocol}//${location.host}${
69
- location.pathname.includes('/') ?
70
- location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
- : location.pathname
72
- }`;
73
-
74
- const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
- let { skip } = esmsInitOptions;
76
- if (Array.isArray(skip)) {
77
- const l = skip.map(s => new URL(s, baseUrl).href);
78
- skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
- } else if (typeof skip === 'string') {
80
- const r = new RegExp(skip);
81
- skip = s => r.test(s);
82
- } else if (skip instanceof RegExp) {
83
- skip = s => skip.test(s);
84
- }
85
-
86
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
-
88
- const throwError = err => {
89
- (self.reportError || dispatchError)(err), void onerror(err);
90
- };
91
-
92
- function fromParent(parent) {
93
- return parent ? ` imported from ${parent}` : '';
4
+ const hasDocument = typeof document !== 'undefined';
5
+
6
+ const noop = () => {};
7
+
8
+ const dynamicImport = (u, errUrl) => import(u);
9
+
10
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
+
12
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
+ Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
+
15
+ // shim mode is determined on initialization, no late shim mode
16
+ const shimMode =
17
+ hasDocument ?
18
+ esmsInitOptions.shimMode ||
19
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
+ .length > 0
21
+ : true;
22
+
23
+ const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
+ let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
+ const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
+ const tsTransform =
28
+ esmsInitOptions.tsTransform ||
29
+ (document.currentScript &&
30
+ document.currentScript.src.replace(/\.js$/, '-typescript.js')) ||
31
+ './es-module-shims-typescript.js';
32
+
33
+ const mapOverrides = esmsInitOptions.mapOverrides;
34
+
35
+ let nonce = esmsInitOptions.nonce;
36
+ if (!nonce && hasDocument) {
37
+ const nonceElement = document.querySelector('script[nonce]');
38
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
39
+ }
40
+
41
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
42
+
43
+ const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
44
+
45
+ function globalHook(name) {
46
+ return typeof name === 'string' ? self[name] : name;
47
+ }
48
+
49
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
50
+ const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
51
+ const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
52
+ const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
53
+ const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
54
+ const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
55
+ const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
56
+ const typescriptEnabled = enable.includes('typescript') || enableAll;
57
+
58
+ const onpolyfill =
59
+ esmsInitOptions.onpolyfill ?
60
+ globalHook(esmsInitOptions.onpolyfill)
61
+ : () => {
62
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
+ };
64
+
65
+ const baseUrl =
66
+ hasDocument ?
67
+ document.baseURI
68
+ : `${location.protocol}//${location.host}${
69
+ location.pathname.includes('/') ?
70
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
+ : location.pathname
72
+ }`;
73
+
74
+ const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
+ let { skip } = esmsInitOptions;
76
+ if (Array.isArray(skip)) {
77
+ const l = skip.map(s => new URL(s, baseUrl).href);
78
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
+ } else if (typeof skip === 'string') {
80
+ const r = new RegExp(skip);
81
+ skip = s => r.test(s);
82
+ } else if (skip instanceof RegExp) {
83
+ skip = s => skip.test(s);
84
+ }
85
+
86
+ const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
+
88
+ const throwError = err => {
89
+ (self.reportError || dispatchError)(err), void onerror(err);
90
+ };
91
+
92
+ function fromParent(parent) {
93
+ return parent ? ` imported from ${parent}` : '';
94
94
  }
95
95
 
96
96
  const backslashRegEx = /\\/g;
@@ -453,17 +453,18 @@
453
453
  }
454
454
  // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
455
455
  // because we can't syntactically pass through to dynamic import with a second argument in this libarary
456
- const url = await importHandler(id, opts, parentUrl);
457
- const source =
458
- typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string' ?
459
- `export{default}from'${url}'with{type:"${opts.with.type}"}`
460
- : null;
456
+ let url = await importHandler(id, opts, parentUrl);
457
+ let source = null;
458
+ if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
459
+ source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
460
+ url += '?entry';
461
+ }
461
462
  return topLevelLoad(url, { credentials: 'same-origin' }, source);
462
463
  }
463
464
 
464
465
  // import.source()
465
466
  // (opts not currently supported as no use cases yet)
466
- if (sourcePhaseEnabled)
467
+ if (shimMode || sourcePhaseEnabled)
467
468
  importShim.source = async function importShimSource(specifier, opts, parentUrl) {
468
469
  if (typeof opts === 'string') {
469
470
  parentUrl = opts;
@@ -536,7 +537,12 @@
536
537
  (!multipleImportMaps || supportsMultipleImportMaps) &&
537
538
  !importMapSrc &&
538
539
  !typescriptEnabled;
539
- if (sourcePhaseEnabled && typeof WebAssembly !== 'undefined' && !Object.getPrototypeOf(WebAssembly.Module).name) {
540
+ if (
541
+ !shimMode &&
542
+ sourcePhaseEnabled &&
543
+ typeof WebAssembly !== 'undefined' &&
544
+ !Object.getPrototypeOf(WebAssembly.Module).name
545
+ ) {
540
546
  const s = Symbol();
541
547
  const brand = m =>
542
548
  Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
@@ -913,7 +919,10 @@
913
919
  )});export default s;`,
914
920
  t: 'css'
915
921
  };
916
- } else if ((typescriptEnabled && tsContentType.test(contentType)) || url.endsWith('.ts') || url.endsWith('.mts')) {
922
+ } else if (
923
+ (shimMode || typescriptEnabled) &&
924
+ (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
925
+ ) {
917
926
  const source = await res.text();
918
927
  // if we don't have a ts transform hook, try to load it
919
928
  if (!esmsTsTransform) {
@@ -1008,12 +1017,16 @@
1008
1017
  load.L = load.f.then(async () => {
1009
1018
  let childFetchOpts = fetchOpts;
1010
1019
  load.d = load.a[0]
1011
- .map(({ n, d, t }) => {
1020
+ .map(({ n, d, t, a }) => {
1012
1021
  const sourcePhase = t >= 4;
1013
1022
  if (sourcePhase) {
1014
- if (!sourcePhaseEnabled) throw featErr('source-phase');
1023
+ if (!shimMode && !sourcePhaseEnabled) throw featErr('source-phase');
1015
1024
  if (!supportsSourcePhase) load.n = true;
1016
1025
  }
1026
+ if (a > 0) {
1027
+ if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
1028
+ if (!supportsCssType && !supportsJsonType) load.n = true;
1029
+ }
1017
1030
  if (d !== -1 || !n) return;
1018
1031
  const resolved = resolve(n, load.r || load.u);
1019
1032
  if (resolved.n) load.n = true;
@@ -1118,7 +1131,7 @@
1118
1131
  if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
1119
1132
  if (!legacyAcceptingImportMaps && !multipleImportMaps) {
1120
1133
  multipleImportMaps = true;
1121
- if (baselinePassthrough && !supportsMultipleImportMaps) {
1134
+ if (!shimMode && baselinePassthrough && !supportsMultipleImportMaps) {
1122
1135
  baselinePassthrough = false;
1123
1136
  if (hasDocument) attachMutationObserver();
1124
1137
  }
@@ -1,96 +1,96 @@
1
- /* ES Module Shims Wasm 2.0.4 */
1
+ /* ES Module Shims Wasm 2.0.6 */
2
2
  (function () {
3
3
 
4
- const hasDocument = typeof document !== 'undefined';
5
-
6
- const noop = () => {};
7
-
8
- const dynamicImport = (u, errUrl) => import(u);
9
-
10
- const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
-
12
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
- Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
-
15
- // shim mode is determined on initialization, no late shim mode
16
- const shimMode =
17
- hasDocument ?
18
- esmsInitOptions.shimMode ||
19
- document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
- .length > 0
21
- : true;
22
-
23
- const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
- const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
- let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
- const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
- const tsTransform =
28
- esmsInitOptions.tsTransform ||
29
- (document.currentScript &&
30
- document.currentScript.src.replace('.js', '-typescript.js')) ||
31
- './es-module-shims-typescript.js';
32
-
33
- const mapOverrides = esmsInitOptions.mapOverrides;
34
-
35
- let nonce = esmsInitOptions.nonce;
36
- if (!nonce && hasDocument) {
37
- const nonceElement = document.querySelector('script[nonce]');
38
- if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
39
- }
40
-
41
- const onerror = globalHook(esmsInitOptions.onerror || noop);
42
-
43
- const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
44
-
45
- function globalHook(name) {
46
- return typeof name === 'string' ? self[name] : name;
47
- }
48
-
49
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
50
- const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
51
- const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
52
- const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
53
- const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
54
- const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
55
- const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
56
- const typescriptEnabled = enable.includes('typescript') || enableAll;
57
-
58
- const onpolyfill =
59
- esmsInitOptions.onpolyfill ?
60
- globalHook(esmsInitOptions.onpolyfill)
61
- : () => {
62
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
- };
64
-
65
- const baseUrl =
66
- hasDocument ?
67
- document.baseURI
68
- : `${location.protocol}//${location.host}${
69
- location.pathname.includes('/') ?
70
- location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
- : location.pathname
72
- }`;
73
-
74
- const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
- let { skip } = esmsInitOptions;
76
- if (Array.isArray(skip)) {
77
- const l = skip.map(s => new URL(s, baseUrl).href);
78
- skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
- } else if (typeof skip === 'string') {
80
- const r = new RegExp(skip);
81
- skip = s => r.test(s);
82
- } else if (skip instanceof RegExp) {
83
- skip = s => skip.test(s);
84
- }
85
-
86
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
-
88
- const throwError = err => {
89
- (self.reportError || dispatchError)(err), void onerror(err);
90
- };
91
-
92
- function fromParent(parent) {
93
- return parent ? ` imported from ${parent}` : '';
4
+ const hasDocument = typeof document !== 'undefined';
5
+
6
+ const noop = () => {};
7
+
8
+ const dynamicImport = (u, errUrl) => import(u);
9
+
10
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
+
12
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
+ Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
+
15
+ // shim mode is determined on initialization, no late shim mode
16
+ const shimMode =
17
+ hasDocument ?
18
+ esmsInitOptions.shimMode ||
19
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
+ .length > 0
21
+ : true;
22
+
23
+ const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
+ let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
+ const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
+ const tsTransform =
28
+ esmsInitOptions.tsTransform ||
29
+ (document.currentScript &&
30
+ document.currentScript.src.replace(/\.js$/, '-typescript.js')) ||
31
+ './es-module-shims-typescript.js';
32
+
33
+ const mapOverrides = esmsInitOptions.mapOverrides;
34
+
35
+ let nonce = esmsInitOptions.nonce;
36
+ if (!nonce && hasDocument) {
37
+ const nonceElement = document.querySelector('script[nonce]');
38
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
39
+ }
40
+
41
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
42
+
43
+ const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
44
+
45
+ function globalHook(name) {
46
+ return typeof name === 'string' ? self[name] : name;
47
+ }
48
+
49
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
50
+ const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
51
+ const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
52
+ const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
53
+ const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
54
+ const wasmModulesEnabled = enable.includes('wasm-modules') || enableAll;
55
+ const sourcePhaseEnabled = enable.includes('source-phase') || enableAll;
56
+ const typescriptEnabled = enable.includes('typescript') || enableAll;
57
+
58
+ const onpolyfill =
59
+ esmsInitOptions.onpolyfill ?
60
+ globalHook(esmsInitOptions.onpolyfill)
61
+ : () => {
62
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
+ };
64
+
65
+ const baseUrl =
66
+ hasDocument ?
67
+ document.baseURI
68
+ : `${location.protocol}//${location.host}${
69
+ location.pathname.includes('/') ?
70
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
+ : location.pathname
72
+ }`;
73
+
74
+ const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
+ let { skip } = esmsInitOptions;
76
+ if (Array.isArray(skip)) {
77
+ const l = skip.map(s => new URL(s, baseUrl).href);
78
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
+ } else if (typeof skip === 'string') {
80
+ const r = new RegExp(skip);
81
+ skip = s => r.test(s);
82
+ } else if (skip instanceof RegExp) {
83
+ skip = s => skip.test(s);
84
+ }
85
+
86
+ const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
+
88
+ const throwError = err => {
89
+ (self.reportError || dispatchError)(err), void onerror(err);
90
+ };
91
+
92
+ function fromParent(parent) {
93
+ return parent ? ` imported from ${parent}` : '';
94
94
  }
95
95
 
96
96
  const backslashRegEx = /\\/g;
@@ -453,17 +453,18 @@
453
453
  }
454
454
  // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
455
455
  // because we can't syntactically pass through to dynamic import with a second argument in this libarary
456
- const url = await importHandler(id, opts, parentUrl);
457
- const source =
458
- typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string' ?
459
- `export{default}from'${url}'with{type:"${opts.with.type}"}`
460
- : null;
456
+ let url = await importHandler(id, opts, parentUrl);
457
+ let source = null;
458
+ if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
459
+ source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
460
+ url += '?entry';
461
+ }
461
462
  return topLevelLoad(url, { credentials: 'same-origin' }, source);
462
463
  }
463
464
 
464
465
  // import.source()
465
466
  // (opts not currently supported as no use cases yet)
466
- if (sourcePhaseEnabled)
467
+ if (shimMode || sourcePhaseEnabled)
467
468
  importShim.source = async function importShimSource(specifier, opts, parentUrl) {
468
469
  if (typeof opts === 'string') {
469
470
  parentUrl = opts;
@@ -536,7 +537,12 @@
536
537
  (!multipleImportMaps || supportsMultipleImportMaps) &&
537
538
  !importMapSrc &&
538
539
  !typescriptEnabled;
539
- if (sourcePhaseEnabled && typeof WebAssembly !== 'undefined' && !Object.getPrototypeOf(WebAssembly.Module).name) {
540
+ if (
541
+ !shimMode &&
542
+ sourcePhaseEnabled &&
543
+ typeof WebAssembly !== 'undefined' &&
544
+ !Object.getPrototypeOf(WebAssembly.Module).name
545
+ ) {
540
546
  const s = Symbol();
541
547
  const brand = m =>
542
548
  Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
@@ -913,7 +919,10 @@
913
919
  )});export default s;`,
914
920
  t: 'css'
915
921
  };
916
- } else if ((typescriptEnabled && tsContentType.test(contentType)) || url.endsWith('.ts') || url.endsWith('.mts')) {
922
+ } else if (
923
+ (shimMode || typescriptEnabled) &&
924
+ (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
925
+ ) {
917
926
  const source = await res.text();
918
927
  // if we don't have a ts transform hook, try to load it
919
928
  if (!esmsTsTransform) {
@@ -1008,12 +1017,16 @@
1008
1017
  load.L = load.f.then(async () => {
1009
1018
  let childFetchOpts = fetchOpts;
1010
1019
  load.d = load.a[0]
1011
- .map(({ n, d, t }) => {
1020
+ .map(({ n, d, t, a }) => {
1012
1021
  const sourcePhase = t >= 4;
1013
1022
  if (sourcePhase) {
1014
- if (!sourcePhaseEnabled) throw featErr('source-phase');
1023
+ if (!shimMode && !sourcePhaseEnabled) throw featErr('source-phase');
1015
1024
  if (!supportsSourcePhase) load.n = true;
1016
1025
  }
1026
+ if (a > 0) {
1027
+ if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
1028
+ if (!supportsCssType && !supportsJsonType) load.n = true;
1029
+ }
1017
1030
  if (d !== -1 || !n) return;
1018
1031
  const resolved = resolve(n, load.r || load.u);
1019
1032
  if (resolved.n) load.n = true;
@@ -1118,7 +1131,7 @@
1118
1131
  if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
1119
1132
  if (!legacyAcceptingImportMaps && !multipleImportMaps) {
1120
1133
  multipleImportMaps = true;
1121
- if (baselinePassthrough && !supportsMultipleImportMaps) {
1134
+ if (!shimMode && baselinePassthrough && !supportsMultipleImportMaps) {
1122
1135
  baselinePassthrough = false;
1123
1136
  if (hasDocument) attachMutationObserver();
1124
1137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {