ts-swc-transform 2.11.10 → 2.11.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +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 { 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":["patchCJS","interop","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensionsCJS","replaceExtension","path","extname","basename"],"mappings":";;;;;;;;;;;QAeA;eAAwBA;;QAXXC;eAAAA;;;2DAJI;mCACsC;;;;;;AAGhD,IAAMA,UAAU;AAWR,SAASD,SAASE,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,yCAAoB,EAACR,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIT;IAEf,OAAOW,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,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 { InternalConfigOptions } from '../types.ts';\n\n// Read straight off the parsed tsconfig JSON, which is arbitrary data rather\n// than typescript's own CompilerOptions.\ninterface InternalCompilerOptions {\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":["patchCJS","interop","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensionsCJS","replaceExtension","path","extname","basename"],"mappings":";;;;;;;;;;;QAgBA;eAAwBA;;QAZXC;eAAAA;;;2DAJI;mCACsC;;;;;;AAGhD,IAAMA,UAAU;AAYR,SAASD,SAASE,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,yCAAoB,EAACR,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIT;IAEf,OAAOW,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,QAAQ;AACrD"}
@@ -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 { 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":["patchESM","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensions","replaceExtension","path","extname","basename"],"mappings":";;;;+BAWA;;;eAAwBA;;;2DATP;mCAGmC;;;;;;AAMrC,SAASA,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,sCAAiB,EAACR,OAAOO,IAAI;IAExD,OAAOE,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,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 { InternalConfigOptions } from '../types.ts';\nimport { replaceExtension, rewriteExtensions } from './rewriteExtensions.ts';\n\n// Read straight off the parsed tsconfig JSON, which is arbitrary data rather\n// than typescript's own CompilerOptions.\ninterface InternalCompilerOptions {\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":["patchESM","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensions","replaceExtension","path","extname","basename"],"mappings":";;;;+BAYA;;;eAAwBA;;;2DAVP;mCAEmC;;;;;;AAQrC,SAASA,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,sCAAiB,EAACR,OAAOO,IAAI;IAExD,OAAOE,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,QAAQ;AACrD"}
@@ -12,7 +12,21 @@ var _installoptional = require("install-optional");
12
12
  var _lodashdebounce = /*#__PURE__*/ _interop_require_default(require("lodash.debounce"));
13
13
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
14
14
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
15
+ var _tsconstants = /*#__PURE__*/ _interop_require_default(require("ts-constants"));
15
16
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
17
+ function _define_property(obj, key, value) {
18
+ if (key in obj) {
19
+ Object.defineProperty(obj, key, {
20
+ value: value,
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true
24
+ });
25
+ } else {
26
+ obj[key] = value;
27
+ }
28
+ return obj;
29
+ }
16
30
  function _instanceof(left, right) {
17
31
  "@swc/helpers - instanceof";
18
32
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
@@ -26,12 +40,68 @@ function _interop_require_default(obj) {
26
40
  default: obj
27
41
  };
28
42
  }
43
+ function _object_spread(target) {
44
+ for(var i = 1; i < arguments.length; i++){
45
+ var source = arguments[i] != null ? arguments[i] : {};
46
+ var ownKeys = Object.keys(source);
47
+ if (typeof Object.getOwnPropertySymbols === "function") {
48
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
+ }));
51
+ }
52
+ ownKeys.forEach(function(key) {
53
+ _define_property(target, key, source[key]);
54
+ });
55
+ }
56
+ return target;
57
+ }
58
+ function ownKeys(object, enumerableOnly) {
59
+ var keys = Object.keys(object);
60
+ if (Object.getOwnPropertySymbols) {
61
+ var symbols = Object.getOwnPropertySymbols(object);
62
+ if (enumerableOnly) {
63
+ symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ });
66
+ }
67
+ keys.push.apply(keys, symbols);
68
+ }
69
+ return keys;
70
+ }
71
+ function _object_spread_props(target, source) {
72
+ source = source != null ? source : {};
73
+ if (Object.getOwnPropertyDescriptors) {
74
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
+ } else {
76
+ ownKeys(Object(source)).forEach(function(key) {
77
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
+ });
79
+ }
80
+ return target;
81
+ }
29
82
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
30
83
  var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
31
84
  var installSyncSWC = (0, _lodashdebounce.default)(_installoptional.installSync, 300, {
32
85
  leading: true,
33
86
  trailing: false
34
87
  });
88
+ // tsconfig spells enums as strings ("es2019", "react-jsx"); swc needs the numbers.
89
+ function enumValue(map, value) {
90
+ if (typeof value !== 'string') return value;
91
+ var wanted = value.replace(/-/g, '').toLowerCase();
92
+ var names = Object.keys(map);
93
+ for(var i = 0; i < names.length; i++){
94
+ if (typeof map[names[i]] === 'number' && names[i].toLowerCase() === wanted) return map[names[i]];
95
+ }
96
+ return undefined;
97
+ }
98
+ function normalizeCompilerOptions(raw) {
99
+ return _object_spread_props(_object_spread({}, raw), {
100
+ target: enumValue(_tsconstants.default.ScriptTarget, raw.target),
101
+ module: enumValue(_tsconstants.default.ModuleKind, raw.module),
102
+ jsx: enumValue(_tsconstants.default.JsxEmit, raw.jsx)
103
+ });
104
+ }
35
105
  function prepareSWCOptions(tsconfig) {
36
106
  installSyncSWC('@swc/core', "".concat(process.platform, "-").concat(process.arch), {
37
107
  cwd: __dirname,
@@ -41,8 +111,10 @@ function prepareSWCOptions(tsconfig) {
41
111
  var ts = _require('typescript');
42
112
  var swc = _require('@swc/core');
43
113
  var transpiler = _require('ts-node/transpilers/swc');
44
- var parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, _path.default.dirname(tsconfig.path));
45
- return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
114
+ // TypeScript 7 dropped the compiler API from the package root, so fall back
115
+ // to resolving the enum-valued fields directly.
116
+ var options = typeof ts.parseJsonConfigFileContent === 'function' ? ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, _path.default.dirname(tsconfig.path)).options : normalizeCompilerOptions(tsconfig.config.compilerOptions || {});
117
+ return transpiler.createSwcOptions(options, undefined, swc, 'swc');
46
118
  } catch (err) {
47
119
  console.log("prepareSWCOptions failed: ".concat(_instanceof(err, Error) ? err.message : String(err)));
48
120
  return {};
@@ -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 instanceof Error ? err.message : String(err)}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["prepareSWCOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","installSyncSWC","debounce","installSync","leading","trailing","tsconfig","process","platform","arch","cwd","filter","matchesLibc","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","Error","message","String"],"mappings":";;;;+BAmBA;;;eAAwBA;;;+BAlBiB;qEACpB;6DACF;2DACF;0DACD;;;;;;;;;;;;;;AAEhB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AASlG,IAAMC,iBAAiBC,IAAAA,uBAAQ,EAACC,4BAAW,EAAE,KAAK;IAAEC,SAAS;IAAMC,UAAU;AAAM;AAEpE,SAASf,kBAAkBgB,QAAkB;IAC1DL,eAAe,aAAa,AAAC,GAAsBM,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI,GAAI;QAAEC,KAAKf;QAAWgB,QAAQC,4BAAW;IAAC;IACzG,IAAI;QACF,IAAMC,KAAKtB,SAAS;QACpB,IAAMuB,MAAMvB,SAAS;QACrB,IAAMwB,aAAaxB,SAAS;QAC5B,IAAMyB,SAASH,GAAGI,0BAA0B,CAACX,SAASY,MAAM,EAAEL,GAAGM,GAAG,EAAEvB,aAAI,CAACC,OAAO,CAACS,SAASV,IAAI;QAChG,OAAOmB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAA6E,OAAjDF,AAAG,YAAHA,KAAeG,SAAQH,IAAII,OAAO,GAAGC,OAAOL;QACrF,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 tsConstants from 'ts-constants';\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\n// tsconfig spells enums as strings (\"es2019\", \"react-jsx\"); swc needs the numbers.\nfunction enumValue(map: Record<string, unknown>, value: unknown): unknown {\n if (typeof value !== 'string') return value;\n const wanted = value.replace(/-/g, '').toLowerCase();\n const names = Object.keys(map);\n for (let i = 0; i < names.length; i++) {\n if (typeof map[names[i]] === 'number' && names[i].toLowerCase() === wanted) return map[names[i]];\n }\n return undefined;\n}\n\nfunction normalizeCompilerOptions(raw: Record<string, unknown>): Record<string, unknown> {\n return {\n ...raw,\n target: enumValue(tsConstants.ScriptTarget as unknown as Record<string, unknown>, raw.target),\n module: enumValue(tsConstants.ModuleKind as unknown as Record<string, unknown>, raw.module),\n jsx: enumValue(tsConstants.JsxEmit as unknown as Record<string, unknown>, raw.jsx),\n };\n}\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 // TypeScript 7 dropped the compiler API from the package root, so fall back\n // to resolving the enum-valued fields directly.\n const options = typeof ts.parseJsonConfigFileContent === 'function' ? ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path)).options : normalizeCompilerOptions((tsconfig.config.compilerOptions || {}) as Record<string, unknown>);\n return transpiler.createSwcOptions(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":["prepareSWCOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","installSyncSWC","debounce","installSync","leading","trailing","enumValue","map","value","wanted","replace","toLowerCase","names","Object","keys","i","length","undefined","normalizeCompilerOptions","raw","target","tsConstants","ScriptTarget","module","ModuleKind","jsx","JsxEmit","tsconfig","process","platform","arch","cwd","filter","matchesLibc","ts","swc","transpiler","options","parseJsonConfigFileContent","config","sys","compilerOptions","createSwcOptions","err","console","log","Error","message","String"],"mappings":";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EC,KAAKpC;QAAWqC,QAAQC,4BAAW;IAAC;IACzG,IAAI;QACF,IAAMC,KAAK3C,SAAS;QACpB,IAAM4C,MAAM5C,SAAS;QACrB,IAAM6C,aAAa7C,SAAS;QAC5B,4EAA4E;QAC5E,gDAAgD;QAChD,IAAM8C,UAAU,OAAOH,GAAGI,0BAA0B,KAAK,aAAaJ,GAAGI,0BAA0B,CAACX,SAASY,MAAM,EAAEL,GAAGM,GAAG,EAAE5C,aAAI,CAACC,OAAO,CAAC8B,SAAS/B,IAAI,GAAGyC,OAAO,GAAGnB,yBAA0BS,SAASY,MAAM,CAACE,eAAe,IAAI,CAAC;QAClO,OAAOL,WAAWM,gBAAgB,CAACL,SAASpB,WAAWkB,KAAK;IAC9D,EAAE,OAAOQ,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAA6E,OAAjDF,AAAG,YAAHA,KAAeG,SAAQH,IAAII,OAAO,GAAGC,OAAOL;QACrF,OAAO,CAAC;IACV;AACF"}
@@ -101,12 +101,12 @@ function transformFile(entry, dest, type, options, mode, callback) {
101
101
  var queue = new _queuecb.default();
102
102
  queue.defer(function(cb) {
103
103
  return _fs.default.writeFile(outPath, output.code, 'utf8', function(err) {
104
- return cb(err !== null && err !== void 0 ? err : undefined);
104
+ return cb(err);
105
105
  });
106
106
  });
107
107
  if (output.map && options.sourceMaps) queue.defer(function(cb) {
108
108
  return _fs.default.writeFile("".concat(outPath, ".map"), output.map, 'utf8', function(err) {
109
- return cb(err !== null && err !== void 0 ? err : undefined);
109
+ return cb(err);
110
110
  });
111
111
  });
112
112
  queue.await(function(err) {
@@ -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';\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\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":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","mode","callback","tsconfig","compilerOptions","config","module","target","swcOptions","prepareSWCOptions","swc","ext","path","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","cb","fs","writeFile","code","err","undefined","map","sourceMaps","await","execBits","chmod","_chmodErr","catch"],"mappings":";;;;+BAgBA;;;eAAwBA;;;yDAfT;oEAEI;6DACA;2DACF;8DACC;iEAEG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAASF,cAAcK,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAA8B,EAAEC,IAAwB,EAAEC,QAA+B;IAC3K,IAAIC,WAAWH,QAAQG,QAAQ;IAE/B,oBAAoB;IACpB,IAAIJ,SAAS,OAAO;QAClB,IAAMK,kBAAkB,wCAAMD,SAASE,MAAM,CAACD,eAAe,IAAI,CAAC;YAAIE,QAAQ;YAAqBC,QAAQ;;QAC3GJ,WAAW,wCAAKA;YAAUE,QAAQ,wCAAKF,SAASE,MAAM;gBAAED,iBAAAA;;;IAC1D;IAEA,IAAMI,aAAaC,IAAAA,4BAAiB,EAACN;IACrC,IAAMO,MAAMjB,SAAS;IACrB,IAAMkB,MAAMC,aAAI,CAACC,OAAO,CAAChB,MAAMiB,QAAQ;IAEvCJ,IACGlB,aAAa,CAACK,MAAMkB,QAAQ,EAAE,wCACzBJ,QAAQ,UAAUA,QAAQ,SAASH,WAAWQ,UAAU,GAAGR,WAAWS,aAAa;QACvFC,UAAUrB,MAAMiB,QAAQ;QAEzBK,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYtB,SAAS,QAAQuB,IAAAA,mBAAQ,EAACzB,OAAOuB,QAAQpB,WAAWuB,IAAAA,mBAAQ,EAAC1B,OAAOuB,QAAQpB;QAC9F,IAAMW,MAAMC,aAAI,CAACC,OAAO,CAAChB,MAAMe,IAAI;QACnC,IAAMY,UAAUZ,aAAI,CAACa,IAAI,CAAC3B,MAAM,AAACa,CAAAA,MAAMd,MAAMe,IAAI,CAACc,KAAK,CAAC,GAAG,CAACf,IAAIgB,MAAM,IAAI9B,MAAMe,IAAI,AAAD,IAAKS;QAExFO,IAAAA,sBAAM,EAAChB,aAAI,CAACiB,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAAC,SAACC;uBAAOC,WAAE,CAACC,SAAS,CAACX,SAASJ,OAAOgB,IAAI,EAAE,QAAQ,SAACC;2BAAQJ,GAAGI,gBAAAA,iBAAAA,MAAOC;;;YAClF,IAAIlB,OAAOmB,GAAG,IAAIvC,QAAQwC,UAAU,EAAEV,MAAME,KAAK,CAAC,SAACC;uBAAOC,WAAE,CAACC,SAAS,CAAC,AAAC,GAAU,OAARX,SAAQ,SAAOJ,OAAOmB,GAAG,EAAY,QAAQ,SAACF;2BAAQJ,GAAGI,gBAAAA,iBAAAA,MAAOC;;;YAC1IR,MAAMW,KAAK,CAAC,SAACJ;gBACX,IAAIA,KAAK,OAAOnC,SAASmC;gBAEzB,IAAIpC,MAAM;oBACR,IAAMyC,WAAWzC,OAAO;oBACxB,IAAIyC,UAAU;wBACZR,WAAE,CAACS,KAAK,CAACnB,SAAS,MAAQkB,UAAU,SAACE;4BACnC1C,SAAS,MAAMsB;wBACjB;wBACA;oBACF;gBACF;gBACAtB,SAAS,MAAMsB;YACjB;QACF;IACF,GACCqB,KAAK,CAAC3C;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 mkdirp from 'mkdirp-classic';\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\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)));\n if (output.map && options.sourceMaps) queue.defer((cb) => fs.writeFile(`${outPath}.map`, output.map as string, 'utf8', (err) => cb(err)));\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":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","mode","callback","tsconfig","compilerOptions","config","module","target","swcOptions","prepareSWCOptions","swc","ext","path","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","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AK,CAAC,GAAG,CAACf,IAAIgB,MAAM,IAAI9B,MAAMe,IAAI,AAAD,IAAKS;QAExFO,IAAAA,sBAAM,EAAChB,aAAI,CAACiB,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAAC,SAACC;uBAAOC,WAAE,CAACC,SAAS,CAACX,SAASJ,OAAOgB,IAAI,EAAE,QAAQ,SAACC;2BAAQJ,GAAGI;;;YAC3E,IAAIjB,OAAOkB,GAAG,IAAItC,QAAQuC,UAAU,EAAET,MAAME,KAAK,CAAC,SAACC;uBAAOC,WAAE,CAACC,SAAS,CAAC,AAAC,GAAU,OAARX,SAAQ,SAAOJ,OAAOkB,GAAG,EAAY,QAAQ,SAACD;2BAAQJ,GAAGI;;;YACnIP,MAAMU,KAAK,CAAC,SAACH;gBACX,IAAIA,KAAK,OAAOnC,SAASmC;gBAEzB,IAAIpC,MAAM;oBACR,IAAMwC,WAAWxC,OAAO;oBACxB,IAAIwC,UAAU;wBACZP,WAAE,CAACQ,KAAK,CAAClB,SAAS,MAAQiB,UAAU,SAACE;4BACnCzC,SAAS,MAAMsB;wBACjB;wBACA;oBACF;gBACF;gBACAtB,SAAS,MAAMsB;YACjB;QACF;IACF,GACCoB,KAAK,CAAC1C;AACX"}
@@ -84,12 +84,14 @@ var worker = major >= 20 ? run : (0, _nodeversioncall.bind)('>=20', workerPath,
84
84
  });
85
85
  function transformDirectory(src, dest, type, options, callback) {
86
86
  try {
87
+ var _loadConfigSync;
87
88
  if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
88
89
  if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
89
90
  if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
90
91
  callback = typeof options === 'function' ? options : callback;
91
92
  options = typeof options === 'function' ? {} : options || {};
92
- var tsconfig = options.tsconfig ? options.tsconfig : (0, _readtsconfigsync.default)(src);
93
+ var tsconfig = options.tsconfig ? options.tsconfig : (_loadConfigSync = (0, _readtsconfigsync.default)(src)) !== null && _loadConfigSync !== void 0 ? _loadConfigSync : undefined;
94
+ if (!tsconfig) throw new Error('transformDirectory: failed to load tsconfig');
93
95
  var opts = _object_spread_props(_object_spread({}, options), {
94
96
  tsconfig: tsconfig
95
97
  });
@@ -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, 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":["transformDirectory","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","src","dest","type","options","callback","worker","bind","callbacks","spawnOptions","Error","tsconfig","loadConfigSync","opts","Promise","resolve","reject","err","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;6DAxBL;+BACE;2DACJ;uEACU;0DACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACpH,OAAOjB,SAASU,YAAYG,KAAKC,MAAMC,MAAMC,SAASC;AACxD;AAEA,8DAA8D;AAC9D,IAAMC,SAASvB,SAAS,KAAKiB,MAAMO,IAAAA,qBAAI,EAAC,QAAQT,YAAY;IAAEU,WAAW;IAAMC,cAAc;AAAM;AAMpF,SAAS3B,mBAAmBmB,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,IAAMO,WAAWP,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,GAAGC,IAAAA,yBAAc,EAACX;QACtE,IAAMY,OAA8B,wCAAKT;YAASO,UAAAA;;QAElD,IAAI,OAAON,aAAa,YAAY,OAAOC,OAAOL,KAAKC,MAAMC,MAAMU,MAAMR;QACzE,OAAO,IAAIS,QAAkB,SAACC,SAASC;mBAAWV,OAAOL,KAAKC,MAAMC,MAAMU,MAAM,SAACI,KAAKC;uBAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;;;IAC5I,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOZ,aAAa,YAAY,OAAOA,SAASY;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) ?? undefined);\n if (!tsconfig) throw new Error('transformDirectory: failed to load tsconfig');\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":["transformDirectory","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","src","dest","type","options","callback","worker","bind","callbacks","spawnOptions","loadConfigSync","Error","tsconfig","undefined","opts","Promise","resolve","reject","err","result"],"mappings":";;;;+BAwBA;;;eAAwBA;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,MAAM;QAC/B,IAAMG,OAA8B,wCAAKV;YAASQ,UAAAA;;QAElD,IAAI,OAAOP,aAAa,YAAY,OAAOC,OAAOL,KAAKC,MAAMC,MAAMW,MAAMT;QACzE,OAAO,IAAIU,QAAkB,SAACC,SAASC;mBAAWX,OAAOL,KAAKC,MAAMC,MAAMW,MAAM,SAACI,KAAKC;uBAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;;;IAC5I,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOb,aAAa,YAAY,OAAOA,SAASa;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
@@ -30,9 +30,11 @@ var worker = major >= 20 ? run : (0, _nodeversioncall.bindSync)('>=20', workerPa
30
30
  spawnOptions: false
31
31
  });
32
32
  function transformSync(contents, fileName, tsconfig) {
33
+ var _loadConfigSync;
33
34
  if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');
34
35
  if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');
35
- if (!tsconfig) tsconfig = (0, _readtsconfigsync.default)(process.cwd());
36
+ if (!tsconfig) tsconfig = (_loadConfigSync = (0, _readtsconfigsync.default)(process.cwd())) !== null && _loadConfigSync !== void 0 ? _loadConfigSync : undefined;
37
+ if (!tsconfig) throw new Error('transformSync: failed to load tsconfig');
36
38
  return worker(contents, fileName, tsconfig);
37
39
  }
38
40
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport { bindSync } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } 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', 'transformSync.js');\n\nfunction run(contents: string, fileName: string, tsconfig: TSConfig) {\n return _require(workerPath)(contents, fileName, tsconfig);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bindSync('>=20', workerPath, { spawnOptions: false });\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return worker(contents, fileName, tsconfig) as Output;\n}\n"],"names":["transformSync","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","contents","fileName","tsconfig","worker","bindSync","spawnOptions","Error","loadConfigSync","cwd"],"mappings":";;;;+BAqBA;;;eAAwBA;;;6DArBL;+BACM;2DACR;uEACU;0DACX;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IACjE,OAAOf,SAASU,YAAYG,UAAUC,UAAUC;AAClD;AAEA,8DAA8D;AAC9D,IAAMC,SAASrB,SAAS,KAAKiB,MAAMK,IAAAA,yBAAQ,EAAC,QAAQP,YAAY;IAAEQ,cAAc;AAAM;AAGvE,SAASxB,cAAcmB,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIM,MAAM;IAClD,IAAI,OAAOL,aAAa,UAAU,MAAM,IAAIK,MAAM;IAClD,IAAI,CAACJ,UAAUA,WAAWK,IAAAA,yBAAc,EAACxB,QAAQyB,GAAG;IACpD,OAAOL,OAAOH,UAAUC,UAAUC;AACpC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport { bindSync } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } 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', 'transformSync.js');\n\nfunction run(contents: string, fileName: string, tsconfig: TSConfig) {\n return _require(workerPath)(contents, fileName, tsconfig);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bindSync('>=20', workerPath, { spawnOptions: false });\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd()) ?? undefined;\n if (!tsconfig) throw new Error('transformSync: failed to load tsconfig');\n return worker(contents, fileName, tsconfig) as Output;\n}\n"],"names":["transformSync","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","contents","fileName","tsconfig","worker","bindSync","spawnOptions","loadConfigSync","Error","cwd","undefined"],"mappings":";;;;+BAqBA;;;eAAwBA;;;6DArBL;+BACM;2DACR;uEACU;0DACX;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IACjE,OAAOf,SAASU,YAAYG,UAAUC,UAAUC;AAClD;AAEA,8DAA8D;AAC9D,IAAMC,SAASrB,SAAS,KAAKiB,MAAMK,IAAAA,yBAAQ,EAAC,QAAQP,YAAY;IAAEQ,cAAc;AAAM;AAGvE,SAASxB,cAAcmB,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;QAGjEI;IAF1B,IAAI,OAAON,aAAa,UAAU,MAAM,IAAIO,MAAM;IAClD,IAAI,OAAON,aAAa,UAAU,MAAM,IAAIM,MAAM;IAClD,IAAI,CAACL,UAAUA,YAAWI,kBAAAA,IAAAA,yBAAc,EAACvB,QAAQyB,GAAG,iBAA1BF,6BAAAA,kBAAiCG;IAC3D,IAAI,CAACP,UAAU,MAAM,IAAIK,MAAM;IAC/B,OAAOJ,OAAOH,UAAUC,UAAUC;AACpC"}
@@ -84,11 +84,13 @@ var worker = major >= 20 ? run : (0, _nodeversioncall.bind)('>=20', workerPath,
84
84
  });
85
85
  function transformTypes(src, dest, options, callback) {
86
86
  try {
87
+ var _loadConfigSync;
87
88
  if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');
88
89
  if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');
89
90
  callback = typeof options === 'function' ? options : callback;
90
91
  options = typeof options === 'function' ? {} : options || {};
91
- var tsconfig = options.tsconfig ? options.tsconfig : (0, _readtsconfigsync.default)(src);
92
+ var tsconfig = options.tsconfig ? options.tsconfig : (_loadConfigSync = (0, _readtsconfigsync.default)(src)) !== null && _loadConfigSync !== void 0 ? _loadConfigSync : undefined;
93
+ if (!tsconfig) throw new Error('transformTypes: failed to load tsconfig');
92
94
  var opts = _object_spread_props(_object_spread({}, options), {
93
95
  tsconfig: tsconfig
94
96
  });
@@ -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, 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":["transformTypes","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","src","dest","options","callback","worker","bind","callbacks","spawnOptions","Error","tsconfig","loadConfigSync","opts","Promise","resolve","reject","err","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;6DAxBL;+BACE;2DACJ;uEACU;0DACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9F,OAAOhB,SAASU,YAAYG,KAAKC,MAAMC,SAASC;AAClD;AAEA,8DAA8D;AAC9D,IAAMC,SAAStB,SAAS,KAAKiB,MAAMM,IAAAA,qBAAI,EAAC,QAAQR,YAAY;IAAES,WAAW;IAAMC,cAAc;AAAM;AAMpF,SAAS1B,eAAemB,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,IAAMO,WAAWP,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,GAAGC,IAAAA,yBAAc,EAACV;QACtE,IAAMW,OAA8B,wCAAKT;YAASO,UAAAA;;QAElD,IAAI,OAAON,aAAa,YAAY,OAAOC,OAAOJ,KAAKC,MAAMU,MAAMR;QACnE,OAAO,IAAIS,QAAkB,SAACC,SAASC;mBAAWV,OAAOJ,KAAKC,MAAMU,MAAM,SAACI,KAAKC;uBAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;;;IACtI,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOZ,aAAa,YAAY,OAAOA,SAASY;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) ?? undefined);\n if (!tsconfig) throw new Error('transformTypes: failed to load tsconfig');\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":["transformTypes","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","src","dest","options","callback","worker","bind","callbacks","spawnOptions","loadConfigSync","Error","tsconfig","undefined","opts","Promise","resolve","reject","err","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;6DAxBL;+BACE;2DACJ;uEACU;0DACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC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D,KAAK;QACZ,IAAI,OAAOb,aAAa,YAAY,OAAOA,SAASa;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
@@ -104,6 +104,24 @@ var _ref;
104
104
  var _os_cpus;
105
105
  var concurrency = Math.min(64, Math.max(8, ((_ref = (_os_cpus = _os.default.cpus()) === null || _os_cpus === void 0 ? void 0 : _os_cpus.length) !== null && _ref !== void 0 ? _ref : 4) * 8));
106
106
  var tscPath = (0, _resolvebinsync.default)('typescript', 'tsc');
107
+ function compilerMajor() {
108
+ try {
109
+ var pkg = JSON.parse(_fs.default.readFileSync(_path.default.join(_path.default.dirname(tscPath), '..', 'package.json'), 'utf8'));
110
+ return +String(pkg.version).split('.')[0] || 0;
111
+ } catch (unused) {
112
+ return 0;
113
+ }
114
+ }
115
+ // TypeScript 7 removed options that only ever affected JS emit, which swc handles.
116
+ // Older compilers still accept them, so only rewrite when the installed tsc would reject them.
117
+ function sanitizeForCompiler(options) {
118
+ if (compilerMajor() < 7) return options;
119
+ var sanitized = _object_spread({}, options);
120
+ delete sanitized.downlevelIteration;
121
+ if (sanitized.moduleResolution === 'node' || sanitized.moduleResolution === 'node10') sanitized.moduleResolution = 'bundler';
122
+ if (typeof sanitized.target === 'string' && /^es[35]$/i.test(sanitized.target)) sanitized.target = 'es2015';
123
+ return sanitized;
124
+ }
107
125
  /* ---------------- root file filtering ---------------- */ function isAllowedRootFile(basename) {
108
126
  return basename.endsWith('.d.ts') || basename.endsWith('.d.mts') || basename.endsWith('.d.cts') || basename.endsWith('.ts') || basename.endsWith('.tsx') || basename.endsWith('.mts') || basename.endsWith('.cts') || basename.endsWith('.js') || basename.endsWith('.jsx') || basename.endsWith('.mjs') || basename.endsWith('.cjs');
109
127
  }
@@ -170,7 +188,7 @@ function transformTypesWorker(src, dest, options, callback) {
170
188
  var _tsconfig_config_compilerOptions;
171
189
  if (err1) return callback(err1);
172
190
  if (rootFiles.length === 0) return callback(null, []);
173
- var compilerOptions = _object_spread_props(_object_spread({}, tsconfig.config.compilerOptions), {
191
+ var compilerOptions = sanitizeForCompiler(_object_spread_props(_object_spread({}, tsconfig.config.compilerOptions), {
174
192
  rootDir: src,
175
193
  outDir: dest,
176
194
  noEmit: false,
@@ -179,7 +197,7 @@ function transformTypesWorker(src, dest, options, callback) {
179
197
  emitDeclarationOnly: true,
180
198
  // Suppress TS6 deprecation warnings (TS5101/TS5107) for consumers still on legacy Node-targeted options.
181
199
  ignoreDeprecations: '6.0'
182
- });
200
+ }));
183
201
  var rewrite = ((_tsconfig_config_compilerOptions = tsconfig.config.compilerOptions) === null || _tsconfig_config_compilerOptions === void 0 ? void 0 : _tsconfig_config_compilerOptions.rewriteRelativeImportExtensions) === true;
184
202
  // Avoid collisions across concurrent runs.
185
203
  var tempDir = _path.default.join(dest, '.ts-swc-transform-temp', String(process.pid), String(Date.now()));
@@ -253,7 +271,7 @@ function transformTypesWorker(src, dest, options, callback) {
253
271
  var updated = (0, _rewriteExtensionsts.rewriteExtensions)(content);
254
272
  if (updated === content) cb();
255
273
  else _fs.default.writeFile(file, updated, 'utf8', function(err) {
256
- return cb(err !== null && err !== void 0 ? err : undefined);
274
+ return cb(err);
257
275
  });
258
276
  });
259
277
  });
@@ -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 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 (!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","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":";;;;+BAuEA;;;eAAwBA;;;mEAvEoC;yDAC7C;iEACsB;8BACd;yDACR;2DACE;8DACC;qEACK;sEAMG;mCACQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IALYC;AAA9C,IAAMC,cAAcC,KAAKC,GAAG,CAAC,IAAID,KAAKE,GAAG,CAAC,GAAG,UAACJ,WAAAA,WAAE,CAACK,IAAI,gBAAPL,+BAA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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\nfunction compilerMajor(): number {\n try {\n const pkg = JSON.parse(fs.readFileSync(path.join(path.dirname(tscPath), '..', 'package.json'), 'utf8'));\n return +String(pkg.version).split('.')[0] || 0;\n } catch {\n return 0;\n }\n}\n\n// TypeScript 7 removed options that only ever affected JS emit, which swc handles.\n// Older compilers still accept them, so only rewrite when the installed tsc would reject them.\nfunction sanitizeForCompiler(options: Record<string, unknown>): Record<string, unknown> {\n if (compilerMajor() < 7) return options;\n const sanitized = { ...options };\n delete sanitized.downlevelIteration;\n if (sanitized.moduleResolution === 'node' || sanitized.moduleResolution === 'node10') sanitized.moduleResolution = 'bundler';\n if (typeof sanitized.target === 'string' && /^es[35]$/i.test(sanitized.target)) sanitized.target = 'es2015';\n return sanitized;\n}\n\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 (!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 = sanitizeForCompiler({\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));\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","compilerMajor","pkg","JSON","parse","fs","readFileSync","path","join","dirname","String","version","split","sanitizeForCompiler","options","sanitized","downlevelIteration","moduleResolution","target","test","isAllowedRootFile","basename","endsWith","runCompiler","cmdPath","args","cb","spawn","process","execPath","encoding","parseEmittedFiles","res","dest","out","seen","Set","lines","stdout","stderr","line","trim","replace","isAbsolute","rel","relative","startsWith","has","add","push","src","callback","tsconfig","matcher","createMatcher","rootFiles","iterator","Iterator","forEach","entry","stats","isFile","fullPath","err","compilerOptions","config","rootDir","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","ignoreDeprecations","rewrite","rewriteRelativeImportExtensions","tempDir","pid","Date","now","tempConfigPath","tempConfig","files","include","exclude","references","mkdir","recursive","mkdirErr","writeFile","stringify","writeErr","safeRm","force","runErr","status","source","detail","slice","Error","emittedFiles","postQueue","Queue","file","defer","readFile","readErr","content","updated","rewriteExtensions","await","rmErr"],"mappings":";;;;+BA2FA;;;eAAwBA;;;mEA3FoC;yDAC7C;iEACsB;8BACd;yDACR;2DACE;8DACC;qEACK;sEA0BG;mCACQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAzBYC;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;AAEzC,SAASC;IACP,IAAI;QACF,IAAMC,MAAMC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACC,aAAI,CAACC,IAAI,CAACD,aAAI,CAACE,OAAO,CAACV,UAAU,MAAM,iBAAiB;QAC/F,OAA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F,SAAS,CAACc,MAAMK,SAAS,QAAQ,SAAC5C;mDAAQrC,GAAGqC;;oCACvD;gCACF;4BACF;4BATA,QAAK,YAAcoC,iCAAd,SAAA,6BAAA,QAAA,yBAAA;;4BAAA;4BAAA;;;qCAAA,6BAAA;oCAAA;;;oCAAA;0CAAA;;;;oBAUP;oBAEAC,UAAUS,KAAK,CAAC;wBACdlB,IAAAA,sBAAM,EAAChB,SAAS;4BAAEW,WAAW;4BAAMM,OAAO;wBAAK,GAAG,SAACkB;mCAAU3D,SAAS2D,SAAS,MAAMX;;oBACvF;gBACF;YACF;QACF;IACF;AAEJ"}
@@ -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 { 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
+ {"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 { InternalConfigOptions } from '../types.ts';\n\n// Read straight off the parsed tsconfig JSON, which is arbitrary data rather\n// than typescript's own CompilerOptions.\ninterface InternalCompilerOptions {\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;AAY3R,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 +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 { 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"}
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 { InternalConfigOptions } from '../types.ts';\nimport { replaceExtension, rewriteExtensions } from './rewriteExtensions.ts';\n\n// Read straight off the parsed tsconfig JSON, which is arbitrary data rather\n// than typescript's own CompilerOptions.\ninterface InternalCompilerOptions {\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;AAExB,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,yBAAyB;AAQ7E,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"}
@@ -2,6 +2,7 @@ import { installSync, matchesLibc } from 'install-optional';
2
2
  import debounce from 'lodash.debounce';
3
3
  import Module from 'module';
4
4
  import path from 'path';
5
+ import tsConstants from 'ts-constants';
5
6
  import url from 'url';
6
7
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
7
8
  const __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
@@ -9,6 +10,24 @@ const installSyncSWC = debounce(installSync, 300, {
9
10
  leading: true,
10
11
  trailing: false
11
12
  });
13
+ // tsconfig spells enums as strings ("es2019", "react-jsx"); swc needs the numbers.
14
+ function enumValue(map, value) {
15
+ if (typeof value !== 'string') return value;
16
+ const wanted = value.replace(/-/g, '').toLowerCase();
17
+ const names = Object.keys(map);
18
+ for(let i = 0; i < names.length; i++){
19
+ if (typeof map[names[i]] === 'number' && names[i].toLowerCase() === wanted) return map[names[i]];
20
+ }
21
+ return undefined;
22
+ }
23
+ function normalizeCompilerOptions(raw) {
24
+ return {
25
+ ...raw,
26
+ target: enumValue(tsConstants.ScriptTarget, raw.target),
27
+ module: enumValue(tsConstants.ModuleKind, raw.module),
28
+ jsx: enumValue(tsConstants.JsxEmit, raw.jsx)
29
+ };
30
+ }
12
31
  export default function prepareSWCOptions(tsconfig) {
13
32
  installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, {
14
33
  cwd: __dirname,
@@ -18,8 +37,10 @@ export default function prepareSWCOptions(tsconfig) {
18
37
  const ts = _require('typescript');
19
38
  const swc = _require('@swc/core');
20
39
  const transpiler = _require('ts-node/transpilers/swc');
21
- const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));
22
- return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
40
+ // TypeScript 7 dropped the compiler API from the package root, so fall back
41
+ // to resolving the enum-valued fields directly.
42
+ const options = typeof ts.parseJsonConfigFileContent === 'function' ? ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path)).options : normalizeCompilerOptions(tsconfig.config.compilerOptions || {});
43
+ return transpiler.createSwcOptions(options, undefined, swc, 'swc');
23
44
  } catch (err) {
24
45
  console.log(`prepareSWCOptions failed: ${err instanceof Error ? err.message : String(err)}`);
25
46
  return {};
@@ -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 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
+ {"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 tsConstants from 'ts-constants';\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\n// tsconfig spells enums as strings (\"es2019\", \"react-jsx\"); swc needs the numbers.\nfunction enumValue(map: Record<string, unknown>, value: unknown): unknown {\n if (typeof value !== 'string') return value;\n const wanted = value.replace(/-/g, '').toLowerCase();\n const names = Object.keys(map);\n for (let i = 0; i < names.length; i++) {\n if (typeof map[names[i]] === 'number' && names[i].toLowerCase() === wanted) return map[names[i]];\n }\n return undefined;\n}\n\nfunction normalizeCompilerOptions(raw: Record<string, unknown>): Record<string, unknown> {\n return {\n ...raw,\n target: enumValue(tsConstants.ScriptTarget as unknown as Record<string, unknown>, raw.target),\n module: enumValue(tsConstants.ModuleKind as unknown as Record<string, unknown>, raw.module),\n jsx: enumValue(tsConstants.JsxEmit as unknown as Record<string, unknown>, raw.jsx),\n };\n}\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 // TypeScript 7 dropped the compiler API from the package root, so fall back\n // to resolving the enum-valued fields directly.\n const options = typeof ts.parseJsonConfigFileContent === 'function' ? ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path)).options : normalizeCompilerOptions((tsconfig.config.compilerOptions || {}) as Record<string, unknown>);\n return transpiler.createSwcOptions(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","tsConstants","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","installSyncSWC","leading","trailing","enumValue","map","value","wanted","replace","toLowerCase","names","Object","keys","i","length","undefined","normalizeCompilerOptions","raw","target","ScriptTarget","module","ModuleKind","jsx","JsxEmit","prepareSWCOptions","tsconfig","process","platform","arch","cwd","filter","ts","swc","transpiler","options","parseJsonConfigFileContent","config","sys","compilerOptions","createSwcOptions","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,iBAAiB,eAAe;AACvC,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYN,KAAKO,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AASjH,MAAMQ,iBAAiBZ,SAASF,aAAa,KAAK;IAAEe,SAAS;IAAMC,UAAU;AAAM;AAEnF,mFAAmF;AACnF,SAASC,UAAUC,GAA4B,EAAEC,KAAc;IAC7D,IAAI,OAAOA,UAAU,UAAU,OAAOA;IACtC,MAAMC,SAASD,MAAME,OAAO,CAAC,MAAM,IAAIC,WAAW;IAClD,MAAMC,QAAQC,OAAOC,IAAI,CAACP;IAC1B,IAAK,IAAIQ,IAAI,GAAGA,IAAIH,MAAMI,MAAM,EAAED,IAAK;QACrC,IAAI,OAAOR,GAAG,CAACK,KAAK,CAACG,EAAE,CAAC,KAAK,YAAYH,KAAK,CAACG,EAAE,CAACJ,WAAW,OAAOF,QAAQ,OAAOF,GAAG,CAACK,KAAK,CAACG,EAAE,CAAC;IAClG;IACA,OAAOE;AACT;AAEA,SAASC,yBAAyBC,GAA4B;IAC5D,OAAO;QACL,GAAGA,GAAG;QACNC,QAAQd,UAAUZ,YAAY2B,YAAY,EAAwCF,IAAIC,MAAM;QAC5FE,QAAQhB,UAAUZ,YAAY6B,UAAU,EAAwCJ,IAAIG,MAAM;QAC1FE,KAAKlB,UAAUZ,YAAY+B,OAAO,EAAwCN,IAAIK,GAAG;IACnF;AACF;AAEA,eAAe,SAASE,kBAAkBC,QAAkB;IAC1DxB,eAAe,aAAa,GAAGyB,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKhC;QAAWiC,QAAQ1C;IAAY;IACzG,IAAI;QACF,MAAM2C,KAAKrC,SAAS;QACpB,MAAMsC,MAAMtC,SAAS;QACrB,MAAMuC,aAAavC,SAAS;QAC5B,4EAA4E;QAC5E,gDAAgD;QAChD,MAAMwC,UAAU,OAAOH,GAAGI,0BAA0B,KAAK,aAAaJ,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAE9C,KAAKO,OAAO,CAAC2B,SAASlC,IAAI,GAAG2C,OAAO,GAAGlB,yBAA0BS,SAASW,MAAM,CAACE,eAAe,IAAI,CAAC;QAClO,OAAOL,WAAWM,gBAAgB,CAACL,SAASnB,WAAWiB,KAAK;IAC9D,EAAE,OAAOQ,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,eAAeG,QAAQH,IAAII,OAAO,GAAGC,OAAOL,MAAM;QAC3F,OAAO,CAAC;IACV;AACF"}
@@ -36,8 +36,8 @@ export default function transformFile(entry, dest, type, options, mode, callback
36
36
  const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
37
37
  mkdirp(path.dirname(outPath), ()=>{
38
38
  const queue = new Queue();
39
- queue.defer((cb)=>fs.writeFile(outPath, output.code, 'utf8', (err)=>cb(err !== null && err !== void 0 ? err : undefined)));
40
- if (output.map && options.sourceMaps) queue.defer((cb)=>fs.writeFile(`${outPath}.map`, output.map, 'utf8', (err)=>cb(err !== null && err !== void 0 ? err : undefined)));
39
+ queue.defer((cb)=>fs.writeFile(outPath, output.code, 'utf8', (err)=>cb(err)));
40
+ if (output.map && options.sourceMaps) queue.defer((cb)=>fs.writeFile(`${outPath}.map`, output.map, 'utf8', (err)=>cb(err)));
41
41
  queue.await((err)=>{
42
42
  if (err) return callback(err);
43
43
  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';\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\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","mkdirp","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","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,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcP,OAAOQ,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAI1F,eAAe,SAASG,cAAcC,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAA8B,EAAEC,IAAwB,EAAEC,QAA+B;IAC3K,IAAIC,WAAWH,QAAQG,QAAQ;IAE/B,oBAAoB;IACpB,IAAIJ,SAAS,OAAO;QAClB,MAAMK,kBAAkB;YAAE,GAAID,SAASE,MAAM,CAACD,eAAe,IAAI,CAAC,CAAC;YAAGE,QAAQ;YAAqBC,QAAQ;QAAe;QAC1HJ,WAAW;YAAE,GAAGA,QAAQ;YAAEE,QAAQ;gBAAE,GAAGF,SAASE,M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KAAK,CAAChB,SAAS,QAAQe,UAAU,CAACE;4BACnCnC,SAAS,MAAMkB;wBACjB;wBACA;oBACF;gBACF;gBACAlB,SAAS,MAAMkB;YACjB;QACF;IACF,GACCkB,KAAK,CAACpC;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 mkdirp from 'mkdirp-classic';\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\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)));\n if (output.map && options.sourceMaps) queue.defer((cb) => fs.writeFile(`${outPath}.map`, output.map as string, 'utf8', (err) => cb(err)));\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","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","map","sourceMaps","await","execBits","chmod","_chmodErr","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcP,OAAOQ,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAI1F,eAAe,SAASG,cAAcC,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAA8B,EAAEC,IAAwB,EAAEC,QAA+B;IAC3K,IAAIC,WAAWH,QAAQG,QAAQ;IAE/B,oBAAoB;IACpB,IAAIJ,SAAS,OAAO;QAClB,MAAMK,kBAAkB;YAAE,GAAID,SAASE,MAAM,CAACD,eAAe,IAAI,CAAC,CAAC;YAAGE,QAAQ;YAAqBC,QAAQ;QAAe;QAC1HJ,WAAW;YAAE,GAAGA,QAAQ;YAAEE,QAAQ;gBAAE,GAAGF,SAASE,MAAM;gBAAED;YAAgB;QAAE;IAC5E;IAEA,MAAMI,aAAajB,kBAA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MkB;YACjB;QACF;IACF,GACCiB,KAAK,CAACnC;AACX"}
@@ -17,12 +17,14 @@ const worker = major >= 20 ? run : bind('>=20', workerPath, {
17
17
  });
18
18
  export default function transformDirectory(src, dest, type, options, callback) {
19
19
  try {
20
+ var _loadConfigSync;
20
21
  if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
21
22
  if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
22
23
  if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
23
24
  callback = typeof options === 'function' ? options : callback;
24
25
  options = typeof options === 'function' ? {} : options || {};
25
- const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);
26
+ const tsconfig = options.tsconfig ? options.tsconfig : (_loadConfigSync = loadConfigSync(src)) !== null && _loadConfigSync !== void 0 ? _loadConfigSync : undefined;
27
+ if (!tsconfig) throw new Error('transformDirectory: failed to load tsconfig');
26
28
  const opts = {
27
29
  ...options,
28
30
  tsconfig
@@ -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, 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;A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AM,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) ?? undefined);\n if (!tsconfig) throw new Error('transformDirectory: failed to load tsconfig');\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","undefined","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;YAOsDrB;QANxD,IAAI,OAAOiB,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,IAAI3B,kBAAAA,eAAeiB,kBAAfjB,6BAAAA,kBAAuB4B;QAC/E,IAAI,CAACD,UAAU,MAAM,IAAID,MAAM;QAC/B,MAAMG,OAA8B;YAAE,GAAGT,OAAO;YAAEO;QAAS;QAE3D,IAAI,OAAON,aAAa,YAAY,OAAOC,OAAOL,KAAKC,MAAMC,MAAMU,MAAMR;QACzE,OAAO,IAAIS,QAAkB,CAACC,SAASC,SAAWV,OAAOL,KAAKC,MAAMC,MAAMU,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;IAC5I,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOZ,aAAa,YAAY,OAAOA,SAASY;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
@@ -15,8 +15,10 @@ const worker = major >= 20 ? run : bindSync('>=20', workerPath, {
15
15
  spawnOptions: false
16
16
  });
17
17
  export default function transformSync(contents, fileName, tsconfig) {
18
+ var _loadConfigSync;
18
19
  if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');
19
20
  if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');
20
- if (!tsconfig) tsconfig = loadConfigSync(process.cwd());
21
+ if (!tsconfig) tsconfig = (_loadConfigSync = loadConfigSync(process.cwd())) !== null && _loadConfigSync !== void 0 ? _loadConfigSync : undefined;
22
+ if (!tsconfig) throw new Error('transformSync: failed to load tsconfig');
21
23
  return worker(contents, fileName, tsconfig);
22
24
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport { bindSync } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } 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', 'transformSync.js');\n\nfunction run(contents: string, fileName: string, tsconfig: TSConfig) {\n return _require(workerPath)(contents, fileName, tsconfig);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bindSync('>=20', workerPath, { spawnOptions: false });\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return worker(contents, fileName, tsconfig) as Output;\n}\n"],"names":["Module","bindSync","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","contents","fileName","tsconfig","worker","spawnOptions","transformSync","Error","cwd"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,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,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IACjE,OAAOZ,SAASO,YAAYG,UAAUC,UAAUC;AAClD;AAEA,8DAA8D;AAC9D,MAAMC,SAASlB,SAAS,KAAKc,MAAMlB,SAAS,QAAQgB,YAAY;IAAEO,cAAc;AAAM;AAGtF,eAAe,SAASC,cAAcL,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIM,MAAM;IAClD,IAAI,OAAOL,aAAa,UAAU,MAAM,IAAIK,MAAM;IAClD,IAAI,CAACJ,UAAUA,WAAWnB,eAAeG,QAAQqB,GAAG;IACpD,OAAOJ,OAAOH,UAAUC,UAAUC;AACpC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport { bindSync } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } 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', 'transformSync.js');\n\nfunction run(contents: string, fileName: string, tsconfig: TSConfig) {\n return _require(workerPath)(contents, fileName, tsconfig);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bindSync('>=20', workerPath, { spawnOptions: false });\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd()) ?? undefined;\n if (!tsconfig) throw new Error('transformSync: failed to load tsconfig');\n return worker(contents, fileName, tsconfig) as Output;\n}\n"],"names":["Module","bindSync","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","contents","fileName","tsconfig","worker","spawnOptions","transformSync","Error","cwd","undefined"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,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,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IACjE,OAAOZ,SAASO,YAAYG,UAAUC,UAAUC;AAClD;AAEA,8DAA8D;AAC9D,MAAMC,SAASlB,SAAS,KAAKc,MAAMlB,SAAS,QAAQgB,YAAY;IAAEO,cAAc;AAAM;AAGtF,eAAe,SAASC,cAAcL,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;QAGjEnB;IAF1B,IAAI,OAAOiB,aAAa,UAAU,MAAM,IAAIM,MAAM;IAClD,IAAI,OAAOL,aAAa,UAAU,MAAM,IAAIK,MAAM;IAClD,IAAI,CAACJ,UAAUA,YAAWnB,kBAAAA,eAAeG,QAAQqB,GAAG,iBAA1BxB,6BAAAA,kBAAiCyB;IAC3D,IAAI,CAACN,UAAU,MAAM,IAAII,MAAM;IAC/B,OAAOH,OAAOH,UAAUC,UAAUC;AACpC"}
@@ -17,11 +17,13 @@ const worker = major >= 20 ? run : bind('>=20', workerPath, {
17
17
  });
18
18
  export default function transformTypes(src, dest, options, callback) {
19
19
  try {
20
+ var _loadConfigSync;
20
21
  if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');
21
22
  if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');
22
23
  callback = typeof options === 'function' ? options : callback;
23
24
  options = typeof options === 'function' ? {} : options || {};
24
- const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);
25
+ const tsconfig = options.tsconfig ? options.tsconfig : (_loadConfigSync = loadConfigSync(src)) !== null && _loadConfigSync !== void 0 ? _loadConfigSync : undefined;
26
+ if (!tsconfig) throw new Error('transformTypes: failed to load tsconfig');
25
27
  const opts = {
26
28
  ...options,
27
29
  tsconfig
@@ -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, 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"}
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) ?? undefined);\n if (!tsconfig) throw new Error('transformTypes: failed to load tsconfig');\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","undefined","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;YAMsDpB;QALxD,IAAI,OAAOiB,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,IAAI1B,kBAAAA,eAAeiB,kBAAfjB,6BAAAA,kBAAuB2B;QAC/E,IAAI,CAACD,UAAU,MAAM,IAAID,MAAM;QAC/B,MAAMG,OAA8B;YAAE,GAAGT,OAAO;YAAEO;QAAS;QAE3D,IAAI,OAAON,aAAa,YAAY,OAAOC,OAAOJ,KAAKC,MAAMU,MAAMR;QACnE,OAAO,IAAIS,QAAkB,CAACC,SAASC,SAAWV,OAAOJ,KAAKC,MAAMU,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG,mBAAAA,oBAAAA,SAAU,EAAE;IACtI,EAAE,OAAOD,KAAK;QACZ,IAAI,OAAOZ,aAAa,YAAY,OAAOA,SAASY;QACpD,OAAOH,QAAQE,MAAM,CAACC;IACxB;AACF"}
@@ -10,6 +10,26 @@ import Queue from 'queue-cb';
10
10
  import resolveBin from 'resolve-bin-sync';
11
11
  const concurrency = Math.min(64, Math.max(8, ((_ref = (_os_cpus = os.cpus()) === null || _os_cpus === void 0 ? void 0 : _os_cpus.length) !== null && _ref !== void 0 ? _ref : 4) * 8));
12
12
  const tscPath = resolveBin('typescript', 'tsc');
13
+ function compilerMajor() {
14
+ try {
15
+ const pkg = JSON.parse(fs.readFileSync(path.join(path.dirname(tscPath), '..', 'package.json'), 'utf8'));
16
+ return +String(pkg.version).split('.')[0] || 0;
17
+ } catch {
18
+ return 0;
19
+ }
20
+ }
21
+ // TypeScript 7 removed options that only ever affected JS emit, which swc handles.
22
+ // Older compilers still accept them, so only rewrite when the installed tsc would reject them.
23
+ function sanitizeForCompiler(options) {
24
+ if (compilerMajor() < 7) return options;
25
+ const sanitized = {
26
+ ...options
27
+ };
28
+ delete sanitized.downlevelIteration;
29
+ if (sanitized.moduleResolution === 'node' || sanitized.moduleResolution === 'node10') sanitized.moduleResolution = 'bundler';
30
+ if (typeof sanitized.target === 'string' && /^es[35]$/i.test(sanitized.target)) sanitized.target = 'es2015';
31
+ return sanitized;
32
+ }
13
33
  import createMatcher from '../createMatcher.js';
14
34
  import { rewriteExtensions } from '../lib/rewriteExtensions.js';
15
35
  /* ---------------- root file filtering ---------------- */ function isAllowedRootFile(basename) {
@@ -62,7 +82,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
62
82
  var _tsconfig_config_compilerOptions;
63
83
  if (err) return callback(err);
64
84
  if (rootFiles.length === 0) return callback(null, []);
65
- const compilerOptions = {
85
+ const compilerOptions = sanitizeForCompiler({
66
86
  ...tsconfig.config.compilerOptions,
67
87
  rootDir: src,
68
88
  outDir: dest,
@@ -72,7 +92,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
72
92
  emitDeclarationOnly: true,
73
93
  // Suppress TS6 deprecation warnings (TS5101/TS5107) for consumers still on legacy Node-targeted options.
74
94
  ignoreDeprecations: '6.0'
75
- };
95
+ });
76
96
  const rewrite = ((_tsconfig_config_compilerOptions = tsconfig.config.compilerOptions) === null || _tsconfig_config_compilerOptions === void 0 ? void 0 : _tsconfig_config_compilerOptions.rewriteRelativeImportExtensions) === true;
77
97
  // Avoid collisions across concurrent runs.
78
98
  const tempDir = path.join(dest, '.ts-swc-transform-temp', String(process.pid), String(Date.now()));
@@ -137,7 +157,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
137
157
  if (readErr) return cb();
138
158
  const updated = rewriteExtensions(content);
139
159
  if (updated === content) cb();
140
- else fs.writeFile(file, updated, 'utf8', (err)=>cb(err !== null && err !== void 0 ? err : undefined));
160
+ else fs.writeFile(file, updated, 'utf8', (err)=>cb(err));
141
161
  });
142
162
  });
143
163
  }
@@ -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 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 (!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":["os","spawn","fs","Iterator","safeRm","path","Queue","resolveBin","concurrency","Math","min","max","cpus","length","tscPath","createMatcher","rewriteExtensions","isAllowedRootFile","basename","endsWith","runCompiler","cmdPath","args","cb","process","execPath","encoding","parseEmittedFiles","res","dest","out","seen","Set","lines","stdout","stderr","split","line","trim","test","replace","isAbsolute","rel","relative","startsWith","has","add","push","transformTypesWorker","src","options","callback","tsconfig","matcher","rootFiles","iterator","forEach","entry","stats","isFile","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","mkdir","recursive","mkdirErr","writeFile","JSON","stringify","writeErr","force","runErr","status","source","detail","slice","Error","emittedFiles","postQueue","file","defer","readFile","readErr","content","updated","undefined","await","rmErr"],"mappings":";IAS8CA;AAT9C,OAAOC,WAAqD,iBAAiB;AAC7E,OAAOC,QAAQ,KAAK;AACpB,OAAOC,cAA8B,cAAc;AACnD,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOJ,QAAQ,KAAK;AACpB,OAAOK,UAAU,OAAO;AACxB,O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M,yCAAI;wBACxC,MAAM6D,SAAS,CAAC,mCAAmC,EAAEF,OAAO,aAAa,EAAE5D,OAAO+D,KAAK,CAAC,GAAG,QAAS,WAAW,EAAE9D,OAAO8D,KAAK,CAAC,GAAG,QAAS;wBAC1I7F,OAAOqE,SAAS;4BAAEa,WAAW;4BAAMM,OAAO;wBAAK,GAAG,IAAMzC,SAAS,IAAI+C,MAAMF;wBAC3E;oBACF;oBAEA,MAAMG,eAAexE,kBAAkBC,KAAKC;oBAC5C,IAAIsE,aAAatF,MAAM,KAAK,GAAG;wBAC7BT,OAAOqE,SAAS;4BAAEa,WAAW;4BAAMM,OAAO;wBAAK,GAAG,IAAMzC,SAAS,IAAI+C,MAAM;wBAC3E;oBACF;oBAEA,MAAME,YAAY,IAAI9F;oBAEtB,IAAIiE,SAAS;wBACX,KAAK,MAAM8B,QAAQF,aAAc;4BAC/BC,UAAUE,KAAK,CAAC,CAAC/E;gCACfrB,GAAGqG,QAAQ,CAACF,MAAM,QAAQ,CAACG,SAASC;oCAClC,IAAID,SAAS,OAAOjF;oCACpB,MAAMmF,UAAU1F,kBAAkByF;oCAClC,IAAIC,YAAYD,SAASlF;yCACpBrB,GAAGsF,SAAS,CAACa,MAAMK,SAAS,QAAQ,CAAC7C,MAAQtC,GAAGsC,gBAAAA,iBAAAA,MAAO8C;gCAC9D;4BACF;wBACF;oBACF;oBAEAP,UAAUQ,KAAK,CAAC;wBACdxG,OAAOqE,SAAS;4BAAEa,WAAW;4BAAMM,OAAO;wBAAK,GAAG,CAACiB,QAAU1D,SAAS0D,SAAS,MAAMV;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\nfunction compilerMajor(): number {\n try {\n const pkg = JSON.parse(fs.readFileSync(path.join(path.dirname(tscPath), '..', 'package.json'), 'utf8'));\n return +String(pkg.version).split('.')[0] || 0;\n } catch {\n return 0;\n }\n}\n\n// TypeScript 7 removed options that only ever affected JS emit, which swc handles.\n// Older compilers still accept them, so only rewrite when the installed tsc would reject them.\nfunction sanitizeForCompiler(options: Record<string, unknown>): Record<string, unknown> {\n if (compilerMajor() < 7) return options;\n const sanitized = { ...options };\n delete sanitized.downlevelIteration;\n if (sanitized.moduleResolution === 'node' || sanitized.moduleResolution === 'node10') sanitized.moduleResolution = 'bundler';\n if (typeof sanitized.target === 'string' && /^es[35]$/i.test(sanitized.target)) sanitized.target = 'es2015';\n return sanitized;\n}\n\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 (!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 = sanitizeForCompiler({\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));\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":["os","spawn","fs","Iterator","safeRm","path","Queue","resolveBin","concurrency","Math","min","max","cpus","length","tscPath","compilerMajor","pkg","JSON","parse","readFileSync","join","dirname","String","version","split","sanitizeForCompiler","options","sanitized","downlevelIteration","moduleResolution","target","test","createMatcher","rewriteExtensions","isAllowedRootFile","basename","endsWith","runCompiler","cmdPath","args","cb","process","execPath","encoding","parseEmittedFiles","res","dest","out","seen","Set","lines","stdout","stderr","line","trim","replace","isAbsolute","rel","relative","startsWith","has","add","push","transformTypesWorker","src","callback","tsconfig","matcher","rootFiles","iterator","forEach","entry","stats","isFile","fullPath","err","compilerOptions","config","rootDir","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","ignoreDeprecations","rewrite","rewriteRelativeImportExtensions","tempDir","pid","Date","now","tempConfigPath","tempConfig","files","include","exclude","references","mkdir","recursive","mkdirErr","writeFile","stringify","writeErr","force","runErr","status","source","detail","slice","Error","emittedFiles","postQueue","file","defer","readFile","readErr","content","updated","await","rmErr"],"mappings":";IAS8CA;AAT9C,OAAOC,WAAqD,iBAAiB;AAC7E,OAAOC,QAAQ,KAAK;AACpB,OAAOC,cAA8B,cAAc;AACnD,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOJ,QAAQ,KAAK;AACpB,OAAOK,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,gBAAgB,mBAAmB;AAE1C,MAAMC,cAAcC,KAAKC,GAAG,CAAC,IAAID,KAAKE,GAAG,CAAC,GAAG,UAACX,WAAAA,GAAGY,IAAI,gBAAPZ,+BAAAA,SAAWa,MAAM,uCAAI,KAAK;AAExE,MAAMC,UAAUP,WAAW,cAAc;AAEzC,SAASQ;IACP,IAAI;QACF,MAAMC,MAAMC,KAAKC,KAAK,CAAChB,GAAGiB,YAAY,CAACd,KAAKe,IAAI,CAACf,KAAKgB,OAAO,CAACP,UAAU,MAAM,iBAAiB;QAC/F,OAAO,CAACQ,OAAON,IAAIO,OAAO,EAAEC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI;IAC/C,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,mFAAmF;AACnF,+FAA+F;AAC/F,SAASC,oBAAoBC,OAAgC;IAC3D,IAAIX,kBAAk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AAA,6BAAAA,OAAQvD,MAAM,uCAAI;wBACxC,MAAMC,SAAS9B,gBAAOoF,mBAAAA,6BAAAA,OAAQtD,MAAM,yCAAI;wBACxC,MAAMuD,SAAS,CAAC,mCAAmC,EAAEF,OAAO,aAAa,EAAEtD,OAAOyD,KAAK,CAAC,GAAG,QAAS,WAAW,EAAExD,OAAOwD,KAAK,CAAC,GAAG,QAAS;wBAC1IxG,OAAOmF,SAAS;4BAAEW,WAAW;4BAAMK,OAAO;wBAAK,GAAG,IAAMtC,SAAS,IAAI4C,MAAMF;wBAC3E;oBACF;oBAEA,MAAMG,eAAelE,kBAAkBC,KAAKC;oBAC5C,IAAIgE,aAAajG,MAAM,KAAK,GAAG;wBAC7BT,OAAOmF,SAAS;4BAAEW,WAAW;4BAAMK,OAAO;wBAAK,GAAG,IAAMtC,SAAS,IAAI4C,MAAM;wBAC3E;oBACF;oBAEA,MAAME,YAAY,IAAIzG;oBAEtB,IAAI+E,SAAS;wBACX,KAAK,MAAM2B,QAAQF,aAAc;4BAC/BC,UAAUE,KAAK,CAAC,CAACzE;gCACftC,GAAGgH,QAAQ,CAACF,MAAM,QAAQ,CAACG,SAASC;oCAClC,IAAID,SAAS,OAAO3E;oCACpB,MAAM6E,UAAUpF,kBAAkBmF;oCAClC,IAAIC,YAAYD,SAAS5E;yCACpBtC,GAAGkG,SAAS,CAACY,MAAMK,SAAS,QAAQ,CAAC1C,MAAQnC,GAAGmC;gCACvD;4BACF;wBACF;oBACF;oBAEAoC,UAAUO,KAAK,CAAC;wBACdlH,OAAOmF,SAAS;4BAAEW,WAAW;4BAAMK,OAAO;wBAAK,GAAG,CAACgB,QAAUtD,SAASsD,SAAS,MAAMT;oBACvF;gBACF;YACF;QACF;IACF;AAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-swc-transform",
3
- "version": "2.11.10",
3
+ "version": "2.11.12",
4
4
  "description": "Typescript transformers for swc. Supports Node >= 0.8",
5
5
  "keywords": [
6
6
  "matcher",
@@ -60,8 +60,9 @@
60
60
  "resolve-bin-sync": "^1.0.13",
61
61
  "resolve.exports": "^2.0.3",
62
62
  "test-match": "^1.0.0",
63
+ "ts-constants": "^1.1.13",
63
64
  "ts-node": "^10.9.0",
64
- "typescript": "^6.0.0"
65
+ "typescript": "^7.0.2"
65
66
  },
66
67
  "devDependencies": {
67
68
  "@types/is-absolute": "^1.0.2",