es-module-shims 2.0.6 → 2.0.8

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.
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 2.0.6 */
1
+ /* ES Module Shims 2.0.8 */
2
2
  (function () {
3
3
 
4
4
  const hasDocument = typeof document !== 'undefined';
@@ -468,7 +468,7 @@
468
468
  source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
469
469
  url += '?entry';
470
470
  }
471
- return topLevelLoad(url, { credentials: 'same-origin' }, source);
471
+ return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
472
472
  }
473
473
 
474
474
  // import.source()
@@ -894,6 +894,10 @@
894
894
  }
895
895
 
896
896
  let esmsTsTransform;
897
+ async function initTs() {
898
+ const m = await import(tsTransform);
899
+ if (!esmsTsTransform) esmsTsTransform = m.transform;
900
+ }
897
901
 
898
902
  async function fetchModule(url, fetchOpts, parent) {
899
903
  const mapIntegrity = composedImportMap.integrity[url];
@@ -939,12 +943,9 @@
939
943
  (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
940
944
  ) {
941
945
  const source = await res.text();
942
- // if we don't have a ts transform hook, try to load it
943
- if (!esmsTsTransform) {
944
- ({ transform: esmsTsTransform } = await import(tsTransform));
945
- }
946
+ if (!esmsTsTransform) await initTs();
946
947
  const transformed = esmsTsTransform(source, url);
947
- return { r, s: transformed || source, t: transformed ? 'ts' : 'js' };
948
+ return { r, s: transformed === undefined ? source : transformed, t: transformed !== undefined ? 'ts' : 'js' };
948
949
  } else
949
950
  throw Error(
950
951
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
@@ -1161,6 +1162,21 @@
1161
1162
 
1162
1163
  function processScript(script, ready = readyStateCompleteCnt > 0) {
1163
1164
  if (epCheck(script, ready)) return;
1165
+ if (script.lang === 'ts' && !script.src) {
1166
+ const source = script.innerHTML;
1167
+ return initTs()
1168
+ .then(() => {
1169
+ const transformed = esmsTsTransform(source, baseUrl);
1170
+ return topLevelLoad(
1171
+ baseUrl,
1172
+ getFetchOpts(script),
1173
+ transformed === undefined ? source : transformed,
1174
+ transformed === undefined,
1175
+ undefined
1176
+ );
1177
+ })
1178
+ .catch(throwError);
1179
+ }
1164
1180
  console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
1165
1181
  // does this load block readystate complete
1166
1182
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 2.0.6 */
1
+ /* ES Module Shims 2.0.8 */
2
2
  (function () {
3
3
 
4
4
  const hasDocument = typeof document !== 'undefined';
@@ -459,7 +459,7 @@
459
459
  source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
460
460
  url += '?entry';
461
461
  }
462
- return topLevelLoad(url, { credentials: 'same-origin' }, source);
462
+ return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
463
463
  }
464
464
 
465
465
  // import.source()
@@ -879,6 +879,10 @@
879
879
  }
880
880
 
881
881
  let esmsTsTransform;
882
+ async function initTs() {
883
+ const m = await import(tsTransform);
884
+ if (!esmsTsTransform) esmsTsTransform = m.transform;
885
+ }
882
886
 
883
887
  async function fetchModule(url, fetchOpts, parent) {
884
888
  const mapIntegrity = composedImportMap.integrity[url];
@@ -924,12 +928,9 @@
924
928
  (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
925
929
  ) {
926
930
  const source = await res.text();
927
- // if we don't have a ts transform hook, try to load it
928
- if (!esmsTsTransform) {
929
- ({ transform: esmsTsTransform } = await import(tsTransform));
930
- }
931
+ if (!esmsTsTransform) await initTs();
931
932
  const transformed = esmsTsTransform(source, url);
932
- return { r, s: transformed || source, t: transformed ? 'ts' : 'js' };
933
+ return { r, s: transformed === undefined ? source : transformed, t: transformed !== undefined ? 'ts' : 'js' };
933
934
  } else
934
935
  throw Error(
935
936
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
@@ -1141,6 +1142,21 @@
1141
1142
 
1142
1143
  function processScript(script, ready = readyStateCompleteCnt > 0) {
1143
1144
  if (epCheck(script, ready)) return;
1145
+ if (script.lang === 'ts' && !script.src) {
1146
+ const source = script.innerHTML;
1147
+ return initTs()
1148
+ .then(() => {
1149
+ const transformed = esmsTsTransform(source, baseUrl);
1150
+ return topLevelLoad(
1151
+ baseUrl,
1152
+ getFetchOpts(script),
1153
+ transformed === undefined ? source : transformed,
1154
+ transformed === undefined,
1155
+ undefined
1156
+ );
1157
+ })
1158
+ .catch(throwError);
1159
+ }
1144
1160
  // does this load block readystate complete
1145
1161
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
1146
1162
  // does this load block DOMContentLoaded
@@ -1,4 +1,4 @@
1
- /* ES Module Shims Wasm 2.0.6 */
1
+ /* ES Module Shims Wasm 2.0.8 */
2
2
  (function () {
3
3
 
4
4
  const hasDocument = typeof document !== 'undefined';
@@ -459,7 +459,7 @@
459
459
  source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
460
460
  url += '?entry';
461
461
  }
462
- return topLevelLoad(url, { credentials: 'same-origin' }, source);
462
+ return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
463
463
  }
464
464
 
465
465
  // import.source()
@@ -879,6 +879,10 @@
879
879
  }
880
880
 
881
881
  let esmsTsTransform;
882
+ async function initTs() {
883
+ const m = await import(tsTransform);
884
+ if (!esmsTsTransform) esmsTsTransform = m.transform;
885
+ }
882
886
 
883
887
  async function fetchModule(url, fetchOpts, parent) {
884
888
  const mapIntegrity = composedImportMap.integrity[url];
@@ -924,12 +928,9 @@
924
928
  (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
925
929
  ) {
926
930
  const source = await res.text();
927
- // if we don't have a ts transform hook, try to load it
928
- if (!esmsTsTransform) {
929
- ({ transform: esmsTsTransform } = await import(tsTransform));
930
- }
931
+ if (!esmsTsTransform) await initTs();
931
932
  const transformed = esmsTsTransform(source, url);
932
- return { r, s: transformed || source, t: transformed ? 'ts' : 'js' };
933
+ return { r, s: transformed === undefined ? source : transformed, t: transformed !== undefined ? 'ts' : 'js' };
933
934
  } else
934
935
  throw Error(
935
936
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
@@ -1141,6 +1142,21 @@
1141
1142
 
1142
1143
  function processScript(script, ready = readyStateCompleteCnt > 0) {
1143
1144
  if (epCheck(script, ready)) return;
1145
+ if (script.lang === 'ts' && !script.src) {
1146
+ const source = script.innerHTML;
1147
+ return initTs()
1148
+ .then(() => {
1149
+ const transformed = esmsTsTransform(source, baseUrl);
1150
+ return topLevelLoad(
1151
+ baseUrl,
1152
+ getFetchOpts(script),
1153
+ transformed === undefined ? source : transformed,
1154
+ transformed === undefined,
1155
+ undefined
1156
+ );
1157
+ })
1158
+ .catch(throwError);
1159
+ }
1144
1160
  // does this load block readystate complete
1145
1161
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
1146
1162
  // does this load block DOMContentLoaded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {
@@ -31,7 +31,7 @@
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
33
  "@rollup/plugin-replace": "^2.4.2",
34
- "amaro": "^0.1.8",
34
+ "amaro": "^0.3.0",
35
35
  "es-module-lexer": "1.6.0",
36
36
  "kleur": "^4.1.4",
37
37
  "mime-types": "^2.1.33",