ts-swc-transform 1.13.13 → 1.15.0

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.
Files changed (34) hide show
  1. package/assets/import-meta-resolve.cjs +1481 -0
  2. package/dist/cjs/createMatcher.cjs +1 -0
  3. package/dist/cjs/createMatcher.cjs.map +1 -1
  4. package/dist/cjs/lib/patchCJS.cjs +13 -6
  5. package/dist/cjs/lib/patchCJS.cjs.map +1 -1
  6. package/dist/cjs/lib/swcPrepareOptions.cjs +2 -2
  7. package/dist/cjs/lib/swcPrepareOptions.cjs.map +1 -1
  8. package/dist/cjs/lib/url-file-url.cjs +78 -0
  9. package/dist/cjs/lib/url-file-url.cjs.map +1 -0
  10. package/dist/cjs/toPath.cjs +63 -34
  11. package/dist/cjs/toPath.cjs.map +1 -1
  12. package/dist/esm/createMatcher.mjs +1 -0
  13. package/dist/esm/createMatcher.mjs.map +1 -1
  14. package/dist/esm/lib/patchCJS.mjs +2 -2
  15. package/dist/esm/lib/patchCJS.mjs.map +1 -1
  16. package/dist/esm/lib/swcPrepareOptions.mjs +2 -2
  17. package/dist/esm/lib/swcPrepareOptions.mjs.map +1 -1
  18. package/dist/esm/lib/url-file-url.mjs +54 -0
  19. package/dist/esm/lib/url-file-url.mjs.map +1 -0
  20. package/dist/esm/toPath.mjs +24 -35
  21. package/dist/esm/toPath.mjs.map +1 -1
  22. package/dist/types/lib/patchCJS.d.ts +1 -0
  23. package/dist/types/lib/url-file-url.d.ts +3 -0
  24. package/package.json +8 -9
  25. package/dist/cjs/lib/ensureBindingsSync.cjs +0 -43
  26. package/dist/cjs/lib/ensureBindingsSync.cjs.map +0 -1
  27. package/dist/cjs/lib/fileURLToPath.cjs +0 -23
  28. package/dist/cjs/lib/fileURLToPath.cjs.map +0 -1
  29. package/dist/esm/lib/ensureBindingsSync.mjs +0 -25
  30. package/dist/esm/lib/ensureBindingsSync.mjs.map +0 -1
  31. package/dist/esm/lib/fileURLToPath.mjs +0 -7
  32. package/dist/esm/lib/fileURLToPath.mjs.map +0 -1
  33. package/dist/types/lib/ensureBindingsSync.d.ts +0 -1
  34. package/dist/types/lib/fileURLToPath.d.ts +0 -2
@@ -26,6 +26,7 @@ function createMatcher(tsConfig) {
26
26
  var pattern = (0, _unixify.default)(condition);
27
27
  if (!_pathposix.default.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = _pathposix.default.join(tsconfigPath, pattern);
28
28
  return function match(filePath) {
29
+ // @ts-ignore
29
30
  return filePath.startsWith(pattern) || (0, _minimatch.default)(filePath, pattern);
30
31
  };
31
32
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsConfig","tsconfig","loadTsConfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAOA;;;eAAwBA;;;gEANF;gEACL;8DACG;mEACK;;;;;;AAGV,SAASA,cAAcC,QAAwB;IAC5D,IAAMC,WAAWC,IAAAA,qBAAY,EAAC;QAAED,UAAUD;IAAS,GAAG;IACtD,IAAMG,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACL,SAASG,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACf,CAAAA,SAASgB,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACrD,IAAMa,WAAW,AAACnB,CAAAA,SAASgB,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAErD,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n // @ts-ignore\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsConfig","tsconfig","loadTsConfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAOA;;;eAAwBA;;;gEANF;gEACL;8DACG;mEACK;;;;;;AAGV,SAASA,cAAcC,QAAwB;IAC5D,IAAMC,WAAWC,IAAAA,qBAAY,EAAC;QAAED,UAAUD;IAAS,GAAG;IACtD,IAAMG,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACL,SAASG,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,aAAa;YACb,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACf,CAAAA,SAASgB,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACrD,IAAMa,WAAW,AAACnB,CAAAA,SAASgB,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAErD,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
@@ -2,10 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ default: function() {
8
13
  return patchCJS;
14
+ },
15
+ interop: function() {
16
+ return interop;
9
17
  }
10
18
  });
11
19
  var _constants = require("../constants.cjs");
@@ -15,13 +23,12 @@ function _interop_require_default(obj) {
15
23
  default: obj
16
24
  };
17
25
  }
18
- // https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
19
- var interopClientDefaultExport = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
26
+ var interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
20
27
  var DEFAULT_EXTENSION = '.cjs';
21
28
  function patchCJS(entry, output, options) {
22
29
  var cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
23
30
  output.code = (0, _makeReplacements.default)(entry, output.code, _constants.requireRegEx, _constants.extensions, cjsExtension, options);
24
- output.code += interopClientDefaultExport;
31
+ output.code += interop;
25
32
  return cjsExtension;
26
33
  }
27
34
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interopClientDefaultExport;\n\n return cjsExtension;\n}\n"],"names":["patchCJS","interopClientDefaultExport","DEFAULT_EXTENSION","entry","output","options","cjsExtension","extensions","cjs","code","makeReplacements","requireRegEx"],"mappings":";;;;+BAQA;;;eAAwBA;;;yBARiB;uEACZ;;;;;;AAE7B,0HAA0H;AAC1H,IAAMC,6BAA6B;AAEnC,IAAMC,oBAAoB;AAEX,SAASF,SAASG,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,IAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACC,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FE,OAAOK,IAAI,GAAGC,IAAAA,yBAAgB,EAACP,OAAOC,OAAOK,IAAI,EAAEE,uBAAY,EAAEJ,qBAAU,EAAED,cAAcD;IAC3FD,OAAOK,IAAI,IAAIR;IAEf,OAAOK;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interop;\n\n return cjsExtension;\n}\n"],"names":["patchCJS","interop","DEFAULT_EXTENSION","entry","output","options","cjsExtension","extensions","cjs","code","makeReplacements","requireRegEx"],"mappings":";;;;;;;;;;;IAQA,OAOC;eAPuBA;;IAJXC,OAAO;eAAPA;;;yBAJ4B;uEACZ;;;;;;AAGtB,IAAMA,UAAU;AAEvB,IAAMC,oBAAoB;AAEX,SAASF,SAASG,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,IAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACC,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FE,OAAOK,IAAI,GAAGC,IAAAA,yBAAgB,EAACP,OAAOC,OAAOK,IAAI,EAAEE,uBAAY,EAAEJ,qBAAU,EAAED,cAAcD;IAC3FD,OAAOK,IAAI,IAAIR;IAEf,OAAOK;AACT"}
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
12
- var _ensureBindingsSync = /*#__PURE__*/ _interop_require_default(require("./ensureBindingsSync.cjs"));
12
+ var _installoptional = require("install-optional");
13
13
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
14
14
  function _interop_require_default(obj) {
15
15
  return obj && obj.__esModule ? obj : {
@@ -18,7 +18,7 @@ function _interop_require_default(obj) {
18
18
  }
19
19
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
20
20
  function swcPrepareOptions(tsconfig) {
21
- (0, _ensureBindingsSync.default)('@swc/core', "".concat(process.platform, "-").concat(process.arch));
21
+ (0, _installoptional.installSync)('@swc/core', "".concat(process.platform, "-").concat(process.arch));
22
22
  try {
23
23
  var ts = _require('typescript');
24
24
  var swc = _require('@swc/core');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport ensureBindingsSync from './ensureBindingsSync';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n ensureBindingsSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","tsconfig","ensureBindingsSync","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAOA;;;eAAwBA;;;2DAPP;yEACc;6DAEZ;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,kBAAkBK,QAAwB;IAChEC,IAAAA,2BAAkB,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;IACnE,IAAI;QACF,IAAMC,KAAKT,SAAS;QACpB,IAAMU,MAAMV,SAAS;QACrB,IAAMW,aAAaX,SAAS;QAC5B,IAAMY,SAASH,GAAGI,0BAA0B,CAACT,SAASU,MAAM,EAAEL,GAAGM,GAAG,EAAEC,aAAI,CAACC,OAAO,CAACb,SAASY,IAAI;QAChG,OAAOL,WAAWO,gBAAgB,CAACN,OAAOO,OAAO,EAAEC,WAAWV,KAAK;IACrE,EAAE,OAAOW,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { installSync } from 'install-optional';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","tsconfig","installSync","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAOA;;;eAAwBA;;;2DAPP;+BACW;6DAET;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,kBAAkBK,QAAwB;IAChEC,IAAAA,4BAAW,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;IAC5D,IAAI;QACF,IAAMC,KAAKT,SAAS;QACpB,IAAMU,MAAMV,SAAS;QACrB,IAAMW,aAAaX,SAAS;QAC5B,IAAMY,SAASH,GAAGI,0BAA0B,CAACT,SAASU,MAAM,EAAEL,GAAGM,GAAG,EAAEC,aAAI,CAACC,OAAO,CAACb,SAASY,IAAI;QAChG,OAAOL,WAAWO,gBAAgB,CAACN,OAAOO,OAAO,EAAEC,WAAWV,KAAK;IACrE,EAAE,OAAOW,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
@@ -0,0 +1,78 @@
1
+ // Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js
2
+ // Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE
3
+ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ function _export(target, all) {
8
+ for(var name in all)Object.defineProperty(target, name, {
9
+ enumerable: true,
10
+ get: all[name]
11
+ });
12
+ }
13
+ _export(exports, {
14
+ fileURLToPath: function() {
15
+ return fileURLToPath;
16
+ },
17
+ pathToFileURL: function() {
18
+ return pathToFileURL;
19
+ }
20
+ });
21
+ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
22
+ var _replaceall = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/string/replace-all.js"));
23
+ var _index = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/url/index.js"));
24
+ function _interop_require_default(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
30
+ function fileURLToPath(url) {
31
+ if (typeof url === 'string') {
32
+ url = new _index.default(url);
33
+ }
34
+ if (url.protocol !== 'file:') {
35
+ throw new Error('The URL must use the file: protocol');
36
+ }
37
+ if (isWindows) {
38
+ if (/%2f|%5c/i.test(url.pathname)) {
39
+ throw new Error('The file: URL path must not include encoded \\ or / characters');
40
+ }
41
+ } else {
42
+ if (url.hostname) {
43
+ throw new Error("The file: URL host must be 'localhost' or empty");
44
+ }
45
+ if (/%2f/i.test(url.pathname)) {
46
+ throw new Error('The file: URL path must not include encoded / characters');
47
+ }
48
+ }
49
+ var pathname = _path.default.normalize(decodeURIComponent(url.pathname));
50
+ if (isWindows) {
51
+ if (url.hostname) return "\\\\".concat(url.hostname).concat(pathname);
52
+ var letter = pathname.charCodeAt(1) | 0x20;
53
+ if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */ ) {
54
+ throw new Error('The file: URL path must be absolute');
55
+ }
56
+ return pathname.slice(1);
57
+ }
58
+ return pathname;
59
+ }
60
+ function pathToFileURL(pathname) {
61
+ var resolved = _path.default.resolve(pathname);
62
+ if (pathname[pathname.length - 1] === '/') {
63
+ resolved += '/';
64
+ } else if (isWindows && pathname[pathname.length - 1] === '\\') {
65
+ resolved += '\\';
66
+ }
67
+ resolved = (0, _replaceall.default)(resolved, '%', '%25'); // Must be first
68
+ resolved = (0, _replaceall.default)(resolved, '#', '%23');
69
+ resolved = (0, _replaceall.default)(resolved, '?', '%3f');
70
+ resolved = (0, _replaceall.default)(resolved, '\n', '%0a');
71
+ resolved = (0, _replaceall.default)(resolved, '\r', '%0d');
72
+ resolved = (0, _replaceall.default)(resolved, '\t', '%09');
73
+ if (!isWindows) {
74
+ resolved = (0, _replaceall.default)(resolved, '\\', '%5c');
75
+ }
76
+ return new _index.default("file:".concat(resolved));
77
+ }
78
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport path from 'path';\nimport replaceAll from 'core-js-pure/actual/string/replace-all.js';\nimport URL from 'core-js-pure/actual/url/index.js';\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(url: string | URL): string {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n\n if (url.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (url.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(url.pathname));\n\n if (isWindows) {\n if (url.hostname) return `\\\\\\\\${url.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = replaceAll(resolved, '%', '%25'); // Must be first\n resolved = replaceAll(resolved, '#', '%23');\n resolved = replaceAll(resolved, '?', '%3f');\n resolved = replaceAll(resolved, '\\n', '%0a');\n resolved = replaceAll(resolved, '\\r', '%0d');\n resolved = replaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = replaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URL(`file:${resolved}`);\n}\n"],"names":["fileURLToPath","pathToFileURL","isWindows","process","platform","test","env","OSTYPE","url","URL","protocol","Error","pathname","hostname","path","normalize","decodeURIComponent","letter","charCodeAt","slice","resolved","resolve","length","replaceAll"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;;;;;;;;;;;;IAOjEA,aAAa;eAAbA;;IAwCAC,aAAa;eAAbA;;;2DA7CC;iEACM;4DACP;;;;;;AAChB,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAEpF,SAASP,cAAcQ,GAAiB;IAC7C,IAAI,OAAOA,QAAQ,UAAU;QAC3BA,MAAM,IAAIC,cAAG,CAACD;IAChB;IAEA,IAAIA,IAAIE,QAAQ,KAAK,SAAS;QAC5B,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACG,IAAII,QAAQ,GAAG;YACjC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIH,IAAIK,QAAQ,EAAE;YAChB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAON,IAAI,CAACG,IAAII,QAAQ,GAAG;YAC7B,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,IAAMC,WAAWE,aAAI,CAACC,SAAS,CAACC,mBAAmBR,IAAII,QAAQ;IAE/D,IAAIV,WAAW;QACb,IAAIM,IAAIK,QAAQ,EAAE,OAAO,AAAC,OAAqBD,OAAfJ,IAAIK,QAAQ,EAAY,OAATD;QAE/C,IAAMK,SAASL,SAASM,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAML,SAASM,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIP,MAAM;QAClB;QAEA,OAAOC,SAASO,KAAK,CAAC;IACxB;IAEA,OAAOP;AACT;AAEO,SAASX,cAAcW,QAAgB;IAC5C,IAAIQ,WAAWN,aAAI,CAACO,OAAO,CAACT;IAE5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAIlB,aAAaU,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,KAAK,QAAQ,gBAAgB;IAC7DA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,KAAK;IACrCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,KAAK;IACrCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACtCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACtCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IAEtC,IAAI,CAAClB,WAAW;QACdkB,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACxC;IAEA,OAAO,IAAIX,cAAG,CAAC,AAAC,QAAgB,OAATW;AACzB"}
@@ -8,31 +8,69 @@ Object.defineProperty(exports, "default", {
8
8
  return toPath;
9
9
  }
10
10
  });
11
- var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
11
+ var _module = /*#__PURE__*/ _interop_require_default(require("module"));
12
12
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ var _url = /*#__PURE__*/ _interop_require_default(require("url"));
13
14
  var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
14
15
  var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
16
+ var _importmetaresolvecjs = require("../../assets/import-meta-resolve.cjs");
15
17
  var _constants = require("./constants.cjs");
16
- var _fileURLToPath = /*#__PURE__*/ _interop_require_default(require("./lib/fileURLToPath.cjs"));
18
+ var _urlfileurl = /*#__PURE__*/ _interop_require_wildcard(require("./lib/url-file-url.cjs"));
17
19
  function _interop_require_default(obj) {
18
20
  return obj && obj.__esModule ? obj : {
19
21
  default: obj
20
22
  };
21
23
  }
22
- var existsSync = function(test) {
23
- try {
24
- (_fs.default.accessSync || _fs.default.statSync)(test);
25
- return true;
26
- } catch (_) {
27
- return false;
24
+ function _getRequireWildcardCache(nodeInterop) {
25
+ if (typeof WeakMap !== "function") return null;
26
+ var cacheBabelInterop = new WeakMap();
27
+ var cacheNodeInterop = new WeakMap();
28
+ return (_getRequireWildcardCache = function(nodeInterop) {
29
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
30
+ })(nodeInterop);
31
+ }
32
+ function _interop_require_wildcard(obj, nodeInterop) {
33
+ if (!nodeInterop && obj && obj.__esModule) {
34
+ return obj;
35
+ }
36
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
37
+ return {
38
+ default: obj
39
+ };
40
+ }
41
+ var cache = _getRequireWildcardCache(nodeInterop);
42
+ if (cache && cache.has(obj)) {
43
+ return cache.get(obj);
28
44
  }
29
- };
45
+ var newObj = {
46
+ __proto__: null
47
+ };
48
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
49
+ for(var key in obj){
50
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
51
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
52
+ if (desc && (desc.get || desc.set)) {
53
+ Object.defineProperty(newObj, key, desc);
54
+ } else {
55
+ newObj[key] = obj[key];
56
+ }
57
+ }
58
+ }
59
+ newObj.default = obj;
60
+ if (cache) {
61
+ cache.set(obj, newObj);
62
+ }
63
+ return newObj;
64
+ }
65
+ var useCJS = !_module.default.createRequire;
66
+ var fileURLToPath = _url.default.fileURLToPath || _urlfileurl.fileURLToPath;
67
+ var pathToFileURL = _url.default.pathToFileURL || _urlfileurl.pathToFileURL;
30
68
  function getParentPath(context) {
31
69
  if (context.parentPath) return _path.default.dirname(context.parentPath);
32
70
  return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
33
71
  }
34
72
  function toPath(specifier, context) {
35
- if (specifier.startsWith('file:')) return (0, _fileURLToPath.default)(specifier);
73
+ if (specifier.startsWith('file:')) return fileURLToPath(specifier);
36
74
  if ((0, _isabsolute.default)(specifier)) return specifier;
37
75
  if (specifier[0] === '.') {
38
76
  var parentPath = context ? getParentPath(context) : process.cwd();
@@ -40,30 +78,21 @@ function toPath(specifier, context) {
40
78
  }
41
79
  if (_constants.moduleRegEx.test(specifier)) {
42
80
  var parentPath1 = context ? getParentPath(context) : process.cwd();
43
- var pkg = null;
44
- var main = _resolve.default.sync(specifier, {
45
- basedir: parentPath1,
46
- extensions: [
47
- '.js',
48
- '.json',
49
- '.node',
50
- '.mjs'
51
- ],
52
- packageFilter: function packageFilter(json, dir) {
53
- pkg = {
54
- json: json,
55
- dir: dir
56
- };
57
- return json;
58
- }
59
- });
60
- if (!pkg || !pkg.json.module) return main; // no modules, use main
61
- if (pkg.json.name === specifier) return _path.default.join(pkg.dir, pkg.json.module); // the module
62
- // a relative path. Only accept if it doesn't break the relative naming and it exists
63
- var modulePath = _path.default.join(pkg.dir, pkg.json.module);
64
- var mainPath = _path.default.join(pkg.dir, pkg.json.main);
65
- var moduleResolved = _path.default.join(modulePath, _path.default.relative(mainPath, main));
66
- return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;
81
+ if (useCJS) {
82
+ var entryPath = _resolve.default.sync(specifier, {
83
+ basedir: parentPath1,
84
+ extensions: [
85
+ '.js',
86
+ '.json',
87
+ '.node',
88
+ '.mjs'
89
+ ]
90
+ });
91
+ if (entryPath) return entryPath;
92
+ } else {
93
+ var entryURL = (0, _importmetaresolvecjs.resolve)(specifier, pathToFileURL(parentPath1));
94
+ if (entryURL) return fileURLToPath(entryURL);
95
+ }
67
96
  }
68
97
  return specifier;
69
98
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants';\nimport fileURLToPath from './lib/fileURLToPath';\nimport type { Context } from './types';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.join(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.join(pkg.dir, pkg.json.module);\n const mainPath = path.join(pkg.dir, pkg.json.main);\n const moduleResolved = path.join(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;\n }\n\n return specifier;\n}\n"],"names":["toPath","existsSync","test","fs","accessSync","statSync","_","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","fileURLToPath","isAbsolute","join","moduleRegEx","pkg","main","resolve","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace"],"mappings":";;;;+BAsBA;;;eAAwBA;;;yDAtBT;2DACE;iEACM;8DACH;yBACQ;oEACF;;;;;;AAG1B,IAAMC,aAAa,SAACC;IAClB,IAAI;QACDC,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGH;QAC/B,OAAO;IACT,EAAE,OAAOI,GAAG;QACV,OAAO;IACT;AACF;AAEA,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACX,OAAOQ,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASd,OAAOe,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOC,IAAAA,sBAAa,EAACF;IACxD,IAAIG,IAAAA,mBAAU,EAACH,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACS,IAAI,CAACV,YAAYM;IAC/B;IACA,IAAIK,sBAAW,CAAClB,IAAI,CAACa,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QAEjE,IAAIO,MAAM;QACV,IAAMC,OAAOC,gBAAO,CAACC,IAAI,CAACT,WAAW;YACnCU,SAAShB;YACTiB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;YAC7CC,eAAAA,SAAAA,cAAcC,IAAI,EAAEC,GAAG;gBACrBR,MAAM;oBAAEO,MAAAA;oBAAMC,KAAAA;gBAAI;gBAClB,OAAOD;YACT;QACF;QACA,IAAI,CAACP,OAAO,CAACA,IAAIO,IAAI,CAACE,MAAM,EAAE,OAAOR,MAAM,uBAAuB;QAClE,IAAID,IAAIO,IAAI,CAACG,IAAI,KAAKhB,WAAW,OAAOL,aAAI,CAACS,IAAI,CAACE,IAAIQ,GAAG,EAAER,IAAIO,IAAI,CAACE,MAAM,GAAG,aAAa;QAE1F,qFAAqF;QACrF,IAAME,aAAatB,aAAI,CAACS,IAAI,CAACE,IAAIQ,GAAG,EAAER,IAAIO,IAAI,CAACE,MAAM;QACrD,IAAMG,WAAWvB,aAAI,CAACS,IAAI,CAACE,IAAIQ,GAAG,EAAER,IAAIO,IAAI,CAACN,IAAI;QACjD,IAAMY,iBAAiBxB,aAAI,CAACS,IAAI,CAACa,YAAYtB,aAAI,CAACyB,QAAQ,CAACF,UAAUX;QACrE,OAAOY,eAAeE,OAAO,CAACrB,UAAUsB,OAAO,CAAChB,IAAIO,IAAI,CAACG,IAAI,EAAE,OAAO,KAAK,CAAC9B,WAAWiC,kBAAkBZ,OAAOY;IAClH;IAEA,OAAOnB;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import module from 'module';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolveCJS from 'resolve';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants';\nimport * as urlPolyfills from './lib/url-file-url';\nimport type { Context } from './types';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (useCJS) {\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n } else {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n }\n }\n\n return specifier;\n}\n"],"names":["toPath","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryPath","resolveCJS","sync","basedir","extensions","entryURL","resolveESM"],"mappings":";;;;+BAoBA;;;eAAwBA;;;6DApBL;2DACF;0DACD;iEACO;8DACA;oCAEe;yBACV;kEACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,YAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,YAAaC,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACZ,OAAOS,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASf,OAAOgB,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOb,cAAcY;IACxD,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,sBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAId,QAAQ;YACV,IAAMqB,YAAYC,gBAAU,CAACC,IAAI,CAACR,WAAW;gBAC3CS,SAASf;gBACTgB,YAAY;oBAAC;oBAAO;oBAAS;oBAAS;iBAAO;YAC/C;YACA,IAAIJ,WAAW,OAAOA;QACxB,OAAO;YACL,IAAMK,WAAWC,IAAAA,6BAAU,EAACZ,WAAWT,cAAcG;YACrD,IAAIiB,UAAU,OAAOvB,cAAcuB;QACrC;IACF;IAEA,OAAOX;AACT"}
@@ -11,6 +11,7 @@ export default function createMatcher(tsConfig) {
11
11
  let pattern = unixify(condition);
12
12
  if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);
13
13
  return function match(filePath) {
14
+ // @ts-ignore
14
15
  return filePath.startsWith(pattern) || minimatch(filePath, pattern);
15
16
  };
16
17
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AACA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,iBAAiB;AAG1C,eAAe,SAASC,cAAcC,QAAwB;IAC5D,MAAMC,WAAWH,aAAa;QAAEG,UAAUD;IAAS,GAAG;IACtD,MAAME,eAAeN,KAAKO,OAAO,CAACN,QAAQI,SAASL,IAAI;IAEvD,SAASQ,QAAQC,SAAS;QACxB,IAAIC,UAAUT,QAAQQ;QACtB,IAAI,CAACT,KAAKW,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUV,KAAKa,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYX,UAAUgB,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,SAASY,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACrD,MAAMY,WAAW,AAACf,CAAAA,SAASY,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAErD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWd,QAAQc;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n // @ts-ignore\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AACA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,iBAAiB;AAG1C,eAAe,SAASC,cAAcC,QAAwB;IAC5D,MAAMC,WAAWH,aAAa;QAAEG,UAAUD;IAAS,GAAG;IACtD,MAAME,eAAeN,KAAKO,OAAO,CAACN,QAAQI,SAASL,IAAI;IAEvD,SAASQ,QAAQC,SAAS;QACxB,IAAIC,UAAUT,QAAQQ;QACtB,IAAI,CAACT,KAAKW,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUV,KAAKa,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,aAAa;YACb,OAAOA,SAASH,UAAU,CAACF,YAAYX,UAAUgB,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,SAASY,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACrD,MAAMY,WAAW,AAACf,CAAAA,SAASY,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAErD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWd,QAAQc;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
@@ -1,11 +1,11 @@
1
1
  import { extensions, requireRegEx } from '../constants.mjs';
2
2
  import makeReplacements from './makeReplacements.mjs';
3
3
  // https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
4
- const interopClientDefaultExport = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
4
+ export const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
5
5
  const DEFAULT_EXTENSION = '.cjs';
6
6
  export default function patchCJS(entry, output, options) {
7
7
  const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
8
8
  output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);
9
- output.code += interopClientDefaultExport;
9
+ output.code += interop;
10
10
  return cjsExtension;
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interopClientDefaultExport;\n\n return cjsExtension;\n}\n"],"names":["extensions","requireRegEx","makeReplacements","interopClientDefaultExport","DEFAULT_EXTENSION","patchCJS","entry","output","options","cjsExtension","cjs","code"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,eAAe;AACxD,OAAOC,sBAAsB,qBAAqB;AAElD,0HAA0H;AAC1H,MAAMC,6BAA6B;AAEnC,MAAMC,oBAAoB;AAE1B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQR,UAAU,GAAGQ,QAAQR,UAAU,CAACU,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FG,OAAOI,IAAI,GAAGT,iBAAiBI,OAAOC,OAAOI,IAAI,EAAEV,cAAcD,YAAYS,cAAcD;IAC3FD,OAAOI,IAAI,IAAIR;IAEf,OAAOM;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interop;\n\n return cjsExtension;\n}\n"],"names":["extensions","requireRegEx","makeReplacements","interop","DEFAULT_EXTENSION","patchCJS","entry","output","options","cjsExtension","cjs","code"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,eAAe;AACxD,OAAOC,sBAAsB,qBAAqB;AAElD,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAE3R,MAAMC,oBAAoB;AAE1B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQR,UAAU,GAAGQ,QAAQR,UAAU,CAACU,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FG,OAAOI,IAAI,GAAGT,iBAAiBI,OAAOC,OAAOI,IAAI,EAAEV,cAAcD,YAAYS,cAAcD;IAC3FD,OAAOI,IAAI,IAAIR;IAEf,OAAOM;AACT"}
@@ -1,9 +1,9 @@
1
1
  import path from 'path';
2
- import ensureBindingsSync from './ensureBindingsSync.mjs';
2
+ import { installSync } from 'install-optional';
3
3
  import Module from 'module';
4
4
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
5
5
  export default function swcPrepareOptions(tsconfig) {
6
- ensureBindingsSync('@swc/core', `${process.platform}-${process.arch}`);
6
+ installSync('@swc/core', `${process.platform}-${process.arch}`);
7
7
  try {
8
8
  const ts = _require('typescript');
9
9
  const swc = _require('@swc/core');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport ensureBindingsSync from './ensureBindingsSync';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n ensureBindingsSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["path","ensureBindingsSync","Module","_require","require","createRequire","url","swcPrepareOptions","tsconfig","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,wBAAwB,uBAAuB;AAEtD,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,kBAAkBC,QAAwB;IAChEP,mBAAmB,aAAa,GAAGQ,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;IACrE,IAAI;QACF,MAAMC,KAAKT,SAAS;QACpB,MAAMU,MAAMV,SAAS;QACrB,MAAMW,aAAaX,SAAS;QAC5B,MAAMY,SAASH,GAAGI,0BAA0B,CAACR,SAASS,MAAM,EAAEL,GAAGM,GAAG,EAAElB,KAAKmB,OAAO,CAACX,SAASR,IAAI;QAChG,OAAOc,WAAWM,gBAAgB,CAACL,OAAOM,OAAO,EAAEC,WAAWT,KAAK;IACrE,EAAE,OAAOU,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { installSync } from 'install-optional';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["path","installSync","Module","_require","require","createRequire","url","swcPrepareOptions","tsconfig","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,mBAAmB;AAE/C,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,kBAAkBC,QAAwB;IAChEP,YAAY,aAAa,GAAGQ,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;IAC9D,IAAI;QACF,MAAMC,KAAKT,SAAS;QACpB,MAAMU,MAAMV,SAAS;QACrB,MAAMW,aAAaX,SAAS;QAC5B,MAAMY,SAASH,GAAGI,0BAA0B,CAACR,SAASS,MAAM,EAAEL,GAAGM,GAAG,EAAElB,KAAKmB,OAAO,CAACX,SAASR,IAAI;QAChG,OAAOc,WAAWM,gBAAgB,CAACL,OAAOM,OAAO,EAAEC,WAAWT,KAAK;IACrE,EAAE,OAAOU,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
@@ -0,0 +1,54 @@
1
+ // Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js
2
+ // Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE
3
+ import path from 'path';
4
+ import replaceAll from 'core-js-pure/actual/string/replace-all.js';
5
+ import URL from 'core-js-pure/actual/url/index.js';
6
+ const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
7
+ export function fileURLToPath(url) {
8
+ if (typeof url === 'string') {
9
+ url = new URL(url);
10
+ }
11
+ if (url.protocol !== 'file:') {
12
+ throw new Error('The URL must use the file: protocol');
13
+ }
14
+ if (isWindows) {
15
+ if (/%2f|%5c/i.test(url.pathname)) {
16
+ throw new Error('The file: URL path must not include encoded \\ or / characters');
17
+ }
18
+ } else {
19
+ if (url.hostname) {
20
+ throw new Error("The file: URL host must be 'localhost' or empty");
21
+ }
22
+ if (/%2f/i.test(url.pathname)) {
23
+ throw new Error('The file: URL path must not include encoded / characters');
24
+ }
25
+ }
26
+ const pathname = path.normalize(decodeURIComponent(url.pathname));
27
+ if (isWindows) {
28
+ if (url.hostname) return `\\\\${url.hostname}${pathname}`;
29
+ const letter = pathname.charCodeAt(1) | 0x20;
30
+ if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */ ) {
31
+ throw new Error('The file: URL path must be absolute');
32
+ }
33
+ return pathname.slice(1);
34
+ }
35
+ return pathname;
36
+ }
37
+ export function pathToFileURL(pathname) {
38
+ let resolved = path.resolve(pathname);
39
+ if (pathname[pathname.length - 1] === '/') {
40
+ resolved += '/';
41
+ } else if (isWindows && pathname[pathname.length - 1] === '\\') {
42
+ resolved += '\\';
43
+ }
44
+ resolved = replaceAll(resolved, '%', '%25'); // Must be first
45
+ resolved = replaceAll(resolved, '#', '%23');
46
+ resolved = replaceAll(resolved, '?', '%3f');
47
+ resolved = replaceAll(resolved, '\n', '%0a');
48
+ resolved = replaceAll(resolved, '\r', '%0d');
49
+ resolved = replaceAll(resolved, '\t', '%09');
50
+ if (!isWindows) {
51
+ resolved = replaceAll(resolved, '\\', '%5c');
52
+ }
53
+ return new URL(`file:${resolved}`);
54
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport path from 'path';\nimport replaceAll from 'core-js-pure/actual/string/replace-all.js';\nimport URL from 'core-js-pure/actual/url/index.js';\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(url: string | URL): string {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n\n if (url.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (url.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(url.pathname));\n\n if (isWindows) {\n if (url.hostname) return `\\\\\\\\${url.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = replaceAll(resolved, '%', '%25'); // Must be first\n resolved = replaceAll(resolved, '#', '%23');\n resolved = replaceAll(resolved, '?', '%3f');\n resolved = replaceAll(resolved, '\\n', '%0a');\n resolved = replaceAll(resolved, '\\r', '%0d');\n resolved = replaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = replaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URL(`file:${resolved}`);\n}\n"],"names":["path","replaceAll","URL","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","url","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,UAAU,OAAO;AACxB,OAAOC,gBAAgB,4CAA4C;AACnE,OAAOC,SAAS,mCAAmC;AACnD,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,GAAiB;IAC7C,IAAI,OAAOA,QAAQ,UAAU;QAC3BA,MAAM,IAAIR,IAAIQ;IAChB;IAEA,IAAIA,IAAIC,QAAQ,KAAK,SAAS;QAC5B,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACI,IAAIG,QAAQ,GAAG;YACjC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,IAAII,QAAQ,EAAE;YAChB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAON,IAAI,CAACI,IAAIG,QAAQ,GAAG;YAC7B,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,MAAMC,WAAWb,KAAKe,SAAS,CAACC,mBAAmBN,IAAIG,QAAQ;IAE/D,IAAIV,WAAW;QACb,IAAIO,IAAII,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAEJ,IAAII,QAAQ,GAAGD,UAAU;QAEzD,MAAMI,SAASJ,SAASK,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAMJ,SAASK,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIN,MAAM;QAClB;QAEA,OAAOC,SAASM,KAAK,CAAC;IACxB;IAEA,OAAON;AACT;AAEA,OAAO,SAASO,cAAcP,QAAgB;IAC5C,IAAIQ,WAAWrB,KAAKsB,OAAO,CAACT;IAE5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAIlB,aAAaU,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWpB,WAAWoB,UAAU,KAAK,QAAQ,gBAAgB;IAC7DA,WAAWpB,WAAWoB,UAAU,KAAK;IACrCA,WAAWpB,WAAWoB,UAAU,KAAK;IACrCA,WAAWpB,WAAWoB,UAAU,MAAM;IACtCA,WAAWpB,WAAWoB,UAAU,MAAM;IACtCA,WAAWpB,WAAWoB,UAAU,MAAM;IAEtC,IAAI,CAAClB,WAAW;QACdkB,WAAWpB,WAAWoB,UAAU,MAAM;IACxC;IAEA,OAAO,IAAInB,IAAI,CAAC,KAAK,EAAEmB,UAAU;AACnC"}
@@ -1,17 +1,15 @@
1
- import fs from 'fs';
1
+ import module from 'module';
2
2
  import path from 'path';
3
+ import url from 'url';
3
4
  import isAbsolute from 'is-absolute';
4
- import resolve from 'resolve';
5
+ import resolveCJS from 'resolve';
6
+ // @ts-ignore
7
+ import { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';
5
8
  import { moduleRegEx } from './constants.mjs';
6
- import fileURLToPath from './lib/fileURLToPath.mjs';
7
- const existsSync = (test)=>{
8
- try {
9
- (fs.accessSync || fs.statSync)(test);
10
- return true;
11
- } catch (_) {
12
- return false;
13
- }
14
- };
9
+ import * as urlPolyfills from './lib/url-file-url.mjs';
10
+ const useCJS = !module.createRequire;
11
+ const fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;
12
+ const pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;
15
13
  function getParentPath(context) {
16
14
  if (context.parentPath) return path.dirname(context.parentPath);
17
15
  return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
@@ -25,30 +23,21 @@ export default function toPath(specifier, context) {
25
23
  }
26
24
  if (moduleRegEx.test(specifier)) {
27
25
  const parentPath = context ? getParentPath(context) : process.cwd();
28
- let pkg = null;
29
- const main = resolve.sync(specifier, {
30
- basedir: parentPath,
31
- extensions: [
32
- '.js',
33
- '.json',
34
- '.node',
35
- '.mjs'
36
- ],
37
- packageFilter (json, dir) {
38
- pkg = {
39
- json,
40
- dir
41
- };
42
- return json;
43
- }
44
- });
45
- if (!pkg || !pkg.json.module) return main; // no modules, use main
46
- if (pkg.json.name === specifier) return path.join(pkg.dir, pkg.json.module); // the module
47
- // a relative path. Only accept if it doesn't break the relative naming and it exists
48
- const modulePath = path.join(pkg.dir, pkg.json.module);
49
- const mainPath = path.join(pkg.dir, pkg.json.main);
50
- const moduleResolved = path.join(modulePath, path.relative(mainPath, main));
51
- return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;
26
+ if (useCJS) {
27
+ const entryPath = resolveCJS.sync(specifier, {
28
+ basedir: parentPath,
29
+ extensions: [
30
+ '.js',
31
+ '.json',
32
+ '.node',
33
+ '.mjs'
34
+ ]
35
+ });
36
+ if (entryPath) return entryPath;
37
+ } else {
38
+ const entryURL = resolveESM(specifier, pathToFileURL(parentPath));
39
+ if (entryURL) return fileURLToPath(entryURL);
40
+ }
52
41
  }
53
42
  return specifier;
54
43
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants';\nimport fileURLToPath from './lib/fileURLToPath';\nimport type { Context } from './types';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.join(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.join(pkg.dir, pkg.json.module);\n const mainPath = path.join(pkg.dir, pkg.json.main);\n const moduleResolved = path.join(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;\n }\n\n return specifier;\n}\n"],"names":["fs","path","isAbsolute","resolve","moduleRegEx","fileURLToPath","existsSync","test","accessSync","statSync","_","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","startsWith","join","pkg","main","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,aAAa,UAAU;AAC9B,SAASC,WAAW,QAAQ,cAAc;AAC1C,OAAOC,mBAAmB,sBAAsB;AAGhD,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDP,CAAAA,GAAGQ,UAAU,IAAIR,GAAGS,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOZ,KAAKa,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGd,KAAKa,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOf,cAAcc;IACxD,IAAIjB,WAAWiB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOjB,KAAKoB,IAAI,CAACR,YAAYM;IAC/B;IACA,IAAIf,YAAYG,IAAI,CAACY,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QAEjE,IAAII,MAAM;QACV,MAAMC,OAAOpB,QAAQqB,IAAI,CAACL,WAAW;YACnCM,SAASZ;YACTa,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;YAC7CC,eAAcC,IAAI,EAAEC,GAAG;gBACrBP,MAAM;oBAAEM;oBAAMC;gBAAI;gBAClB,OAAOD;YACT;QACF;QACA,IAAI,CAACN,OAAO,CAACA,IAAIM,IAAI,CAACE,MAAM,EAAE,OAAOP,MAAM,uBAAuB;QAClE,IAAID,IAAIM,IAAI,CAACG,IAAI,KAAKZ,WAAW,OAAOlB,KAAKoB,IAAI,CAACC,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACE,MAAM,GAAG,aAAa;QAE1F,qFAAqF;QACrF,MAAME,aAAa/B,KAAKoB,IAAI,CAACC,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACE,MAAM;QACrD,MAAMG,WAAWhC,KAAKoB,IAAI,CAACC,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACL,IAAI;QACjD,MAAMW,iBAAiBjC,KAAKoB,IAAI,CAACW,YAAY/B,KAAKkC,QAAQ,CAACF,UAAUV;QACrE,OAAOW,eAAeE,OAAO,CAACjB,UAAUkB,OAAO,CAACf,IAAIM,IAAI,CAACG,IAAI,EAAE,OAAO,KAAK,CAACzB,WAAW4B,kBAAkBX,OAAOW;IAClH;IAEA,OAAOf;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import module from 'module';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolveCJS from 'resolve';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants';\nimport * as urlPolyfills from './lib/url-file-url';\nimport type { Context } from './types';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (useCJS) {\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n } else {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n }\n }\n\n return specifier;\n}\n"],"names":["module","path","url","isAbsolute","resolveCJS","resolve","resolveESM","moduleRegEx","urlPolyfills","useCJS","createRequire","fileURLToPath","pathToFileURL","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","startsWith","join","test","entryPath","sync","basedir","extensions","entryURL"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,gBAAgB,UAAU;AACjC,aAAa;AACb,SAASC,WAAWC,UAAU,QAAQ,uCAAuC;AAC7E,SAASC,WAAW,QAAQ,cAAc;AAC1C,YAAYC,kBAAkB,qBAAqB;AAGnD,MAAMC,SAAS,CAACT,OAAOU,aAAa;AACpC,MAAMC,gBAAgBT,IAAIS,aAAa,IAAIH,aAAaG,aAAa;AACrE,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIJ,aAAaI,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOd,KAAKe,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGhB,KAAKe,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOX,cAAcU;IACxD,IAAIlB,WAAWkB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOnB,KAAKsB,IAAI,CAACR,YAAYM;IAC/B;IACA,IAAId,YAAYiB,IAAI,CAACH,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAIX,QAAQ;YACV,MAAMgB,YAAYrB,WAAWsB,IAAI,CAACL,WAAW;gBAC3CM,SAASZ;gBACTa,YAAY;oBAAC;oBAAO;oBAAS;oBAAS;iBAAO;YAC/C;YACA,IAAIH,WAAW,OAAOA;QACxB,OAAO;YACL,MAAMI,WAAWvB,WAAWe,WAAWT,cAAcG;YACrD,IAAIc,UAAU,OAAOlB,cAAckB;QACrC;IACF;IAEA,OAAOR;AACT"}
@@ -1 +1,2 @@
1
+ export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
1
2
  export default function patchCJS(entry: any, output: any, options: any): any;
@@ -0,0 +1,3 @@
1
+ import URL from 'core-js-pure/actual/url/index.js';
2
+ export declare function fileURLToPath(url: string | URL): string;
3
+ export declare function pathToFileURL(pathname: string): URL;