ts-swc-transform 2.2.8 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/cjs/createMatcher.d.cts +2 -3
  2. package/dist/cjs/createMatcher.d.ts +2 -3
  3. package/dist/cjs/createMatcher.js +1 -5
  4. package/dist/cjs/createMatcher.js.map +1 -1
  5. package/dist/cjs/lib/prepareSWCOptions.d.cts +7 -0
  6. package/dist/cjs/lib/prepareSWCOptions.d.ts +7 -0
  7. package/dist/cjs/lib/{swcPrepareOptions.js → prepareSWCOptions.js} +3 -3
  8. package/dist/cjs/lib/prepareSWCOptions.js.map +1 -0
  9. package/dist/cjs/lib/transformFile.js +4 -4
  10. package/dist/cjs/lib/transformFile.js.map +1 -1
  11. package/dist/cjs/transformDirectory.js +2 -4
  12. package/dist/cjs/transformDirectory.js.map +1 -1
  13. package/dist/cjs/transformSync.d.cts +2 -2
  14. package/dist/cjs/transformSync.d.ts +2 -2
  15. package/dist/cjs/transformSync.js +2 -43
  16. package/dist/cjs/transformSync.js.map +1 -1
  17. package/dist/cjs/transformTypes.js +2 -4
  18. package/dist/cjs/transformTypes.js.map +1 -1
  19. package/dist/cjs/types.d.cts +3 -2
  20. package/dist/cjs/types.d.ts +3 -2
  21. package/dist/cjs/workers/transformSync.d.cts +2 -2
  22. package/dist/cjs/workers/transformSync.d.ts +2 -2
  23. package/dist/cjs/workers/transformSync.js +2 -2
  24. package/dist/cjs/workers/transformSync.js.map +1 -1
  25. package/dist/esm/createMatcher.d.ts +2 -3
  26. package/dist/esm/createMatcher.js +1 -5
  27. package/dist/esm/createMatcher.js.map +1 -1
  28. package/dist/esm/lib/prepareSWCOptions.d.ts +7 -0
  29. package/dist/esm/lib/{swcPrepareOptions.js → prepareSWCOptions.js} +2 -2
  30. package/dist/esm/lib/prepareSWCOptions.js.map +1 -0
  31. package/dist/esm/lib/transformFile.js +4 -4
  32. package/dist/esm/lib/transformFile.js.map +1 -1
  33. package/dist/esm/transformDirectory.js +2 -5
  34. package/dist/esm/transformDirectory.js.map +1 -1
  35. package/dist/esm/transformSync.d.ts +2 -2
  36. package/dist/esm/transformSync.js +2 -2
  37. package/dist/esm/transformSync.js.map +1 -1
  38. package/dist/esm/transformTypes.js +2 -5
  39. package/dist/esm/transformTypes.js.map +1 -1
  40. package/dist/esm/types.d.ts +3 -2
  41. package/dist/esm/types.js.map +1 -1
  42. package/dist/esm/workers/transformSync.d.ts +2 -2
  43. package/dist/esm/workers/transformSync.js +2 -2
  44. package/dist/esm/workers/transformSync.js.map +1 -1
  45. package/package.json +2 -2
  46. package/dist/cjs/lib/swcPrepareOptions.d.cts +0 -7
  47. package/dist/cjs/lib/swcPrepareOptions.d.ts +0 -7
  48. package/dist/cjs/lib/swcPrepareOptions.js.map +0 -1
  49. package/dist/cjs/loadTsConfig.d.cts +0 -3
  50. package/dist/cjs/loadTsConfig.d.ts +0 -3
  51. package/dist/cjs/loadTsConfig.js +0 -65
  52. package/dist/cjs/loadTsConfig.js.map +0 -1
  53. package/dist/esm/lib/swcPrepareOptions.d.ts +0 -7
  54. package/dist/esm/lib/swcPrepareOptions.js.map +0 -1
  55. package/dist/esm/loadTsConfig.d.ts +0 -3
  56. package/dist/esm/loadTsConfig.js +0 -9
  57. package/dist/esm/loadTsConfig.js.map +0 -1
@@ -1,3 +1,2 @@
1
- import type { TsConfigResult } from 'get-tsconfig-compat';
2
- import type { Matcher } from './types.ts';
3
- export default function createMatcher(tsConfig: TsConfigResult): Matcher;
1
+ import type { Matcher, TSConfig } from './types.ts';
2
+ export default function createMatcher(tsconfig: TSConfig): Matcher;
@@ -1,3 +1,2 @@
1
- import type { TsConfigResult } from 'get-tsconfig-compat';
2
- import type { Matcher } from './types.ts';
3
- export default function createMatcher(tsConfig: TsConfigResult): Matcher;
1
+ import type { Matcher, TSConfig } from './types.ts';
2
+ export default function createMatcher(tsconfig: TSConfig): Matcher;
@@ -11,16 +11,12 @@ Object.defineProperty(exports, "default", {
11
11
  var _minimatch = /*#__PURE__*/ _interop_require_default(require("minimatch"));
12
12
  var _pathposix = /*#__PURE__*/ _interop_require_default(require("path-posix"));
13
13
  var _unixify = /*#__PURE__*/ _interop_require_default(require("unixify"));
14
- var _loadTsConfigts = /*#__PURE__*/ _interop_require_default(require("./loadTsConfig.js"));
15
14
  function _interop_require_default(obj) {
16
15
  return obj && obj.__esModule ? obj : {
17
16
  default: obj
18
17
  };
19
18
  }
20
- function createMatcher(tsConfig) {
21
- var tsconfig = (0, _loadTsConfigts.default)({
22
- tsconfig: tsConfig
23
- }, 'transformTypes');
19
+ function createMatcher(tsconfig) {
24
20
  var tsconfigPath = _pathposix.default.dirname((0, _unixify.default)(tsconfig.path));
25
21
  function matchFn(condition) {
26
22
  var pattern = (0, _unixify.default)(condition);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig.ts';\nimport type { Matcher } from './types.ts';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsConfig","tsconfig","loadTsConfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAOA;;;eAAwBA;;;gEANF;gEACL;8DACG;qEACK;;;;;;AAGV,SAASA,cAAcC,QAAwB;IAC5D,IAAMC,WAAWC,IAAAA,uBAAY,EAAC;QAAED,UAAUD;IAAS,GAAG;IACtD,IAAMG,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACL,SAASG,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACf,CAAAA,SAASgB,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACrD,IAAMa,WAAW,AAACnB,CAAAA,SAASgB,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAErD,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport type { Matcher, TSConfig } from './types.ts';\n\nexport default function createMatcher(tsconfig: TSConfig): Matcher {\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = ((tsconfig.config.include as string[]) || []).map(matchFn);\n const excludes = ((tsconfig.config.exclude as string[]) || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsconfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAKA;;;eAAwBA;;;gEALF;gEACL;8DACG;;;;;;AAGL,SAASA,cAAcC,QAAkB;IACtD,IAAMC,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACJ,SAASE,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAAC,CAAA,AAACd,SAASe,MAAM,CAACC,OAAO,IAAiB,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACnE,IAAMa,WAAW,AAAC,CAAA,AAAClB,SAASe,MAAM,CAACI,OAAO,IAAiB,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAEnE,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
@@ -0,0 +1,7 @@
1
+ import type { Options } from '@swc/core';
2
+ import type { TSConfig } from '../types.ts';
3
+ export interface TranspilerOptions {
4
+ tsxOptions: Options;
5
+ nonTsxOptions: Options;
6
+ }
7
+ export default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions;
@@ -0,0 +1,7 @@
1
+ import type { Options } from '@swc/core';
2
+ import type { TSConfig } from '../types.ts';
3
+ export interface TranspilerOptions {
4
+ tsxOptions: Options;
5
+ nonTsxOptions: Options;
6
+ }
7
+ export default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
7
  get: function() {
8
- return swcPrepareOptions;
8
+ return prepareSWCOptions;
9
9
  }
10
10
  });
11
11
  var _installoptional = require("install-optional");
@@ -19,7 +19,7 @@ function _interop_require_default(obj) {
19
19
  }
20
20
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
21
21
  var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
22
- function swcPrepareOptions(tsconfig) {
22
+ function prepareSWCOptions(tsconfig) {
23
23
  (0, _installoptional.installSync)('@swc/core', "".concat(process.platform, "-").concat(process.arch), {
24
24
  cwd: __dirname
25
25
  });
@@ -30,7 +30,7 @@ function swcPrepareOptions(tsconfig) {
30
30
  var parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, _path.default.dirname(tsconfig.path));
31
31
  return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
32
32
  } catch (err) {
33
- console.log("swcPrepareOptions failed: ".concat(err.message));
33
+ console.log("prepareSWCOptions failed: ".concat(err.message));
34
34
  return {};
35
35
  }
36
36
  }
@@ -0,0 +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 } from 'install-optional';\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\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`prepareSWCOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["prepareSWCOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","tsconfig","installSync","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAgBA;;;eAAwBA;;;+BAfI;6DACT;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;AASnF,SAASV,kBAAkBW,QAAkB;IAC1DC,IAAAA,4BAAW,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI,GAAI;QAAEC,KAAKX;IAAU;IACjF,IAAI;QACF,IAAMY,KAAKhB,SAAS;QACpB,IAAMiB,MAAMjB,SAAS;QACrB,IAAMkB,aAAalB,SAAS;QAC5B,IAAMmB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEjB,aAAI,CAACC,OAAO,CAACI,SAASL,IAAI;QAChG,OAAOa,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
@@ -15,7 +15,7 @@ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
15
15
  var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
16
16
  var _patchCJSts = /*#__PURE__*/ _interop_require_default(require("../lib/patchCJS.js"));
17
17
  var _patchESMts = /*#__PURE__*/ _interop_require_default(require("../lib/patchESM.js"));
18
- var _swcPrepareOptionsts = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.js"));
18
+ var _prepareSWCOptionsts = /*#__PURE__*/ _interop_require_default(require("../lib/prepareSWCOptions.js"));
19
19
  function _define_property(obj, key, value) {
20
20
  if (key in obj) {
21
21
  Object.defineProperty(obj, key, {
@@ -81,10 +81,10 @@ function transformFile(entry, dest, type, options, callback) {
81
81
  tsconfig = _object_spread({}, tsconfig);
82
82
  tsconfig.config = _object_spread({}, tsconfig.config);
83
83
  tsconfig.config.compilerOptions = _object_spread({}, tsconfig.config.compilerOptions || {});
84
- tsconfig.config.compilerOptions.module = 'CommonJS';
85
- tsconfig.config.compilerOptions.target = 'ES5';
84
+ tsconfig.config.compilerOptions.module = 'commonjs';
85
+ tsconfig.config.compilerOptions.target = 'es5';
86
86
  }
87
- var swcOptions = (0, _swcPrepareOptionsts.default)(tsconfig);
87
+ var swcOptions = (0, _prepareSWCOptionsts.default)(tsconfig);
88
88
  var swc = _require('@swc/core');
89
89
  swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
90
90
  filename: entry.basename
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;iEACG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAASF,cAAcK,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW,mBAAKA;QAChBA,SAASC,MAAM,GAAG,mBAAKD,SAASC,MAAM;QACtCD,SAASC,MAAM,CAACC,eAAe,GAAG,mBAAMF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC;QAC5EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,IAAMC,aAAaC,IAAAA,4BAAiB,EAACN;IACrC,IAAMO,MAAMhB,SAAS;IAErBgB,IACGjB,aAAa,CAACK,MAAMa,QAAQ,EAAE,wCACzBb,MAAMc,QAAQ,CAACC,QAAQ,CAAC,WAAWf,MAAMc,QAAQ,CAACC,QAAQ,CAAC,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QACzHC,UAAUlB,MAAMc,QAAQ;QAEzBK,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYnB,SAAS,QAAQoB,IAAAA,mBAAQ,EAACtB,OAAOoB,QAAQjB,WAAWoB,IAAAA,mBAAQ,EAACvB,OAAOoB,QAAQjB;QAC9F,IAAMqB,MAAMC,aAAI,CAACC,OAAO,CAAC1B,MAAMyB,IAAI;QACnC,IAAME,UAAUF,aAAI,CAACG,IAAI,CAAC3B,MAAM,AAACuB,CAAAA,MAAMxB,MAAMyB,IAAI,CAACI,KAAK,CAAC,GAAG,CAACL,IAAIM,MAAM,IAAI9B,MAAMyB,IAAI,AAAD,IAAKJ;QAExFU,IAAAA,sBAAM,EAACN,aAAI,CAACO,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASP,OAAOmB,IAAI,EAAE;YAC1D,CAACpC,QAAQqC,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOP,OAAOqB,GAAG,EAAE;YACzFR,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMvC,SAASuC,OAAOvC,SAAS,MAAMuB;;QAC7D;IACF,GACCiB,KAAK,CAACxC;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';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","prepareSWCOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;iEACG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAASF,cAAcK,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW,mBAAKA;QAChBA,SAASC,MAAM,GAAG,mBAAKD,SAASC,MAAM;QACtCD,SAASC,MAAM,CAACC,eAAe,GAAG,mBAAMF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC;QAC5EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,IAAMC,aAAaC,IAAAA,4BAAiB,EAACN;IACrC,IAAMO,MAAMhB,SAAS;IAErBgB,IACGjB,aAAa,CAACK,MAAMa,QAAQ,EAAE,wCACzBb,MAAMc,QAAQ,CAACC,QAAQ,CAAC,WAAWf,MAAMc,QAAQ,CAACC,QAAQ,CAAC,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QACzHC,UAAUlB,MAAMc,QAAQ;QAEzBK,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYnB,SAAS,QAAQoB,IAAAA,mBAAQ,EAACtB,OAAOoB,QAAQjB,WAAWoB,IAAAA,mBAAQ,EAACvB,OAAOoB,QAAQjB;QAC9F,IAAMqB,MAAMC,aAAI,CAACC,OAAO,CAAC1B,MAAMyB,IAAI;QACnC,IAAME,UAAUF,aAAI,CAACG,IAAI,CAAC3B,MAAM,AAACuB,CAAAA,MAAMxB,MAAMyB,IAAI,CAACI,KAAK,CAAC,GAAG,CAACL,IAAIM,MAAM,IAAI9B,MAAMyB,IAAI,AAAD,IAAKJ;QAExFU,IAAAA,sBAAM,EAACN,aAAI,CAACO,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASP,OAAOmB,IAAI,EAAE;YAC1D,CAACpC,QAAQqC,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOP,OAAOqB,GAAG,EAAE;YACzFR,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMvC,SAASuC,OAAOvC,SAAS,MAAMuB;;QAC7D;IACF,GACCiB,KAAK,CAACxC;AACX"}
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
12
+ var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync"));
12
13
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
13
- var _loadTsConfigts = /*#__PURE__*/ _interop_require_default(require("./loadTsConfig.js"));
14
14
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
15
15
  function _define_property(obj, key, value) {
16
16
  if (key in obj) {
@@ -71,9 +71,7 @@ function transformDirectory(src, dest, type, options, callback) {
71
71
  options = null;
72
72
  }
73
73
  options = options || {};
74
- var tsconfig = (0, _loadTsConfigts.default)(_object_spread({
75
- cwd: src
76
- }, options), 'transformDirectory');
74
+ var tsconfig = options.tsconfig ? options.tsconfig : (0, _readtsconfigsync.default)(src);
77
75
  options = _object_spread({
78
76
  tsconfig: tsconfig
79
77
  }, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n dispatch(version, src, dest, type, options as ConfigOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;2DAxBP;0DACD;qEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI1F,SAASG,SAASb,OAAe,EAAEc,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IAC1I,IAAIlB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMT,SAAS,qBAAqB;YAAET,SAAAA;YAASmB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAEe,SAAS1B,mBAAmBoB,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAC9C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMK,WAAWC,IAAAA,uBAAY,EAAC;YAAEC,KAAKV;WAAQG,UAAW;QACxDA,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,SAACC,SAASC;mBAC3Bd,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAA0B,SAACG,KAAKQ;gBACjER,MAAMO,OAAOP,OAAOM,QAAQE;YAC9B;;IAEJ,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = (options || {}) as ConfigOptions;\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n dispatch(version, src, dest, type, options as ConfigOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","Error","tsconfig","loadConfigSync","Promise","resolve","reject","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;2DAxBP;uEACU;0DACX;6DAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI1F,SAASG,SAASb,OAAe,EAAEc,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IAC1I,IAAIlB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMT,SAAS,qBAAqB;YAAET,SAAAA;YAASmB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAEe,SAAS1B,mBAAmBoB,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAC9C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAWA,WAAW,CAAC;QACvB,IAAMK,WAAWL,QAAQK,QAAQ,GAAGL,QAAQK,QAAQ,GAAGC,IAAAA,yBAAc,EAACT;QACtEG,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIM,QAAQ,SAACC,SAASC;mBAC3Bb,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAA0B,SAACG,KAAKO;gBACjEP,MAAMM,OAAON,OAAOK,QAAQE;YAC9B;;IAEJ,EAAE,OAAOP,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOI,QAAQE,MAAM,CAACN;IAC7B;AACF"}
@@ -1,3 +1,3 @@
1
+ import type { TSConfig } from './types.ts';
1
2
  import type { Output } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
3
+ export default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output;
@@ -1,3 +1,3 @@
1
+ import type { TSConfig } from './types.ts';
1
2
  import type { Output } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
3
+ export default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output;
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "default", {
8
8
  return transformSync;
9
9
  }
10
10
  });
11
- var _gettsconfigcompat = /*#__PURE__*/ _interop_require_wildcard(require("get-tsconfig-compat"));
12
11
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
12
+ var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync"));
13
13
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
14
14
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
15
15
  function _interop_require_default(obj) {
@@ -17,47 +17,6 @@ function _interop_require_default(obj) {
17
17
  default: obj
18
18
  };
19
19
  }
20
- function _getRequireWildcardCache(nodeInterop) {
21
- if (typeof WeakMap !== "function") return null;
22
- var cacheBabelInterop = new WeakMap();
23
- var cacheNodeInterop = new WeakMap();
24
- return (_getRequireWildcardCache = function(nodeInterop) {
25
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
26
- })(nodeInterop);
27
- }
28
- function _interop_require_wildcard(obj, nodeInterop) {
29
- if (!nodeInterop && obj && obj.__esModule) {
30
- return obj;
31
- }
32
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
33
- return {
34
- default: obj
35
- };
36
- }
37
- var cache = _getRequireWildcardCache(nodeInterop);
38
- if (cache && cache.has(obj)) {
39
- return cache.get(obj);
40
- }
41
- var newObj = {
42
- __proto__: null
43
- };
44
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
45
- for(var key in obj){
46
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
47
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
48
- if (desc && (desc.get || desc.set)) {
49
- Object.defineProperty(newObj, key, desc);
50
- } else {
51
- newObj[key] = obj[key];
52
- }
53
- }
54
- }
55
- newObj.default = obj;
56
- if (cache) {
57
- cache.set(obj, newObj);
58
- }
59
- return newObj;
60
- }
61
20
  var major = +process.versions.node.split('.')[0];
62
21
  var version = major < 14 ? 'stable' : 'local';
63
22
  var __dirname = _path.default.dirname(typeof __filename === 'undefined' ? _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
@@ -70,7 +29,7 @@ function dispatch(version, contents, fileName, tsconfig) {
70
29
  function transformSync(contents, fileName, tsconfig) {
71
30
  if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');
72
31
  if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');
73
- if (!tsconfig) tsconfig = _gettsconfigcompat.getTsconfig(process.cwd());
32
+ if (!tsconfig) tsconfig = (0, _readtsconfigsync.default)(process.cwd());
74
33
  return dispatch(version, contents, fileName, tsconfig);
75
34
  }
76
35
  /* 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 * as getTS from 'get-tsconfig-compat';\nimport path from 'path';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');\n if (!tsconfig) tsconfig = getTS.getTsconfig(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["transformSync","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","contents","fileName","tsconfig","Error","getTS","getTsconfig","cwd"],"mappings":";;;;+BAoBA;;;eAAwBA;;;yEApBD;2DACN;0DACD;6DAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAIhB,YAAY,SAAS,OAAOS,SAASF,YAAYO,UAAUC,UAAUC;IACzE,OAAOP,SAAS,qBAAqBT,SAASO,YAAYO,UAAUC,UAAUC;AAChF;AAIe,SAAStB,cAAcoB,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IAChG,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIE,MAAM;IAClD,IAAI,CAACD,UAAUA,WAAWE,mBAAMC,WAAW,CAACvB,QAAQwB,GAAG;IACvD,OAAOP,SAASb,SAASc,UAAUC,UAAUC;AAC/C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import 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 version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\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('transformTypes: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["transformSync","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","contents","fileName","tsconfig","Error","loadConfigSync","cwd"],"mappings":";;;;+BAqBA;;;eAAwBA;;;2DArBP;uEACU;0DACX;6DASG;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAIhB,YAAY,SAAS,OAAOS,SAASF,YAAYO,UAAUC,UAAUC;IACzE,OAAOP,SAAS,qBAAqBT,SAASO,YAAYO,UAAUC,UAAUC;AAChF;AAGe,SAAStB,cAAcoB,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIE,MAAM;IAClD,IAAI,CAACD,UAAUA,WAAWE,IAAAA,yBAAc,EAACtB,QAAQuB,GAAG;IACpD,OAAON,SAASb,SAASc,UAAUC,UAAUC;AAC/C"}
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
12
+ var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync"));
12
13
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
13
- var _loadTsConfigts = /*#__PURE__*/ _interop_require_default(require("./loadTsConfig.js"));
14
14
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
15
15
  function _define_property(obj, key, value) {
16
16
  if (key in obj) {
@@ -70,9 +70,7 @@ function transformTypes(src, dest, options, callback) {
70
70
  options = null;
71
71
  }
72
72
  options = options || {};
73
- var tsconfig = (0, _loadTsConfigts.default)(_object_spread({
74
- cwd: src
75
- }, options), 'transformTypes');
73
+ var tsconfig = options.tsconfig ? options.tsconfig : (0, _readtsconfigsync.default)(src);
76
74
  options = _object_spread({
77
75
  tsconfig: tsconfig
78
76
  }, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformTypes');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformTypes","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BAuBA;;;eAAwBA;;;2DAvBP;0DACD;qEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIjB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAET,SAAAA;YAASkB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGe,SAASzB,eAAeoB,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIM,MAAM;QAC7C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMK,WAAWC,IAAAA,uBAAY,EAAC;YAAEC,KAAKT;WAAQE,UAAW;QACxDA,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASb,SAASc,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIO,QAAQ,SAACC,SAASC;mBAAWb,SAASb,SAASc,KAAKC,MAAMC,SAAS,SAACG,KAAKQ;uBAAYR,MAAMO,OAAOP,OAAOM,QAAQE;;;IAC9H,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = (options || {}) as ConfigOptions;\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformTypes","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","options","callback","callbacks","err","Error","tsconfig","loadConfigSync","Promise","resolve","reject","result"],"mappings":";;;;+BAuBA;;;eAAwBA;;;2DAvBP;uEACU;0DACX;6DAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIjB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAET,SAAAA;YAASkB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGe,SAASzB,eAAeoB,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIM,MAAM;QAC7C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAWA,WAAW,CAAC;QACvB,IAAMK,WAAWL,QAAQK,QAAQ,GAAGL,QAAQK,QAAQ,GAAGC,IAAAA,yBAAc,EAACR;QACtEE,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASb,SAASc,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIM,QAAQ,SAACC,SAASC;mBAAWZ,SAASb,SAASc,KAAKC,MAAMC,SAAS,SAACG,KAAKO;uBAAYP,MAAMM,OAAON,OAAOK,QAAQE;;;IAC9H,EAAE,OAAOP,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOI,QAAQE,MAAM,CAACN;IAC7B;AACF"}
@@ -1,10 +1,11 @@
1
+ import type { TSConfig } from 'read-tsconfig-sync';
1
2
  export interface Context {
2
3
  parentURL?: string;
3
4
  parentPath?: string;
4
5
  }
5
- import type { TsConfigResult } from 'get-tsconfig-compat';
6
+ export type { TSConfig, TSConfigSchema } from 'read-tsconfig-sync';
6
7
  export interface ConfigOptions {
7
- tsconfig?: TsConfigResult;
8
+ tsconfig?: TSConfig;
8
9
  cwd?: string;
9
10
  sourceMaps?: boolean;
10
11
  }
@@ -1,10 +1,11 @@
1
+ import type { TSConfig } from 'read-tsconfig-sync';
1
2
  export interface Context {
2
3
  parentURL?: string;
3
4
  parentPath?: string;
4
5
  }
5
- import type { TsConfigResult } from 'get-tsconfig-compat';
6
+ export type { TSConfig, TSConfigSchema } from 'read-tsconfig-sync';
6
7
  export interface ConfigOptions {
7
- tsconfig?: TsConfigResult;
8
+ tsconfig?: TSConfig;
8
9
  cwd?: string;
9
10
  sourceMaps?: boolean;
10
11
  }
@@ -1,3 +1,3 @@
1
1
  import type { Output } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
2
+ import type { TSConfig } from '../types.ts';
3
+ export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TSConfig): Output;
@@ -1,3 +1,3 @@
1
1
  import type { Output } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
2
+ import type { TSConfig } from '../types.ts';
3
+ export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TSConfig): Output;
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
12
- var _swcPrepareOptionsts = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.js"));
12
+ var _prepareSWCOptionsts = /*#__PURE__*/ _interop_require_default(require("../lib/prepareSWCOptions.js"));
13
13
  function _define_property(obj, key, value) {
14
14
  if (key in obj) {
15
15
  Object.defineProperty(obj, key, {
@@ -69,7 +69,7 @@ function _object_spread_props(target, source) {
69
69
  }
70
70
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
71
71
  function transformSyncWorker(contents, fileName, tsconfig) {
72
- var swcOptions = (0, _swcPrepareOptionsts.default)(tsconfig);
72
+ var swcOptions = (0, _prepareSWCOptionsts.default)(tsconfig);
73
73
  var swc = _require('@swc/core');
74
74
  return swc.transformSync(contents, _object_spread_props(_object_spread({}, fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
75
75
  filename: fileName
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport Module from 'module';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","contents","fileName","tsconfig","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAOA;;;eAAwBA;;;6DANL;0EACW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,oBAAoBK,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,IAAMC,aAAaC,IAAAA,4BAAiB,EAACF;IACrC,IAAMG,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACN,UAAU,wCAC7BC,SAASM,QAAQ,CAAC,WAAWN,SAASM,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUT;;AAEd"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport Module from 'module';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\nimport type { TSConfig } from '../types.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TSConfig): Output {\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","contents","fileName","tsconfig","swcOptions","prepareSWCOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAOA;;;eAAwBA;;;6DANL;0EACW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE3E,SAASF,oBAAoBK,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IAChG,IAAMC,aAAaC,IAAAA,4BAAiB,EAACF;IACrC,IAAMG,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACN,UAAU,wCAC7BC,SAASM,QAAQ,CAAC,WAAWN,SAASM,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUT;;AAEd"}
@@ -1,3 +1,2 @@
1
- import type { TsConfigResult } from 'get-tsconfig-compat';
2
- import type { Matcher } from './types.ts';
3
- export default function createMatcher(tsConfig: TsConfigResult): Matcher;
1
+ import type { Matcher, TSConfig } from './types.ts';
2
+ export default function createMatcher(tsconfig: TSConfig): Matcher;
@@ -1,11 +1,7 @@
1
1
  import minimatch from 'minimatch';
2
2
  import path from 'path-posix';
3
3
  import unixify from 'unixify';
4
- import loadTsConfig from './loadTsConfig.js';
5
- export default function createMatcher(tsConfig) {
6
- const tsconfig = loadTsConfig({
7
- tsconfig: tsConfig
8
- }, 'transformTypes');
4
+ export default function createMatcher(tsconfig) {
9
5
  const tsconfigPath = path.dirname(unixify(tsconfig.path));
10
6
  function matchFn(condition) {
11
7
  let pattern = unixify(condition);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig.ts';\nimport type { Matcher } from './types.ts';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AACA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,oBAAoB;AAG7C,eAAe,SAASC,cAAcC,QAAwB;IAC5D,MAAMC,WAAWH,aAAa;QAAEG,UAAUD;IAAS,GAAG;IACtD,MAAME,eAAeN,KAAKO,OAAO,CAACN,QAAQI,SAASL,IAAI;IAEvD,SAASQ,QAAQC,SAAS;QACxB,IAAIC,UAAUT,QAAQQ;QACtB,IAAI,CAACT,KAAKW,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUV,KAAKa,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYX,UAAUgB,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,SAASY,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACrD,MAAMY,WAAW,AAACf,CAAAA,SAASY,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAErD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWd,QAAQc;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport type { Matcher, TSConfig } from './types.ts';\n\nexport default function createMatcher(tsconfig: TSConfig): Matcher {\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = ((tsconfig.config.include as string[]) || []).map(matchFn);\n const excludes = ((tsconfig.config.exclude as string[]) || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["minimatch","path","unixify","createMatcher","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AAAA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAG9B,eAAe,SAASC,cAAcC,QAAkB;IACtD,MAAMC,eAAeJ,KAAKK,OAAO,CAACJ,QAAQE,SAASH,IAAI;IAEvD,SAASM,QAAQC,SAAS;QACxB,IAAIC,UAAUP,QAAQM;QACtB,IAAI,CAACP,KAAKS,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUR,KAAKW,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYT,UAAUc,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAAC,CAAA,AAACX,SAASY,MAAM,CAACC,OAAO,IAAiB,EAAE,AAAD,EAAGC,GAAG,CAACX;IACnE,MAAMY,WAAW,AAAC,CAAA,AAACf,SAASY,MAAM,CAACI,OAAO,IAAiB,EAAE,AAAD,EAAGF,GAAG,CAACX;IAEnE,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWZ,QAAQY;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
@@ -0,0 +1,7 @@
1
+ import type { Options } from '@swc/core';
2
+ import type { TSConfig } from '../types.ts';
3
+ export interface TranspilerOptions {
4
+ tsxOptions: Options;
5
+ nonTsxOptions: Options;
6
+ }
7
+ export default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions;
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import url from 'url';
5
5
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
6
6
  const __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
7
- export default function swcPrepareOptions(tsconfig) {
7
+ export default function prepareSWCOptions(tsconfig) {
8
8
  installSync('@swc/core', `${process.platform}-${process.arch}`, {
9
9
  cwd: __dirname
10
10
  });
@@ -15,7 +15,7 @@ export default function swcPrepareOptions(tsconfig) {
15
15
  const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));
16
16
  return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
17
17
  } catch (err) {
18
- console.log(`swcPrepareOptions failed: ${err.message}`);
18
+ console.log(`prepareSWCOptions failed: ${err.message}`);
19
19
  return {};
20
20
  }
21
21
  }
@@ -0,0 +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 } from 'install-optional';\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\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`prepareSWCOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["installSync","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","prepareSWCOptions","tsconfig","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AACA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,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,eAAe,SAASQ,kBAAkBC,QAAkB;IAC1DZ,YAAY,aAAa,GAAGa,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKT;IAAU;IACjF,IAAI;QACF,MAAMU,KAAKb,SAAS;QACpB,MAAMc,MAAMd,SAAS;QACrB,MAAMe,aAAaf,SAAS;QAC5B,MAAMgB,SAASH,GAAGI,0BAA0B,CAACT,SAASU,MAAM,EAAEL,GAAGM,GAAG,EAAErB,KAAKM,OAAO,CAACI,SAASV,IAAI;QAChG,OAAOiB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
@@ -5,7 +5,7 @@ import path from 'path';
5
5
  import Queue from 'queue-cb';
6
6
  import patchCJS from '../lib/patchCJS.js';
7
7
  import patchESM from '../lib/patchESM.js';
8
- import swcPrepareOptions from '../lib/swcPrepareOptions.js';
8
+ import prepareSWCOptions from '../lib/prepareSWCOptions.js';
9
9
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
10
10
  export default function transformFile(entry, dest, type, options, callback) {
11
11
  let tsconfig = options.tsconfig;
@@ -20,10 +20,10 @@ export default function transformFile(entry, dest, type, options, callback) {
20
20
  tsconfig.config.compilerOptions = {
21
21
  ...tsconfig.config.compilerOptions || {}
22
22
  };
23
- tsconfig.config.compilerOptions.module = 'CommonJS';
24
- tsconfig.config.compilerOptions.target = 'ES5';
23
+ tsconfig.config.compilerOptions.module = 'commonjs';
24
+ tsconfig.config.compilerOptions.target = 'es5';
25
25
  }
26
- const swcOptions = swcPrepareOptions(tsconfig);
26
+ const swcOptions = prepareSWCOptions(tsconfig);
27
27
  const swc = _require('@swc/core');
28
28
  swc.transformFile(entry.fullPath, {
29
29
  ...entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","swcPrepareOptions","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","ext","extname","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,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,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW;YAAE,GAAGA,QAAQ;QAAC;QACzBA,SAASC,MAAM,GAAG;YAAE,GAAGD,SAASC,MAAM;QAAC;QACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;YAAE,GAAIF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAC;QAAE;QAC/EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,MAAMC,aAAahB,kBAAkBW;IACrC,MAAMM,MAAMhB,SAAS;IAErBgB,IACGZ,aAAa,CAACC,MAAMY,QAAQ,EAAE;QAC7B,GAAIZ,MAAMa,QAAQ,CAACC,QAAQ,CAAC,WAAWd,MAAMa,QAAQ,CAACC,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QACzHC,UAAUjB,MAAMa,QAAQ;IAC1B,GACCK,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYlB,SAAS,QAAQT,SAASO,OAAOmB,QAAQhB,WAAWX,SAASQ,OAAOmB,QAAQhB;QAC9F,MAAMkB,MAAM/B,KAAKgC,OAAO,CAACtB,MAAMV,IAAI;QACnC,MAAMiC,UAAUjC,KAAKkC,IAAI,CAACvB,MAAM,AAACoB,CAAAA,MAAMrB,MAAMV,IAAI,CAACmC,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAI1B,MAAMV,IAAI,AAAD,IAAK8B;QAExFhC,OAAOE,KAAKqC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIrC;YAClBqC,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC7B,QAAQ8B,UAAU,IAAIL,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMmB;QAC7D;IACF,GACCc,KAAK,CAACjC;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';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\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","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","ext","extname","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,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,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW;YAAE,GAAGA,QAAQ;QAAC;QACzBA,SAASC,MAAM,GAAG;YAAE,GAAGD,SAASC,MAAM;QAAC;QACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;YAAE,GAAIF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAC;QAAE;QAC/EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,MAAMC,aAAahB,kBAAkBW;IACrC,MAAMM,MAAMhB,SAAS;IAErBgB,IACGZ,aAAa,CAACC,MAAMY,QAAQ,EAAE;QAC7B,GAAIZ,MAAMa,QAAQ,CAACC,QAAQ,CAAC,WAAWd,MAAMa,QAAQ,CAACC,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QACzHC,UAAUjB,MAAMa,QAAQ;IAC1B,GACCK,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYlB,SAAS,QAAQT,SAASO,OAAOmB,QAAQhB,WAAWX,SAASQ,OAAOmB,QAAQhB;QAC9F,MAAMkB,MAAM/B,KAAKgC,OAAO,CAACtB,MAAMV,IAAI;QACnC,MAAMiC,UAAUjC,KAAKkC,IAAI,CAACvB,MAAM,AAACoB,CAAAA,MAAMrB,MAAMV,IAAI,CAACmC,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAI1B,MAAMV,IAAI,AAAD,IAAK8B;QAExFhC,OAAOE,KAAKqC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIrC;YAClBqC,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC7B,QAAQ8B,UAAU,IAAIL,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMmB;QAC7D;IACF,GACCc,KAAK,CAACjC;AACX"}
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
+ import loadConfigSync from 'read-tsconfig-sync';
2
3
  import url from 'url';
3
- import loadTsConfig from './loadTsConfig.js';
4
4
  const major = +process.versions.node.split('.')[0];
5
5
  const version = major < 14 ? 'stable' : 'local';
6
6
  const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
@@ -28,10 +28,7 @@ export default function transformDirectory(src, dest, type, options, callback) {
28
28
  options = null;
29
29
  }
30
30
  options = options || {};
31
- const tsconfig = loadTsConfig({
32
- cwd: src,
33
- ...options
34
- }, 'transformDirectory');
31
+ const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);
35
32
  options = {
36
33
  tsconfig,
37
34
  ...options
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n dispatch(version, src, dest, type, options as ConfigOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;AAE7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYjB,GAAG,IAAIgB;AAI1F,SAASE,SAASX,OAAe,EAAEY,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IAC1I,IAAIhB,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAER;YAASiB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAEA,eAAe,SAASC,mBAAmBP,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAC9C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMM,WAAW3B,aAAa;YAAE4B,KAAKV;YAAK,GAAGG,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,CAACC,SAASC,SAC3Bd,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAA0B,CAACG,KAAKQ;gBACjER,MAAMO,OAAOP,OAAOM,QAAQE;YAC9B;IAEJ,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = (options || {}) as ConfigOptions;\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n dispatch(version, src, dest, type, options as ConfigOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","loadConfigSync","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAEtB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAI1F,SAASE,SAASX,OAAe,EAAEY,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IAC1I,IAAIhB,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAER;YAASiB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAEA,eAAe,SAASC,mBAAmBP,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAC9C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAWA,WAAW,CAAC;QACvB,MAAMM,WAAWN,QAAQM,QAAQ,GAAGN,QAAQM,QAAQ,GAAG5B,eAAemB;QACtEG,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIM,QAAQ,CAACC,SAASC,SAC3Bb,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAA0B,CAACG,KAAKO;gBACjEP,MAAMM,OAAON,OAAOK,QAAQE;YAC9B;IAEJ,EAAE,OAAOP,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOI,QAAQE,MAAM,CAACN;IAC7B;AACF"}
@@ -1,3 +1,3 @@
1
+ import type { TSConfig } from './types.ts';
1
2
  import type { Output } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
3
+ export default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output;
@@ -1,5 +1,5 @@
1
- import * as getTS from 'get-tsconfig-compat';
2
1
  import path from 'path';
2
+ import loadConfigSync from 'read-tsconfig-sync';
3
3
  import url from 'url';
4
4
  const major = +process.versions.node.split('.')[0];
5
5
  const version = major < 14 ? 'stable' : 'local';
@@ -14,6 +14,6 @@ function dispatch(version, contents, fileName, tsconfig) {
14
14
  export default function transformSync(contents, fileName, tsconfig) {
15
15
  if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');
16
16
  if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');
17
- if (!tsconfig) tsconfig = getTS.getTsconfig(process.cwd());
17
+ if (!tsconfig) tsconfig = loadConfigSync(process.cwd());
18
18
  return dispatch(version, contents, fileName, tsconfig);
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport path from 'path';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');\n if (!tsconfig) tsconfig = getTS.getTsconfig(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["getTS","path","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","contents","fileName","tsconfig","transformSync","Error","getTsconfig","cwd"],"mappings":"AAAA,YAAYA,WAAW,sBAAsB;AAC7C,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYR,KAAKS,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAaZ,KAAKa,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAE1F,SAASE,SAASX,OAAO,EAAEY,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAId,YAAY,SAAS,OAAOQ,SAASH,YAAYO,UAAUC,UAAUC;IACzE,OAAON,SAAS,qBAAqBR,SAASK,YAAYO,UAAUC,UAAUC;AAChF;AAIA,eAAe,SAASC,cAAcH,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IAChG,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAII,MAAM;IAClD,IAAI,OAAOH,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,CAACF,UAAUA,WAAWtB,MAAMyB,WAAW,CAACrB,QAAQsB,GAAG;IACvD,OAAOP,SAASX,SAASY,UAAUC,UAAUC;AAC/C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import 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 version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\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('transformTypes: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["path","loadConfigSync","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","contents","fileName","tsconfig","transformSync","Error","cwd"],"mappings":"AAAA,OAAOA,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,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAE1F,SAASE,SAASX,OAAO,EAAEY,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAId,YAAY,SAAS,OAAOQ,SAASH,YAAYO,UAAUC,UAAUC;IACzE,OAAON,SAAS,qBAAqBR,SAASK,YAAYO,UAAUC,UAAUC;AAChF;AAGA,eAAe,SAASC,cAAcH,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAII,MAAM;IAClD,IAAI,OAAOH,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,CAACF,UAAUA,WAAWrB,eAAeG,QAAQqB,GAAG;IACpD,OAAON,SAASX,SAASY,UAAUC,UAAUC;AAC/C"}
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
+ import loadConfigSync from 'read-tsconfig-sync';
2
3
  import url from 'url';
3
- import loadTsConfig from './loadTsConfig.js';
4
4
  const major = +process.versions.node.split('.')[0];
5
5
  const version = major < 14 ? 'stable' : 'local';
6
6
  const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
@@ -27,10 +27,7 @@ export default function transformTypes(src, dest, options, callback) {
27
27
  options = null;
28
28
  }
29
29
  options = options || {};
30
- const tsconfig = loadTsConfig({
31
- cwd: src,
32
- ...options
33
- }, 'transformTypes');
30
+ const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);
34
31
  options = {
35
32
  tsconfig,
36
33
  ...options
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformTypes');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","options","callback","callbacks","err","transformTypes","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;AAE7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYjB,GAAG,IAAIgB;AAE1F,SAASE,SAASX,OAAO,EAAEY,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIf,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMP,SAAS,qBAAqB;YAAER;YAASgB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGA,eAAe,SAASC,eAAeN,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMM,WAAW1B,aAAa;YAAE2B,KAAKT;YAAK,GAAGE,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASX,SAASY,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIO,QAAQ,CAACC,SAASC,SAAWb,SAASX,SAASY,KAAKC,MAAMC,SAAS,CAACG,KAAKQ,SAAYR,MAAMO,OAAOP,OAAOM,QAAQE;IAC9H,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | 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 if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = (options || {}) as ConfigOptions;\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","loadConfigSync","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","options","callback","callbacks","err","transformTypes","Error","tsconfig","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAEtB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAE1F,SAASE,SAASX,OAAO,EAAEY,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIf,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMP,SAAS,qBAAqB;YAAER;YAASgB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGA,eAAe,SAASC,eAAeN,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAWA,WAAW,CAAC;QACvB,MAAMM,WAAWN,QAAQM,QAAQ,GAAGN,QAAQM,QAAQ,GAAG3B,eAAemB;QACtEE,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASX,SAASY,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIM,QAAQ,CAACC,SAASC,SAAWZ,SAASX,SAASY,KAAKC,MAAMC,SAAS,CAACG,KAAKO,SAAYP,MAAMM,OAAON,OAAOK,QAAQE;IAC9H,EAAE,OAAOP,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOI,QAAQE,MAAM,CAACN;IAC7B;AACF"}
@@ -1,10 +1,11 @@
1
+ import type { TSConfig } from 'read-tsconfig-sync';
1
2
  export interface Context {
2
3
  parentURL?: string;
3
4
  parentPath?: string;
4
5
  }
5
- import type { TsConfigResult } from 'get-tsconfig-compat';
6
+ export type { TSConfig, TSConfigSchema } from 'read-tsconfig-sync';
6
7
  export interface ConfigOptions {
7
- tsconfig?: TsConfigResult;
8
+ tsconfig?: TSConfig;
8
9
  cwd?: string;
9
10
  sourceMaps?: boolean;
10
11
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/types.ts"],"sourcesContent":["export interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport interface ConfigOptions {\n tsconfig?: TsConfigResult;\n cwd?: string;\n sourceMaps?: boolean;\n}\n\nexport type TransformDirectoryCallback = (err?: Error, filePaths?: string[]) => void;\nexport type TransformFileCallback = (err?: Error, destFilePath?: string) => void;\nexport type TransformTypesCallback = (err?: Error, filePaths?: string[]) => void;\n\nexport type Matcher = (filePath: string) => boolean;\n\nexport type TargetType = 'cjs' | 'esm';\n"],"names":[],"mappings":"AAmBA,WAAuC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/types.ts"],"sourcesContent":["import type { TSConfig } from 'read-tsconfig-sync';\n\nexport interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n\nexport type { TSConfig, TSConfigSchema } from 'read-tsconfig-sync';\nexport interface ConfigOptions {\n tsconfig?: TSConfig;\n cwd?: string;\n sourceMaps?: boolean;\n}\n\nexport type TransformDirectoryCallback = (err?: Error, filePaths?: string[]) => void;\nexport type TransformFileCallback = (err?: Error, destFilePath?: string) => void;\nexport type TransformTypesCallback = (err?: Error, filePaths?: string[]) => void;\n\nexport type Matcher = (filePath: string) => boolean;\n\nexport type TargetType = 'cjs' | 'esm';\n"],"names":[],"mappings":"AAoBA,WAAuC"}
@@ -1,3 +1,3 @@
1
1
  import type { Output } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
2
+ import type { TSConfig } from '../types.ts';
3
+ export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TSConfig): Output;
@@ -1,8 +1,8 @@
1
1
  import Module from 'module';
2
- import swcPrepareOptions from '../lib/swcPrepareOptions.js';
2
+ import prepareSWCOptions from '../lib/prepareSWCOptions.js';
3
3
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
4
4
  export default function transformSyncWorker(contents, fileName, tsconfig) {
5
- const swcOptions = swcPrepareOptions(tsconfig);
5
+ const swcOptions = prepareSWCOptions(tsconfig);
6
6
  const swc = _require('@swc/core');
7
7
  return swc.transformSync(contents, {
8
8
  ...fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport Module from 'module';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["Module","swcPrepareOptions","_require","require","createRequire","url","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":"AACA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,MAAMC,aAAaT,kBAAkBQ;IACrC,MAAME,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACL,UAAU;QACjC,GAAIC,SAASK,QAAQ,CAAC,WAAWL,SAASK,QAAQ,CAAC,UAAUH,WAAWI,UAAU,GAAGJ,WAAWK,aAAa;QAC7GC,UAAUR;IACZ;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport Module from 'module';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\nimport type { TSConfig } from '../types.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TSConfig): Output {\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["Module","prepareSWCOptions","_require","require","createRequire","url","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":"AACA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,uBAAuB,8BAA8B;AAG5D,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,eAAe,SAASG,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IAChG,MAAMC,aAAaT,kBAAkBQ;IACrC,MAAME,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACL,UAAU;QACjC,GAAIC,SAASK,QAAQ,CAAC,WAAWL,SAASK,QAAQ,CAAC,UAAUH,WAAWI,UAAU,GAAGJ,WAAWK,aAAa;QAC7GC,UAAUR;IACZ;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-swc-transform",
3
- "version": "2.2.8",
3
+ "version": "2.4.0",
4
4
  "description": "Typescript transformers for swc. Supports Node >= 0.8",
5
5
  "keywords": [
6
6
  "matcher",
@@ -47,7 +47,6 @@
47
47
  "core-js-pure": "*",
48
48
  "exit": "^0.1.2",
49
49
  "fs-iterator": "^6.0.5",
50
- "get-tsconfig-compat": "^2.0.3",
51
50
  "install-optional": "^0.1.76",
52
51
  "is-absolute": "^1.0.0",
53
52
  "lodash.find": "^4.6.0",
@@ -56,6 +55,7 @@
56
55
  "node-version-call": "^1.8.5",
57
56
  "path-posix": "^1.0.0",
58
57
  "queue-cb": "^1.5.5",
58
+ "read-tsconfig-sync": "^0.1.0",
59
59
  "resolve": "^1.22.10",
60
60
  "rimraf2": "^2.8.2",
61
61
  "ts-node": "*",
@@ -1,7 +0,0 @@
1
- import type { Options } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export interface TranspilerOptions {
4
- tsxOptions: Options;
5
- nonTsxOptions: Options;
6
- }
7
- export default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions;
@@ -1,7 +0,0 @@
1
- import type { Options } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export interface TranspilerOptions {
4
- tsxOptions: Options;
5
- nonTsxOptions: Options;
6
- }
7
- export default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync } from 'install-optional';\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 { TsConfigResult } from 'get-tsconfig-compat';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","tsconfig","installSync","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAgBA;;;eAAwBA;;;+BAfI;6DACT;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;AASnF,SAASV,kBAAkBW,QAAwB;IAChEC,IAAAA,4BAAW,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI,GAAI;QAAEC,KAAKX;IAAU;IACjF,IAAI;QACF,IAAMY,KAAKhB,SAAS;QACpB,IAAMiB,MAAMjB,SAAS;QACrB,IAAMkB,aAAalB,SAAS;QAC5B,IAAMmB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEjB,aAAI,CAACC,OAAO,CAACI,SAASL,IAAI;QAChG,OAAOa,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
@@ -1,3 +0,0 @@
1
- import * as getTS from 'get-tsconfig-compat';
2
- import type { ConfigOptions } from './types.ts';
3
- export default function loadTsConfig(options: ConfigOptions, name: string): getTS.TsConfigResult;
@@ -1,3 +0,0 @@
1
- import * as getTS from 'get-tsconfig-compat';
2
- import type { ConfigOptions } from './types.ts';
3
- export default function loadTsConfig(options: ConfigOptions, name: string): getTS.TsConfigResult;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return loadTsConfig;
9
- }
10
- });
11
- var _gettsconfigcompat = /*#__PURE__*/ _interop_require_wildcard(require("get-tsconfig-compat"));
12
- function _getRequireWildcardCache(nodeInterop) {
13
- if (typeof WeakMap !== "function") return null;
14
- var cacheBabelInterop = new WeakMap();
15
- var cacheNodeInterop = new WeakMap();
16
- return (_getRequireWildcardCache = function(nodeInterop) {
17
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
18
- })(nodeInterop);
19
- }
20
- function _interop_require_wildcard(obj, nodeInterop) {
21
- if (!nodeInterop && obj && obj.__esModule) {
22
- return obj;
23
- }
24
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
- return {
26
- default: obj
27
- };
28
- }
29
- var cache = _getRequireWildcardCache(nodeInterop);
30
- if (cache && cache.has(obj)) {
31
- return cache.get(obj);
32
- }
33
- var newObj = {
34
- __proto__: null
35
- };
36
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
37
- for(var key in obj){
38
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
39
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
40
- if (desc && (desc.get || desc.set)) {
41
- Object.defineProperty(newObj, key, desc);
42
- } else {
43
- newObj[key] = obj[key];
44
- }
45
- }
46
- }
47
- newObj.default = obj;
48
- if (cache) {
49
- cache.set(obj, newObj);
50
- }
51
- return newObj;
52
- }
53
- function _type_of(obj) {
54
- "@swc/helpers - typeof";
55
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
56
- }
57
- function loadTsConfig(options, name) {
58
- var tsconfig = options.tsconfig;
59
- if (!tsconfig) tsconfig = _gettsconfigcompat.getTsconfig(options.cwd || process.cwd());
60
- if ((typeof tsconfig === "undefined" ? "undefined" : _type_of(tsconfig)) !== 'object') throw new Error("".concat(name, ": missing valid tsconfig"));
61
- if (tsconfig.path === undefined) throw new Error("".concat(name, ": expecting tsconfig.path"));
62
- if (tsconfig.config === undefined) throw new Error("".concat(name, ": expecting tsconfig.config"));
63
- return tsconfig;
64
- }
65
- /* 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 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/loadTsConfig.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport type { ConfigOptions } from './types.ts';\n\nexport default function loadTsConfig(options: ConfigOptions, name: string): getTS.TsConfigResult {\n let tsconfig = options.tsconfig;\n if (!tsconfig) tsconfig = getTS.getTsconfig(options.cwd || process.cwd());\n\n if (typeof tsconfig !== 'object') throw new Error(`${name}: missing valid tsconfig`);\n if (tsconfig.path === undefined) throw new Error(`${name}: expecting tsconfig.path`);\n if (tsconfig.config === undefined) throw new Error(`${name}: expecting tsconfig.config`);\n return tsconfig;\n}\n"],"names":["loadTsConfig","options","name","tsconfig","getTS","getTsconfig","cwd","process","Error","path","undefined","config"],"mappings":";;;;+BAGA;;;eAAwBA;;;yEAHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGR,SAASA,aAAaC,OAAsB,EAAEC,IAAY;IACvE,IAAIC,WAAWF,QAAQE,QAAQ;IAC/B,IAAI,CAACA,UAAUA,WAAWC,mBAAMC,WAAW,CAACJ,QAAQK,GAAG,IAAIC,QAAQD,GAAG;IAEtE,IAAI,CAAA,OAAOH,yCAAP,SAAOA,SAAO,MAAM,UAAU,MAAM,IAAIK,MAAM,AAAC,GAAO,OAALN,MAAK;IAC1D,IAAIC,SAASM,IAAI,KAAKC,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IACzD,IAAIC,SAASQ,MAAM,KAAKD,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IAC3D,OAAOC;AACT"}
@@ -1,7 +0,0 @@
1
- import type { Options } from '@swc/core';
2
- import type { TsConfigResult } from 'get-tsconfig-compat';
3
- export interface TranspilerOptions {
4
- tsxOptions: Options;
5
- nonTsxOptions: Options;
6
- }
7
- export default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync } from 'install-optional';\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 { TsConfigResult } from 'get-tsconfig-compat';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["installSync","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","swcPrepareOptions","tsconfig","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AACA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,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,eAAe,SAASQ,kBAAkBC,QAAwB;IAChEZ,YAAY,aAAa,GAAGa,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKT;IAAU;IACjF,IAAI;QACF,MAAMU,KAAKb,SAAS;QACpB,MAAMc,MAAMd,SAAS;QACrB,MAAMe,aAAaf,SAAS;QAC5B,MAAMgB,SAASH,GAAGI,0BAA0B,CAACT,SAASU,MAAM,EAAEL,GAAGM,GAAG,EAAErB,KAAKM,OAAO,CAACI,SAASV,IAAI;QAChG,OAAOiB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
@@ -1,3 +0,0 @@
1
- import * as getTS from 'get-tsconfig-compat';
2
- import type { ConfigOptions } from './types.ts';
3
- export default function loadTsConfig(options: ConfigOptions, name: string): getTS.TsConfigResult;
@@ -1,9 +0,0 @@
1
- import * as getTS from 'get-tsconfig-compat';
2
- export default function loadTsConfig(options, name) {
3
- let tsconfig = options.tsconfig;
4
- if (!tsconfig) tsconfig = getTS.getTsconfig(options.cwd || process.cwd());
5
- if (typeof tsconfig !== 'object') throw new Error(`${name}: missing valid tsconfig`);
6
- if (tsconfig.path === undefined) throw new Error(`${name}: expecting tsconfig.path`);
7
- if (tsconfig.config === undefined) throw new Error(`${name}: expecting tsconfig.config`);
8
- return tsconfig;
9
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/loadTsConfig.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport type { ConfigOptions } from './types.ts';\n\nexport default function loadTsConfig(options: ConfigOptions, name: string): getTS.TsConfigResult {\n let tsconfig = options.tsconfig;\n if (!tsconfig) tsconfig = getTS.getTsconfig(options.cwd || process.cwd());\n\n if (typeof tsconfig !== 'object') throw new Error(`${name}: missing valid tsconfig`);\n if (tsconfig.path === undefined) throw new Error(`${name}: expecting tsconfig.path`);\n if (tsconfig.config === undefined) throw new Error(`${name}: expecting tsconfig.config`);\n return tsconfig;\n}\n"],"names":["getTS","loadTsConfig","options","name","tsconfig","getTsconfig","cwd","process","Error","path","undefined","config"],"mappings":"AAAA,YAAYA,WAAW,sBAAsB;AAG7C,eAAe,SAASC,aAAaC,OAAsB,EAAEC,IAAY;IACvE,IAAIC,WAAWF,QAAQE,QAAQ;IAC/B,IAAI,CAACA,UAAUA,WAAWJ,MAAMK,WAAW,CAACH,QAAQI,GAAG,IAAIC,QAAQD,GAAG;IAEtE,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAII,MAAM,GAAGL,KAAK,wBAAwB,CAAC;IACnF,IAAIC,SAASK,IAAI,KAAKC,WAAW,MAAM,IAAIF,MAAM,GAAGL,KAAK,yBAAyB,CAAC;IACnF,IAAIC,SAASO,MAAM,KAAKD,WAAW,MAAM,IAAIF,MAAM,GAAGL,KAAK,2BAA2B,CAAC;IACvF,OAAOC;AACT"}