ts-swc-transform 2.8.2 → 2.10.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 +17 -20
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformSync.js +10 -7
- package/dist/cjs/transformSync.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 +17 -20
- 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/resolveCJS.js +1 -1
- package/dist/esm/lib/resolveCJS.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 +17 -20
- package/dist/esm/transformDirectory.js.map +1 -1
- package/dist/esm/transformSync.js +10 -7
- package/dist/esm/transformSync.js.map +1 -1
- package/dist/esm/transformTypes.d.ts +4 -1
- package/dist/esm/transformTypes.js +17 -20
- 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 +5 -5
|
@@ -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","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B,QAAQnB;YAC9F,IAAMU,MAAMC,aAAI,CAACC,OAAO,CAACf,MAAMc,IAAI;YACnC,IAAMgB,UAAUhB,aAAI,CAACiB,IAAI,CAAC9B,MAAM,AAACY,CAAAA,MAAMb,MAAMc,IAAI,CAACkB,KAAK,CAAC,GAAG,CAACnB,IAAIoB,MAAM,IAAIjC,MAAMc,IAAI,AAAD,IAAKa;YAExFO,IAAAA,sBAAM,EAACpB,aAAI,CAACqB,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[]>;
|
|
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformDirectory;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
12
|
+
var _nodeversioncall = require("node-version-call");
|
|
11
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
14
|
var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync"));
|
|
13
15
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
14
|
-
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
15
16
|
function _define_property(obj, key, value) {
|
|
16
17
|
if (key in obj) {
|
|
17
18
|
Object.defineProperty(obj, key, {
|
|
@@ -46,21 +47,17 @@ function _object_spread(target) {
|
|
|
46
47
|
return target;
|
|
47
48
|
}
|
|
48
49
|
var major = +process.versions.node.split('.')[0];
|
|
49
|
-
var
|
|
50
|
+
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
50
51
|
var __dirname = _path.default.dirname(typeof __filename === 'undefined' ? _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
|
|
51
52
|
var workerPath = _path.default.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);
|
|
55
|
-
try {
|
|
56
|
-
callback(null, _require('node-version-call')({
|
|
57
|
-
version: version,
|
|
58
|
-
callbacks: true
|
|
59
|
-
}, workerPath, src, dest, type, options));
|
|
60
|
-
} catch (err) {
|
|
61
|
-
callback(err);
|
|
62
|
-
}
|
|
53
|
+
function run(src, dest, type, options, callback) {
|
|
54
|
+
return _require(workerPath)(src, dest, type, options, callback);
|
|
63
55
|
}
|
|
56
|
+
// spawnOptions: false - no node/npm spawn (library call only)
|
|
57
|
+
var worker = major >= 20 ? run : (0, _nodeversioncall.bind)('>=20', workerPath, {
|
|
58
|
+
callbacks: true,
|
|
59
|
+
spawnOptions: false
|
|
60
|
+
});
|
|
64
61
|
function transformDirectory(src, dest, type, options, callback) {
|
|
65
62
|
try {
|
|
66
63
|
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
@@ -68,16 +65,16 @@ function transformDirectory(src, dest, type, options, callback) {
|
|
|
68
65
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
69
66
|
if (typeof options === 'function') {
|
|
70
67
|
callback = options;
|
|
71
|
-
options =
|
|
68
|
+
options = undefined;
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
var tsconfig =
|
|
75
|
-
|
|
70
|
+
var baseOpts = options || {};
|
|
71
|
+
var tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : (0, _readtsconfigsync.default)(src);
|
|
72
|
+
var opts = _object_spread({
|
|
76
73
|
tsconfig: tsconfig
|
|
77
|
-
},
|
|
78
|
-
if (typeof callback === 'function') return
|
|
74
|
+
}, baseOpts);
|
|
75
|
+
if (typeof callback === 'function') return worker(src, dest, type, opts, callback);
|
|
79
76
|
return new Promise(function(resolve, reject) {
|
|
80
|
-
return
|
|
77
|
+
return worker(src, dest, type, opts, function(err, result) {
|
|
81
78
|
err ? reject(err) : resolve(result);
|
|
82
79
|
});
|
|
83
80
|
});
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nfunction run(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n return _require(workerPath)(src, dest, type, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n const baseOpts = (options || {}) as ConfigOptions;\n const tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : loadConfigSync(src);\n const opts: ConfigOptions = { tsconfig, ...baseOpts };\n\n if (typeof callback === 'function') return worker(src, dest, type, opts, callback);\n return new Promise((resolve, reject) =>\n worker(src, dest, type, opts, (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","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","src","dest","type","options","callback","worker","bind","callbacks","spawnOptions","Error","undefined","baseOpts","tsconfig","loadConfigSync","opts","Promise","resolve","reject","err","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;6DAxBL;+BACE;2DACJ;uEACU;0DACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACpH,OAAOjB,SAASU,YAAYG,KAAKC,MAAMC,MAAMC,SAASC;AACxD;AAEA,8DAA8D;AAC9D,IAAMC,SAASvB,SAAS,KAAKiB,MAAMO,IAAAA,qBAAI,EAAC,QAAQT,YAAY;IAAEU,WAAW;IAAMC,cAAc;AAAM;AAMpF,SAAS3B,mBAAmBmB,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIS,MAAM;QAC7C,IAAI,OAAOR,SAAS,UAAU,MAAM,IAAIQ,MAAM;QAC9C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAE9C,IAAI,OAAON,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAUO;QACZ;QACA,IAAMC,WAAYR,WAAW,CAAC;QAC9B,IAAMS,WAAWD,SAASC,QAAQ,GAAGD,SAASC,QAAQ,GAAGC,IAAAA,yBAAc,EAACb;QACxE,IAAMc,OAAsB;YAAEF,UAAAA;WAAaD;QAE3C,IAAI,OAAOP,aAAa,YAAY,OAAOC,OAAOL,KAAKC,MAAMC,MAAMY,MAAMV;QACzE,OAAO,IAAIW,QAAQ,SAACC,SAASC;mBAC3BZ,OAAOL,KAAKC,MAAMC,MAAMY,MAAM,SAACI,KAAKC;gBAClCD,MAAMD,OAAOC,OAAOF,QAAQG;YAC9B;;IAEJ,EAAE,OAAOD,KAAK;QACZ,IAAId,UAAUA,SAASc;aAClB,OAAOH,QAAQE,MAAM,CAACC;IAC7B;AACF"}
|
|
@@ -8,28 +8,31 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformSync;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
12
|
+
var _nodeversioncall = require("node-version-call");
|
|
11
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
14
|
var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync"));
|
|
13
15
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
14
|
-
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
15
16
|
function _interop_require_default(obj) {
|
|
16
17
|
return obj && obj.__esModule ? obj : {
|
|
17
18
|
default: obj
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
var major = +process.versions.node.split('.')[0];
|
|
21
|
-
var
|
|
22
|
+
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
22
23
|
var __dirname = _path.default.dirname(typeof __filename === 'undefined' ? _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
|
|
23
24
|
var workerPath = _path.default.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);
|
|
27
|
-
return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);
|
|
25
|
+
function run(contents, fileName, tsconfig) {
|
|
26
|
+
return _require(workerPath)(contents, fileName, tsconfig);
|
|
28
27
|
}
|
|
28
|
+
// spawnOptions: false - no node/npm spawn (library call only)
|
|
29
|
+
var worker = major >= 20 ? run : (0, _nodeversioncall.bind)('>=20', workerPath, {
|
|
30
|
+
spawnOptions: false
|
|
31
|
+
});
|
|
29
32
|
function transformSync(contents, fileName, tsconfig) {
|
|
30
33
|
if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');
|
|
31
34
|
if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');
|
|
32
35
|
if (!tsconfig) tsconfig = (0, _readtsconfigsync.default)(process.cwd());
|
|
33
|
-
return
|
|
36
|
+
return worker(contents, fileName, tsconfig);
|
|
34
37
|
}
|
|
35
38
|
/* 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 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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nfunction run(contents: string, fileName: string, tsconfig: TSConfig) {\n return _require(workerPath)(contents, fileName, tsconfig);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { spawnOptions: false });\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return worker(contents, fileName, tsconfig) as Output;\n}\n"],"names":["transformSync","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","contents","fileName","tsconfig","worker","bind","spawnOptions","Error","loadConfigSync","cwd"],"mappings":";;;;+BAqBA;;;eAAwBA;;;6DArBL;+BACE;2DACJ;uEACU;0DACX;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IACjE,OAAOf,SAASU,YAAYG,UAAUC,UAAUC;AAClD;AAEA,8DAA8D;AAC9D,IAAMC,SAASrB,SAAS,KAAKiB,MAAMK,IAAAA,qBAAI,EAAC,QAAQP,YAAY;IAAEQ,cAAc;AAAM;AAGnE,SAASxB,cAAcmB,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIM,MAAM;IAClD,IAAI,OAAOL,aAAa,UAAU,MAAM,IAAIK,MAAM;IAClD,IAAI,CAACJ,UAAUA,WAAWK,IAAAA,yBAAc,EAACxB,QAAQyB,GAAG;IACpD,OAAOL,OAAOH,UAAUC,UAAUC;AACpC"}
|
|
@@ -1,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[]>;
|
|
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformTypes;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
12
|
+
var _nodeversioncall = require("node-version-call");
|
|
11
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
14
|
var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync"));
|
|
13
15
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
14
|
-
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
15
16
|
function _define_property(obj, key, value) {
|
|
16
17
|
if (key in obj) {
|
|
17
18
|
Object.defineProperty(obj, key, {
|
|
@@ -46,37 +47,33 @@ function _object_spread(target) {
|
|
|
46
47
|
return target;
|
|
47
48
|
}
|
|
48
49
|
var major = +process.versions.node.split('.')[0];
|
|
49
|
-
var
|
|
50
|
+
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
50
51
|
var __dirname = _path.default.dirname(typeof __filename === 'undefined' ? _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
|
|
51
52
|
var workerPath = _path.default.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (version === 'local') return _require(workerPath)(src, dest, options, callback);
|
|
55
|
-
try {
|
|
56
|
-
callback(null, _require('node-version-call')({
|
|
57
|
-
version: version,
|
|
58
|
-
callbacks: true
|
|
59
|
-
}, workerPath, src, dest, options));
|
|
60
|
-
} catch (err) {
|
|
61
|
-
callback(err);
|
|
62
|
-
}
|
|
53
|
+
function run(src, dest, options, callback) {
|
|
54
|
+
return _require(workerPath)(src, dest, options, callback);
|
|
63
55
|
}
|
|
56
|
+
// spawnOptions: false - no node/npm spawn (library call only)
|
|
57
|
+
var worker = major >= 20 ? run : (0, _nodeversioncall.bind)('>=20', workerPath, {
|
|
58
|
+
callbacks: true,
|
|
59
|
+
spawnOptions: false
|
|
60
|
+
});
|
|
64
61
|
function transformTypes(src, dest, options, callback) {
|
|
65
62
|
try {
|
|
66
63
|
if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');
|
|
67
64
|
if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');
|
|
68
65
|
if (typeof options === 'function') {
|
|
69
66
|
callback = options;
|
|
70
|
-
options =
|
|
67
|
+
options = undefined;
|
|
71
68
|
}
|
|
72
|
-
|
|
73
|
-
var tsconfig =
|
|
74
|
-
|
|
69
|
+
var baseOpts = options || {};
|
|
70
|
+
var tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : (0, _readtsconfigsync.default)(src);
|
|
71
|
+
var opts = _object_spread({
|
|
75
72
|
tsconfig: tsconfig
|
|
76
|
-
},
|
|
77
|
-
if (typeof callback === 'function') return
|
|
73
|
+
}, baseOpts);
|
|
74
|
+
if (typeof callback === 'function') return worker(src, dest, opts, callback);
|
|
78
75
|
return new Promise(function(resolve, reject) {
|
|
79
|
-
return
|
|
76
|
+
return worker(src, dest, opts, function(err, result) {
|
|
80
77
|
return err ? reject(err) : resolve(result);
|
|
81
78
|
});
|
|
82
79
|
});
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nfunction run(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n return _require(workerPath)(src, dest, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n const baseOpts = (options || {}) as ConfigOptions;\n const tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : loadConfigSync(src);\n const opts: ConfigOptions = { tsconfig, ...baseOpts };\n\n if (typeof callback === 'function') return worker(src, dest, opts, callback);\n return new Promise((resolve, reject) => worker(src, dest, opts, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformTypes","major","process","versions","node","split","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","run","src","dest","options","callback","worker","bind","callbacks","spawnOptions","Error","undefined","baseOpts","tsconfig","loadConfigSync","opts","Promise","resolve","reject","err","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;6DAxBL;+BACE;2DACJ;uEACU;0DACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIhB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASQ,IAAIC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9F,OAAOhB,SAASU,YAAYG,KAAKC,MAAMC,SAASC;AAClD;AAEA,8DAA8D;AAC9D,IAAMC,SAAStB,SAAS,KAAKiB,MAAMM,IAAAA,qBAAI,EAAC,QAAQR,YAAY;IAAES,WAAW;IAAMC,cAAc;AAAM;AAMpF,SAAS1B,eAAemB,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAE9C,IAAI,OAAON,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAUO;QACZ;QACA,IAAMC,WAAYR,WAAW,CAAC;QAC9B,IAAMS,WAAWD,SAASC,QAAQ,GAAGD,SAASC,QAAQ,GAAGC,IAAAA,yBAAc,EAACZ;QACxE,IAAMa,OAAsB;YAAEF,UAAAA;WAAaD;QAE3C,IAAI,OAAOP,aAAa,YAAY,OAAOC,OAAOJ,KAAKC,MAAMY,MAAMV;QACnE,OAAO,IAAIW,QAAQ,SAACC,SAASC;mBAAWZ,OAAOJ,KAAKC,MAAMY,MAAM,SAACI,KAAKC;uBAAYD,MAAMD,OAAOC,OAAOF,QAAQG;;;IAChH,EAAE,OAAOD,KAAK;QACZ,IAAId,UAAUA,SAASc;aAClB,OAAOH,QAAQE,MAAM,CAACC;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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C,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;8DACC;wBAIa;2BACD;sEACJ;mCACQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlC,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAS3E,SAASF,qBAAqBK,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9H,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,wBAAa,EA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AeC,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,4 @@
|
|
|
1
|
+
var _resolve_default;
|
|
1
2
|
/**
|
|
2
3
|
* CJS resolver
|
|
3
4
|
*
|
|
@@ -6,7 +7,6 @@
|
|
|
6
7
|
*
|
|
7
8
|
* Note: CJS does not support subpath imports (#prefix) - those are ESM-only.
|
|
8
9
|
*/ import * as resolve from 'resolve';
|
|
9
|
-
var _resolve_default;
|
|
10
10
|
const resolveSync = ((_resolve_default = resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : resolve).sync;
|
|
11
11
|
/**
|
|
12
12
|
* Resolve a CJS specifier to an absolute file path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolveCJS.ts"],"sourcesContent":["/**\n * CJS resolver\n *\n * Uses the `resolve` npm package for CommonJS-style module resolution.\n * Handles main field, index.js, etc.\n *\n * Note: CJS does not support subpath imports (#prefix) - those are ESM-only.\n */\n\nimport * as resolve from 'resolve';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\n/**\n * Resolve a CJS specifier to an absolute file path\n *\n * @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')\n * @param basedir - The directory to resolve from\n * @returns The resolved absolute file path\n * @throws Error if module cannot be found\n */\nexport default function resolveCJS(specifier: string, basedir: string): string {\n return resolveSync(specifier, {\n basedir,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n}\n"],"names":["resolve","resolveSync","default","sync","resolveCJS","specifier","basedir","extensions"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolveCJS.ts"],"sourcesContent":["/**\n * CJS resolver\n *\n * Uses the `resolve` npm package for CommonJS-style module resolution.\n * Handles main field, index.js, etc.\n *\n * Note: CJS does not support subpath imports (#prefix) - those are ESM-only.\n */\n\nimport * as resolve from 'resolve';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\n/**\n * Resolve a CJS specifier to an absolute file path\n *\n * @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')\n * @param basedir - The directory to resolve from\n * @returns The resolved absolute file path\n * @throws Error if module cannot be found\n */\nexport default function resolveCJS(specifier: string, basedir: string): string {\n return resolveSync(specifier, {\n basedir,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n}\n"],"names":["resolve","resolveSync","default","sync","resolveCJS","specifier","basedir","extensions"],"mappings":"IAWqBA;AAXrB;;;;;;;CAOC,GAED,YAAYA,aAAa,UAAU;AAEnC,MAAMC,cAAc,EAACD,mBAAAA,QAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,SAASG,IAAI;AAErD;;;;;;;CAOC,GACD,eAAe,SAASC,WAAWC,SAAiB,EAAEC,OAAe;IACnE,OAAOL,YAAYI,WAAW;QAC5BC;QACAC,YAAY;YAAC;YAAO;YAAS;YAAS;SAAO;IAC/C;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,uBA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ACf,IAAIgB,MAAM,IAAI5B,MAAMV,IAAI,AAAD,IAAKkC;YAExFpC,OAAOE,KAAKuC,OAAO,CAACJ,UAAU;gBAC5B,MAAMK,QAAQ,IAAIvC;gBAClBuC,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAMR,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,23 +1,20 @@
|
|
|
1
|
+
import Module from 'module';
|
|
2
|
+
import { bind } from 'node-version-call';
|
|
1
3
|
import path from 'path';
|
|
2
4
|
import loadConfigSync from 'read-tsconfig-sync';
|
|
3
5
|
import url from 'url';
|
|
4
6
|
const major = +process.versions.node.split('.')[0];
|
|
5
|
-
const
|
|
7
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
6
8
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
9
|
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function dispatch(version, src, dest, type, options, callback) {
|
|
11
|
-
if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);
|
|
12
|
-
try {
|
|
13
|
-
callback(null, _require('node-version-call')({
|
|
14
|
-
version,
|
|
15
|
-
callbacks: true
|
|
16
|
-
}, workerPath, src, dest, type, options));
|
|
17
|
-
} catch (err) {
|
|
18
|
-
callback(err);
|
|
19
|
-
}
|
|
10
|
+
function run(src, dest, type, options, callback) {
|
|
11
|
+
return _require(workerPath)(src, dest, type, options, callback);
|
|
20
12
|
}
|
|
13
|
+
// spawnOptions: false - no node/npm spawn (library call only)
|
|
14
|
+
const worker = major >= 20 ? run : bind('>=20', workerPath, {
|
|
15
|
+
callbacks: true,
|
|
16
|
+
spawnOptions: false
|
|
17
|
+
});
|
|
21
18
|
export default function transformDirectory(src, dest, type, options, callback) {
|
|
22
19
|
try {
|
|
23
20
|
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
@@ -25,16 +22,16 @@ export default function transformDirectory(src, dest, type, options, callback) {
|
|
|
25
22
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
26
23
|
if (typeof options === 'function') {
|
|
27
24
|
callback = options;
|
|
28
|
-
options =
|
|
25
|
+
options = undefined;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
|
-
const tsconfig =
|
|
32
|
-
|
|
27
|
+
const baseOpts = options || {};
|
|
28
|
+
const tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : loadConfigSync(src);
|
|
29
|
+
const opts = {
|
|
33
30
|
tsconfig,
|
|
34
|
-
...
|
|
31
|
+
...baseOpts
|
|
35
32
|
};
|
|
36
|
-
if (typeof callback === 'function') return
|
|
37
|
-
return new Promise((resolve, reject)=>
|
|
33
|
+
if (typeof callback === 'function') return worker(src, dest, type, opts, callback);
|
|
34
|
+
return new Promise((resolve, reject)=>worker(src, dest, type, opts, (err, result)=>{
|
|
38
35
|
err ? reject(err) : resolve(result);
|
|
39
36
|
}));
|
|
40
37
|
} catch (err) {
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nfunction run(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n return _require(workerPath)(src, dest, type, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n const baseOpts = (options || {}) as ConfigOptions;\n const tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : loadConfigSync(src);\n const opts: ConfigOptions = { tsconfig, ...baseOpts };\n\n if (typeof callback === 'function') return worker(src, dest, type, opts, callback);\n return new Promise((resolve, reject) =>\n worker(src, dest, type, opts, (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":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","src","dest","type","options","callback","worker","callbacks","spawnOptions","transformDirectory","Error","undefined","baseOpts","tsconfig","opts","Promise","resolve","reject","err","result"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,IAAI,QAAQ,oBAAoB;AACzC,OAAOC,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,WAAW,OAAOC,YAAY,cAAcX,OAAOY,aAAa,CAAC,YAAYR,GAAG,IAAIO;AAC1F,MAAME,YAAYX,KAAKY,OAAO,CAAC,OAAOC,eAAe,cAAcX,I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|
|
1
3
|
import path from 'path';
|
|
2
4
|
import loadConfigSync from 'read-tsconfig-sync';
|
|
3
5
|
import url from 'url';
|
|
4
6
|
const major = +process.versions.node.split('.')[0];
|
|
5
|
-
const
|
|
7
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
6
8
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
9
|
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function dispatch(version, contents, fileName, tsconfig) {
|
|
11
|
-
if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);
|
|
12
|
-
return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);
|
|
10
|
+
function run(contents, fileName, tsconfig) {
|
|
11
|
+
return _require(workerPath)(contents, fileName, tsconfig);
|
|
13
12
|
}
|
|
13
|
+
// spawnOptions: false - no node/npm spawn (library call only)
|
|
14
|
+
const worker = major >= 20 ? run : bind('>=20', workerPath, {
|
|
15
|
+
spawnOptions: false
|
|
16
|
+
});
|
|
14
17
|
export default function transformSync(contents, fileName, tsconfig) {
|
|
15
18
|
if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');
|
|
16
19
|
if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');
|
|
17
20
|
if (!tsconfig) tsconfig = loadConfigSync(process.cwd());
|
|
18
|
-
return
|
|
21
|
+
return worker(contents, fileName, tsconfig);
|
|
19
22
|
}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nfunction run(contents: string, fileName: string, tsconfig: TSConfig) {\n return _require(workerPath)(contents, fileName, tsconfig);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { spawnOptions: false });\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return worker(contents, fileName, tsconfig) as Output;\n}\n"],"names":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","contents","fileName","tsconfig","worker","spawnOptions","transformSync","Error","cwd"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,IAAI,QAAQ,oBAAoB;AACzC,OAAOC,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,WAAW,OAAOC,YAAY,cAAcX,OAAOY,aAAa,CAAC,YAAYR,GAAG,IAAIO;AAC1F,MAAME,YAAYX,KAAKY,OAAO,CAAC,OAAOC,eAAe,cAAcX,IAAIY,aAAa,CAAC,YAAYZ,GAAG,IAAIW;AACxG,MAAME,aAAaf,KAAKgB,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASM,IAAIC,QAAgB,EAAEC,QAAgB,EAAEC,QAAkB;IACjE,OAAOZ,SAASO,YAAYG,UAAUC,UAAUC;AAClD;AAEA,8DAA8D;AAC9D,MAAMC,SAASlB,SAAS,KAAKc,MAAMlB,KAAK,QAAQgB,YAAY;IAAEO,cAAc;AAAM;AAGlF,eAAe,SAASC,cAAcL,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIM,MAAM;IAClD,IAAI,OAAOL,aAAa,UAAU,MAAM,IAAIK,MAAM;IAClD,IAAI,CAACJ,UAAUA,WAAWnB,eAAeG,QAAQqB,GAAG;IACpD,OAAOJ,OAAOH,UAAUC,UAAUC;AACpC"}
|
|
@@ -1,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,39 +1,36 @@
|
|
|
1
|
+
import Module from 'module';
|
|
2
|
+
import { bind } from 'node-version-call';
|
|
1
3
|
import path from 'path';
|
|
2
4
|
import loadConfigSync from 'read-tsconfig-sync';
|
|
3
5
|
import url from 'url';
|
|
4
6
|
const major = +process.versions.node.split('.')[0];
|
|
5
|
-
const
|
|
7
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
6
8
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
9
|
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function dispatch(version, src, dest, options, callback) {
|
|
11
|
-
if (version === 'local') return _require(workerPath)(src, dest, options, callback);
|
|
12
|
-
try {
|
|
13
|
-
callback(null, _require('node-version-call')({
|
|
14
|
-
version,
|
|
15
|
-
callbacks: true
|
|
16
|
-
}, workerPath, src, dest, options));
|
|
17
|
-
} catch (err) {
|
|
18
|
-
callback(err);
|
|
19
|
-
}
|
|
10
|
+
function run(src, dest, options, callback) {
|
|
11
|
+
return _require(workerPath)(src, dest, options, callback);
|
|
20
12
|
}
|
|
13
|
+
// spawnOptions: false - no node/npm spawn (library call only)
|
|
14
|
+
const worker = major >= 20 ? run : bind('>=20', workerPath, {
|
|
15
|
+
callbacks: true,
|
|
16
|
+
spawnOptions: false
|
|
17
|
+
});
|
|
21
18
|
export default function transformTypes(src, dest, options, callback) {
|
|
22
19
|
try {
|
|
23
20
|
if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');
|
|
24
21
|
if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');
|
|
25
22
|
if (typeof options === 'function') {
|
|
26
23
|
callback = options;
|
|
27
|
-
options =
|
|
24
|
+
options = undefined;
|
|
28
25
|
}
|
|
29
|
-
|
|
30
|
-
const tsconfig =
|
|
31
|
-
|
|
26
|
+
const baseOpts = options || {};
|
|
27
|
+
const tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : loadConfigSync(src);
|
|
28
|
+
const opts = {
|
|
32
29
|
tsconfig,
|
|
33
|
-
...
|
|
30
|
+
...baseOpts
|
|
34
31
|
};
|
|
35
|
-
if (typeof callback === 'function') return
|
|
36
|
-
return new Promise((resolve, reject)=>
|
|
32
|
+
if (typeof callback === 'function') return worker(src, dest, opts, callback);
|
|
33
|
+
return new Promise((resolve, reject)=>worker(src, dest, opts, (err, result)=>err ? reject(err) : resolve(result)));
|
|
37
34
|
} catch (err) {
|
|
38
35
|
if (callback) callback(err);
|
|
39
36
|
else return Promise.reject(err);
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import Module from 'module';\nimport { bind } from 'node-version-call';\nimport path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nfunction run(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n return _require(workerPath)(src, dest, options, callback);\n}\n\n// spawnOptions: false - no node/npm spawn (library call only)\nconst worker = major >= 20 ? run : bind('>=20', workerPath, { callbacks: true, spawnOptions: false });\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n const baseOpts = (options || {}) as ConfigOptions;\n const tsconfig = baseOpts.tsconfig ? baseOpts.tsconfig : loadConfigSync(src);\n const opts: ConfigOptions = { tsconfig, ...baseOpts };\n\n if (typeof callback === 'function') return worker(src, dest, opts, callback);\n return new Promise((resolve, reject) => worker(src, dest, opts, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["Module","bind","path","loadConfigSync","url","major","process","versions","node","split","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","run","src","dest","options","callback","worker","callbacks","spawnOptions","transformTypes","Error","undefined","baseOpts","tsconfig","opts","Promise","resolve","reject","err","result"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAASC,IAAI,QAAQ,oBAAoB;AACzC,OAAOC,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,WAAW,OAAOC,YAAY,cAAcX,OAAOY,aAAa,CAAC,YAAYR,GAAG,IAAIO;AAC1F,MAAME,YAAYX,KAAKY,OAAO,CAAC,OAAOC,eAAe,cAAcX,IAAIY,aAAa,CAAC,YAAYZ,GAAG,IAAIW;AACxG,MAAME,aAAaf,KAAKgB,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,SAASM,IAAIC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9F,OAAOb,SAASO,YAAYG,KAAKC,MAAMC,SAASC;AAClD;AAEA,8DAA8D;AAC9D,MAAMC,SAASnB,SAAS,KAAKc,MAAMlB,KAAK,QAAQgB,YAAY;IAAEQ,WAAW;IAAMC,cAAc;AAAM;AAMnG,eAAe,SAASC,eAAeP,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAE9C,IAAI,OAAON,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAUO;QACZ;QACA,MAAMC,WAAYR,WAAW,CAAC;QAC9B,MAAMS,WAAWD,SAASC,QAAQ,GAAGD,SAASC,QAAQ,GAAG5B,eAAeiB;QACxE,MAAMY,OAAsB;YAAED;YAAU,GAAGD,QAAQ;QAAC;QAEpD,IAAI,OAAOP,aAAa,YAAY,OAAOC,OAAOJ,KAAKC,MAAMW,MAAMT;QACnE,OAAO,IAAIU,QAAQ,CAACC,SAASC,SAAWX,OAAOJ,KAAKC,MAAMW,MAAM,CAACI,KAAKC,SAAYD,MAAMD,OAAOC,OAAOF,QAAQG;IAChH,EAAE,OAAOD,KAAK;QACZ,IAAIb,UAAUA,SAASa;aAClB,OAAOH,QAAQE,MAAM,CAACC;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,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,cAAc,QAAQ,eAAe;AAC9C,SAASC,aAAa,QAAQ,kBAAkB;AAChD,OAAOC,mBAAmB,sBAAsB;AAChD,SAASC,iBAAiB,QAAQ,8BAA8B;AAIhE,eAAe,SAASC,qBAAqBC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9H,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUR,cAAcO;IAC9B,MAAME,KAAKf,SAAS;IAEpB,MAAMgB,UAAU,EAAE;IAClB,M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AAC,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.10.0",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -47,12 +47,12 @@
|
|
|
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",
|
|
55
|
-
"node-version-call": "^
|
|
55
|
+
"node-version-call": "^2.0.0",
|
|
56
56
|
"queue-cb": "^1.0.0",
|
|
57
57
|
"read-tsconfig-sync": "^1.0.3",
|
|
58
58
|
"resolve": "^1.3.1",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@types/mocha": "*",
|
|
66
66
|
"@types/node": "*",
|
|
67
67
|
"cr": "^0.1.0",
|
|
68
|
-
"cross-spawn-cb": "^
|
|
68
|
+
"cross-spawn-cb": "^3.0.0",
|
|
69
69
|
"fs-remove-compat": "^1.0.0",
|
|
70
70
|
"mock-exports-only-pkg": "file:test/data/mock-exports-only-pkg",
|
|
71
71
|
"mock-subpath-imports-pkg": "file:test/data/mock-subpath-imports-pkg",
|