ts-swc-transform 2.8.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/prepareSWCOptions.js +2 -1
- package/dist/cjs/lib/prepareSWCOptions.js.map +1 -1
- package/dist/cjs/lib/resolveCJS.d.cts +17 -0
- package/dist/cjs/lib/resolveCJS.d.ts +17 -0
- package/dist/cjs/lib/resolveCJS.js +80 -0
- package/dist/cjs/lib/resolveCJS.js.map +1 -0
- package/dist/cjs/lib/resolveESM.d.cts +19 -0
- package/dist/cjs/lib/resolveESM.d.ts +19 -0
- package/dist/cjs/lib/resolveESM.js +180 -0
- package/dist/cjs/lib/resolveESM.js.map +1 -0
- 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/toPath.js +27 -22
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/cjs/transformDirectory.d.cts +4 -1
- package/dist/cjs/transformDirectory.d.ts +4 -1
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformTypes.d.cts +4 -1
- package/dist/cjs/transformTypes.d.ts +4 -1
- package/dist/cjs/transformTypes.js.map +1 -1
- package/dist/cjs/workers/transformDirectory.d.cts +1 -1
- package/dist/cjs/workers/transformDirectory.d.ts +1 -1
- package/dist/cjs/workers/transformDirectory.js +1 -4
- package/dist/cjs/workers/transformDirectory.js.map +1 -1
- package/dist/cjs/workers/transformTypes.d.cts +1 -1
- package/dist/cjs/workers/transformTypes.d.ts +1 -1
- package/dist/cjs/workers/transformTypes.js +2 -8
- package/dist/cjs/workers/transformTypes.js.map +1 -1
- package/dist/esm/lib/prepareSWCOptions.js +3 -2
- package/dist/esm/lib/prepareSWCOptions.js.map +1 -1
- package/dist/esm/lib/resolveCJS.d.ts +17 -0
- package/dist/esm/lib/resolveCJS.js +28 -0
- package/dist/esm/lib/resolveCJS.js.map +1 -0
- package/dist/esm/lib/resolveESM.d.ts +19 -0
- package/dist/esm/lib/resolveESM.js +163 -0
- package/dist/esm/lib/resolveESM.js.map +1 -0
- package/dist/esm/lib/transformFile.d.ts +1 -1
- package/dist/esm/lib/transformFile.js.map +1 -1
- package/dist/esm/toPath.js +26 -21
- package/dist/esm/toPath.js.map +1 -1
- package/dist/esm/transformDirectory.d.ts +4 -1
- package/dist/esm/transformDirectory.js.map +1 -1
- package/dist/esm/transformTypes.d.ts +4 -1
- package/dist/esm/transformTypes.js.map +1 -1
- package/dist/esm/workers/transformDirectory.d.ts +1 -1
- package/dist/esm/workers/transformDirectory.js +1 -4
- package/dist/esm/workers/transformDirectory.js.map +1 -1
- package/dist/esm/workers/transformTypes.d.ts +1 -1
- package/dist/esm/workers/transformTypes.js +2 -8
- package/dist/esm/workers/transformTypes.js.map +1 -1
- package/package.json +4 -3
- package/dist/cjs/lib/resolve-with-exports.d.cts +0 -16
- package/dist/cjs/lib/resolve-with-exports.d.ts +0 -16
- package/dist/cjs/lib/resolve-with-exports.js +0 -157
- package/dist/cjs/lib/resolve-with-exports.js.map +0 -1
- package/dist/esm/lib/resolve-with-exports.d.ts +0 -16
- package/dist/esm/lib/resolve-with-exports.js +0 -140
- package/dist/esm/lib/resolve-with-exports.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.ts';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;\nexport default function transformDirectory(src: string, dest: string, type: TargetType): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options: ConfigOptions): Promise<string[]>;\nexport default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = (options || {}) as ConfigOptions;\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback);\n return new Promise((resolve, reject) =>\n dispatch(version, src, dest, type, options as ConfigOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","loadConfigSync","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAEtB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAI1F,SAASE,SAASX,OAAe,EAAEY,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IAC1I,IAAIhB,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAER;YAASiB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAMA,eAAe,SAASC,mBAAmBP,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAC9C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAWA,WAAW,CAAC;QACvB,MAAMM,WAAWN,QAAQM,QAAQ,GAAGN,QAAQM,QAAQ,GAAG5B,eAAemB;QACtEG,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIM,QAAQ,CAACC,SAASC,SAC3Bb,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAA0B,CAACG,KAAKO;gBACjEP,MAAMM,OAAON,OAAOK,QAAQE;YAC9B;IAEJ,EAAE,OAAOP,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOI,QAAQE,MAAM,CAACN;IAC7B;AACF"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from './types.js';
|
|
2
|
-
export default function transformTypes(src: string, dest: string,
|
|
2
|
+
export default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;
|
|
3
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
4
|
+
export default function transformTypes(src: string, dest: string): Promise<string[]>;
|
|
5
|
+
export default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback):
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.ts';\n\nexport default function transformTypes(src: string, dest: string, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;\nexport default function transformTypes(src: string, dest: string): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options: ConfigOptions): Promise<string[]>;\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): void | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = (options || {}) as ConfigOptions;\n const tsconfig = options.tsconfig ? options.tsconfig : loadConfigSync(src);\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","loadConfigSync","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","options","callback","callbacks","err","transformTypes","Error","tsconfig","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAEtB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAE1F,SAASE,SAASX,OAAO,EAAEY,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIf,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMP,SAAS,qBAAqB;YAAER;YAASgB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAQA,eAAe,SAASC,eAAeN,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAWA,WAAW,CAAC;QACvB,MAAMM,WAAWN,QAAQM,QAAQ,GAAGN,QAAQM,QAAQ,GAAG3B,eAAemB;QACtEE,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASX,SAASY,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIM,QAAQ,CAACC,SAASC,SAAWZ,SAASX,SAASY,KAAKC,MAAMC,SAAS,CAACG,KAAKO,SAAYP,MAAMM,OAAON,OAAOK,QAAQE;IAC9H,EAAE,OAAOP,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOI,QAAQE,MAAM,CAACN;IAC7B;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
|
|
2
|
-
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback):
|
|
2
|
+
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): void;
|
|
@@ -18,10 +18,7 @@ export default function transformDirectoryWorker(src, dest, type, options, callb
|
|
|
18
18
|
if (ext && extensions.indexOf(ext) < 0) return;
|
|
19
19
|
entries.push(entry);
|
|
20
20
|
}, (err)=>{
|
|
21
|
-
if (err)
|
|
22
|
-
callback(err);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
21
|
+
if (err) return callback(err);
|
|
25
22
|
const results = [];
|
|
26
23
|
options = {
|
|
27
24
|
...options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport transformFile from '../lib/transformFile.ts';\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.ts';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries: Entry[] = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["Iterator","path","Queue","extensions","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","ext","extname","indexOf","push","err","results","queue","defer","cb","outPath","normalize","sourceMaps","await"],"mappings":"AAAA,OAAOA,cAA8B,cAAc;AACnD,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,SAASC,UAAU,EAAEC,aAAa,QAAQ,kBAAkB;AAC5D,OAAOC,mBAAmB,sBAAsB;AAChD,OAAOC,mBAAmB,0BAA0B;AAIpD,eAAe,SAASC,yBAAyBC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACxJ,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUT,cAAcQ;IAE9B,MAAME,UAAmB,EAAE;IAC3B,MAAMC,WAAW,IAAIhB,SAASQ;IAC9BQ,SAASC,OAAO,CACd,CAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIjB,cAAckB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACP,QAAQI,MAAMK,QAAQ,GAAG;QAC9B,MAAMC,MAAMvB,KAAKwB,OAAO,CAACP,MAAMG,QAAQ;QACvC,IAAIG,OAAOrB,WAAWuB,OAAO,CAACF,OAAO,GAAG;QACxCT,QAAQY,IAAI,CAACT;IACf,GACA,CAACU;QACC,IAAIA,KAAK,OAAOhB,SAASgB;QACzB,MAAMC,UAAU,EAAE;QAClBlB,UAAU;YAAE,GAAGA,OAAO;YAAEE;QAAS;QAEjC,MAAMiB,QAAQ,IAAI5B;QAClBa,QAAQE,OAAO,CAAC,CAACC;YACfY,MAAMC,KAAK,CAAC,CAACC,KACX1B,cAAcY,OAAOT,MAAMC,MAAMC,SAAS,CAACiB,KAAKK;oBAC9C,IAAIL,KAAK,OAAOI,GAAGJ;oBACnBC,QAAQF,IAAI,CAAC1B,KAAKiC,SAAS,CAACD;oBAC5B,IAAItB,QAAQwB,UAAU,EAAEN,QAAQF,IAAI,CAAC,GAAG1B,KAAKiC,SAAS,CAACD,SAAS,IAAI,CAAC;oBACrED;gBACF;QAEJ;QACAF,MAAMM,KAAK,CAAC,CAACR,MAASA,MAAMhB,SAASgB,OAAOhB,SAAS,MAAMiB;IAC7D;AAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ConfigOptions, TransformTypesCallback } from '../types.js';
|
|
2
|
-
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback):
|
|
2
|
+
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): void;
|
|
@@ -23,10 +23,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
23
23
|
}, {
|
|
24
24
|
concurrency: Infinity
|
|
25
25
|
}, (err)=>{
|
|
26
|
-
if (err)
|
|
27
|
-
callback(err);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
26
|
+
if (err) return callback(err);
|
|
30
27
|
// Step 1: Stat all source files to get their modes (async)
|
|
31
28
|
const sourceModes = new Map();
|
|
32
29
|
const statQueue = new Queue();
|
|
@@ -39,10 +36,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
39
36
|
});
|
|
40
37
|
});
|
|
41
38
|
statQueue.await((statErr)=>{
|
|
42
|
-
if (statErr)
|
|
43
|
-
callback(statErr);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
39
|
+
if (statErr) return callback(statErr);
|
|
46
40
|
// Step 2: TypeScript emit (inherently sync - cannot change)
|
|
47
41
|
const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
|
|
48
42
|
const config = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): void => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n // Step 1: Stat all source files to get their modes (async)\n const sourceModes = new Map<string, number>();\n const statQueue = new Queue();\n entries.forEach((entry) => {\n statQueue.defer((cb) => {\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (!statErr) sourceModes.set(entry.fullPath, stats.mode);\n cb(); // Continue even on error\n });\n });\n });\n\n statQueue.await((statErr) => {\n if (statErr) return callback(statErr);\n\n // Step 2: TypeScript emit (inherently sync - cannot change)\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // Step 3: Post-process emitted files (async)\n const postQueue = new Queue();\n\n if (res.emittedFiles) {\n res.emittedFiles.forEach((file) => {\n // 3a: Rewrite extensions (convert from sync to async)\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (compilerOptions.options.rewriteRelativeImportExtensions) {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n postQueue.defer((cb) => {\n fs.readFile(file, 'utf8', (readErr, content) => {\n if (readErr) return cb(); // Ignore errors, continue\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFile(file, updated, 'utf8', () => cb()); // Ignore write errors\n } else {\n cb();\n }\n });\n });\n }\n }\n\n // 3b: Apply executable permissions from source files\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n const relativePath = path.relative(dest, file);\n const baseName = relativePath.replace(/\\.d\\.(ts|mts|cts)$/, '');\n\n for (const [srcPath, mode] of sourceModes) {\n const srcRelative = path.relative(src, srcPath);\n const srcBase = srcRelative.replace(/\\.(ts|tsx|mts|cts)$/, '');\n if (baseName === srcBase) {\n const execBits = mode & 0o111;\n if (execBits) {\n postQueue.defer((cb) => {\n fs.chmod(file, 0o644 | execBits, () => cb()); // Ignore chmod errors\n });\n }\n break;\n }\n }\n }\n });\n }\n\n postQueue.await(() => callback(null, res.emittedFiles));\n });\n }\n );\n}\n"],"names":["fs","Iterator","Module","path","Queue","_require","require","createRequire","url","stringEndsWith","typeFileRegEx","createMatcher","rewriteExtensions","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","push","concurrency","Infinity","err","sourceModes","Map","statQueue","defer","cb","stat","statErr","set","mode","await","compilerOptions","convertCompilerOptionsFromJson","config","fileNames","map","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","postQueue","emittedFiles","file","rewriteRelativeImportExtensions","readFile","readErr","content","updated","writeFile","relativePath","relative","baseName","replace","srcPath","srcRelative","srcBase","execBits","chmod"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,cAA8B,cAAc;AACnD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,cAAc,QAAQ,eAAe;AAC9C,SAASC,aAAa,Q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D,MAAM,aAAa9D,eAAe8D,MAAM,WAAW;wBACrG,MAAMO,eAAe3E,KAAK4E,QAAQ,CAAChE,MAAMwD;wBACzC,MAAMS,WAAWF,aAAaG,OAAO,CAAC,sBAAsB;wBAE5D,KAAK,MAAM,CAACC,SAASxC,KAAK,IAAIR,YAAa;4BACzC,MAAMiD,cAAchF,KAAK4E,QAAQ,CAACjE,KAAKoE;4BACvC,MAAME,UAAUD,YAAYF,OAAO,CAAC,uBAAuB;4BAC3D,IAAID,aAAaI,SAAS;gCACxB,MAAMC,WAAW3C,OAAO;gCACxB,IAAI2C,UAAU;oCACZhB,UAAUhC,KAAK,CAAC,CAACC;wCACftC,GAAGsF,KAAK,CAACf,MAAM,QAAQc,UAAU,IAAM/C,OAAO,sBAAsB;oCACtE;gCACF;gCACA;4BACF;wBACF;oBACF;gBACF;YACF;YAEA+B,UAAU1B,KAAK,CAAC,IAAM1B,SAAS,MAAMkD,IAAIG,YAAY;QACvD;IACF;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@swc/core": "^1.15.5",
|
|
48
48
|
"core-js-pure": "^3.20.0",
|
|
49
49
|
"exit-compat": "^1.0.0",
|
|
50
|
-
"fs-iterator": "^
|
|
51
|
-
"install-optional": "^1.
|
|
50
|
+
"fs-iterator": "^7.0.0",
|
|
51
|
+
"install-optional": "^1.1.1",
|
|
52
52
|
"is-absolute": "^1.0.0",
|
|
53
53
|
"lodash.debounce": "^4.0.8",
|
|
54
54
|
"mkdirp-classic": "^0.5.2",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"cross-spawn-cb": "^2.0.0",
|
|
69
69
|
"fs-remove-compat": "^1.0.0",
|
|
70
70
|
"mock-exports-only-pkg": "file:test/data/mock-exports-only-pkg",
|
|
71
|
+
"mock-subpath-imports-pkg": "file:test/data/mock-subpath-imports-pkg",
|
|
71
72
|
"node-version-use": "*",
|
|
72
73
|
"pinkie-promise": "*",
|
|
73
74
|
"react": "^19.2.3",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight ESM exports field resolver
|
|
3
|
-
* Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
|
|
4
|
-
*
|
|
5
|
-
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
|
-
* On older Node, toPath.ts skips this and falls back to resolve.sync().
|
|
7
|
-
*
|
|
8
|
-
* This implementation handles packages with ONLY an exports field (no main),
|
|
9
|
-
* which the resolve package cannot handle on its own.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Resolve a module specifier using the exports field in package.json
|
|
13
|
-
* This implementation directly finds the package and reads its exports,
|
|
14
|
-
* bypassing the resolve package which can't handle exports-only packages.
|
|
15
|
-
*/
|
|
16
|
-
export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight ESM exports field resolver
|
|
3
|
-
* Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
|
|
4
|
-
*
|
|
5
|
-
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
|
-
* On older Node, toPath.ts skips this and falls back to resolve.sync().
|
|
7
|
-
*
|
|
8
|
-
* This implementation handles packages with ONLY an exports field (no main),
|
|
9
|
-
* which the resolve package cannot handle on its own.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Resolve a module specifier using the exports field in package.json
|
|
13
|
-
* This implementation directly finds the package and reads its exports,
|
|
14
|
-
* bypassing the resolve package which can't handle exports-only packages.
|
|
15
|
-
*/
|
|
16
|
-
export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight ESM exports field resolver
|
|
3
|
-
* Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
|
|
4
|
-
*
|
|
5
|
-
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
|
-
* On older Node, toPath.ts skips this and falls back to resolve.sync().
|
|
7
|
-
*
|
|
8
|
-
* This implementation handles packages with ONLY an exports field (no main),
|
|
9
|
-
* which the resolve package cannot handle on its own.
|
|
10
|
-
*/ "use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", {
|
|
12
|
-
value: true
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, /**
|
|
15
|
-
* Resolve a module specifier using the exports field in package.json
|
|
16
|
-
* This implementation directly finds the package and reads its exports,
|
|
17
|
-
* bypassing the resolve package which can't handle exports-only packages.
|
|
18
|
-
*/ "default", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function() {
|
|
21
|
-
return resolveWithExports;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
25
|
-
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
26
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
27
|
-
function _interop_require_default(obj) {
|
|
28
|
-
return obj && obj.__esModule ? obj : {
|
|
29
|
-
default: obj
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
var _resolveExports = null;
|
|
33
|
-
function getResolveExports() {
|
|
34
|
-
if (_resolveExports === null) {
|
|
35
|
-
try {
|
|
36
|
-
// Use dynamic require to avoid loading on older Node versions
|
|
37
|
-
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
38
|
-
_resolveExports = _require('resolve.exports');
|
|
39
|
-
} catch (_) {
|
|
40
|
-
// If resolve.exports fails to load, return null
|
|
41
|
-
// This shouldn't happen on Node >= 12.2, but handle gracefully
|
|
42
|
-
_resolveExports = null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return _resolveExports;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parse a specifier into package name and subpath
|
|
49
|
-
* "lodash" → { pkgName: "lodash", subpath: "." }
|
|
50
|
-
* "lodash/get" → { pkgName: "lodash", subpath: "./get" }
|
|
51
|
-
* "@scope/pkg" → { pkgName: "@scope/pkg", subpath: "." }
|
|
52
|
-
* "@scope/pkg/foo" → { pkgName: "@scope/pkg", subpath: "./foo" }
|
|
53
|
-
*/ function parseSpecifier(specifier) {
|
|
54
|
-
var parts = specifier.split('/');
|
|
55
|
-
var pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
|
|
56
|
-
var remainder = specifier.slice(pkgName.length);
|
|
57
|
-
var subpath = remainder ? ".".concat(remainder) : '.';
|
|
58
|
-
return {
|
|
59
|
-
pkgName: pkgName,
|
|
60
|
-
subpath: subpath
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Find the package.json for a package by walking up node_modules
|
|
65
|
-
*/ function findPackageJson(pkgName, basedir) {
|
|
66
|
-
var dir = basedir;
|
|
67
|
-
var root = _path.default.parse(dir).root;
|
|
68
|
-
while(dir !== root){
|
|
69
|
-
var candidate = _path.default.join(dir, 'node_modules', pkgName, 'package.json');
|
|
70
|
-
try {
|
|
71
|
-
if (_fs.default.existsSync(candidate)) {
|
|
72
|
-
return candidate;
|
|
73
|
-
}
|
|
74
|
-
} catch (_) {
|
|
75
|
-
// Ignore filesystem errors
|
|
76
|
-
}
|
|
77
|
-
var parent = _path.default.dirname(dir);
|
|
78
|
-
if (parent === dir) break;
|
|
79
|
-
dir = parent;
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Read and parse a package.json file
|
|
85
|
-
*/ function readPackageJson(pkgJsonPath) {
|
|
86
|
-
try {
|
|
87
|
-
var content = _fs.default.readFileSync(pkgJsonPath, 'utf8');
|
|
88
|
-
return JSON.parse(content);
|
|
89
|
-
} catch (_) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function resolveWithExports(specifier, basedir) {
|
|
94
|
-
var conditions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [
|
|
95
|
-
'node',
|
|
96
|
-
'import'
|
|
97
|
-
];
|
|
98
|
-
var resolveExportsMod = getResolveExports();
|
|
99
|
-
if (!resolveExportsMod) {
|
|
100
|
-
// resolve.exports not available, return null to trigger fallback
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
var resolveExportsFn = resolveExportsMod.exports, legacy = resolveExportsMod.legacy;
|
|
104
|
-
var _parseSpecifier = parseSpecifier(specifier), pkgName = _parseSpecifier.pkgName, subpath = _parseSpecifier.subpath;
|
|
105
|
-
// Find the package.json
|
|
106
|
-
var pkgJsonPath = findPackageJson(pkgName, basedir);
|
|
107
|
-
if (!pkgJsonPath) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
// Read package.json
|
|
111
|
-
var pkg = readPackageJson(pkgJsonPath);
|
|
112
|
-
if (!pkg) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
var pkgDir = _path.default.dirname(pkgJsonPath);
|
|
116
|
-
// Try exports field first
|
|
117
|
-
try {
|
|
118
|
-
var resolved = resolveExportsFn(pkg, subpath, {
|
|
119
|
-
conditions: conditions
|
|
120
|
-
});
|
|
121
|
-
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
122
|
-
return _path.default.join(pkgDir, resolved[0]);
|
|
123
|
-
}
|
|
124
|
-
} catch (_) {
|
|
125
|
-
// exports field parsing failed, try legacy
|
|
126
|
-
}
|
|
127
|
-
// Try legacy main/module fields
|
|
128
|
-
try {
|
|
129
|
-
var legacyMain = legacy(pkg);
|
|
130
|
-
if (legacyMain) {
|
|
131
|
-
// legacy() can return string, string[], or browser field object
|
|
132
|
-
var mainPath;
|
|
133
|
-
if (typeof legacyMain === 'string') {
|
|
134
|
-
mainPath = legacyMain;
|
|
135
|
-
} else if (Array.isArray(legacyMain)) {
|
|
136
|
-
mainPath = legacyMain[0];
|
|
137
|
-
}
|
|
138
|
-
// Ignore browser field objects (they map file paths, not entry points)
|
|
139
|
-
if (mainPath) {
|
|
140
|
-
return _path.default.join(pkgDir, mainPath);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
} catch (_) {
|
|
144
|
-
// legacy parsing failed
|
|
145
|
-
}
|
|
146
|
-
// Last resort: try index.js
|
|
147
|
-
var indexPath = _path.default.join(pkgDir, 'index.js');
|
|
148
|
-
try {
|
|
149
|
-
if (_fs.default.existsSync(indexPath)) {
|
|
150
|
-
return indexPath;
|
|
151
|
-
}
|
|
152
|
-
} catch (_) {
|
|
153
|
-
// Ignore
|
|
154
|
-
}
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolve-with-exports.ts"],"sourcesContent":["/**\n * Lightweight ESM exports field resolver\n * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)\n *\n * Only loaded on Node >= 12.2 where module.createRequire exists.\n * On older Node, toPath.ts skips this and falls back to resolve.sync().\n *\n * This implementation handles packages with ONLY an exports field (no main),\n * which the resolve package cannot handle on its own.\n */\n\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\n\n// Lazy-load resolve.exports to avoid requiring it on older Node versions\n// resolve.exports requires Node >= 10, but this code only runs on Node >= 12.2\ntype ResolveExportsModule = typeof import('resolve.exports');\nlet _resolveExports: ResolveExportsModule | null = null;\n\nfunction getResolveExports(): ResolveExportsModule | null {\n if (_resolveExports === null) {\n try {\n // Use dynamic require to avoid loading on older Node versions\n const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n _resolveExports = _require('resolve.exports') as ResolveExportsModule;\n } catch (_) {\n // If resolve.exports fails to load, return null\n // This shouldn't happen on Node >= 12.2, but handle gracefully\n _resolveExports = null;\n }\n }\n return _resolveExports;\n}\n\n/**\n * Parse a specifier into package name and subpath\n * \"lodash\" → { pkgName: \"lodash\", subpath: \".\" }\n * \"lodash/get\" → { pkgName: \"lodash\", subpath: \"./get\" }\n * \"@scope/pkg\" → { pkgName: \"@scope/pkg\", subpath: \".\" }\n * \"@scope/pkg/foo\" → { pkgName: \"@scope/pkg\", subpath: \"./foo\" }\n */\nfunction parseSpecifier(specifier: string): { pkgName: string; subpath: string } {\n const parts = specifier.split('/');\n const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];\n const remainder = specifier.slice(pkgName.length);\n const subpath = remainder ? `.${remainder}` : '.';\n return { pkgName, subpath };\n}\n\n/**\n * Find the package.json for a package by walking up node_modules\n */\nfunction findPackageJson(pkgName: string, basedir: string): string | null {\n let dir = basedir;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const candidate = path.join(dir, 'node_modules', pkgName, 'package.json');\n try {\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n } catch (_) {\n // Ignore filesystem errors\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n return null;\n}\n\n/**\n * Read and parse a package.json file\n */\nfunction readPackageJson(pkgJsonPath: string): Record<string, unknown> | null {\n try {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return JSON.parse(content);\n } catch (_) {\n return null;\n }\n}\n\n/**\n * Resolve a module specifier using the exports field in package.json\n * This implementation directly finds the package and reads its exports,\n * bypassing the resolve package which can't handle exports-only packages.\n */\nexport default function resolveWithExports(specifier: string, basedir: string, conditions: string[] = ['node', 'import']): string | null {\n const resolveExportsMod = getResolveExports();\n if (!resolveExportsMod) {\n // resolve.exports not available, return null to trigger fallback\n return null;\n }\n\n const { exports: resolveExportsFn, legacy } = resolveExportsMod;\n const { pkgName, subpath } = parseSpecifier(specifier);\n\n // Find the package.json\n const pkgJsonPath = findPackageJson(pkgName, basedir);\n if (!pkgJsonPath) {\n return null;\n }\n\n // Read package.json\n const pkg = readPackageJson(pkgJsonPath);\n if (!pkg) {\n return null;\n }\n\n const pkgDir = path.dirname(pkgJsonPath);\n\n // Try exports field first\n try {\n const resolved = resolveExportsFn(pkg, subpath, { conditions });\n if (resolved?.[0]) {\n return path.join(pkgDir, resolved[0]);\n }\n } catch (_) {\n // exports field parsing failed, try legacy\n }\n\n // Try legacy main/module fields\n try {\n const legacyMain = legacy(pkg);\n if (legacyMain) {\n // legacy() can return string, string[], or browser field object\n let mainPath: string | undefined;\n if (typeof legacyMain === 'string') {\n mainPath = legacyMain;\n } else if (Array.isArray(legacyMain)) {\n mainPath = legacyMain[0];\n }\n // Ignore browser field objects (they map file paths, not entry points)\n if (mainPath) {\n return path.join(pkgDir, mainPath);\n }\n }\n } catch (_) {\n // legacy parsing failed\n }\n\n // Last resort: try index.js\n const indexPath = path.join(pkgDir, 'index.js');\n try {\n if (fs.existsSync(indexPath)) {\n return indexPath;\n }\n } catch (_) {\n // Ignore\n }\n\n return null;\n}\n"],"names":["resolveWithExports","_resolveExports","getResolveExports","_require","require","Module","createRequire","_","parseSpecifier","specifier","parts","split","pkgName","slice","join","remainder","length","subpath","findPackageJson","basedir","dir","root","path","parse","candidate","fs","existsSync","parent","dirname","readPackageJson","pkgJsonPath","content","readFileSync","JSON","conditions","resolveExportsMod","exports","resolveExportsFn","legacy","pkg","pkgDir","resolved","legacyMain","mainPath","Array","isArray","indexPath"],"mappings":"AAAA;;;;;;;;;CASC;;;;+BA6ED;;;;CAIC,GACD;;;eAA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OAAOpC,GAAG;IACV,wBAAwB;IAC1B;IAEA,4BAA4B;IAC5B,IAAMuC,YAAYxB,aAAI,CAACR,IAAI,CAAC0B,QAAQ;IACpC,IAAI;QACF,IAAIf,WAAE,CAACC,UAAU,CAACoB,YAAY;YAC5B,OAAOA;QACT;IACF,EAAE,OAAOvC,GAAG;IACV,SAAS;IACX;IAEA,OAAO;AACT"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight ESM exports field resolver
|
|
3
|
-
* Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
|
|
4
|
-
*
|
|
5
|
-
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
|
-
* On older Node, toPath.ts skips this and falls back to resolve.sync().
|
|
7
|
-
*
|
|
8
|
-
* This implementation handles packages with ONLY an exports field (no main),
|
|
9
|
-
* which the resolve package cannot handle on its own.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Resolve a module specifier using the exports field in package.json
|
|
13
|
-
* This implementation directly finds the package and reads its exports,
|
|
14
|
-
* bypassing the resolve package which can't handle exports-only packages.
|
|
15
|
-
*/
|
|
16
|
-
export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight ESM exports field resolver
|
|
3
|
-
* Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
|
|
4
|
-
*
|
|
5
|
-
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
|
-
* On older Node, toPath.ts skips this and falls back to resolve.sync().
|
|
7
|
-
*
|
|
8
|
-
* This implementation handles packages with ONLY an exports field (no main),
|
|
9
|
-
* which the resolve package cannot handle on its own.
|
|
10
|
-
*/ import fs from 'fs';
|
|
11
|
-
import Module from 'module';
|
|
12
|
-
import path from 'path';
|
|
13
|
-
let _resolveExports = null;
|
|
14
|
-
function getResolveExports() {
|
|
15
|
-
if (_resolveExports === null) {
|
|
16
|
-
try {
|
|
17
|
-
// Use dynamic require to avoid loading on older Node versions
|
|
18
|
-
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
19
|
-
_resolveExports = _require('resolve.exports');
|
|
20
|
-
} catch (_) {
|
|
21
|
-
// If resolve.exports fails to load, return null
|
|
22
|
-
// This shouldn't happen on Node >= 12.2, but handle gracefully
|
|
23
|
-
_resolveExports = null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return _resolveExports;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Parse a specifier into package name and subpath
|
|
30
|
-
* "lodash" → { pkgName: "lodash", subpath: "." }
|
|
31
|
-
* "lodash/get" → { pkgName: "lodash", subpath: "./get" }
|
|
32
|
-
* "@scope/pkg" → { pkgName: "@scope/pkg", subpath: "." }
|
|
33
|
-
* "@scope/pkg/foo" → { pkgName: "@scope/pkg", subpath: "./foo" }
|
|
34
|
-
*/ function parseSpecifier(specifier) {
|
|
35
|
-
const parts = specifier.split('/');
|
|
36
|
-
const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
|
|
37
|
-
const remainder = specifier.slice(pkgName.length);
|
|
38
|
-
const subpath = remainder ? `.${remainder}` : '.';
|
|
39
|
-
return {
|
|
40
|
-
pkgName,
|
|
41
|
-
subpath
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Find the package.json for a package by walking up node_modules
|
|
46
|
-
*/ function findPackageJson(pkgName, basedir) {
|
|
47
|
-
let dir = basedir;
|
|
48
|
-
const root = path.parse(dir).root;
|
|
49
|
-
while(dir !== root){
|
|
50
|
-
const candidate = path.join(dir, 'node_modules', pkgName, 'package.json');
|
|
51
|
-
try {
|
|
52
|
-
if (fs.existsSync(candidate)) {
|
|
53
|
-
return candidate;
|
|
54
|
-
}
|
|
55
|
-
} catch (_) {
|
|
56
|
-
// Ignore filesystem errors
|
|
57
|
-
}
|
|
58
|
-
const parent = path.dirname(dir);
|
|
59
|
-
if (parent === dir) break;
|
|
60
|
-
dir = parent;
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Read and parse a package.json file
|
|
66
|
-
*/ function readPackageJson(pkgJsonPath) {
|
|
67
|
-
try {
|
|
68
|
-
const content = fs.readFileSync(pkgJsonPath, 'utf8');
|
|
69
|
-
return JSON.parse(content);
|
|
70
|
-
} catch (_) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Resolve a module specifier using the exports field in package.json
|
|
76
|
-
* This implementation directly finds the package and reads its exports,
|
|
77
|
-
* bypassing the resolve package which can't handle exports-only packages.
|
|
78
|
-
*/ export default function resolveWithExports(specifier, basedir, conditions = [
|
|
79
|
-
'node',
|
|
80
|
-
'import'
|
|
81
|
-
]) {
|
|
82
|
-
const resolveExportsMod = getResolveExports();
|
|
83
|
-
if (!resolveExportsMod) {
|
|
84
|
-
// resolve.exports not available, return null to trigger fallback
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
const { exports: resolveExportsFn, legacy } = resolveExportsMod;
|
|
88
|
-
const { pkgName, subpath } = parseSpecifier(specifier);
|
|
89
|
-
// Find the package.json
|
|
90
|
-
const pkgJsonPath = findPackageJson(pkgName, basedir);
|
|
91
|
-
if (!pkgJsonPath) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
// Read package.json
|
|
95
|
-
const pkg = readPackageJson(pkgJsonPath);
|
|
96
|
-
if (!pkg) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
const pkgDir = path.dirname(pkgJsonPath);
|
|
100
|
-
// Try exports field first
|
|
101
|
-
try {
|
|
102
|
-
const resolved = resolveExportsFn(pkg, subpath, {
|
|
103
|
-
conditions
|
|
104
|
-
});
|
|
105
|
-
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
106
|
-
return path.join(pkgDir, resolved[0]);
|
|
107
|
-
}
|
|
108
|
-
} catch (_) {
|
|
109
|
-
// exports field parsing failed, try legacy
|
|
110
|
-
}
|
|
111
|
-
// Try legacy main/module fields
|
|
112
|
-
try {
|
|
113
|
-
const legacyMain = legacy(pkg);
|
|
114
|
-
if (legacyMain) {
|
|
115
|
-
// legacy() can return string, string[], or browser field object
|
|
116
|
-
let mainPath;
|
|
117
|
-
if (typeof legacyMain === 'string') {
|
|
118
|
-
mainPath = legacyMain;
|
|
119
|
-
} else if (Array.isArray(legacyMain)) {
|
|
120
|
-
mainPath = legacyMain[0];
|
|
121
|
-
}
|
|
122
|
-
// Ignore browser field objects (they map file paths, not entry points)
|
|
123
|
-
if (mainPath) {
|
|
124
|
-
return path.join(pkgDir, mainPath);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} catch (_) {
|
|
128
|
-
// legacy parsing failed
|
|
129
|
-
}
|
|
130
|
-
// Last resort: try index.js
|
|
131
|
-
const indexPath = path.join(pkgDir, 'index.js');
|
|
132
|
-
try {
|
|
133
|
-
if (fs.existsSync(indexPath)) {
|
|
134
|
-
return indexPath;
|
|
135
|
-
}
|
|
136
|
-
} catch (_) {
|
|
137
|
-
// Ignore
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolve-with-exports.ts"],"sourcesContent":["/**\n * Lightweight ESM exports field resolver\n * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)\n *\n * Only loaded on Node >= 12.2 where module.createRequire exists.\n * On older Node, toPath.ts skips this and falls back to resolve.sync().\n *\n * This implementation handles packages with ONLY an exports field (no main),\n * which the resolve package cannot handle on its own.\n */\n\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\n\n// Lazy-load resolve.exports to avoid requiring it on older Node versions\n// resolve.exports requires Node >= 10, but this code only runs on Node >= 12.2\ntype ResolveExportsModule = typeof import('resolve.exports');\nlet _resolveExports: ResolveExportsModule | null = null;\n\nfunction getResolveExports(): ResolveExportsModule | null {\n if (_resolveExports === null) {\n try {\n // Use dynamic require to avoid loading on older Node versions\n const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n _resolveExports = _require('resolve.exports') as ResolveExportsModule;\n } catch (_) {\n // If resolve.exports fails to load, return null\n // This shouldn't happen on Node >= 12.2, but handle gracefully\n _resolveExports = null;\n }\n }\n return _resolveExports;\n}\n\n/**\n * Parse a specifier into package name and subpath\n * \"lodash\" → { pkgName: \"lodash\", subpath: \".\" }\n * \"lodash/get\" → { pkgName: \"lodash\", subpath: \"./get\" }\n * \"@scope/pkg\" → { pkgName: \"@scope/pkg\", subpath: \".\" }\n * \"@scope/pkg/foo\" → { pkgName: \"@scope/pkg\", subpath: \"./foo\" }\n */\nfunction parseSpecifier(specifier: string): { pkgName: string; subpath: string } {\n const parts = specifier.split('/');\n const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];\n const remainder = specifier.slice(pkgName.length);\n const subpath = remainder ? `.${remainder}` : '.';\n return { pkgName, subpath };\n}\n\n/**\n * Find the package.json for a package by walking up node_modules\n */\nfunction findPackageJson(pkgName: string, basedir: string): string | null {\n let dir = basedir;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const candidate = path.join(dir, 'node_modules', pkgName, 'package.json');\n try {\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n } catch (_) {\n // Ignore filesystem errors\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n return null;\n}\n\n/**\n * Read and parse a package.json file\n */\nfunction readPackageJson(pkgJsonPath: string): Record<string, unknown> | null {\n try {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return JSON.parse(content);\n } catch (_) {\n return null;\n }\n}\n\n/**\n * Resolve a module specifier using the exports field in package.json\n * This implementation directly finds the package and reads its exports,\n * bypassing the resolve package which can't handle exports-only packages.\n */\nexport default function resolveWithExports(specifier: string, basedir: string, conditions: string[] = ['node', 'import']): string | null {\n const resolveExportsMod = getResolveExports();\n if (!resolveExportsMod) {\n // resolve.exports not available, return null to trigger fallback\n return null;\n }\n\n const { exports: resolveExportsFn, legacy } = resolveExportsMod;\n const { pkgName, subpath } = parseSpecifier(specifier);\n\n // Find the package.json\n const pkgJsonPath = findPackageJson(pkgName, basedir);\n if (!pkgJsonPath) {\n return null;\n }\n\n // Read package.json\n const pkg = readPackageJson(pkgJsonPath);\n if (!pkg) {\n return null;\n }\n\n const pkgDir = path.dirname(pkgJsonPath);\n\n // Try exports field first\n try {\n const resolved = resolveExportsFn(pkg, subpath, { conditions });\n if (resolved?.[0]) {\n return path.join(pkgDir, resolved[0]);\n }\n } catch (_) {\n // exports field parsing failed, try legacy\n }\n\n // Try legacy main/module fields\n try {\n const legacyMain = legacy(pkg);\n if (legacyMain) {\n // legacy() can return string, string[], or browser field object\n let mainPath: string | undefined;\n if (typeof legacyMain === 'string') {\n mainPath = legacyMain;\n } else if (Array.isArray(legacyMain)) {\n mainPath = legacyMain[0];\n }\n // Ignore browser field objects (they map file paths, not entry points)\n if (mainPath) {\n return path.join(pkgDir, mainPath);\n }\n }\n } catch (_) {\n // legacy parsing failed\n }\n\n // Last resort: try index.js\n const indexPath = path.join(pkgDir, 'index.js');\n try {\n if (fs.existsSync(indexPath)) {\n return indexPath;\n }\n } catch (_) {\n // Ignore\n }\n\n return null;\n}\n"],"names":["fs","Module","path","_resolveExports","getResolveExports","_require","require","createRequire","url","_","parseSpecifier","specifier","parts","split","pkgName","slice","join","remainder","length","subpath","findPackageJson","basedir","dir","root","parse","candidate","existsSync","parent","dirname","readPackageJson","pkgJsonPath","content","readFileSync","JSON","resolveWithExports","conditions","resolveExportsMod","exports","resolveExportsFn","legacy","pkg","pkgDir","resolved","legacyMain","mainPath","Array","isArray","indexPath"],"mappings":"AAAA;;;;;;;;;CASC,GAED,OAA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