ts-swc-transform 2.8.2 → 2.9.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.
- package/dist/cjs/lib/prepareSWCOptions.js +2 -1
- package/dist/cjs/lib/prepareSWCOptions.js.map +1 -1
- package/dist/cjs/lib/transformFile.d.cts +1 -1
- package/dist/cjs/lib/transformFile.d.ts +1 -1
- package/dist/cjs/lib/transformFile.js.map +1 -1
- package/dist/cjs/transformDirectory.d.cts +4 -1
- package/dist/cjs/transformDirectory.d.ts +4 -1
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformTypes.d.cts +4 -1
- package/dist/cjs/transformTypes.d.ts +4 -1
- package/dist/cjs/transformTypes.js.map +1 -1
- package/dist/cjs/workers/transformDirectory.d.cts +1 -1
- package/dist/cjs/workers/transformDirectory.d.ts +1 -1
- package/dist/cjs/workers/transformDirectory.js +1 -4
- package/dist/cjs/workers/transformDirectory.js.map +1 -1
- package/dist/cjs/workers/transformTypes.d.cts +1 -1
- package/dist/cjs/workers/transformTypes.d.ts +1 -1
- package/dist/cjs/workers/transformTypes.js +2 -8
- package/dist/cjs/workers/transformTypes.js.map +1 -1
- package/dist/esm/lib/prepareSWCOptions.js +3 -2
- package/dist/esm/lib/prepareSWCOptions.js.map +1 -1
- package/dist/esm/lib/transformFile.d.ts +1 -1
- package/dist/esm/lib/transformFile.js.map +1 -1
- package/dist/esm/transformDirectory.d.ts +4 -1
- package/dist/esm/transformDirectory.js.map +1 -1
- package/dist/esm/transformTypes.d.ts +4 -1
- package/dist/esm/transformTypes.js.map +1 -1
- package/dist/esm/workers/transformDirectory.d.ts +1 -1
- package/dist/esm/workers/transformDirectory.js +1 -4
- package/dist/esm/workers/transformDirectory.js.map +1 -1
- package/dist/esm/workers/transformTypes.d.ts +1 -1
- package/dist/esm/workers/transformTypes.js +2 -8
- package/dist/esm/workers/transformTypes.js.map +1 -1
- package/package.json +3 -3
|
@@ -26,7 +26,8 @@ var installSyncSWC = (0, _lodashdebounce.default)(_installoptional.installSync,
|
|
|
26
26
|
});
|
|
27
27
|
function prepareSWCOptions(tsconfig) {
|
|
28
28
|
installSyncSWC('@swc/core', "".concat(process.platform, "-").concat(process.arch), {
|
|
29
|
-
cwd: __dirname
|
|
29
|
+
cwd: __dirname,
|
|
30
|
+
filter: _installoptional.matchesLibc
|
|
30
31
|
});
|
|
31
32
|
try {
|
|
32
33
|
var ts = _require('typescript');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/prepareSWCOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync } from 'install-optional';\nimport debounce from 'lodash.debounce';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TSConfig } from '../types.ts';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nconst installSyncSWC = debounce(installSync, 300, { leading: true, trailing: false });\n\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\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","installSyncSWC","debounce","installSync","leading","trailing","tsconfig","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAmBA;;;eAAwBA;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/prepareSWCOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync, matchesLibc } from 'install-optional';\nimport debounce from 'lodash.debounce';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TSConfig } from '../types.ts';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nconst installSyncSWC = debounce(installSync, 300, { leading: true, trailing: false });\n\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname, filter: matchesLibc });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`prepareSWCOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["prepareSWCOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","installSyncSWC","debounce","installSync","leading","trailing","tsconfig","process","platform","arch","cwd","filter","matchesLibc","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAmBA;;;eAAwBA;;;+BAlBiB;qEACpB;6DACF;2DACF;0DACD;;;;;;AAEhB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AASlG,IAAMC,iBAAiBC,IAAAA,uBAAQ,EAACC,4BAAW,EAAE,KAAK;IAAEC,SAAS;IAAMC,UAAU;AAAM;AAEpE,SAASf,kBAAkBgB,QAAkB;IAC1DL,eAAe,aAAa,AAAC,GAAsBM,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI,GAAI;QAAEC,KAAKf;QAAWgB,QAAQC,4BAAW;IAAC;IACzG,IAAI;QACF,IAAMC,KAAKtB,SAAS;QACpB,IAAMuB,MAAMvB,SAAS;QACrB,IAAMwB,aAAaxB,SAAS;QAC5B,IAAMyB,SAASH,GAAGI,0BAA0B,CAACX,SAASY,MAAM,EAAEL,GAAGM,GAAG,EAAEvB,aAAI,CAACC,OAAO,CAACS,SAASV,IAAI;QAChG,OAAOmB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Entry } from 'fs-iterator';
|
|
2
2
|
import type { ConfigOptions, TargetType, TransformFileCallback } from '../types.js';
|
|
3
|
-
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback):
|
|
3
|
+
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Entry } from 'fs-iterator';
|
|
2
2
|
import type { ConfigOptions, TargetType, TransformFileCallback } from '../types.js';
|
|
3
|
-
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback):
|
|
3
|
+
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback):
|
|
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): void {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n // Get source file mode to preserve executable permissions\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (statErr) return callback(statErr);\n\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => {\n if (err) return callback(err);\n\n // Preserve executable permissions from source (only +x bits, not full mode)\n const execBits = stats.mode & 0o111;\n if (execBits) {\n fs.chmod(outPath, 0o644 | execBits, (_chmodErr) => {\n // Ignore chmod errors (e.g., on Windows)\n callback(null, outPath);\n });\n } else {\n callback(null, outPath);\n }\n });\n });\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","ext","path","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","fs","stat","statErr","stats","extTarget","patchESM","patchCJS","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","writeFile","bind","code","map","sourceMaps","await","err","execBits","mode","chmod","_chmodErr","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;iEACG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAAS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OAAO,CAACL,UAAU;gBAC5B,IAAMM,QAAQ,IAAIC,gBAAK;gBACvBD,MAAME,KAAK,CAACf,WAAE,CAACgB,SAAS,CAACC,IAAI,CAAC,MAAMV,SAASR,OAAOmB,IAAI,EAAE;gBAC1D,IAAInB,OAAOoB,GAAG,IAAIvC,QAAQwC,UAAU,EAAEP,MAAME,KAAK,CAACf,WAAE,CAACgB,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARV,SAAQ,SAAOR,OAAOoB,GAAG,EAAE;gBACxGN,MAAMQ,KAAK,CAAC,SAACC;oBACX,IAAIA,KAAK,OAAOzC,SAASyC;oBAEzB,4EAA4E;oBAC5E,IAAMC,WAAWpB,MAAMqB,IAAI,GAAG;oBAC9B,IAAID,UAAU;wBACZvB,WAAE,CAACyB,KAAK,CAAClB,SAAS,MAAQgB,UAAU,SAACG;4BACnC,yCAAyC;4BACzC7C,SAAS,MAAM0B;wBACjB;oBACF,OAAO;wBACL1B,SAAS,MAAM0B;oBACjB;gBACF;YACF;QACF;IACF,GACCoB,KAAK,CAAC9C;AACX"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.js';
|
|
2
|
-
export default function transformDirectory(src: string, dest: string, type: TargetType,
|
|
2
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;
|
|
3
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
4
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;
|
|
5
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.js';
|
|
2
|
-
export default function transformDirectory(src: string, dest: string, type: TargetType,
|
|
2
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;
|
|
3
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
4
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;
|
|
5
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
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)
|
|
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) {\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, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n 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);\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":";;;;+BA4BA;;;eAAwBA;;;2DA5BP;uEACU;0DACX;6DAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AA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MC,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,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from './types.js';
|
|
2
|
-
export default function transformTypes(src: string, dest: string,
|
|
2
|
+
export default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;
|
|
3
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
4
|
+
export default function transformTypes(src: string, dest: string): Promise<string[]>;
|
|
5
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from './types.js';
|
|
2
|
-
export default function transformTypes(src: string, dest: string,
|
|
2
|
+
export default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;
|
|
3
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
4
|
+
export default function transformTypes(src: string, dest: string): Promise<string[]>;
|
|
5
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
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):
|
|
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';\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n 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":";;;;+BA4BA;;;eAAwBA;;;2DA5BP;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;AAQe,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,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
|
|
2
|
-
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback):
|
|
2
|
+
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
|
|
2
|
-
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback):
|
|
2
|
+
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
@@ -85,10 +85,7 @@ function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
|
85
85
|
if (ext && _constantsts.extensions.indexOf(ext) < 0) return;
|
|
86
86
|
entries.push(entry);
|
|
87
87
|
}, function(err) {
|
|
88
|
-
if (err)
|
|
89
|
-
callback(err);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
88
|
+
if (err) return callback(err);
|
|
92
89
|
var results = [];
|
|
93
90
|
options = _object_spread_props(_object_spread({}, options), {
|
|
94
91
|
tsconfig: tsconfig
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries: Entry[] = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","err","results","queue","Queue","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BAUA;;;eAAwBA;;;iEAVa;2DACpB;8DACC;2BAEwB;sEAChB;sEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIX,SAASA,yBAAyBC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACxJ,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,wBAAa,EAACF;IAE9B,IAAMG,UAAmB,EAAE;IAC3B,IAAMC,WAAW,IAAIC,mBAAQ,CAACV;IAC9BS,SAASE,OAAO,CACd,SAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIC,0BAAa,CAACC,IAAI,CAACL,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACT,QAAQM,MAAMM,QAAQ,GAAG;QAC9B,IAAMC,MAAMC,aAAI,CAACC,OAAO,CAACT,MAAMG,QAAQ;QACvC,IAAII,OAAOG,uBAAU,CAACC,OAAO,CAACJ,OAAO,GAAG;QACxCX,QAAQgB,IAAI,CAACZ;IACf,GACA,SAACa;QACC,IAAIA,KAAK,OAAOrB,SAASqB;QACzB,IAAMC,UAAU,EAAE;QAClBvB,UAAU,wCAAKA;YAASE,UAAAA;;QAExB,IAAMsB,QAAQ,IAAIC,gBAAK;QACvBpB,QAAQG,OAAO,CAAC,SAACC;YACfe,MAAME,KAAK,CAAC,SAACC;uBACXC,IAAAA,wBAAa,EAACnB,OAAOX,MAAMC,MAAMC,SAAS,SAACsB,KAAKO;oBAC9C,IAAIP,KAAK,OAAOK,GAAGL;oBACnBC,QAAQF,IAAI,CAACJ,aAAI,CAACa,SAAS,CAACD;oBAC5B,IAAI7B,QAAQ+B,UAAU,EAAER,QAAQF,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACa,SAAS,CAACD,UAAS;oBAChEF;gBACF;;QAEJ;QACAH,MAAMQ,KAAK,CAAC,SAACV;mBAASA,MAAMrB,SAASqB,OAAOrB,SAAS,MAAMsB;;IAC7D;AAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from '../types.js';
|
|
2
|
-
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback):
|
|
2
|
+
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from '../types.js';
|
|
2
|
-
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback):
|
|
2
|
+
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
@@ -136,10 +136,7 @@ function transformTypesWorker(src, dest, options, callback) {
|
|
|
136
136
|
}, {
|
|
137
137
|
concurrency: Infinity
|
|
138
138
|
}, function(err) {
|
|
139
|
-
if (err)
|
|
140
|
-
callback(err);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
139
|
+
if (err) return callback(err);
|
|
143
140
|
// Step 1: Stat all source files to get their modes (async)
|
|
144
141
|
var sourceModes = new Map();
|
|
145
142
|
var statQueue = new _queuecb.default();
|
|
@@ -152,10 +149,7 @@ function transformTypesWorker(src, dest, options, callback) {
|
|
|
152
149
|
});
|
|
153
150
|
});
|
|
154
151
|
statQueue.await(function(statErr) {
|
|
155
|
-
if (statErr)
|
|
156
|
-
callback(statErr);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
152
|
+
if (statErr) return callback(statErr);
|
|
159
153
|
// Step 2: TypeScript emit (inherently sync - cannot change)
|
|
160
154
|
var compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
|
|
161
155
|
var config = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n // Step 1: Stat all source files to get their modes (async)\n const sourceModes = new Map<string, number>();\n const statQueue = new Queue();\n entries.forEach((entry) => {\n statQueue.defer((cb) => {\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (!statErr) sourceModes.set(entry.fullPath, stats.mode);\n cb(); // Continue even on error\n });\n });\n });\n\n statQueue.await((statErr) => {\n if (statErr) return callback(statErr);\n\n // Step 2: TypeScript emit (inherently sync - cannot change)\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // Step 3: Post-process emitted files (async)\n const postQueue = new Queue();\n\n if (res.emittedFiles) {\n res.emittedFiles.forEach((file) => {\n // 3a: Rewrite extensions (convert from sync to async)\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (compilerOptions.options.rewriteRelativeImportExtensions) {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n postQueue.defer((cb) => {\n fs.readFile(file, 'utf8', (readErr, content) => {\n if (readErr) return cb(); // Ignore errors, continue\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFile(file, updated, 'utf8', () => cb()); // Ignore write errors\n } else {\n cb();\n }\n });\n });\n }\n }\n\n // 3b: Apply executable permissions from source files\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n const relativePath = path.relative(dest, file);\n const baseName = relativePath.replace(/\\.d\\.(ts|mts|cts)$/, '');\n\n for (const [srcPath, mode] of sourceModes) {\n const srcRelative = path.relative(src, srcPath);\n const srcBase = srcRelative.replace(/\\.(ts|tsx|mts|cts)$/, '');\n if (baseName === srcBase) {\n const execBits = mode & 0o111;\n if (execBits) {\n postQueue.defer((cb) => {\n fs.chmod(file, 0o644 | execBits, () => cb()); // Ignore chmod errors\n });\n }\n break;\n }\n }\n }\n });\n }\n\n postQueue.await(() => callback(null, res.emittedFiles));\n });\n }\n );\n}\n"],"names":["transformTypesWorker","_require","require","Module","createRequire","src","dest","options","callback","tsconfig","matcher","createMatcher","ts","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","push","concurrency","Infinity","err","sourceModes","Map","statQueue","Queue","defer","cb","fs","stat","statErr","set","mode","await","compilerOptions","convertCompilerOptionsFromJson","config","fileNames","map","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","postQueue","emittedFiles","file","rewriteRelativeImportExtensions","stringEndsWith","readFile","readErr","content","updated","rewriteExtensions","writeFile","relativePath","path","relative","baseName","replace","srcPath","srcRelative","srcBase","execBits","chmod"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAfT;iEACsB;6DAClB;2DACF;8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OAAOtC,MAAM,0BAA0B;oCACpD,IAAMwC,UAAUC,IAAAA,sCAAiB,EAACF;oCAClC,IAAIC,YAAYD,SAAS;wCACvBtC,WAAE,CAACyC,SAAS,CAACR,MAAMM,SAAS,QAAQ;mDAAMxC;4CAAO,sBAAsB;oCACzE,OAAO;wCACLA;oCACF;gCACF;4BACF;wBACF;oBACF;oBAEA,qDAAqD;oBACrD,IAAIoC,IAAAA,wBAAc,EAACF,MAAM,YAAYE,IAAAA,wBAAc,EAACF,MAAM,aAAaE,IAAAA,wBAAc,EAACF,MAAM,WAAW;wBACrG,IAAMS,eAAeC,aAAI,CAACC,QAAQ,CAACxE,MAAM6D;wBACzC,IAAMY,WAAWH,aAAaI,OAAO,CAAC,sBAAsB;4BAEvD,kCAAA,2BAAA;;;gCAAA,mCAAA,iBAAOC,0BAAS3C;gCACnB,IAAM4C,cAAcL,aAAI,CAACC,QAAQ,CAACzE,KAAK4E;gCACvC,IAAME,UAAUD,YAAYF,OAAO,CAAC,uBAAuB;gCAC3D,IAAID,aAAaI,SAAS;oCACxB,IAAMC,WAAW9C,OAAO;oCACxB,IAAI8C,UAAU;wCACZnB,UAAUjC,KAAK,CAAC,SAACC;4CACfC,WAAE,CAACmD,KAAK,CAAClB,MAAM,MAAQiB,UAAU;uDAAMnD;gDAAO,sBAAsB;wCACtE;oCACF;oCACA,OAAA;gCACF;4BACF;4BAZA,QAAK,YAAyBL,gCAAzB,SAAA,6BAAA,QAAA,yBAAA;;;;;4BAAA;4BAAA;;;qCAAA,6BAAA;oCAAA;;;oCAAA;0CAAA;;;;oBAaP;gBACF;YACF;YAEAqC,UAAU1B,KAAK,CAAC;uBAAM/B,SAAS,MAAMuD,IAAIG,YAAY;;QACvD;IACF;AAEJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { installSync } from 'install-optional';
|
|
1
|
+
import { installSync, matchesLibc } from 'install-optional';
|
|
2
2
|
import debounce from 'lodash.debounce';
|
|
3
3
|
import Module from 'module';
|
|
4
4
|
import path from 'path';
|
|
@@ -11,7 +11,8 @@ const installSyncSWC = debounce(installSync, 300, {
|
|
|
11
11
|
});
|
|
12
12
|
export default function prepareSWCOptions(tsconfig) {
|
|
13
13
|
installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, {
|
|
14
|
-
cwd: __dirname
|
|
14
|
+
cwd: __dirname,
|
|
15
|
+
filter: matchesLibc
|
|
15
16
|
});
|
|
16
17
|
try {
|
|
17
18
|
const ts = _require('typescript');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/prepareSWCOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync } from 'install-optional';\nimport debounce from 'lodash.debounce';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TSConfig } from '../types.ts';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nconst installSyncSWC = debounce(installSync, 300, { leading: true, trailing: false });\n\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\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","debounce","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","installSyncSWC","leading","trailing","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;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/prepareSWCOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync, matchesLibc } from 'install-optional';\nimport debounce from 'lodash.debounce';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TSConfig } from '../types.ts';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nconst installSyncSWC = debounce(installSync, 300, { leading: true, trailing: false });\n\nexport default function prepareSWCOptions(tsconfig: TSConfig): TranspilerOptions {\n installSyncSWC('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname, filter: matchesLibc });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`prepareSWCOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["installSync","matchesLibc","debounce","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","installSyncSWC","leading","trailing","prepareSWCOptions","tsconfig","process","platform","arch","cwd","filter","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAC5D,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AASjH,MAAMQ,iBAAiBX,SAASF,aAAa,KAAK;IAAEc,SAAS;IAAMC,UAAU;AAAM;AAEnF,eAAe,SAASC,kBAAkBC,QAAkB;IAC1DJ,eAAe,aAAa,GAAGK,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKZ;QAAWa,QAAQrB;IAAY;IACzG,IAAI;QACF,MAAMsB,KAAKjB,SAAS;QACpB,MAAMkB,MAAMlB,SAAS;QACrB,MAAMmB,aAAanB,SAAS;QAC5B,MAAMoB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEzB,KAAKM,OAAO,CAACO,SAASb,IAAI;QAChG,OAAOqB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Entry } from 'fs-iterator';
|
|
2
2
|
import type { ConfigOptions, TargetType, TransformFileCallback } from '../types.js';
|
|
3
|
-
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback):
|
|
3
|
+
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback):
|
|
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): void {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n // Get source file mode to preserve executable permissions\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (statErr) return callback(statErr);\n\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => {\n if (err) return callback(err);\n\n // Preserve executable permissions from source (only +x bits, not full mode)\n const execBits = stats.mode & 0o111;\n if (execBits) {\n fs.chmod(outPath, 0o644 | execBits, (_chmodErr) => {\n // Ignore chmod errors (e.g., on Windows)\n callback(null, outPath);\n });\n } else {\n callback(null, outPath);\n }\n });\n });\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","ext","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","stat","statErr","stats","extTarget","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","map","sourceMaps","await","err","execBits","mode","chmod","_chmodErr","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,IAA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AAMR,SAASL,OAAOc,IAAI,EAAE;gBAC1D,IAAId,OAAOe,GAAG,IAAIhC,QAAQiC,UAAU,EAAEN,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEL,OAAOe,GAAG,EAAE;gBACxGL,MAAMO,KAAK,CAAC,CAACC;oBACX,IAAIA,KAAK,OAAOlC,SAASkC;oBAEzB,4EAA4E;oBAC5E,MAAMC,WAAWhB,MAAMiB,IAAI,GAAG;oBAC9B,IAAID,UAAU;wBACZpD,GAAGsD,KAAK,CAAChB,SAAS,QAAQc,UAAU,CAACG;4BACnC,yCAAyC;4BACzCtC,SAAS,MAAMqB;wBACjB;oBACF,OAAO;wBACLrB,SAAS,MAAMqB;oBACjB;gBACF;YACF;QACF;IACF,GACCkB,KAAK,CAACvC;AACX"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.js';
|
|
2
|
-
export default function transformDirectory(src: string, dest: string, type: TargetType,
|
|
2
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;
|
|
3
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
4
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;
|
|
5
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
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)
|
|
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) {\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, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n 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);\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;AAMA,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,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from './types.js';
|
|
2
|
-
export default function transformTypes(src: string, dest: string,
|
|
2
|
+
export default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;
|
|
3
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
4
|
+
export default function transformTypes(src: string, dest: string): Promise<string[]>;
|
|
5
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
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):
|
|
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';\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n 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;AAQA,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,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
|
|
2
|
-
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback):
|
|
2
|
+
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
@@ -18,10 +18,7 @@ export default function transformDirectoryWorker(src, dest, type, options, callb
|
|
|
18
18
|
if (ext && extensions.indexOf(ext) < 0) return;
|
|
19
19
|
entries.push(entry);
|
|
20
20
|
}, (err)=>{
|
|
21
|
-
if (err)
|
|
22
|
-
callback(err);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
21
|
+
if (err) return callback(err);
|
|
25
22
|
const results = [];
|
|
26
23
|
options = {
|
|
27
24
|
...options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries: Entry[] = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["Iterator","path","Queue","extensions","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","ext","extname","indexOf","push","err","results","queue","defer","cb","outPath","normalize","sourceMaps","await"],"mappings":"AAAA,OAAOA,cAA8B,cAAc;AACnD,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,SAASC,UAAU,EAAEC,aAAa,QAAQ,kBAAkB;AAC5D,OAAOC,mBAAmB,sBAAsB;AAChD,OAAOC,mBAAmB,0BAA0B;AAIpD,eAAe,SAASC,yBAAyBC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACxJ,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUT,cAAcQ;IAE9B,MAAME,UAAmB,EAAE;IAC3B,MAAMC,WAAW,IAAIhB,SAASQ;IAC9BQ,SAASC,OAAO,CACd,CAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIjB,cAAckB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACP,QAAQI,MAAMK,QAAQ,GAAG;QAC9B,MAAMC,MAAMvB,KAAKwB,OAAO,CAACP,MAAMG,QAAQ;QACvC,IAAIG,OAAOrB,WAAWuB,OAAO,CAACF,OAAO,GAAG;QACxCT,QAAQY,IAAI,CAACT;IACf,GACA,CAACU;QACC,IAAIA,KAAK,OAAOhB,SAASgB;QACzB,MAAMC,UAAU,EAAE;QAClBlB,UAAU;YAAE,GAAGA,OAAO;YAAEE;QAAS;QAEjC,MAAMiB,QAAQ,IAAI5B;QAClBa,QAAQE,OAAO,CAAC,CAACC;YACfY,MAAMC,KAAK,CAAC,CAACC,KACX1B,cAAcY,OAAOT,MAAMC,MAAMC,SAAS,CAACiB,KAAKK;oBAC9C,IAAIL,KAAK,OAAOI,GAAGJ;oBACnBC,QAAQF,IAAI,CAAC1B,KAAKiC,SAAS,CAACD;oBAC5B,IAAItB,QAAQwB,UAAU,EAAEN,QAAQF,IAAI,CAAC,GAAG1B,KAAKiC,SAAS,CAACD,SAAS,IAAI,CAAC;oBACrED;gBACF;QAEJ;QACAF,MAAMM,KAAK,CAAC,CAACR,MAASA,MAAMhB,SAASgB,OAAOhB,SAAS,MAAMiB;IAC7D;AAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from '../types.js';
|
|
2
|
-
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback):
|
|
2
|
+
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
@@ -23,10 +23,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
23
23
|
}, {
|
|
24
24
|
concurrency: Infinity
|
|
25
25
|
}, (err)=>{
|
|
26
|
-
if (err)
|
|
27
|
-
callback(err);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
26
|
+
if (err) return callback(err);
|
|
30
27
|
// Step 1: Stat all source files to get their modes (async)
|
|
31
28
|
const sourceModes = new Map();
|
|
32
29
|
const statQueue = new Queue();
|
|
@@ -39,10 +36,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
39
36
|
});
|
|
40
37
|
});
|
|
41
38
|
statQueue.await((statErr)=>{
|
|
42
|
-
if (statErr)
|
|
43
|
-
callback(statErr);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
39
|
+
if (statErr) return callback(statErr);
|
|
46
40
|
// Step 2: TypeScript emit (inherently sync - cannot change)
|
|
47
41
|
const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
|
|
48
42
|
const config = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n // Step 1: Stat all source files to get their modes (async)\n const sourceModes = new Map<string, number>();\n const statQueue = new Queue();\n entries.forEach((entry) => {\n statQueue.defer((cb) => {\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (!statErr) sourceModes.set(entry.fullPath, stats.mode);\n cb(); // Continue even on error\n });\n });\n });\n\n statQueue.await((statErr) => {\n if (statErr) return callback(statErr);\n\n // Step 2: TypeScript emit (inherently sync - cannot change)\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // Step 3: Post-process emitted files (async)\n const postQueue = new Queue();\n\n if (res.emittedFiles) {\n res.emittedFiles.forEach((file) => {\n // 3a: Rewrite extensions (convert from sync to async)\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (compilerOptions.options.rewriteRelativeImportExtensions) {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n postQueue.defer((cb) => {\n fs.readFile(file, 'utf8', (readErr, content) => {\n if (readErr) return cb(); // Ignore errors, continue\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFile(file, updated, 'utf8', () => cb()); // Ignore write errors\n } else {\n cb();\n }\n });\n });\n }\n }\n\n // 3b: Apply executable permissions from source files\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n const relativePath = path.relative(dest, file);\n const baseName = relativePath.replace(/\\.d\\.(ts|mts|cts)$/, '');\n\n for (const [srcPath, mode] of sourceModes) {\n const srcRelative = path.relative(src, srcPath);\n const srcBase = srcRelative.replace(/\\.(ts|tsx|mts|cts)$/, '');\n if (baseName === srcBase) {\n const execBits = mode & 0o111;\n if (execBits) {\n postQueue.defer((cb) => {\n fs.chmod(file, 0o644 | execBits, () => cb()); // Ignore chmod errors\n });\n }\n break;\n }\n }\n }\n });\n }\n\n postQueue.await(() => callback(null, res.emittedFiles));\n });\n }\n );\n}\n"],"names":["fs","Iterator","Module","path","Queue","_require","require","createRequire","url","stringEndsWith","typeFileRegEx","createMatcher","rewriteExtensions","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","push","concurrency","Infinity","err","sourceModes","Map","statQueue","defer","cb","stat","statErr","set","mode","await","compilerOptions","convertCompilerOptionsFromJson","config","fileNames","map","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","postQueue","emittedFiles","file","rewriteRelativeImportExtensions","readFile","readErr","content","updated","writeFile","relativePath","relative","baseName","replace","srcPath","srcRelative","srcBase","execBits","chmod"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,cAA8B,cAAc;AACnD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,MAA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AAO,sBAAsB;oCACzE,OAAO;wCACLA;oCACF;gCACF;4BACF;wBACF;oBACF;oBAEA,qDAAqD;oBACrD,IAAI7B,eAAe8D,MAAM,YAAY9D,eAAe8D,MAAM,aAAa9D,eAAe8D,MAAM,WAAW;wBACrG,MAAMO,eAAe3E,KAAK4E,QAAQ,CAAChE,MAAMwD;wBACzC,MAAMS,WAAWF,aAAaG,OAAO,CAAC,sBAAsB;wBAE5D,KAAK,MAAM,CAACC,SAASxC,KAAK,IAAIR,YAAa;4BACzC,MAAMiD,cAAchF,KAAK4E,QAAQ,CAACjE,KAAKoE;4BACvC,MAAME,UAAUD,YAAYF,OAAO,CAAC,uBAAuB;4BAC3D,IAAID,aAAaI,SAAS;gCACxB,MAAMC,WAAW3C,OAAO;gCACxB,IAAI2C,UAAU;oCACZhB,UAAUhC,KAAK,CAAC,CAACC;wCACftC,GAAGsF,KAAK,CAACf,MAAM,QAAQc,UAAU,IAAM/C,OAAO,sBAAsB;oCACtE;gCACF;gCACA;4BACF;wBACF;oBACF;gBACF;YACF;YAEA+B,UAAU1B,KAAK,CAAC,IAAM1B,SAAS,MAAMkD,IAAIG,YAAY;QACvD;IACF;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@swc/core": "^1.15.5",
|
|
48
48
|
"core-js-pure": "^3.20.0",
|
|
49
49
|
"exit-compat": "^1.0.0",
|
|
50
|
-
"fs-iterator": "^
|
|
51
|
-
"install-optional": "^1.
|
|
50
|
+
"fs-iterator": "^7.0.0",
|
|
51
|
+
"install-optional": "^1.1.1",
|
|
52
52
|
"is-absolute": "^1.0.0",
|
|
53
53
|
"lodash.debounce": "^4.0.8",
|
|
54
54
|
"mkdirp-classic": "^0.5.2",
|