ts-swc-transform 2.11.6 → 2.11.7

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 (62) hide show
  1. package/dist/cjs/lib/patchCJS.d.cts +2 -2
  2. package/dist/cjs/lib/patchCJS.d.ts +2 -2
  3. package/dist/cjs/lib/patchCJS.js.map +1 -1
  4. package/dist/cjs/lib/patchESM.d.cts +2 -2
  5. package/dist/cjs/lib/patchESM.d.ts +2 -2
  6. package/dist/cjs/lib/patchESM.js.map +1 -1
  7. package/dist/cjs/lib/prepareSWCOptions.js +8 -1
  8. package/dist/cjs/lib/prepareSWCOptions.js.map +1 -1
  9. package/dist/cjs/lib/rewriteExtensions.d.cts +1 -6
  10. package/dist/cjs/lib/rewriteExtensions.d.ts +1 -6
  11. package/dist/cjs/lib/rewriteExtensions.js.map +1 -1
  12. package/dist/cjs/lib/transformFile.d.cts +2 -2
  13. package/dist/cjs/lib/transformFile.d.ts +2 -2
  14. package/dist/cjs/lib/transformFile.js +22 -9
  15. package/dist/cjs/lib/transformFile.js.map +1 -1
  16. package/dist/cjs/lib/urlFileUrl.js +2 -1
  17. package/dist/cjs/lib/urlFileUrl.js.map +1 -1
  18. package/dist/cjs/resolveFileSync.d.cts +1 -1
  19. package/dist/cjs/resolveFileSync.d.ts +1 -1
  20. package/dist/cjs/resolveFileSync.js.map +1 -1
  21. package/dist/cjs/transformDirectory.js +27 -3
  22. package/dist/cjs/transformDirectory.js.map +1 -1
  23. package/dist/cjs/transformTypes.js +27 -3
  24. package/dist/cjs/transformTypes.js.map +1 -1
  25. package/dist/cjs/types.d.cts +6 -3
  26. package/dist/cjs/types.d.ts +6 -3
  27. package/dist/cjs/workers/transformDirectory.d.cts +2 -2
  28. package/dist/cjs/workers/transformDirectory.d.ts +2 -2
  29. package/dist/cjs/workers/transformDirectory.js +12 -9
  30. package/dist/cjs/workers/transformDirectory.js.map +1 -1
  31. package/dist/cjs/workers/transformTypes.d.cts +2 -2
  32. package/dist/cjs/workers/transformTypes.d.ts +2 -2
  33. package/dist/cjs/workers/transformTypes.js +21 -10
  34. package/dist/cjs/workers/transformTypes.js.map +1 -1
  35. package/dist/esm/lib/patchCJS.d.ts +2 -2
  36. package/dist/esm/lib/patchCJS.js.map +1 -1
  37. package/dist/esm/lib/patchESM.d.ts +2 -2
  38. package/dist/esm/lib/patchESM.js.map +1 -1
  39. package/dist/esm/lib/prepareSWCOptions.js +1 -1
  40. package/dist/esm/lib/prepareSWCOptions.js.map +1 -1
  41. package/dist/esm/lib/rewriteExtensions.d.ts +1 -6
  42. package/dist/esm/lib/rewriteExtensions.js.map +1 -1
  43. package/dist/esm/lib/transformFile.d.ts +2 -2
  44. package/dist/esm/lib/transformFile.js +14 -12
  45. package/dist/esm/lib/transformFile.js.map +1 -1
  46. package/dist/esm/lib/urlFileUrl.js +2 -1
  47. package/dist/esm/lib/urlFileUrl.js.map +1 -1
  48. package/dist/esm/resolveFileSync.d.ts +1 -1
  49. package/dist/esm/resolveFileSync.js.map +1 -1
  50. package/dist/esm/transformDirectory.js +3 -3
  51. package/dist/esm/transformDirectory.js.map +1 -1
  52. package/dist/esm/transformTypes.js +3 -3
  53. package/dist/esm/transformTypes.js.map +1 -1
  54. package/dist/esm/types.d.ts +6 -3
  55. package/dist/esm/types.js.map +1 -1
  56. package/dist/esm/workers/transformDirectory.d.ts +2 -2
  57. package/dist/esm/workers/transformDirectory.js +12 -9
  58. package/dist/esm/workers/transformDirectory.js.map +1 -1
  59. package/dist/esm/workers/transformTypes.d.ts +2 -2
  60. package/dist/esm/workers/transformTypes.js +19 -10
  61. package/dist/esm/workers/transformTypes.js.map +1 -1
  62. package/package.json +4 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import type fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries: Entry[] = [];\n const modeByPath = new Map<string, number>();\n const iterator = new Iterator(src, { alwaysStat: true });\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n\n const stats = entry.stats as fs.Stats;\n if (stats.mode) {\n modeByPath.set(entry.fullPath, stats.mode);\n }\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n const mode = modeByPath.get(entry.fullPath);\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, mode, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","entries","modeByPath","Map","iterator","Iterator","alwaysStat","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","mode","set","err","results","queue","Queue","get","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BAWA;;;eAAwBA;;;iEAVa;2DACpB;8DACC;2BAEwB;sEAChB;sEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIX,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S,CAACD;oBAC5B,IAAInC,QAAQqC,UAAU,EAAET,QAAQJ,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACgB,SAAS,CAACD,UAAS;oBAChEF;gBACF;;QAEJ;QACAJ,MAAMS,KAAK,CAAC,SAACX;mBAASA,MAAM1B,SAAS0B,OAAO1B,SAAS,MAAM2B;;IAC7D;AAEJ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import type fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { InternalConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: InternalConfigOptions, callback: TransformDirectoryCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries: Entry[] = [];\n const modeByPath = new Map<string, number>();\n const iterator = new Iterator(src, { alwaysStat: true });\n iterator.forEach(\n (entry: Entry): void => {\n const stats = entry.stats as fs.Stats | undefined;\n if (!stats || !stats.isFile()) return;\n const basename = entry.basename as string;\n if (basename[0] === '.') return;\n if (typeFileRegEx.test(basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n\n if (stats.mode) {\n modeByPath.set(entry.fullPath, stats.mode);\n }\n },\n (err) => {\n if (err) return callback(err);\n const results: string[] = [];\n const opts: InternalConfigOptions = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n const mode = modeByPath.get(entry.fullPath);\n queue.defer((cb) =>\n transformFile(entry, dest, type, opts, mode, (err, outPath) => {\n if (err) return cb(err);\n if (outPath) {\n results.push(path.normalize(outPath));\n if (opts.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n }\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","entries","modeByPath","Map","iterator","Iterator","alwaysStat","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","mode","set","err","results","opts","queue","Queue","get","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BAWA;;;eAAwBA;;;iEAVa;2DACpB;8DACC;2BAEwB;sEAChB;sEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIX,SAASA,yBAAyBC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAA8B,EAAEC,QAAoC;IAChK,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,wBAAa,EAACF;IAE9B,IAAMG,UAAmB,EAAE;IAC3B,IAAMC,aAAa,IAAIC;IACvB,IAAMC,WAAW,IAAIC,mBAAQ,CAACZ,KAAK;QAAEa,YAAY;IAAK;IACtDF,SAASG,OAAO,CACd,SAACC;QACC,IAAMC,QAAQD,MAAMC,KAAK;QACzB,IAAI,CAACA,SAAS,CAACA,MAAMC,MAAM,IAAI;QAC/B,IAAMC,WAAWH,MAAMG,QAAQ;QAC/B,IAAIA,QAAQ,CAAC,EAAE,KAAK,KAAK;QACzB,IAAIC,0BAAa,CAACC,IAAI,CAACF,WAAW;QAClC,IAAI,CAACZ,QAAQS,MAAMM,QAAQ,GAAG;QAC9B,IAAMC,MAAMC,aAAI,CAACC,OAAO,CAACN;QACzB,IAAII,OAAOG,uBAAU,CAACC,OAAO,CAACJ,OAAO,GAAG;QACxCd,QAAQmB,IAAI,CAACZ;QAEb,IAAIC,MAAMY,IAAI,EAAE;YACdnB,WAAWoB,GAAG,CAACd,MAAMM,QAAQ,EAAEL,MAAMY,IAAI;QAC3C;IACF,GACA,SAACE;QACC,IAAIA,KAAK,OAAO1B,SAAS0B;QACzB,IAAMC,UAAoB,EAAE;QAC5B,IAAMC,OAA8B,wCAAK7B;YAASE,UAAAA;;QAElD,IAAM4B,QAAQ,IAAIC,gBAAK;QACvB1B,QAAQM,OAAO,CAAC,SAACC;YACf,IAAMa,OAAOnB,WAAW0B,GAAG,CAACpB,MAAMM,QAAQ;YAC1CY,MAAMG,KAAK,CAAC,SAACC;uBACXC,IAAAA,wBAAa,EAACvB,OAAOd,MAAMC,MAAM8B,MAAMJ,MAAM,SAACE,KAAKS;oBACjD,IAAIT,KAAK,OAAOO,GAAGP;oBACnB,IAAIS,SAAS;wBACXR,QAAQJ,IAAI,CAACJ,aAAI,CAACiB,SAAS,CAACD;wBAC5B,IAAIP,KAAKS,UAAU,EAAEV,QAAQJ,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACiB,SAAS,CAACD,UAAS;oBAC/D;oBACAF;gBACF;;QAEJ;QACAJ,MAAMS,KAAK,CAAC,SAACZ;mBAASA,MAAM1B,SAAS0B,OAAO1B,SAAS,MAAM2B;;IAC7D;AAEJ"}
@@ -1,2 +1,2 @@
1
- import type { ConfigOptions, TransformTypesCallback } from '../types.js';
2
- export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
1
+ import type { InternalConfigOptions, TransformTypesCallback } from '../types.js';
2
+ export default function transformTypesWorker(src: string, dest: string, options: InternalConfigOptions, callback: TransformTypesCallback): void;
@@ -1,2 +1,2 @@
1
- import type { ConfigOptions, TransformTypesCallback } from '../types.js';
2
- export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
1
+ import type { InternalConfigOptions, TransformTypesCallback } from '../types.js';
2
+ export default function transformTypesWorker(src: string, dest: string, options: InternalConfigOptions, callback: TransformTypesCallback): void;
@@ -158,10 +158,12 @@ function transformTypesWorker(src, dest, options, callback) {
158
158
  var rootFiles = [];
159
159
  var iterator = new _fsiterator.default(src);
160
160
  iterator.forEach(function(entry) {
161
- if (!entry.stats.isFile()) return;
162
- if (entry.basename[0] === '.') return;
163
- if (_constantsts.typeFileRegEx.test(entry.basename)) return;
164
- if (!isAllowedRootFile(entry.basename)) return;
161
+ var stats = entry.stats;
162
+ if (!stats || !stats.isFile()) return;
163
+ var basename = entry.basename;
164
+ if (basename[0] === '.') return;
165
+ if (_constantsts.typeFileRegEx.test(basename)) return;
166
+ if (!isAllowedRootFile(basename)) return;
165
167
  if (!matcher(entry.fullPath)) return;
166
168
  rootFiles.push(entry.fullPath);
167
169
  }, {
@@ -177,7 +179,7 @@ function transformTypesWorker(src, dest, options, callback) {
177
179
  allowJs: true,
178
180
  declaration: true,
179
181
  emitDeclarationOnly: true,
180
- downlevelIteration: undefined,
182
+ // Suppress TS6 deprecation warnings (TS5101/TS5107) for consumers still on legacy Node-targeted options.
181
183
  ignoreDeprecations: '6.0'
182
184
  });
183
185
  var rewrite = ((_tsconfig_config_compilerOptions = tsconfig.config.compilerOptions) === null || _tsconfig_config_compilerOptions === void 0 ? void 0 : _tsconfig_config_compilerOptions.rewriteRelativeImportExtensions) === true;
@@ -214,14 +216,20 @@ function transformTypesWorker(src, dest, options, callback) {
214
216
  'false'
215
217
  ];
216
218
  runCompiler(tscPath, args, function(runErr, res) {
217
- if (runErr || res.status !== 0) {
218
- var _ref;
219
- var msg = "TypeScript compiler failed (status=".concat(res === null || res === void 0 ? void 0 : res.status, ").\n").concat("stderr:\n".concat(String((_ref = res === null || res === void 0 ? void 0 : res.stderr) !== null && _ref !== void 0 ? _ref : '')).slice(0, 20000));
219
+ if (runErr || !res || res.status !== 0) {
220
+ var _ref, _ref1;
221
+ // cross-spawn-cb sets runErr (with stdout/stderr/status copied onto it) on non-zero exit
222
+ // and does NOT pass res — read from runErr first, then fall back to res.
223
+ var source = runErr !== null && runErr !== void 0 ? runErr : res;
224
+ var status = source === null || source === void 0 ? void 0 : source.status;
225
+ var stdout = String((_ref = source === null || source === void 0 ? void 0 : source.stdout) !== null && _ref !== void 0 ? _ref : '');
226
+ var stderr = String((_ref1 = source === null || source === void 0 ? void 0 : source.stderr) !== null && _ref1 !== void 0 ? _ref1 : '');
227
+ var detail = "TypeScript compiler failed (status=".concat(status, ").\nstdout:\n").concat(stdout.slice(0, 100000), "\nstderr:\n").concat(stderr.slice(0, 20000));
220
228
  (0, _fsremovecompat.safeRm)(tempDir, {
221
229
  recursive: true,
222
230
  force: true
223
231
  }, function() {
224
- return callback(runErr !== null && runErr !== void 0 ? runErr : new Error(msg));
232
+ return callback(new Error(detail));
225
233
  });
226
234
  return;
227
235
  }
@@ -245,7 +253,10 @@ function transformTypesWorker(src, dest, options, callback) {
245
253
  _fs.default.readFile(file, 'utf8', function(readErr, content) {
246
254
  if (readErr) return cb();
247
255
  var updated = (0, _rewriteExtensionsts.rewriteExtensions)(content);
248
- updated === content ? cb() : _fs.default.writeFile(file, updated, 'utf8', cb);
256
+ if (updated === content) cb();
257
+ else _fs.default.writeFile(file, updated, 'utf8', function(err) {
258
+ return cb(err !== null && err !== void 0 ? err : undefined);
259
+ });
249
260
  });
250
261
  });
251
262
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import spawn, { type SpawnCallback, type SpawnResult } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport { safeRm } from 'fs-remove-compat';\nimport os from 'os';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\n\nconst concurrency = Math.min(64, Math.max(8, (os.cpus()?.length ?? 4) * 8));\n\nconst tscPath = resolveBin('typescript', 'tsc');\n\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\n/* ---------------- root file filtering ---------------- */\n\nfunction isAllowedRootFile(basename: string): boolean {\n return (\n basename.endsWith('.d.ts') ||\n basename.endsWith('.d.mts') ||\n basename.endsWith('.d.cts') ||\n basename.endsWith('.ts') ||\n basename.endsWith('.tsx') ||\n basename.endsWith('.mts') ||\n basename.endsWith('.cts') ||\n basename.endsWith('.js') ||\n basename.endsWith('.jsx') ||\n basename.endsWith('.mjs') ||\n basename.endsWith('.cjs')\n );\n}\n\n/* ---------------- compiler execution ---------------- */\n\nfunction runCompiler(cmdPath: string, args: string[], cb: SpawnCallback): void {\n spawn(process.execPath, [cmdPath, ...args], { encoding: 'utf8' }, cb);\n}\n\n/* ---------------- emitted file parsing ---------------- */\n\nfunction parseEmittedFiles(res: SpawnResult, dest: string): string[] {\n const out: string[] = [];\n const seen = new Set<string>();\n const lines = `${res.stdout}\\n${res.stderr}`.split(/\\r?\\n/);\n\n for (let line of lines) {\n line = line.trim();\n if (!line) continue;\n\n if (/^TSFILE:\\s+/i.test(line)) line = line.replace(/^TSFILE:\\s+/i, '').trim();\n\n if (!path.isAbsolute(line)) continue;\n if (!(line.endsWith('.d.ts') || line.endsWith('.d.mts') || line.endsWith('.d.cts'))) continue;\n\n // Optional safety: only accept outputs under dest\n const rel = path.relative(dest, line);\n if (rel.startsWith('..') || path.isAbsolute(rel)) continue;\n\n if (!seen.has(line)) {\n seen.add(line);\n out.push(line);\n }\n }\n\n return out;\n}\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const rootFiles: string[] = [];\n const iterator = new Iterator(src);\n\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!isAllowedRootFile(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n\n rootFiles.push(entry.fullPath);\n },\n { concurrency },\n (err) => {\n if (err) return callback(err);\n if (rootFiles.length === 0) return callback(null, []);\n\n const compilerOptions = {\n ...tsconfig.config.compilerOptions,\n rootDir: src,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n downlevelIteration: undefined,\n ignoreDeprecations: '6.0',\n };\n\n const rewrite = tsconfig.config.compilerOptions?.rewriteRelativeImportExtensions === true;\n\n // Avoid collisions across concurrent runs.\n const tempDir = path.join(dest, '.ts-swc-transform-temp', String(process.pid), String(Date.now()));\n const tempConfigPath = path.join(tempDir, 'tsconfig.json');\n\n const tempConfig = {\n compilerOptions,\n files: rootFiles,\n include: [],\n exclude: [],\n ...(tsconfig.config.references && { references: tsconfig.config.references }),\n };\n\n fs.mkdir(tempDir, { recursive: true }, (mkdirErr) => {\n if (mkdirErr) return callback(mkdirErr);\n\n fs.writeFile(tempConfigPath, JSON.stringify(tempConfig, null, 2), 'utf8', (writeErr) => {\n if (writeErr) {\n safeRm(tempDir, { recursive: true, force: true }, () => callback(writeErr));\n return;\n }\n\n const args = ['--project', tempConfigPath, '--listEmittedFiles', '--pretty', 'false'];\n\n runCompiler(tscPath, args, (runErr, res) => {\n if (runErr || res.status !== 0) {\n const msg = `TypeScript compiler failed (status=${res?.status}).\\n${`stderr:\\n${String(res?.stderr ?? '')}`.slice(0, 20_000)}`;\n safeRm(tempDir, { recursive: true, force: true }, () => callback(runErr ?? new Error(msg)));\n return;\n }\n\n const emittedFiles = parseEmittedFiles(res, dest);\n if (emittedFiles.length === 0) {\n safeRm(tempDir, { recursive: true, force: true }, () => callback(new Error('TypeScript compiler produced no emitted declaration files')));\n return;\n }\n\n const postQueue = new Queue();\n\n if (rewrite) {\n for (const file of emittedFiles) {\n postQueue.defer((cb) => {\n fs.readFile(file, 'utf8', (readErr, content) => {\n if (readErr) return cb();\n const updated = rewriteExtensions(content);\n updated === content ? cb() : fs.writeFile(file, updated, 'utf8', cb);\n });\n });\n }\n }\n\n postQueue.await(() => {\n safeRm(tempDir, { recursive: true, force: true }, (rmErr) => callback(rmErr || null, emittedFiles));\n });\n });\n });\n });\n }\n );\n}\n"],"names":["transformTypesWorker","os","concurrency","Math","min","max","cpus","length","tscPath","resolveBin","isAllowedRootFile","basename","endsWith","runCompiler","cmdPath","args","cb","spawn","process","execPath","encoding","parseEmittedFiles","res","dest","out","seen","Set","lines","stdout","stderr","split","line","trim","test","replace","path","isAbsolute","rel","relative","startsWith","has","add","push","src","options","callback","tsconfig","matcher","createMatcher","rootFiles","iterator","Iterator","forEach","entry","stats","isFile","typeFileRegEx","fullPath","err","compilerOptions","config","rootDir","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","downlevelIteration","undefined","ignoreDeprecations","rewrite","rewriteRelativeImportExtensions","tempDir","join","String","pid","Date","now","tempConfigPath","tempConfig","files","include","exclude","references","fs","mkdir","recursive","mkdirErr","writeFile","JSON","stringify","writeErr","safeRm","force","runErr","status","msg","slice","Error","emittedFiles","postQueue","Queue","file","defer","readFile","readErr","content","updated","rewriteExtensions","await","rmErr"],"mappings":";;;;+BAwEA;;;eAAwBA;;;mEAxEoC;yDAC7C;iEACsB;8BACd;yDACR;2DACE;8DACC;qEACK;2BAMO;sEACJ;mCACQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IANYC;AAA9C,IAAMC,cAAcC,KAAKC,GAAG,CAAC,IAAID,KAAKE,GAAG,CAAC,GAAG,UAACJ,WAAAA,WAAE,CAACK,IAAI,gBAAPL,+BAAAA,SAAWM,MAAM,uCAAI,KAAK;AAExE,IAAMC,UAAUC,IAAAA,uBAAU,EAAC,cAAc;AAQzC,yDAAyD,GAEzD,SAASC,kBAAkBC,QAAgB;IACzC,OACEA,SAASC,QAAQ,CAAC,YAClBD,SAASC,QAAQ,CAAC,aAClBD,SAASC,QAAQ,CAAC,aAClBD,SAASC,QAAQ,CAAC,UAClBD,SAAS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,SAAS,IAAIqD,MAAM;;wBAC3E;oBACF;oBAEA,IAAME,YAAY,IAAIC,gBAAK;oBAE3B,IAAI/B,SAAS;4BACN,kCAAA,2BAAA;;;gCAAA,IAAMgC,OAAN;gCACHF,UAAUG,KAAK,CAAC,SAACvF;oCACfoE,WAAE,CAACoB,QAAQ,CAACF,MAAM,QAAQ,SAACG,SAASC;wCAClC,IAAID,SAAS,OAAOzF;wCACpB,IAAM2F,UAAUC,IAAAA,sCAAiB,EAACF;wCAClCC,YAAYD,UAAU1F,OAAOoE,WAAE,CAACI,SAAS,CAACc,MAAMK,SAAS,QAAQ3F;oCACnE;gCACF;4BACF;4BARA,QAAK,YAAcmF,iCAAd,SAAA,6BAAA,QAAA,yBAAA;;4BAAA;4BAAA;;;qCAAA,6BAAA;oCAAA;;;oCAAA;0CAAA;;;;oBASP;oBAEAC,UAAUS,KAAK,CAAC;wBACdjB,IAAAA,sBAAM,EAACpB,SAAS;4BAAEc,WAAW;4BAAMO,OAAO;wBAAK,GAAG,SAACiB;mCAAUjE,SAASiE,SAAS,MAAMX;;oBACvF;gBACF;YACF;QACF;IACF;AAEJ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import spawn, { type SpawnCallback, type SpawnResult } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport { safeRm } from 'fs-remove-compat';\nimport os from 'os';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\n\nconst concurrency = Math.min(64, Math.max(8, (os.cpus()?.length ?? 4) * 8));\n\nconst tscPath = resolveBin('typescript', 'tsc');\n\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { InternalConfigOptions, TransformTypesCallback } from '../types.ts';\n\n/* ---------------- root file filtering ---------------- */\n\nfunction isAllowedRootFile(basename: string): boolean {\n return (\n basename.endsWith('.d.ts') ||\n basename.endsWith('.d.mts') ||\n basename.endsWith('.d.cts') ||\n basename.endsWith('.ts') ||\n basename.endsWith('.tsx') ||\n basename.endsWith('.mts') ||\n basename.endsWith('.cts') ||\n basename.endsWith('.js') ||\n basename.endsWith('.jsx') ||\n basename.endsWith('.mjs') ||\n basename.endsWith('.cjs')\n );\n}\n\n/* ---------------- compiler execution ---------------- */\n\nfunction runCompiler(cmdPath: string, args: string[], cb: SpawnCallback): void {\n spawn(process.execPath, [cmdPath, ...args], { encoding: 'utf8' }, cb);\n}\n\n/* ---------------- emitted file parsing ---------------- */\n\nfunction parseEmittedFiles(res: SpawnResult, dest: string): string[] {\n const out: string[] = [];\n const seen = new Set<string>();\n const lines = `${res.stdout}\\n${res.stderr}`.split(/\\r?\\n/);\n\n for (let line of lines) {\n line = line.trim();\n if (!line) continue;\n\n if (/^TSFILE:\\s+/i.test(line)) line = line.replace(/^TSFILE:\\s+/i, '').trim();\n\n if (!path.isAbsolute(line)) continue;\n if (!(line.endsWith('.d.ts') || line.endsWith('.d.mts') || line.endsWith('.d.cts'))) continue;\n\n // Optional safety: only accept outputs under dest\n const rel = path.relative(dest, line);\n if (rel.startsWith('..') || path.isAbsolute(rel)) continue;\n\n if (!seen.has(line)) {\n seen.add(line);\n out.push(line);\n }\n }\n\n return out;\n}\n\nexport default function transformTypesWorker(src: string, dest: string, options: InternalConfigOptions, callback: TransformTypesCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const rootFiles: string[] = [];\n const iterator = new Iterator(src);\n\n iterator.forEach(\n (entry: Entry): void => {\n const stats = entry.stats as fs.Stats | undefined;\n if (!stats || !stats.isFile()) return;\n const basename = entry.basename as string;\n if (basename[0] === '.') return;\n if (typeFileRegEx.test(basename)) return;\n if (!isAllowedRootFile(basename)) return;\n if (!matcher(entry.fullPath)) return;\n\n rootFiles.push(entry.fullPath);\n },\n { concurrency },\n (err) => {\n if (err) return callback(err);\n if (rootFiles.length === 0) return callback(null, []);\n\n const compilerOptions = {\n ...tsconfig.config.compilerOptions,\n rootDir: src,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n // Suppress TS6 deprecation warnings (TS5101/TS5107) for consumers still on legacy Node-targeted options.\n ignoreDeprecations: '6.0',\n };\n\n const rewrite = (tsconfig.config.compilerOptions as { rewriteRelativeImportExtensions?: boolean } | undefined)?.rewriteRelativeImportExtensions === true;\n\n // Avoid collisions across concurrent runs.\n const tempDir = path.join(dest, '.ts-swc-transform-temp', String(process.pid), String(Date.now()));\n const tempConfigPath = path.join(tempDir, 'tsconfig.json');\n\n const tempConfig = {\n compilerOptions,\n files: rootFiles,\n include: [],\n exclude: [],\n ...(tsconfig.config.references && { references: tsconfig.config.references }),\n };\n\n fs.mkdir(tempDir, { recursive: true }, (mkdirErr) => {\n if (mkdirErr) return callback(mkdirErr);\n\n fs.writeFile(tempConfigPath, JSON.stringify(tempConfig, null, 2), 'utf8', (writeErr) => {\n if (writeErr) {\n safeRm(tempDir, { recursive: true, force: true }, () => callback(writeErr));\n return;\n }\n\n const args = ['--project', tempConfigPath, '--listEmittedFiles', '--pretty', 'false'];\n\n runCompiler(tscPath, args, (runErr, res) => {\n if (runErr || !res || res.status !== 0) {\n // cross-spawn-cb sets runErr (with stdout/stderr/status copied onto it) on non-zero exit\n // and does NOT pass res — read from runErr first, then fall back to res.\n const source = (runErr as unknown as SpawnResult | undefined) ?? res;\n const status = source?.status;\n const stdout = String(source?.stdout ?? '');\n const stderr = String(source?.stderr ?? '');\n const detail = `TypeScript compiler failed (status=${status}).\\nstdout:\\n${stdout.slice(0, 100_000)}\\nstderr:\\n${stderr.slice(0, 20_000)}`;\n safeRm(tempDir, { recursive: true, force: true }, () => callback(new Error(detail)));\n return;\n }\n\n const emittedFiles = parseEmittedFiles(res, dest);\n if (emittedFiles.length === 0) {\n safeRm(tempDir, { recursive: true, force: true }, () => callback(new Error('TypeScript compiler produced no emitted declaration files')));\n return;\n }\n\n const postQueue = new Queue();\n\n if (rewrite) {\n for (const file of emittedFiles) {\n postQueue.defer((cb) => {\n fs.readFile(file, 'utf8', (readErr, content) => {\n if (readErr) return cb();\n const updated = rewriteExtensions(content);\n if (updated === content) cb();\n else fs.writeFile(file, updated, 'utf8', (err) => cb(err ?? undefined));\n });\n });\n }\n }\n\n postQueue.await(() => {\n safeRm(tempDir, { recursive: true, force: true }, (rmErr) => callback(rmErr || null, emittedFiles));\n });\n });\n });\n });\n }\n );\n}\n"],"names":["transformTypesWorker","os","concurrency","Math","min","max","cpus","length","tscPath","resolveBin","isAllowedRootFile","basename","endsWith","runCompiler","cmdPath","args","cb","spawn","process","execPath","encoding","parseEmittedFiles","res","dest","out","seen","Set","lines","stdout","stderr","split","line","trim","test","replace","path","isAbsolute","rel","relative","startsWith","has","add","push","src","options","callback","tsconfig","matcher","createMatcher","rootFiles","iterator","Iterator","forEach","entry","stats","isFile","typeFileRegEx","fullPath","err","compilerOptions","config","rootDir","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","ignoreDeprecations","rewrite","rewriteRelativeImportExtensions","tempDir","join","String","pid","Date","now","tempConfigPath","tempConfig","files","include","exclude","references","fs","mkdir","recursive","mkdirErr","writeFile","JSON","stringify","writeErr","safeRm","force","runErr","status","source","detail","slice","Error","emittedFiles","postQueue","Queue","file","defer","readFile","readErr","content","updated","rewriteExtensions","undefined","await","rmErr"],"mappings":";;;;+BAwEA;;;eAAwBA;;;mEAxEoC;yDAC7C;iEACsB;8BACd;yDACR;2DACE;8DACC;qEACK;2BAMO;sEACJ;mCACQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IANYC;AAA9C,IAAMC,cAAcC,KAAKC,GAAG,CAAC,IAAID,KAAKE,GAAG,CAAC,GAAG,UAACJ,WAAAA,WAAE,CAACK,IAAI,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MZ;;oBACvF;gBACF;YACF;QACF;IACF;AAEJ"}
@@ -1,5 +1,5 @@
1
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; }";
2
2
  import type { Output } from '@swc/core';
3
3
  import type { Entry } from 'fs-iterator';
4
- import type { ConfigOptions } from '../types.js';
5
- export default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string;
4
+ import type { InternalConfigOptions } from '../types.js';
5
+ export default function patchCJS(entry: Entry, output: Output, options: InternalConfigOptions): string;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\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\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensionsCJS","interop","patchCJS","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,yBAAyB;AAEhF,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAW3R,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGX,qBAAqBI,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIV;IAEf,OAAOF,iBAAiBD,KAAKc,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\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\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { InternalConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: InternalConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensionsCJS","interop","patchCJS","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,yBAAyB;AAEhF,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAW3R,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGX,qBAAqBI,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIV;IAEf,OAAOF,iBAAiBD,KAAKc,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
@@ -1,4 +1,4 @@
1
1
  import type { Output } from '@swc/core';
2
2
  import type { Entry } from 'fs-iterator';
3
- import type { ConfigOptions } from '../types.js';
4
- export default function patchESM(entry: Entry, output: Output, options: ConfigOptions): string;
3
+ import type { InternalConfigOptions } from '../types.js';
4
+ export default function patchESM(entry: Entry, output: Output, options: InternalConfigOptions): string;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchESM.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport path from 'path';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\nimport { replaceExtension, rewriteExtensions } from './rewriteExtensions.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchESM(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensions(output.code);\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensions","patchESM","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAEA,OAAOA,UAAU,OAAO;AAGxB,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,yBAAyB;AAM7E,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGV,kBAAkBG,OAAOO,IAAI;IAExD,OAAOX,iBAAiBD,KAAKa,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchESM.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport path from 'path';\nimport type { CompilerOptions } from 'typescript';\nimport type { InternalConfigOptions } from '../types.ts';\nimport { replaceExtension, rewriteExtensions } from './rewriteExtensions.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchESM(entry: Entry, output: Output, options: InternalConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensions(output.code);\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensions","patchESM","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAEA,OAAOA,UAAU,OAAO;AAGxB,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,yBAAyB;AAM7E,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGV,kBAAkBG,OAAOO,IAAI;IAExD,OAAOX,iBAAiBD,KAAKa,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
@@ -21,7 +21,7 @@ export default function prepareSWCOptions(tsconfig) {
21
21
  const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));
22
22
  return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
23
23
  } catch (err) {
24
- console.log(`prepareSWCOptions failed: ${err.message}`);
24
+ console.log(`prepareSWCOptions failed: ${err instanceof Error ? err.message : String(err)}`);
25
25
  return {};
26
26
  }
27
27
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/prepareSWCOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync, matchesLibc } from 'install-optional';\nimport debounce from 'lodash.debounce';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TSConfig } from '../types.ts';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nconst installSyncSWC = debounce(installSync, 300, { leading: true, trailing: false });\n\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname, filter: matchesLibc });\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(`prepareSWCOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["installSync","matchesLibc","debounce","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","installSyncSWC","leading","trailing","prepareSWCOptions","tsconfig","process","platform","arch","cwd","filter","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAC5D,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AASjH,MAAMQ,iBAAiBX,SAASF,aAAa,KAAK;IAAEc,SAAS;IAAMC,UAAU;AAAM;AAEnF,eAAe,SAASC,kBAAkBC,QAAkB;IAC1DJ,eAAe,aAAa,GAAGK,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKZ;QAAWa,QAAQrB;IAAY;IACzG,IAAI;QACF,MAAMsB,KAAKjB,SAAS;QACpB,MAAMkB,MAAMlB,SAAS;QACrB,MAAMmB,aAAanB,SAAS;QAC5B,MAAMoB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEzB,KAAKM,OAAO,CAACO,SAASb,IAAI;QAChG,OAAOqB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,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/prepareSWCOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync, matchesLibc } from 'install-optional';\nimport debounce from 'lodash.debounce';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TSConfig } from '../types.ts';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nconst installSyncSWC = debounce(installSync, 300, { leading: true, trailing: false });\n\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname, filter: matchesLibc });\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(`prepareSWCOptions failed: ${err instanceof Error ? err.message : String(err)}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["installSync","matchesLibc","debounce","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","installSyncSWC","leading","trailing","prepareSWCOptions","tsconfig","process","platform","arch","cwd","filter","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","Error","message","String"],"mappings":"AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAC5D,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AASjH,MAAMQ,iBAAiBX,SAASF,aAAa,KAAK;IAAEc,SAAS;IAAMC,UAAU;AAAM;AAEnF,eAAe,SAASC,kBAAkBC,QAAkB;IAC1DJ,eAAe,aAAa,GAAGK,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKZ;QAAWa,QAAQrB;IAAY;IACzG,IAAI;QACF,MAAMsB,KAAKjB,SAAS;QACpB,MAAMkB,MAAMlB,SAAS;QACrB,MAAMmB,aAAanB,SAAS;QAC5B,MAAMoB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEzB,KAAKM,OAAO,CAACO,SAASb,IAAI;QAChG,OAAOqB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,eAAeG,QAAQH,IAAII,OAAO,GAAGC,OAAOL,MAAM;QAC3F,OAAO,CAAC;IACV;AACF"}
@@ -1,9 +1,4 @@
1
- export declare const extensions: {
2
- '.ts': string;
3
- '.tsx': string;
4
- '.mts': string;
5
- '.cts': string;
6
- };
1
+ export declare const extensions: Record<string, string>;
7
2
  export declare function replaceExtension(ext: string): string;
8
3
  export declare function rewriteExtensions(content: string): string;
9
4
  export declare function rewriteExtensionsCJS(content: string): string;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import { stringStartsWith } from '../compat.ts';\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 stringStartsWith(path, './') || stringStartsWith(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":["stringStartsWith","extensions","replaceExtension","ext","replace","undefined","isRelativePath","path","rewriteExtensions","content","result","match","_keyword","_typeKeyword","newExt","rewriteExtensionsCJS"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,eAAe;AAEhD,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,iBAAiBO,MAAM,SAASP,iBAAiBO,MAAM;AAChE;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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E,GAAGW,OAAO,EAAE,CAAC;IACrH;IAEA,OAAOJ;AACT;AAEA,8DAA8D;AAC9D,OAAO,SAASK,qBAAqBN,OAAe;IAClD,8BAA8B;IAC9B,IAAIC,SAASF,kBAAkBC;IAE/B,2CAA2C;IAC3C,gCAAgC;IAChCC,SAASA,OAAON,OAAO,CAAC,2DAA2D,CAACO,OAAOJ,MAAMJ;QAC/F,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,OAAOJ;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import { stringStartsWith } from '../compat.ts';\n\nexport const extensions: Record<string, string> = {\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 stringStartsWith(path, './') || stringStartsWith(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":["stringStartsWith","extensions","replaceExtension","ext","replace","undefined","isRelativePath","path","rewriteExtensions","content","result","match","_keyword","_typeKeyword","newExt","rewriteExtensionsCJS"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,eAAe;AAEhD,OAAO,MAAMC,aAAqC;IAChD,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,iBAAiBO,MAAM,SAASP,iBAAiBO,MAAM;AAChE;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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ACzC,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,OAAOJ;AACT"}
@@ -1,3 +1,3 @@
1
1
  import type { Entry } from 'fs-iterator';
2
- import type { ConfigOptions, TargetType, TransformFileCallback } from '../types.js';
3
- export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, mode: number | undefined, callback: TransformFileCallback): void;
2
+ import type { InternalConfigOptions, TargetType, TransformFileCallback } from '../types.js';
3
+ export default function transformFile(entry: Entry, dest: string, type: TargetType, options: InternalConfigOptions, mode: number | undefined, callback: TransformFileCallback): void;
@@ -1,5 +1,4 @@
1
1
  import fs from 'fs';
2
- import mkdirp from 'mkdirp-classic';
3
2
  import Module from 'module';
4
3
  import path from 'path';
5
4
  import Queue from 'queue-cb';
@@ -7,21 +6,24 @@ import patchCJS from '../lib/patchCJS.js';
7
6
  import patchESM from '../lib/patchESM.js';
8
7
  import prepareSWCOptions from '../lib/prepareSWCOptions.js';
9
8
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
9
+ // mkdirp-classic ships no types and @types/mkdirp-classic does not exist on npm — load via require to keep type-checking clean
10
+ const mkdirp = _require('mkdirp-classic');
10
11
  export default function transformFile(entry, dest, type, options, mode, callback) {
11
12
  let tsconfig = options.tsconfig;
12
13
  // overrides for cjs
13
14
  if (type === 'cjs') {
14
- tsconfig = {
15
- ...tsconfig
16
- };
17
- tsconfig.config = {
18
- ...tsconfig.config
15
+ const compilerOptions = {
16
+ ...tsconfig.config.compilerOptions || {},
17
+ module: 'commonjs',
18
+ target: 'es5'
19
19
  };
20
- tsconfig.config.compilerOptions = {
21
- ...tsconfig.config.compilerOptions || {}
20
+ tsconfig = {
21
+ ...tsconfig,
22
+ config: {
23
+ ...tsconfig.config,
24
+ compilerOptions
25
+ }
22
26
  };
23
- tsconfig.config.compilerOptions.module = 'commonjs';
24
- tsconfig.config.compilerOptions.target = 'es5';
25
27
  }
26
28
  const swcOptions = prepareSWCOptions(tsconfig);
27
29
  const swc = _require('@swc/core');
@@ -35,8 +37,8 @@ export default function transformFile(entry, dest, type, options, mode, callback
35
37
  const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
36
38
  mkdirp(path.dirname(outPath), ()=>{
37
39
  const queue = new Queue();
38
- queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
39
- if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
40
+ queue.defer((cb)=>fs.writeFile(outPath, output.code, 'utf8', (err)=>cb(err !== null && err !== void 0 ? err : undefined)));
41
+ if (output.map && options.sourceMaps) queue.defer((cb)=>fs.writeFile(`${outPath}.map`, output.map, 'utf8', (err)=>cb(err !== null && err !== void 0 ? err : undefined)));
40
42
  queue.await((err)=>{
41
43
  if (err) return callback(err);
42
44
  if (mode) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, mode: number | undefined, callback: TransformFileCallback): void {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => {\n if (err) return callback(err);\n\n if (mode) {\n const execBits = mode & 0o111;\n if (execBits) {\n fs.chmod(outPath, 0o644 | execBits, (_chmodErr) => {\n callback(null, outPath);\n });\n return;\n }\n }\n callback(null, outPath);\n });\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","transformFile","entry","dest","type","options","mode","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","ext","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","map","sourceMaps","await","err","execBits","chmod","_chmodErr","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5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ACmC,KAAK,CAAC,GAAG,CAACZ,IAAIa,MAAM,IAAI1B,MAAMV,IAAI,AAAD,IAAKgC;QAExFlC,OAAOE,KAAKqC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIrC;YAClBqC,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASF,OAAOW,IAAI,EAAE;YAC1D,IAAIX,OAAOY,GAAG,IAAI9B,QAAQ+B,UAAU,EAAEN,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEF,OAAOY,GAAG,EAAE;YACxGL,MAAMO,KAAK,CAAC,CAACC;gBACX,IAAIA,KAAK,OAAO/B,SAAS+B;gBAEzB,IAAIhC,MAAM;oBACR,MAAMiC,WAAWjC,OAAO;oBACxB,IAAIiC,UAAU;wBACZlD,GAAGmD,KAAK,CAACf,SAAS,QAAQc,UAAU,CAACE;4BACnClC,SAAS,MAAMkB;wBACjB;wBACA;oBACF;gBACF;gBACAlB,SAAS,MAAMkB;YACjB;QACF;IACF,GACCiB,KAAK,CAACnC;AACX"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// mkdirp-classic ships no types and @types/mkdirp-classic does not exist on npm — load via require to keep type-checking clean\nconst mkdirp: (p: string, cb: (err: Error | null) => void) => void = _require('mkdirp-classic');\n\nimport type { InternalConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: InternalConfigOptions, mode: number | undefined, callback: TransformFileCallback): void {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n const compilerOptions = { ...(tsconfig.config.compilerOptions || {}), module: 'commonjs' as const, target: 'es5' as const };\n tsconfig = { ...tsconfig, config: { ...tsconfig.config, compilerOptions } };\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename as string);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer((cb) => fs.writeFile(outPath, output.code, 'utf8', (err) => cb(err ?? undefined)));\n if (output.map && options.sourceMaps) queue.defer((cb) => fs.writeFile(`${outPath}.map`, output.map as string, 'utf8', (err) => cb(err ?? undefined)));\n queue.await((err) => {\n if (err) return callback(err);\n\n if (mode) {\n const execBits = mode & 0o111;\n if (execBits) {\n fs.chmod(outPath, 0o644 | execBits, (_chmodErr) => {\n callback(null, outPath);\n });\n return;\n }\n }\n callback(null, outPath);\n });\n });\n })\n .catch(callback);\n}\n"],"names":["fs","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","mkdirp","transformFile","entry","dest","type","options","mode","callback","tsconfig","compilerOptions","config","module","target","swcOptions","swc","ext","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","outPath","join","slice","length","dirname","queue","defer","cb","writeFile","code","err","undefined","map","sourceMaps","await","execBits","chmod","_chmodErr","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAA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AACZ,IAAIa,MAAM,IAAI1B,MAAMX,IAAI,AAAD,IAAKiC;QAExFxB,OAAOT,KAAKsC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAItC;YAClBsC,MAAMC,KAAK,CAAC,CAACC,KAAO3C,GAAG4C,SAAS,CAACR,SAASF,OAAOW,IAAI,EAAE,QAAQ,CAACC,MAAQH,GAAGG,gBAAAA,iBAAAA,MAAOC;YAClF,IAAIb,OAAOc,GAAG,IAAIhC,QAAQiC,UAAU,EAAER,MAAMC,KAAK,CAAC,CAACC,KAAO3C,GAAG4C,SAAS,CAAC,GAAGR,QAAQ,IAAI,CAAC,EAAEF,OAAOc,GAAG,EAAY,QAAQ,CAACF,MAAQH,GAAGG,gBAAAA,iBAAAA,MAAOC;YAC1IN,MAAMS,KAAK,CAAC,CAACJ;gBACX,IAAIA,KAAK,OAAO5B,SAAS4B;gBAEzB,IAAI7B,MAAM;oBACR,MAAMkC,WAAWlC,OAAO;oBACxB,IAAIkC,UAAU;wBACZnD,GAAGoD,KAAK,CAAChB,SAAS,QAAQe,UAAU,CAACE;4BACnCnC,SAAS,MAAMkB;wBACjB;wBACA;oBACF;gBACF;gBACAlB,SAAS,MAAMkB;YACjB;QACF;IACF,GACCkB,KAAK,CAACpC;AACX"}
@@ -1,3 +1,4 @@
1
+ var _process_env_OSTYPE;
1
2
  // Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js
2
3
  // Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE
3
4
  import Module from 'module';
@@ -12,7 +13,7 @@ let URLClass = url.URL;
12
13
  if (!URLClass) {
13
14
  URLClass = _require('core-js-pure/actual/url/index.js');
14
15
  }
15
- const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
16
+ const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test((_process_env_OSTYPE = process.env.OSTYPE) !== null && _process_env_OSTYPE !== void 0 ? _process_env_OSTYPE : '');
16
17
  export function fileURLToPath(urlInput) {
17
18
  let parsedUrl;
18
19
  if (typeof urlInput === 'string') {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.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 Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nlet URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n let parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.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 = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["Module","path","url","stringReplaceAll","_require","require","createRequire","URLClass","URL","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","urlInput","parsedUrl","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,eAAe;AAEhD,yBAAyB;AACzB,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYJ,GAAG,IAAIG;AAE1F,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIE,WAAuB,AAACL,IAAYM,GAAG;AAC3C,IAAI,CAACD,UAAU;IACbA,WAAWH,SAAS;AACtB;AAEA,MAAMK,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,QAAsB;IAClD,IAAIC;IACJ,IAAI,OAAOD,aAAa,UAAU;QAChCC,YAAY,IA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MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAE5C,IAAI,CAACnB,WAAW;QACdmB,WAAWzB,iBAAiByB,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,CAAC,KAAK,EAAEqB,UAAU;AACxC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.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 Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nlet URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE ?? '');\n\nexport function fileURLToPath(urlInput: string | URL): string {\n let parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.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 = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["process","Module","path","url","stringReplaceAll","_require","require","createRequire","URLClass","URL","isWindows","platform","test","env","OSTYPE","fileURLToPath","urlInput","parsedUrl","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"IAmByEA;AAnBzE,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,eAAe;AAEhD,yBAAyB;AACzB,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYJ,GAAG,IAAIG;AAE1F,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIE,WAAuB,AAACL,IAAYM,GAAG;AAC3C,IAAI,CAACD,UAAU;IACbA,WAAWH,SAAS;AACtB;AAEA,MAAMK,YAAYV,QAAQW,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,EAACZ,sBAAAA,QA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nEA,WAAWxB,iBAAiBwB,UAAU,KAAK;IAC3CA,WAAWxB,iBAAiBwB,UAAU,KAAK;IAC3CA,WAAWxB,iBAAiBwB,UAAU,MAAM;IAC5CA,WAAWxB,iBAAiBwB,UAAU,MAAM;IAC5CA,WAAWxB,iBAAiBwB,UAAU,MAAM;IAE5C,IAAI,CAAClB,WAAW;QACdkB,WAAWxB,iBAAiBwB,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIpB,SAAS,CAAC,KAAK,EAAEoB,UAAU;AACxC"}
@@ -1,2 +1,2 @@
1
1
  import type { Context } from './types.js';
2
- export default function resolveFileSync(specifier: string, context?: Context): string;
2
+ export default function resolveFileSync(specifier: string, context?: Context): string | null;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { arrayFind } from './compat.ts';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.ts';\nimport toPath from './toPath.ts';\nimport type { Context } from './types.ts';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context): string {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier[specifier.length - 1] === '/') {\n const items = fs.readdirSync(filePath);\n const item = arrayFind(indexExtensions, (x) => items.indexOf(x) !== -1);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = arrayFind(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","arrayFind","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","length","items","readdirSync","item","indexOf","join","test","ext","extname","basename","slice","dirname","extTest","basenameTest"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,EAAEC,WAAW,EAAEC,aAAa,QAAQ,iBAAiB;AACxE,OAAOC,YAAY,cAAc;AAGjC,MAAMC,kBAAkBJ,WAAWK,GAAG,CAAC,CAACC,IAAM,CAAC,KAAK,EAAEA,GAAG;AAEzD,eAAe,SAASC,gBAAgBC,SAAiB,EAAEC,OAAiB;IAC1E,MAAMC,WAAWP,OAAOK,WAAWC;IACnC,IAAIE;IACJ,IAAI;QACFA,OAAOd,GAAGe,QAAQ,CAACF;IACrB,EAAE,OAAOG,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACF,QAAQA,KAAKG,WAAW,MAAON,SAAS,CAACA,UAAUO,MAAM,GAAG,EAAE,KAAK,KAAK;YAC3E,MAAMC,QAAQnB,GAAGoB,WAAW,CAACP;YAC7B,MAAMQ,OAAOnB,UAAUK,iBAAiB,CAACE,IAAMU,MAAMG,OAAO,CAACb,OAAO,CAAC;YACrE,IAAIY,MAAM,OAAOpB,KAAKsB,IAAI,CAACV,UAAUQ;QACvC,OAAO,IAAI,CAACP,QAAQ,CAACV,YAAYoB,IAAI,CAACb,YAAY;YAChD,MAAMc,MAAMxB,KAAKyB,OAAO,CAACb;YACzB,MAAMc,WAAWF,MAAMxB,KAAK0B,QAAQ,CAACd,UAAUe,KAAK,CAAC,GAAG,CAACH,IAAIP,MAAM,IAAIjB,KAAK0B,QAAQ,CAACd;YACrF,MAAMM,QAAQnB,GAAGoB,WAAW,CAACnB,KAAK4B,OAAO,CAAChB;YAC1C,MAAMQ,OAAOnB,UAAUiB,OAAO,CAACV;gBAC7B,IAAIJ,cAAcmB,IAAI,CAACf,IAAI,OAAO;gBAClC,MAAMqB,UAAU7B,KAAKyB,OAAO,CAACjB;gBAC7B,MAAMsB,eAAeD,UAAU7B,KAAK0B,QAAQ,CAAClB,GAAGmB,KAAK,CAAC,GAAG,CAACE,QAAQZ,MAAM,IAAIjB,KAAK0B,QAAQ,CAAClB;gBAC1F,OAAOkB,aAAaI;YACtB;YACA,IAAIV,MAAM,OAAOpB,KAAKsB,IAAI,CAACtB,KAAK4B,OAAO,CAAChB,WAAWQ;QACrD;QACA,wBAAwB;QACxB,OAAOP,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { arrayFind } from './compat.ts';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.ts';\nimport toPath from './toPath.ts';\nimport type { Context } from './types.ts';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context): string | null {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats | undefined;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier[specifier.length - 1] === '/') {\n const items = fs.readdirSync(filePath);\n const item = arrayFind(indexExtensions, (x) => items.indexOf(x) !== -1);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = arrayFind(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","arrayFind","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","length","items","readdirSync","item","indexOf","join","test","ext","extname","basename","slice","dirname","extTest","basenameTest"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,EAAEC,WAAW,EAAEC,aAAa,QAAQ,iBAAiB;AACxE,OAAOC,YAAY,cAAc;AAGjC,MAAMC,kBAAkBJ,WAAWK,GAAG,CAAC,CAACC,IAAM,CAAC,KAAK,EAAEA,GAAG;AAEzD,eAAe,SAASC,gBAAgBC,SAAiB,EAAEC,OAAiB;IAC1E,MAAMC,WAAWP,OAAOK,WAAWC;IACnC,IAAIE;IACJ,IAAI;QACFA,OAAOd,GAAGe,QAAQ,CAACF;IACrB,EAAE,OAAOG,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACF,QAAQA,KAAKG,WAAW,MAAON,SAAS,CAACA,UAAUO,MAAM,GAAG,EAAE,KAAK,KAAK;YAC3E,MAAMC,QAAQnB,GAAGoB,WAAW,CAACP;YAC7B,MAAMQ,OAAOnB,UAAUK,iBAAiB,CAACE,IAAMU,MAAMG,OAAO,CAACb,OAAO,CAAC;YACrE,IAAIY,MAAM,OAAOpB,KAAKsB,IAAI,CAACV,UAAUQ;QACvC,OAAO,IAAI,CAACP,QAAQ,CAACV,YAAYoB,IAAI,CAACb,YAAY;YAChD,MAAMc,MAAMxB,KAAKyB,OAAO,CAACb;YACzB,MAAMc,WAAWF,MAAMxB,KAAK0B,QAAQ,CAACd,UAAUe,KAAK,CAAC,GAAG,CAACH,IAAIP,MAAM,IAAIjB,KAAK0B,QAAQ,CAACd;YACrF,MAAMM,QAAQnB,GAAGoB,WAAW,CAACnB,KAAK4B,OAAO,CAAChB;YAC1C,MAAMQ,OAAOnB,UAAUiB,OAAO,CAACV;gBAC7B,IAAIJ,cAAcmB,IAAI,CAACf,IAAI,OAAO;gBAClC,MAAMqB,UAAU7B,KAAKyB,OAAO,CAACjB;gBAC7B,MAAMsB,eAAeD,UAAU7B,KAAK0B,QAAQ,CAAClB,GAAGmB,KAAK,CAAC,GAAG,CAACE,QAAQZ,MAAM,IAAIjB,KAAK0B,QAAQ,CAAClB;gBAC1F,OAAOkB,aAAaI;YACtB;YACA,IAAIV,MAAM,OAAOpB,KAAKsB,IAAI,CAACtB,KAAK4B,OAAO,CAAChB,WAAWQ;QACrD;QACA,wBAAwB;QACxB,OAAOP,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
@@ -24,11 +24,11 @@ export default function transformDirectory(src, dest, type, options, callback) {
24
24
  options = typeof options === 'function' ? {} : options || {};
25
25
  const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);
26
26
  const opts = {
27
- tsconfig,
28
- ...options
27
+ ...options,
28
+ tsconfig
29
29
  };
30
30
  if (typeof callback === 'function') return worker(src, dest, type, opts, callback);
31
- return new Promise((resolve, reject)=>worker(src, dest, type, opts, (err, result)=>err ? reject(err) : resolve(result)));
31
+ return new Promise((resolve, reject)=>worker(src, dest, type, opts, (err, result)=>err ? reject(err) : resolve(result !== null && result !== void 0 ? result : [])));
32
32
  } catch (err) {
33
33
  if (typeof callback === 'function') return callback(err);
34
34
  return Promise.reject(err);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nfunction run(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n return _require(workerPath)(src, dest, type, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ConfigOptions);\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n const opts: ConfigOptions = { tsconfig, ...options };\n\n if (typeof callback === 'function') return worker(src, dest, type, opts, callback);\n return new Promise((resolve, reject) => worker(src, dest, type, opts, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (typeof callback === 'function') return callback(err);\n return Promise.reject(err);\n }\n}\n"],"names":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","src","dest","type","options","callback","worker","callbacks","spawnOptions","transformDirectory","Error","tsconfig","opts","Promise","res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;QAEnD,IAAI,OAAOC,aAAa,YAAY,OAAOC,OAAOL,KAAKC,MAAMC,MAAMS,MAAMP;QACzE,OAAO,IAAIQ,QAAQ,CAACC,SAASC,SAAWT,OAAOL,KAAKC,MAAMC,MAAMS,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG;IACtH,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOX,aAAa,YAAY,OAAOA,SAASW;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, InternalConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nfunction run(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n return _require(workerPath)(src, dest, type, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ConfigOptions);\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n const opts: InternalConfigOptions = { ...options, tsconfig };\n\n if (typeof callback === 'function') return worker(src, dest, type, opts, callback);\n return new Promise<string[]>((resolve, reject) => worker(src, dest, type, opts, (err, result) => (err ? reject(err) : resolve(result ?? []))));\n } catch (err) {\n if (typeof callback === 'function') return callback(err as Error);\n return Promise.reject(err);\n }\n}\n"],"names":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","src","dest","type","options","callback","worker","callbacks","spawnOptions","transformDirectory","Error","tsconfig","opts","Promise","resolve","reject","err","result"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,IAAI,QAAQ,oBAAoB;AACzC,OAAOC,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,WAAW,OAAOC,YAAY,cAAcX,OAAOY,aAAa,CAAC,YAAYR,GAAG,IAAIO;AAC1F,MAAME,YAAYX,KAAKY,OAAO,CAAC,OAAOC,eAAe,cAAcX,IAAIY,aAAa,CAAC,YAAYZ,GAAG,IAAIW;AACxG,MAAME,aAAaf,KAAKgB,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASM,IAAIC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACpH,OAAOd,SAASO,YAAYG,KAAKC,MAAMC,MAAMC,SAASC;AACxD;AAEA,8DAA8D;AAC9D,MAAMC,SAASpB,SAAS,KAAKc,MAAMlB,KAAK,QAAQgB,YAAY;IAAES,WAAW;IAAMC,cAAc;AAAM;AAMnG,eAAe,SAASC,mBAAmBR,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIS,MAAM;QAC7C,IAAI,OAAOR,SAAS,UAAU,MAAM,IAAIQ,MAAM;QAC9C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAE9CL,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAC7D,MAAMO,WAAWP,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,GAAG3B,eAAeiB;QACtE,MAAMW,OAA8B;YAAE,GAAGR,OAAO;YAAEO;QAAS;QAE3D,IAAI,OAAON,aAAa,YAAY,OAAOC,OAAOL,KAAKC,MAAMC,MAAMS,MAAMP;QACzE,OAAO,IAAIQ,QAAkB,CAACC,SAASC,SAAWT,OAAOL,KAAKC,MAAMC,MAAMS,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;IAC5I,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOX,aAAa,YAAY,OAAOA,SAASW;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
@@ -23,11 +23,11 @@ export default function transformTypes(src, dest, options, callback) {
23
23
  options = typeof options === 'function' ? {} : options || {};
24
24
  const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);
25
25
  const opts = {
26
- tsconfig,
27
- ...options
26
+ ...options,
27
+ tsconfig
28
28
  };
29
29
  if (typeof callback === 'function') return worker(src, dest, opts, callback);
30
- return new Promise((resolve, reject)=>worker(src, dest, opts, (err, result)=>err ? reject(err) : resolve(result)));
30
+ return new Promise((resolve, reject)=>worker(src, dest, opts, (err, result)=>err ? reject(err) : resolve(result !== null && result !== void 0 ? result : [])));
31
31
  } catch (err) {
32
32
  if (typeof callback === 'function') return callback(err);
33
33
  return Promise.reject(err);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nfunction run(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n return _require(workerPath)(src, dest, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ConfigOptions);\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n const opts: ConfigOptions = { tsconfig, ...options };\n\n if (typeof callback === 'function') return worker(src, dest, opts, callback);\n return new Promise((resolve, reject) => worker(src, dest, opts, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (typeof callback === 'function') return callback(err);\n return Promise.reject(err);\n }\n}\n"],"names":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","src","dest","options","callback","worker","callbacks","spawnOptions","transformTypes","Error","tsconfig","opts","Promise","resolve","reject","err","result"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,IAAI,QAAQ,oBAAoB;AACzC,OAAOC,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,WAAW,OAAOC,YAAY,cAAcX,OAAOY,aAAa,CAAC,YAAYR,GAAG,IAAIO;AAC1F,MAAME,YAAYX,KAAKY,OAAO,CAAC,OAAOC,eAAe,cAAcX,IAAIY,aAAa,CAAC,YAAYZ,GAAG,IAAIW;AACxG,MAAME,aAAaf,KAAKgB,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASM,IAAIC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9F,OAAOb,SAASO,YAAYG,KAAKC,MAAMC,SAASC;AAClD;AAEA,8DAA8D;AAC9D,MAAMC,SAASnB,SAAS,KAAKc,MAAMlB,KAAK,QAAQgB,YAAY;IAAEQ,WAAW;IAAMC,cAAc;AAAM;AAMnG,eAAe,SAASC,eAAeP,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAE9CL,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAC7D,MAAMO,WAAWP,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,GAAG1B,eAAeiB;QACtE,MAAMU,OAAsB;YAAED;YAAU,GAAGP,OAAO;QAAC;QAEnD,IAAI,OAAOC,aAAa,YAAY,OAAOC,OAAOJ,KAAKC,MAAMS,MAAMP;QACnE,OAAO,IAAIQ,QAAQ,CAACC,SAASC,SAAWT,OAAOJ,KAAKC,MAAMS,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG;IAChH,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOX,aAAa,YAAY,OAAOA,SAASW;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, InternalConfigOptions, TransformTypesCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nfunction run(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n return _require(workerPath)(src, dest, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ConfigOptions);\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n const opts: InternalConfigOptions = { ...options, tsconfig };\n\n if (typeof callback === 'function') return worker(src, dest, opts, callback);\n return new Promise<string[]>((resolve, reject) => worker(src, dest, opts, (err, result) => (err ? reject(err) : resolve(result ?? []))));\n } catch (err) {\n if (typeof callback === 'function') return callback(err as Error);\n return Promise.reject(err);\n }\n}\n"],"names":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","src","dest","options","callback","worker","callbacks","spawnOptions","transformTypes","Error","tsconfig","opts","Promise","resolve","reject","err","result"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,IAAI,QAAQ,oBAAoB;AACzC,OAAOC,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,WAAW,OAAOC,YAAY,cAAcX,OAAOY,aAAa,CAAC,YAAYR,GAAG,IAAIO;AAC1F,MAAME,YAAYX,KAAKY,OAAO,CAAC,OAAOC,eAAe,cAAcX,IAAIY,aAAa,CAAC,YAAYZ,GAAG,IAAIW;AACxG,MAAME,aAAaf,KAAKgB,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASM,IAAIC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9F,OAAOb,SAASO,YAAYG,KAAKC,MAAMC,SAASC;AAClD;AAEA,8DAA8D;AAC9D,MAAMC,SAASnB,SAAS,KAAKc,MAAMlB,KAAK,QAAQgB,YAAY;IAAEQ,WAAW;IAAMC,cAAc;AAAM;AAMnG,eAAe,SAASC,eAAeP,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAE9CL,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAC7D,MAAMO,WAAWP,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,GAAG1B,eAAeiB;QACtE,MAAMU,OAA8B;YAAE,GAAGR,OAAO;YAAEO;QAAS;QAE3D,IAAI,OAAON,aAAa,YAAY,OAAOC,OAAOJ,KAAKC,MAAMS,MAAMP;QACnE,OAAO,IAAIQ,QAAkB,CAACC,SAASC,SAAWT,OAAOJ,KAAKC,MAAMS,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;IACtI,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOX,aAAa,YAAY,OAAOA,SAASW;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
@@ -9,8 +9,11 @@ export interface ConfigOptions {
9
9
  cwd?: string;
10
10
  sourceMaps?: boolean;
11
11
  }
12
- export type TransformDirectoryCallback = (err?: Error, filePaths?: string[]) => void;
13
- export type TransformFileCallback = (err?: Error, destFilePath?: string) => void;
14
- export type TransformTypesCallback = (err?: Error, filePaths?: string[]) => void;
12
+ export interface InternalConfigOptions extends ConfigOptions {
13
+ tsconfig: TSConfig;
14
+ }
15
+ export type TransformDirectoryCallback = (err?: Error | null, filePaths?: string[]) => void;
16
+ export type TransformFileCallback = (err?: Error | null, destFilePath?: string) => void;
17
+ export type TransformTypesCallback = (err?: Error | null, filePaths?: string[]) => void;
15
18
  export type Matcher = (filePath: string) => boolean;
16
19
  export type TargetType = 'cjs' | 'esm';
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/types.ts"],"sourcesContent":["import type { TSConfig } from 'read-tsconfig-sync';\n\nexport interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n\nexport type { TSConfig, TSConfigSchema } from 'read-tsconfig-sync';\nexport interface ConfigOptions {\n tsconfig?: TSConfig;\n cwd?: string;\n sourceMaps?: boolean;\n}\n\nexport type TransformDirectoryCallback = (err?: Error, filePaths?: string[]) => void;\nexport type TransformFileCallback = (err?: Error, destFilePath?: string) => void;\nexport type TransformTypesCallback = (err?: Error, filePaths?: string[]) => void;\n\nexport type Matcher = (filePath: string) => boolean;\n\nexport type TargetType = 'cjs' | 'esm';\n"],"names":[],"mappings":"AAoBA,WAAuC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/types.ts"],"sourcesContent":["import type { TSConfig } from 'read-tsconfig-sync';\n\nexport interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n\nexport type { TSConfig, TSConfigSchema } from 'read-tsconfig-sync';\nexport interface ConfigOptions {\n tsconfig?: TSConfig;\n cwd?: string;\n sourceMaps?: boolean;\n}\n\n// Workers receive options after tsconfig has been resolved by the public entry points.\nexport interface InternalConfigOptions extends ConfigOptions {\n tsconfig: TSConfig;\n}\n\nexport type TransformDirectoryCallback = (err?: Error | null, filePaths?: string[]) => void;\nexport type TransformFileCallback = (err?: Error | null, destFilePath?: string) => void;\nexport type TransformTypesCallback = (err?: Error | null, filePaths?: string[]) => void;\n\nexport type Matcher = (filePath: string) => boolean;\n\nexport type TargetType = 'cjs' | 'esm';\n"],"names":[],"mappings":"AAyBA,WAAuC"}
@@ -1,2 +1,2 @@
1
- import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
2
- export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
1
+ import type { InternalConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
2
+ export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: InternalConfigOptions, callback: TransformDirectoryCallback): void;