ts-swc-transform 2.6.18 → 2.6.20

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.
@@ -22,6 +22,12 @@ _export(exports, {
22
22
  return rewriteExtensionsCJS;
23
23
  }
24
24
  });
25
+ var _startswith = /*#__PURE__*/ _interop_require_default(require("starts-with"));
26
+ function _interop_require_default(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
25
31
  var extensions = {
26
32
  '.ts': '.js',
27
33
  '.tsx': '.js',
@@ -34,30 +40,30 @@ function replaceExtension(ext) {
34
40
  }
35
41
  // Helper to check if a path is relative (starts with ./ or ../)
36
42
  function isRelativePath(path) {
37
- return path.startsWith('./') || path.startsWith('../');
43
+ return (0, _startswith.default)(path, './') || (0, _startswith.default)(path, '../');
38
44
  }
39
45
  function rewriteExtensions(content) {
40
46
  var result = content;
41
47
  // Pattern 1: Import/Export statements (with optional 'type' keyword)
42
- // Matches: import { X } from './path.ts'
43
- // import type { X } from './path.ts'
44
- // export * from './path.ts'
45
- // export type * from './path.ts'
46
- result = result.replace(/\b(import|export)(\s+type)?(?:\s+[^'"]*?\s+from\s+|\s+)['"]([^'"]+)\.(tsx?|mts|cts)['"]/g, function(match, keyword, typeKeyword, path, ext) {
48
+ // Matches: import { X } from './path.js'
49
+ // import type { X } from './path.js'
50
+ // export * from './path.js'
51
+ // export type * from './path.js'
52
+ result = result.replace(/\b(import|export)(\s+type)?(?:\s+[^'"]*?\s+from\s+|\s+)['"]([^'"]+)\.(tsx?|mts|cts)['"]/g, function(match, _keyword, _typeKeyword, path, ext) {
47
53
  if (!isRelativePath(path)) return match;
48
54
  var newExt = replaceExtension(".".concat(ext));
49
55
  return match.replace(".".concat(ext, '"'), "".concat(newExt, '"')).replace(".".concat(ext, "'"), "".concat(newExt, "'")).replace(".".concat(ext, "`"), "".concat(newExt, "`"));
50
56
  });
51
57
  // Pattern 2: Dynamic import types
52
- // Matches: typeof import('./path.ts')
58
+ // Matches: typeof import('./path.js')
53
59
  result = result.replace(/\bimport\s*\(\s*['"]([^'"]+)\.(tsx?|mts|cts)['"]\s*\)/g, function(match, path, ext) {
54
60
  if (!isRelativePath(path)) return match;
55
61
  var newExt = replaceExtension(".".concat(ext));
56
62
  return match.replace(".".concat(ext, '"'), "".concat(newExt, '"')).replace(".".concat(ext, "'"), "".concat(newExt, "'")).replace(".".concat(ext, "`"), "".concat(newExt, "`"));
57
63
  });
58
64
  // Pattern 3: Triple-slash path references
59
- // Matches: /// <reference path="./file.ts" />
60
- // /// <reference path="./file.d.ts" />
65
+ // Matches: /// <reference path="./file.js" />
66
+ // /// <reference path="./file.d.js" />
61
67
  result = result.replace(/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)\.(d\.ts|tsx?|mts|cts)['"]\s*\/>/g, function(match, path, ext) {
62
68
  if (!isRelativePath(path)) return match;
63
69
  // Special case: .d.ts → .d.js
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["export const extensions = {\n '.ts': '.js',\n '.tsx': '.js',\n '.mts': '.mjs',\n '.cts': '.cjs',\n};\n\nexport function replaceExtension(ext: string): string {\n const replace = extensions[ext];\n return replace === undefined ? ext : replace;\n}\n\n// Helper to check if a path is relative (starts with ./ or ../)\nfunction isRelativePath(path: string): boolean {\n return path.startsWith('./') || path.startsWith('../');\n}\n\n// Multi-pattern transformer for TypeScript extension rewriting\n// See: https://github.com/microsoft/TypeScript/issues/61037\n// TODO: Remove when TypeScript natively supports rewriteRelativeImportExtensions in .d.ts files\n\nexport function rewriteExtensions(content: string): string {\n let result = content;\n\n // Pattern 1: Import/Export statements (with optional 'type' keyword)\n // Matches: import { X } from './path.ts'\n // import type { X } from './path.ts'\n // export * from './path.ts'\n // export type * from './path.ts'\n result = result.replace(\n /\\b(import|export)(\\s+type)?(?:\\s+[^'\"]*?\\s+from\\s+|\\s+)['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]/g,\n (match, keyword, typeKeyword, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n // Pattern 2: Dynamic import types\n // Matches: typeof import('./path.ts')\n result = result.replace(\n /\\bimport\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g,\n (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n // Pattern 3: Triple-slash path references\n // Matches: /// <reference path=\"./file.ts\" />\n // /// <reference path=\"./file.d.ts\" />\n result = result.replace(\n /\\/\\/\\/\\s*<reference\\s+path\\s*=\\s*['\"]([^'\"]+)\\.(d\\.ts|tsx?|mts|cts)['\"]\\s*\\/>/g,\n (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n // Special case: .d.ts → .d.js\n const newExt = ext === 'd.ts' ? '.d.js' : replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n return result;\n}\n\n// CJS-specific version that also handles require() statements\nexport function rewriteExtensionsCJS(content: string): string {\n // Start with all ESM patterns\n let result = rewriteExtensions(content);\n\n // Pattern 4: CommonJS require() statements\n // Matches: require('./path.ts')\n result = result.replace(\n /\\brequire\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g,\n (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n return result;\n}\n"],"names":["extensions","replaceExtension","rewriteExtensions","rewriteExtensionsCJS","ext","replace","undefined","isRelativePath","path","startsWith","content","result","match","keyword","typeKeyword","newExt"],"mappings":";;;;;;;;;;;QAAaA;eAAAA;;QAOGC;eAAAA;;QAcAC;eAAAA;;QA6CAC;eAAAA;;;AAlET,IAAMH,aAAa;IACxB,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;AACV;AAEO,SAASC,iBAAiBG,GAAW;IAC1C,IAAMC,UAAUL,UAAU,CAACI,IAAI;IAC/B,OAAOC,YAAYC,YAAYF,MAAMC;AACvC;AAEA,gEAAgE;AAChE,SAASE,eAAeC,IAAY;IAClC,OAAOA,KAAKC,UAAU,CAAC,SAASD,KAAKC,UAAU,CAAC;AAClD;AAMO,SAASP,kBAAkBQ,OAAe;IAC/C,IAAIC,SAASD;IAEb,qEAAqE;IACrE,yCAAyC;IACzC,8CAA8C;IAC9C,qCAAqC;IACrC,0CAA0C;IAC1CC,SAASA,OAAON,OAAO,CACrB,4FACA,SAACO,OAAOC,SAASC,aAAaN,MAAMJ;QAClC,IAAI,CAACG,eAAeC,OAAO,OAAOI;QAClC,IAAMG,SAASd,iBAAiB,AAAC,IAAO,OAAJG;QACpC,OAAOQ,MAAMP,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAI,AAAC,GAAS,OAAPW,QAAO,MAAIV,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAI,AAAC,GAAS,OAAPW,QAAO,MAAIV,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAK,AAAC,GAAS,OAAPW,QAAO;IAClH;IAGF,kCAAkC;IAClC,sCAAsC;IACtCJ,SAASA,OAAON,OAAO,CACrB,0DACA,SAACO,OAAOJ,MAAMJ;QACZ,IAAI,CAACG,eAAeC,OAAO,OAAOI;QAClC,IAAMG,SAASd,iBAAiB,AAAC,IAAO,OAAJG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QAAO;IAClH;IAGF,OAAOJ;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import startsWith from 'starts-with';\n\nexport const extensions = {\n '.ts': '.js',\n '.tsx': '.js',\n '.mts': '.mjs',\n '.cts': '.cjs',\n};\n\nexport function replaceExtension(ext: string): string {\n const replace = extensions[ext];\n return replace === undefined ? ext : replace;\n}\n\n// Helper to check if a path is relative (starts with ./ or ../)\nfunction isRelativePath(path: string): boolean {\n return startsWith(path, './') || startsWith(path, '../');\n}\n\n// Multi-pattern transformer for TypeScript extension rewriting\n// See: https://github.com/microsoft/TypeScript/issues/61037\n// TODO: Remove when TypeScript natively supports rewriteRelativeImportExtensions in .d.ts files\n\nexport function rewriteExtensions(content: string): string {\n let result = content;\n\n // Pattern 1: Import/Export statements (with optional 'type' keyword)\n // Matches: import { X } from './path.ts'\n // import type { X } from './path.ts'\n // export * from './path.ts'\n // export type * from './path.ts'\n result = result.replace(/\\b(import|export)(\\s+type)?(?:\\s+[^'\"]*?\\s+from\\s+|\\s+)['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]/g, (match, _keyword, _typeKeyword, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 2: Dynamic import types\n // Matches: typeof import('./path.ts')\n result = result.replace(/\\bimport\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 3: Triple-slash path references\n // Matches: /// <reference path=\"./file.ts\" />\n // /// <reference path=\"./file.d.ts\" />\n result = result.replace(/\\/\\/\\/\\s*<reference\\s+path\\s*=\\s*['\"]([^'\"]+)\\.(d\\.ts|tsx?|mts|cts)['\"]\\s*\\/>/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n // Special case: .d.ts → .d.js\n const newExt = ext === 'd.ts' ? '.d.js' : replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n\n// CJS-specific version that also handles require() statements\nexport function rewriteExtensionsCJS(content: string): string {\n // Start with all ESM patterns\n let result = rewriteExtensions(content);\n\n // Pattern 4: CommonJS require() statements\n // Matches: require('./path.ts')\n result = result.replace(/\\brequire\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n"],"names":["extensions","replaceExtension","rewriteExtensions","rewriteExtensionsCJS","ext","replace","undefined","isRelativePath","path","startsWith","content","result","match","_keyword","_typeKeyword","newExt"],"mappings":";;;;;;;;;;;QAEaA;eAAAA;;QAOGC;eAAAA;;QAcAC;eAAAA;;QAoCAC;eAAAA;;;iEA3DO;;;;;;AAEhB,IAAMH,aAAa;IACxB,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;AACV;AAEO,SAASC,iBAAiBG,GAAW;IAC1C,IAAMC,UAAUL,UAAU,CAACI,IAAI;IAC/B,OAAOC,YAAYC,YAAYF,MAAMC;AACvC;AAEA,gEAAgE;AAChE,SAASE,eAAeC,IAAY;IAClC,OAAOC,IAAAA,mBAAU,EAACD,MAAM,SAASC,IAAAA,mBAAU,EAACD,MAAM;AACpD;AAMO,SAASN,kBAAk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I,MAAI,AAAC,GAAS,OAAPW,QAAO,MAAIV,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAI,AAAC,GAAS,OAAPW,QAAO,MAAIV,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAK,AAAC,GAAS,OAAPW,QAAO;IAClH;IAEA,OAAOJ;AACT;AAGO,SAASR,qBAAqBO,OAAe;IAClD,8BAA8B;IAC9B,IAAIC,SAAST,kBAAkBQ;IAE/B,2CAA2C;IAC3C,gCAAgC;IAChCC,SAASA,OAAON,OAAO,CAAC,2DAA2D,SAACO,OAAOJ,MAAMJ;QAC/F,IAAI,CAACG,eAAeC,OAAO,OAAOI;QAClC,IAAMG,SAASd,iBAAiB,AAAC,IAAO,OAAJG;QACpC,OAAOQ,MAAMP,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAI,AAAC,GAAS,OAAPW,QAAO,MAAIV,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAI,AAAC,GAAS,OAAPW,QAAO,MAAIV,OAAO,CAAC,AAAC,IAAO,OAAJD,KAAI,MAAK,AAAC,GAAS,OAAPW,QAAO;IAClH;IAEA,OAAOJ;AACT"}
@@ -12,6 +12,7 @@ var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"))
12
12
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
13
13
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
14
14
  var _resolve = /*#__PURE__*/ _interop_require_wildcard(require("resolve"));
15
+ var _startswith = /*#__PURE__*/ _interop_require_default(require("starts-with"));
15
16
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
16
17
  var _constantsts = require("./constants.js");
17
18
  var _importmetaresolvets = /*#__PURE__*/ _interop_require_default(require("./lib/import-meta-resolve.js"));
@@ -67,15 +68,12 @@ var resolveSync = ((_resolve_default = _resolve.default) !== null && _resolve_de
67
68
  var useCJS = !_module.default.createRequire;
68
69
  var fileURLToPath = _url.default.fileURLToPath || _urlFileUrlts.fileURLToPath;
69
70
  var pathToFileURL = _url.default.pathToFileURL || _urlFileUrlts.pathToFileURL;
70
- var startsWith = function(string, check) {
71
- return string.lastIndexOf(check, 0) === 0;
72
- };
73
71
  function getParentPath(context) {
74
72
  if (context.parentPath) return _path.default.dirname(context.parentPath);
75
73
  return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
76
74
  }
77
75
  function toPath(specifier, context) {
78
- if (startsWith(specifier, 'file:')) return fileURLToPath(specifier);
76
+ if ((0, _startswith.default)(specifier, 'file:')) return fileURLToPath(specifier);
79
77
  if ((0, _isabsolute.default)(specifier)) return specifier;
80
78
  if (specifier[0] === '.') {
81
79
  var parentPath = context ? getParentPath(context) : process.cwd();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport url from 'url';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\nconst startsWith = (string, check) => string.lastIndexOf(check, 0) === 0;\n\nfunction getParentPath(context: Context): string {\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): string {\n if (startsWith(specifier, '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 try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","resolve","resolveSync","default","sync","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","startsWith","string","check","lastIndexOf","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","isAbsolute","join","moduleRegEx","test","entryURL","importMetaResolve","_","entryPath","basedir","extensions"],"mappings":";;;;+BAsBA;;;eAAwBA;;;iEAtBD;6DACJ;2DACF;+DACQ;0DACT;2BACY;0EACE;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGTC;AAArB,IAAMC,cAAc,AAACD,CAAAA,CAAAA,mBAAAA,SAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,QAAM,EAAGG,IAAI;AAErD,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,cAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,cAAaC,aAAa;AACrE,IAAMC,aAAa,SAACC,QAAQC;WAAUD,OAAOE,WAAW,CAACD,OAAO,OAAO;;AAEvE,SAASE,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACpB,OAAOiB,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASvB,OAAOwB,SAAiB,EAAEP,OAAiB;IACjE,IAAIL,WAAWY,WAAW,UAAU,OAAOhB,cAAcgB;IACzD,IAAIC,IAAAA,mBAAU,EAACD,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACO,IAAI,CAACR,YAAYM;IAC/B;IACA,IAAIG,wBAAW,CAACC,IAAI,CAACJ,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAAClB,QAAQ;YACX,IAAI;gBACF,IAAMwB,WAAWC,IAAAA,4BAAiB,EAACN,WAAWb,cAAcO;gBAC5D,IAAIW,UAAU,OAAOrB,cAAcqB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAY9B,YAAYsB,WAAW;YACvCS,SAASf;YACTgB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOR;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport startsWith from 'starts-with';\nimport url from 'url';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context): string {\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): string {\n if (startsWith(specifier, '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 try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","resolve","resolveSync","default","sync","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryURL","importMetaResolve","_","entryPath","basedir","extensions"],"mappings":";;;;+BAsBA;;;eAAwBA;;;iEAtBD;6DACJ;2DACF;+DACQ;iEACF;0DACP;2BACY;0EACE;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGTC;AAArB,IAAMC,cAAc,AAACD,CAAAA,CAAAA,mBAAAA,SAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,QAAM,EAAGG,IAAI;AAErD,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,cAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,cAAaC,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,CAAChB,OAAOa,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASnB,OAAOoB,SAAiB,EAAEP,OAAiB;IACjE,IAAIQ,IAAAA,mBAAU,EAACD,WAAW,UAAU,OAAOZ,cAAcY;IACzD,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,wBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,4BAAiB,EAACP,WAAWT,cAAcG;gBAC5D,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAY3B,YAAYkB,WAAW;YACvCU,SAAShB;YACTiB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
@@ -1,3 +1,4 @@
1
+ import startsWith from 'starts-with';
1
2
  export const extensions = {
2
3
  '.ts': '.js',
3
4
  '.tsx': '.js',
@@ -10,7 +11,7 @@ export function replaceExtension(ext) {
10
11
  }
11
12
  // Helper to check if a path is relative (starts with ./ or ../)
12
13
  function isRelativePath(path) {
13
- return path.startsWith('./') || path.startsWith('../');
14
+ return startsWith(path, './') || startsWith(path, '../');
14
15
  }
15
16
  // Multi-pattern transformer for TypeScript extension rewriting
16
17
  // See: https://github.com/microsoft/TypeScript/issues/61037
@@ -22,21 +23,21 @@ export function rewriteExtensions(content) {
22
23
  // import type { X } from './path.js'
23
24
  // export * from './path.js'
24
25
  // export type * from './path.js'
25
- result = result.replace(/\b(import|export)(\s+type)?(?:\s+[^'"]*?\s+from\s+|\s+)['"]([^'"]+)\.(tsx?|mts|cts)['"]/g, (match, keyword, typeKeyword, path, ext)=>{
26
+ result = result.replace(/\b(import|export)(\s+type)?(?:\s+[^'"]*?\s+from\s+|\s+)['"]([^'"]+)\.(tsx?|mts|cts)['"]/g, (match, _keyword, _typeKeyword, path, ext)=>{
26
27
  if (!isRelativePath(path)) return match;
27
28
  const newExt = replaceExtension(`.${ext}`);
28
29
  return match.replace(`.${ext}"`, `${newExt}"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\``, `${newExt}\``);
29
30
  });
30
31
  // Pattern 2: Dynamic import types
31
- // Matches: typeof import('./path.ts')
32
+ // Matches: typeof import('./path.js')
32
33
  result = result.replace(/\bimport\s*\(\s*['"]([^'"]+)\.(tsx?|mts|cts)['"]\s*\)/g, (match, path, ext)=>{
33
34
  if (!isRelativePath(path)) return match;
34
35
  const newExt = replaceExtension(`.${ext}`);
35
36
  return match.replace(`.${ext}"`, `${newExt}"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\``, `${newExt}\``);
36
37
  });
37
38
  // Pattern 3: Triple-slash path references
38
- // Matches: /// <reference path="./file.ts" />
39
- // /// <reference path="./file.d.ts" />
39
+ // Matches: /// <reference path="./file.js" />
40
+ // /// <reference path="./file.d.js" />
40
41
  result = result.replace(/\/\/\/\s*<reference\s+path\s*=\s*['"]([^'"]+)\.(d\.ts|tsx?|mts|cts)['"]\s*\/>/g, (match, path, ext)=>{
41
42
  if (!isRelativePath(path)) return match;
42
43
  // Special case: .d.ts → .d.js
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["export const extensions = {\n '.ts': '.js',\n '.tsx': '.js',\n '.mts': '.mjs',\n '.cts': '.cjs',\n};\n\nexport function replaceExtension(ext: string): string {\n const replace = extensions[ext];\n return replace === undefined ? ext : replace;\n}\n\n// Helper to check if a path is relative (starts with ./ or ../)\nfunction isRelativePath(path: string): boolean {\n return path.startsWith('./') || path.startsWith('../');\n}\n\n// Multi-pattern transformer for TypeScript extension rewriting\n// See: https://github.com/microsoft/TypeScript/issues/61037\n// TODO: Remove when TypeScript natively supports rewriteRelativeImportExtensions in .d.ts files\n\nexport function rewriteExtensions(content: string): string {\n let result = content;\n\n // Pattern 1: Import/Export statements (with optional 'type' keyword)\n // Matches: import { X } from './path.ts'\n // import type { X } from './path.ts'\n // export * from './path.ts'\n // export type * from './path.ts'\n result = result.replace(\n /\\b(import|export)(\\s+type)?(?:\\s+[^'\"]*?\\s+from\\s+|\\s+)['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]/g,\n (match, keyword, typeKeyword, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n // Pattern 2: Dynamic import types\n // Matches: typeof import('./path.ts')\n result = result.replace(\n /\\bimport\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g,\n (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n // Pattern 3: Triple-slash path references\n // Matches: /// <reference path=\"./file.ts\" />\n // /// <reference path=\"./file.d.ts\" />\n result = result.replace(\n /\\/\\/\\/\\s*<reference\\s+path\\s*=\\s*['\"]([^'\"]+)\\.(d\\.ts|tsx?|mts|cts)['\"]\\s*\\/>/g,\n (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n // Special case: .d.ts → .d.js\n const newExt = ext === 'd.ts' ? '.d.js' : replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n return result;\n}\n\n// CJS-specific version that also handles require() statements\nexport function rewriteExtensionsCJS(content: string): string {\n // Start with all ESM patterns\n let result = rewriteExtensions(content);\n\n // Pattern 4: CommonJS require() statements\n // Matches: require('./path.ts')\n result = result.replace(\n /\\brequire\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g,\n (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n }\n );\n\n return result;\n}\n"],"names":["extensions","replaceExtension","ext","replace","undefined","isRelativePath","path","startsWith","rewriteExtensions","content","result","match","keyword","typeKeyword","newExt","rewriteExtensionsCJS"],"mappings":"AAAA,OAAO,MAAMA,aAAa;IACxB,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;AACV,EAAE;AAEF,OAAO,SAASC,iBAAiBC,GAAW;IAC1C,MAAMC,UAAUH,UAAU,CAACE,IAAI;IAC/B,OAAOC,YAAYC,YAAYF,MAAMC;AACvC;AAEA,gEAAgE;AAChE,SAASE,eAAeC,IAAY;IAClC,OAAOA,KAAKC,UAAU,CAAC,SAASD,KAAKC,UAAU,CAAC;AAClD;AAEA,+DAA+D;AAC/D,4DAA4D;AAC5D,gGAAgG;AAEhG,OAAO,SAASC,kBAAkBC,OAAe;IAC/C,IAAIC,SAASD;IAEb,qEAAqE;IACrE,yCAAyC;IACzC,8CAA8C;IAC9C,qCAAqC;IACrC,0CAA0C;IAC1CC,SAASA,OAAOP,OAAO,CACrB,4FACA,CAACQ,OAAOC,SAASC,aAAaP,MAAMJ;QAClC,IAAI,CAACG,eAAeC,OAAO,OAAOK;QAClC,MAAMG,SAASb,iBAAiB,CAAC,CAAC,EAAEC,KAAK;QACzC,OAAOS,MAAMR,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,CAAC,CAAC,E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O,SAASK,qBAAqBN,OAAe;IAClD,8BAA8B;IAC9B,IAAIC,SAASF,kBAAkBC;IAE/B,2CAA2C;IAC3C,gCAAgC;IAChCC,SAASA,OAAOP,OAAO,CACrB,2DACA,CAACQ,OAAOL,MAAMJ;QACZ,IAAI,CAACG,eAAeC,OAAO,OAAOK;QAClC,MAAMG,SAASb,iBAAiB,CAAC,CAAC,EAAEC,KAAK;QACzC,OAAOS,MAAMR,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,CAAC,CAAC,EAAE,GAAGY,OAAO,CAAC,CAAC,EAAEX,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,CAAC,CAAC,EAAE,GAAGY,OAAO,CAAC,CAAC,EAAEX,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,EAAE,CAAC,EAAE,GAAGY,OAAO,EAAE,CAAC;IACrH;IAGF,OAAOJ;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import startsWith from 'starts-with';\n\nexport const extensions = {\n '.ts': '.js',\n '.tsx': '.js',\n '.mts': '.mjs',\n '.cts': '.cjs',\n};\n\nexport function replaceExtension(ext: string): string {\n const replace = extensions[ext];\n return replace === undefined ? ext : replace;\n}\n\n// Helper to check if a path is relative (starts with ./ or ../)\nfunction isRelativePath(path: string): boolean {\n return startsWith(path, './') || startsWith(path, '../');\n}\n\n// Multi-pattern transformer for TypeScript extension rewriting\n// See: https://github.com/microsoft/TypeScript/issues/61037\n// TODO: Remove when TypeScript natively supports rewriteRelativeImportExtensions in .d.ts files\n\nexport function rewriteExtensions(content: string): string {\n let result = content;\n\n // Pattern 1: Import/Export statements (with optional 'type' keyword)\n // Matches: import { X } from './path.ts'\n // import type { X } from './path.ts'\n // export * from './path.ts'\n // export type * from './path.ts'\n result = result.replace(/\\b(import|export)(\\s+type)?(?:\\s+[^'\"]*?\\s+from\\s+|\\s+)['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]/g, (match, _keyword, _typeKeyword, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 2: Dynamic import types\n // Matches: typeof import('./path.ts')\n result = result.replace(/\\bimport\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 3: Triple-slash path references\n // Matches: /// <reference path=\"./file.ts\" />\n // /// <reference path=\"./file.d.ts\" />\n result = result.replace(/\\/\\/\\/\\s*<reference\\s+path\\s*=\\s*['\"]([^'\"]+)\\.(d\\.ts|tsx?|mts|cts)['\"]\\s*\\/>/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n // Special case: .d.ts → .d.js\n const newExt = ext === 'd.ts' ? '.d.js' : replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n\n// CJS-specific version that also handles require() statements\nexport function rewriteExtensionsCJS(content: string): string {\n // Start with all ESM patterns\n let result = rewriteExtensions(content);\n\n // Pattern 4: CommonJS require() statements\n // Matches: require('./path.ts')\n result = result.replace(/\\brequire\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n"],"names":["startsWith","extensions","replaceExtension","ext","replace","undefined","isRelativePath","path","rewriteExtensions","content","result","match","_keyword","_typeKeyword","newExt","rewriteExtensionsCJS"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AAErC,OAAO,MAAMC,aAAa;IACxB,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;AACV,EAAE;AAEF,OAAO,SAASC,iBAAiBC,GAAW;IAC1C,MAAMC,UAAUH,UAAU,CAACE,IAAI;IAC/B,OAAOC,YAAYC,YAAYF,MAAMC;AACvC;AAEA,gEAAgE;AAChE,SAASE,eAAeC,IAAY;IAClC,OAAOP,WAAWO,MAAM,SAASP,WAAWO,MAAM;AACpD;AAEA,+DAA+D;AAC/D,4DAA4D;AAC5D,gGAAgG;AAEhG,OAAO,SAASC,kBAAkBC,OAAe;IAC/C,IAAIC,SAASD;IAEb,qEAAqE;IACrE,yCAAyC;IACzC,8CAA8C;IAC9C,qCAAqC;IACrC,0CAA0C;IAC1CC,SAASA,OAAON,OAAO,CAAC,4FAA4F,CAACO,OAAOC,UAAUC,cAAcN,MAAMJ;QACxJ,IAAI,CAACG,eAAeC,OAAO,OAAOI;QAClC,MAAMG,SAASZ,iBAAiB,CAAC,CAAC,EAAEC,KAAK;QACzC,OAAOQ,MAAMP,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,CAAC,CAAC,EAAE,GAAGW,OAAO,CAAC,CAAC,EAAEV,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,CAAC,CAAC,EAAE,GAAGW,OAAO,CAAC,CAAC,EAAEV,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,EAAE,CAAC,EAAE,GAAGW,OAAO,EAAE,CAAC;IACrH;IAEA,kCAAkC;IAClC,sCAAsC;IACtCJ,SAASA,OAAON,OAAO,CAAC,0DAA0D,CAACO,OAAOJ,MAAMJ;QAC9F,IAAI,CAACG,eAAeC,OAAO,OAAOI;QAClC,MAAMG,SAASZ,iBAAiB,CAAC,CAAC,EAAE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,CAAC,EAAED,IAAI,CAAC,CAAC,EAAE,GAAGW,OAAO,CAAC,CAAC,EAAEV,OAAO,CAAC,CAAC,CAAC,EAAED,IAAI,EAAE,CAAC,EAAE,GAAGW,OAAO,EAAE,CAAC;IACrH;IAEA,OAAOJ;AACT"}
@@ -2,6 +2,7 @@ import isAbsolute from 'is-absolute';
2
2
  import module from 'module';
3
3
  import path from 'path';
4
4
  import * as resolve from 'resolve';
5
+ import startsWith from 'starts-with';
5
6
  import url from 'url';
6
7
  import { moduleRegEx } from './constants.js';
7
8
  import importMetaResolve from './lib/import-meta-resolve.js';
@@ -11,7 +12,6 @@ const resolveSync = ((_resolve_default = resolve.default) !== null && _resolve_d
11
12
  const useCJS = !module.createRequire;
12
13
  const fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;
13
14
  const pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;
14
- const startsWith = (string, check)=>string.lastIndexOf(check, 0) === 0;
15
15
  function getParentPath(context) {
16
16
  if (context.parentPath) return path.dirname(context.parentPath);
17
17
  return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport url from 'url';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\nconst startsWith = (string, check) => string.lastIndexOf(check, 0) === 0;\n\nfunction getParentPath(context: Context): string {\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): string {\n if (startsWith(specifier, '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 try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["isAbsolute","module","path","resolve","url","moduleRegEx","importMetaResolve","urlPolyfills","resolveSync","default","sync","useCJS","createRequire","fileURLToPath","pathToFileURL","startsWith","string","check","lastIndexOf","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","join","test","entryURL","_","entryPath","basedir","extensions"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,YAAYC,aAAa,UAAU;AACnC,OAAOC,SAAS,MAAM;AACtB,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,uBAAuB,+BAA+B;AAC7D,YAAYC,kBAAkB,sBAAsB;IAG/BJ;AAArB,MAAMK,cAAc,AAACL,CAAAA,CAAAA,mBAAAA,QAAQM,OAAO,cAAfN,8BAAAA,mBAAmBA,OAAM,EAAGO,IAAI;AAErD,MAAMC,SAAS,CAACV,OAAOW,aAAa;AACpC,MAAMC,gBAAgBT,IAAIS,aAAa,IAAIN,aAAaM,aAAa;AACrE,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIP,aAAaO,aAAa;AACrE,MAAMC,aAAa,CAACC,QAAQC,QAAUD,OAAOE,WAAW,CAACD,OAAO,OAAO;AAEvE,SAASE,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOnB,KAAKoB,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGrB,KAAKoB,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIL,WAAWY,WAAW,UAAU,OAAOd,cAAcc;IACzD,IAAI3B,WAAW2B,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOxB,KAAK0B,IAAI,CAACP,YAAYM;IAC/B;IACA,IAAItB,YAAYwB,IAAI,CAACF,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACf,QAAQ;YACX,IAAI;gBACF,MAAMmB,WAAWxB,kBAAkBqB,WAAWb,cAAcO;gBAC5D,IAAIS,UAAU,OAAOjB,cAAciB;YACrC,EAAE,OAAOC,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,MAAMC,YAAYxB,YAAYmB,WAAW;YACvCM,SAASZ;YACTa,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOL;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport startsWith from 'starts-with';\nimport url from 'url';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context): string {\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): string {\n if (startsWith(specifier, '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 try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["isAbsolute","module","path","resolve","startsWith","url","moduleRegEx","importMetaResolve","urlPolyfills","resolveSync","default","sync","useCJS","createRequire","fileURLToPath","pathToFileURL","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","join","test","entryURL","_","entryPath","basedir","extensions"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,YAAYC,aAAa,UAAU;AACnC,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,SAAS,MAAM;AACtB,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,uBAAuB,+BAA+B;AAC7D,YAAYC,kBAAkB,sBAAsB;IAG/BL;AAArB,MAAMM,cAAc,AAACN,CAAAA,CAAAA,mBAAAA,QAAQO,OAAO,cAAfP,8BAAAA,mBAAmBA,OAAM,EAAGQ,IAAI;AAErD,MAAMC,SAAS,CAACX,OAAOY,aAAa;AACpC,MAAMC,gBAAgBT,IAAIS,aAAa,IAAIN,aAAaM,aAAa;AACrE,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIP,aAAaO,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOhB,KAAKiB,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGlB,KAAKiB,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIb,WAAWoB,WAAW,UAAU,OAAOV,cAAcU;IACzD,IAAIxB,WAAWwB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOrB,KAAKuB,IAAI,CAACP,YAAYM;IAC/B;IACA,IAAIlB,YAAYoB,IAAI,CAACF,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACX,QAAQ;YACX,IAAI;gBACF,MAAMe,WAAWpB,kBAAkBiB,WAAWT,cAAcG;gBAC5D,IAAIS,UAAU,OAAOb,cAAca;YACrC,EAAE,OAAOC,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,MAAMC,YAAYpB,YAAYe,WAAW;YACvCM,SAASZ;YACTa,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOL;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-swc-transform",
3
- "version": "2.6.18",
3
+ "version": "2.6.20",
4
4
  "description": "Typescript transformers for swc. Supports Node >= 0.8",
5
5
  "keywords": [
6
6
  "matcher",
@@ -29,7 +29,7 @@
29
29
  "./package.json": "./package.json"
30
30
  },
31
31
  "main": "dist/cjs/index.js",
32
- "types": "dist/cjs/index.d.cts",
32
+ "types": "dist/cjs/index.d.ts",
33
33
  "files": [
34
34
  "dist",
35
35
  "assets"
@@ -56,6 +56,7 @@
56
56
  "read-tsconfig-sync": "*",
57
57
  "resolve": "*",
58
58
  "rimraf2": "*",
59
+ "starts-with": "^1.0.2",
59
60
  "test-match": "*",
60
61
  "ts-node": "*",
61
62
  "typescript": "*"