ts-swc-transform 2.7.6 → 2.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nvar hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nvar hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n var len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nvar hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n var escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["stringEndsWith","stringReplaceAll","stringStartsWith","hasStartsWith","String","prototype","startsWith","str","search","position","indexOf","hasEndsWith","endsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","replace","escaped","RegExp"],"mappings":";;;;;;;;;;;QA2BgBA;eAAAA;;QAgBAC;eAAAA;;QA/BAC;eAAAA;;;AAZhB;;;CAGC,GAED;;;;CAIC,GACD,IAAIC,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAEpD,SAASJ,iBAAiBK,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIN,eAAe;QACjB,OAAOI,IAAID,UAAU,CAACE,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,IAAIE,cAAc,OAAOP,OAAOC,SAAS,CAACO,QAAQ,KAAK;AAEhD,SAASZ,eAAeO,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAII,MAAMJ,aAAaK,YAAYP,IAAIQ,MAAM,GAAGN;IAChD,OAAOF,IAAIS,WAAW,CAACR,YAAYK,MAAML,OAAOO,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAIE,gBAAgB,OAAO,AAACb,OAAOC,SAAS,CAASa,UAAU,KAAK;AAE7D,SAASjB,iBAAiBM,GAAW,EAAEC,MAAc,EAAEW,OAAe;IAC3E,IAAIF,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACV,IAAYW,UAAU,CAACV,QAAQW;IACzC;IACA,kCAAkC;IAClC,IAAIC,UAAUZ,OAAOW,OAAO,CAAC,uBAAuB;IACpD,OAAOZ,IAAIY,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["stringEndsWith","stringReplaceAll","stringStartsWith","hasStartsWith","String","prototype","startsWith","str","search","position","indexOf","hasEndsWith","endsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","replace","escaped","RegExp"],"mappings":";;;;;;;;;;;QA2BgBA;eAAAA;;QAgBAC;eAAAA;;QA/BAC;eAAAA;;;AAZhB;;;CAGC,GAED;;;;CAIC,GACD,IAAMC,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAEtD,SAASJ,iBAAiBK,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIN,eAAe;QACjB,OAAOI,IAAID,UAAU,CAACE,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,IAAME,cAAc,OAAOP,OAAOC,SAAS,CAACO,QAAQ,KAAK;AAElD,SAASZ,eAAeO,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAMI,MAAMJ,aAAaK,YAAYP,IAAIQ,MAAM,GAAGN;IAClD,OAAOF,IAAIS,WAAW,CAACR,YAAYK,MAAML,OAAOO,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAME,gBAAgB,OAAO,AAACb,OAAOC,SAAS,CAASa,UAAU,KAAK;AAE/D,SAASjB,iBAAiBM,GAAW,EAAEC,MAAc,EAAEW,OAAe;IAC3E,IAAIF,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACV,IAAYW,UAAU,CAACV,QAAQW;IACzC;IACA,kCAAkC;IAClC,IAAMC,UAAUZ,OAAOW,OAAO,CAAC,uBAAuB;IACtD,OAAOZ,IAAIY,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
@@ -1,4 +1,4 @@
1
- export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
1
+ export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
2
2
  import type { Output } from '@swc/core';
3
3
  import type { Entry } from 'fs-iterator';
4
4
  import type { ConfigOptions } from '../types.js';
@@ -1,4 +1,4 @@
1
- export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
1
+ export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
2
2
  import type { Output } from '@swc/core';
3
3
  import type { Entry } from 'fs-iterator';
4
4
  import type { ConfigOptions } from '../types.js';
@@ -23,7 +23,7 @@ function _interop_require_default(obj) {
23
23
  default: obj
24
24
  };
25
25
  }
26
- var interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
26
+ var interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
27
27
  function patchCJS(entry, output, options) {
28
28
  var rewrite = (options.tsconfig.config.compilerOptions || {}).rewriteRelativeImportExtensions;
29
29
  if (rewrite) output.code = (0, _rewriteExtensionsts.rewriteExtensionsCJS)(output.code);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["patchCJS","interop","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensionsCJS","replaceExtension","path","extname","basename"],"mappings":";;;;;;;;;;;QAeA;eAAwBA;;QAXXC;eAAAA;;;2DAJI;mCACsC;;;;;;AAGhD,IAAMA,UAAU;AAWR,SAASD,SAASE,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,yCAAoB,EAACR,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIT;IAEf,OAAOW,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,QAAQ;AACrD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["patchCJS","interop","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensionsCJS","replaceExtension","path","extname","basename"],"mappings":";;;;;;;;;;;QAeA;eAAwBA;;QAXXC;eAAAA;;;2DAJI;mCACsC;;;;;;AAGhD,IAAMA,UAAU;AAWR,SAASD,SAASE,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,yCAAoB,EAACR,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIT;IAEf,OAAOW,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,QAAQ;AACrD"}
@@ -90,15 +90,29 @@ function transformFile(entry, dest, type, options, callback) {
90
90
  swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
91
91
  filename: entry.basename
92
92
  })).then(function(output) {
93
- var extTarget = type === 'esm' ? (0, _patchESMts.default)(entry, output, options) : (0, _patchCJSts.default)(entry, output, options);
94
- var ext = _path.default.extname(entry.path);
95
- var outPath = _path.default.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
96
- (0, _mkdirpclassic.default)(_path.default.dirname(outPath), function() {
97
- var queue = new _queuecb.default();
98
- queue.defer(_fs.default.writeFile.bind(null, outPath, output.code, 'utf8'));
99
- if (output.map && options.sourceMaps) queue.defer(_fs.default.writeFile.bind(null, "".concat(outPath, ".map"), output.map, 'utf8'));
100
- queue.await(function(err) {
101
- return err ? callback(err) : callback(null, outPath);
93
+ // Get source file mode to preserve executable permissions
94
+ _fs.default.stat(entry.fullPath, function(statErr, stats) {
95
+ if (statErr) return callback(statErr);
96
+ var extTarget = type === 'esm' ? (0, _patchESMts.default)(entry, output, options) : (0, _patchCJSts.default)(entry, output, options);
97
+ var ext = _path.default.extname(entry.path);
98
+ var outPath = _path.default.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
99
+ (0, _mkdirpclassic.default)(_path.default.dirname(outPath), function() {
100
+ var queue = new _queuecb.default();
101
+ queue.defer(_fs.default.writeFile.bind(null, outPath, output.code, 'utf8'));
102
+ if (output.map && options.sourceMaps) queue.defer(_fs.default.writeFile.bind(null, "".concat(outPath, ".map"), output.map, 'utf8'));
103
+ queue.await(function(err) {
104
+ if (err) return callback(err);
105
+ // Preserve executable permissions from source (only +x bits, not full mode)
106
+ var execBits = stats.mode & 73;
107
+ if (execBits) {
108
+ _fs.default.chmod(outPath, 420 | execBits, function(_chmodErr) {
109
+ // Ignore chmod errors (e.g., on Windows)
110
+ callback(null, outPath);
111
+ });
112
+ } else {
113
+ callback(null, outPath);
114
+ }
115
+ });
102
116
  });
103
117
  });
104
118
  }).catch(callback);
@@ -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): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n 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 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) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","prepareSWCOptions","swc","ext","path","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","map","sourceMaps","await","err","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;iEACG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAASF,cAAcK,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW,mBAAKA;QAChBA,SAASC,MAAM,GAAG,mBAAKD,SAASC,MAAM;QACtCD,SAASC,MAAM,CAACC,eAAe,GAAG,mBAAMF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC;QAC5EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,IAAMC,aAAaC,IAAAA,4BAAiB,EAACN;IACrC,IAAMO,MAAMhB,SAAS;IACrB,IAAMiB,MAAMC,aAAI,CAACC,OAAO,CAACf,MAAMgB,QAAQ;IAEvCJ,IACGjB,aAAa,CAACK,MAAMiB,QAAQ,EAAE,wCACzBJ,QAAQ,UAAUA,QAAQ,SAASH,WAAWQ,UAAU,GAAGR,WAAWS,aAAa;QACvFC,UAAUpB,MAAMgB,QAAQ;QAEzBK,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYrB,SAAS,QAAQsB,IAAAA,mBAAQ,EAACxB,OAAOsB,QAAQnB,WAAWsB,IAAAA,mBAAQ,EAACzB,OAAOsB,QAAQnB;QAC9F,IAAMU,MAAMC,aAAI,CAACC,OAAO,CAACf,MAAMc,IAAI;QACnC,IAAMY,UAAUZ,aAAI,CAACa,IAAI,CAAC1B,MAAM,AAACY,CAAAA,MAAMb,MAAMc,IAAI,CAACc,KAAK,CAAC,GAAG,CAACf,IAAIgB,MAAM,IAAI7B,MAAMc,IAAI,AAAD,IAAKS;QAExFO,IAAAA,sBAAM,EAAChB,aAAI,CAACiB,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASJ,OAAOgB,IAAI,EAAE;YAC1D,IAAIhB,OAAOiB,GAAG,IAAIpC,QAAQqC,UAAU,EAAER,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOJ,OAAOiB,GAAG,EAAE;YACxGP,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMtC,SAASsC,OAAOtC,SAAS,MAAMsB;;QAC7D;IACF,GACCiB,KAAK,CAACvC;AACX"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n // Get source file mode to preserve executable permissions\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (statErr) return callback(statErr);\n\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => {\n if (err) return callback(err);\n\n // Preserve executable permissions from source (only +x bits, not full mode)\n const execBits = stats.mode & 0o111;\n if (execBits) {\n fs.chmod(outPath, 0o644 | execBits, (_chmodErr) => {\n // Ignore chmod errors (e.g., on Windows)\n callback(null, outPath);\n });\n } else {\n callback(null, outPath);\n }\n });\n });\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","prepareSWCOptions","swc","ext","path","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","fs","stat","statErr","stats","extTarget","patchESM","patchCJS","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","writeFile","bind","code","map","sourceMaps","await","err","execBits","mode","chmod","_chmodErr","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;iEACG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,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 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nvar _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nvar URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n var parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["fileURLToPath","pathToFileURL","_require","require","Module","createRequire","URLClass","url","URL","isWindows","process","platform","test","env","OSTYPE","urlInput","parsedUrl","protocol","Error","pathname","hostname","path","normalize","decodeURIComponent","letter","charCodeAt","slice","resolved","resolve","length","stringReplaceAll"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;;;;;;;;;;;;QAoBjEA;eAAAA;;QA2CAC;eAAAA;;;6DA7DG;2DACF;0DACD;wBAEiB;;;;;;AAEjC,yBAAyB;AACzB,IAAIC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAExF,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIG,WAAuB,AAACC,YAAG,CAASC,GAAG;AAC3C,IAAI,CAACF,UAAU;IACbA,WAAWJ,SAAS;AACtB;AAEA,IAAMO,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAEpF,SAASd,cAAce,QAAsB;IAClD,IAAIC;IACJ,IAAI,OAAOD,aAAa,UAAU;QAChCC,YAAY,IAAIV,SAASS;IAC3B,OAAO;QACLC,YAAYD;IACd;IAEA,IAAIC,UAAUC,QAAQ,KAAK,SAAS;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACI,UAAUG,QAAQ,GAAG;YACvC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,UAAUI,QAAQ,EAAE;YACtB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAON,IAAI,CAACI,UAAUG,QAAQ,GAAG;YACnC,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,IAAMC,WAAWE,aAAI,CAACC,SAAS,CAACC,mBAAmBP,UAAUG,QAAQ;IAErE,IAAIV,WAAW;QACb,IAAIO,UAAUI,QAAQ,EAAE,OAAO,AAAC,OAA2BD,OAArBH,UAAUI,QAAQ,EAAY,OAATD;QAE3D,IAAMK,SAASL,SAASM,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAML,SAASM,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIP,MAAM;QAClB;QAEA,OAAOC,SAASO,KAAK,CAAC;IACxB;IAEA,OAAOP;AACT;AAEO,SAASlB,cAAckB,QAAgB;IAC5C,IAAIQ,WAAWN,aAAI,CAACO,OAAO,CAACT;IAE5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAIlB,aAAaU,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK,QAAQ,gBAAgB;IACnEA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK;IAC3CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK;IAC3CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC5CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC5CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAE5C,IAAI,CAAClB,WAAW;QACdkB,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,AAAC,QAAgB,OAATqB;AAC9B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nlet URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n let parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["fileURLToPath","pathToFileURL","_require","require","Module","createRequire","URLClass","url","URL","isWindows","process","platform","test","env","OSTYPE","urlInput","parsedUrl","protocol","Error","pathname","hostname","path","normalize","decodeURIComponent","letter","charCodeAt","slice","resolved","resolve","length","stringReplaceAll"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;;;;;;;;;;;;QAoBjEA;eAAAA;;QA2CAC;eAAAA;;;6DA7DG;2DACF;0DACD;wBAEiB;;;;;;AAEjC,yBAAyB;AACzB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIG,WAAuB,AAACC,YAAG,CAASC,GAAG;AAC3C,IAAI,CAACF,UAAU;IACbA,WAAWJ,SAAS;AACtB;AAEA,IAAMO,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAEpF,SAASd,cAAce,QAAsB;IAClD,IAAIC;IACJ,IAAI,OAAOD,aAAa,UAAU;QAChCC,YAAY,IAAIV,SAASS;IAC3B,OAAO;QACLC,YAAYD;IACd;IAEA,IAAIC,UAAUC,QAAQ,KAAK,SAAS;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACI,UAAUG,QAAQ,GAAG;YACvC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,UAAUI,QAAQ,EAAE;YACtB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAON,IAAI,CAACI,UAAUG,QAAQ,GAAG;YACnC,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,IAAMC,WAAWE,aAAI,CAACC,SAAS,CAACC,mBAAmBP,UAAUG,QAAQ;IAErE,IAAIV,WAAW;QACb,IAAIO,UAAUI,QAAQ,EAAE,OAAO,AAAC,OAA2BD,OAArBH,UAAUI,QAAQ,EAAY,OAATD;QAE3D,IAAMK,SAASL,SAASM,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAML,SAASM,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIP,MAAM;QAClB;QAEA,OAAOC,SAASO,KAAK,CAAC;IACxB;IAEA,OAAOP;AACT;AAEO,SAASlB,cAAckB,QAAgB;IAC5C,IAAIQ,WAAWN,aAAI,CAACO,OAAO,CAACT;IAE5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAIlB,aAAaU,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK,QAAQ,gBAAgB;IACnEA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK;IAC3CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK;IAC3CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC5CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC5CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAE5C,IAAI,CAAClB,WAAW;QACdkB,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,AAAC,QAAgB,OAATqB;AAC9B"}
@@ -11,10 +11,20 @@ Object.defineProperty(exports, "default", {
11
11
  var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
12
  var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
13
13
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
14
+ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
15
+ var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
14
16
  var _compatts = require("../compat.js");
15
17
  var _constantsts = require("../constants.js");
16
18
  var _createMatcherts = /*#__PURE__*/ _interop_require_default(require("../createMatcher.js"));
17
19
  var _rewriteExtensionsts = require("../lib/rewriteExtensions.js");
20
+ function _array_like_to_array(arr, len) {
21
+ if (len == null || len > arr.length) len = arr.length;
22
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
23
+ return arr2;
24
+ }
25
+ function _array_with_holes(arr) {
26
+ if (Array.isArray(arr)) return arr;
27
+ }
18
28
  function _define_property(obj, key, value) {
19
29
  if (key in obj) {
20
30
  Object.defineProperty(obj, key, {
@@ -33,6 +43,33 @@ function _interop_require_default(obj) {
33
43
  default: obj
34
44
  };
35
45
  }
46
+ function _iterable_to_array_limit(arr, i) {
47
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
48
+ if (_i == null) return;
49
+ var _arr = [];
50
+ var _n = true;
51
+ var _d = false;
52
+ var _s, _e;
53
+ try {
54
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
55
+ _arr.push(_s.value);
56
+ if (i && _arr.length === i) break;
57
+ }
58
+ } catch (err) {
59
+ _d = true;
60
+ _e = err;
61
+ } finally{
62
+ try {
63
+ if (!_n && _i["return"] != null) _i["return"]();
64
+ } finally{
65
+ if (_d) throw _e;
66
+ }
67
+ }
68
+ return _arr;
69
+ }
70
+ function _non_iterable_rest() {
71
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
72
+ }
36
73
  function _object_spread(target) {
37
74
  for(var i = 1; i < arguments.length; i++){
38
75
  var source = arguments[i] != null ? arguments[i] : {};
@@ -72,6 +109,17 @@ function _object_spread_props(target, source) {
72
109
  }
73
110
  return target;
74
111
  }
112
+ function _sliced_to_array(arr, i) {
113
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
114
+ }
115
+ function _unsupported_iterable_to_array(o, minLen) {
116
+ if (!o) return;
117
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
118
+ var n = Object.prototype.toString.call(o).slice(8, -1);
119
+ if (n === "Object" && o.constructor) n = o.constructor.name;
120
+ if (n === "Map" || n === "Set") return Array.from(n);
121
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
122
+ }
75
123
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
76
124
  function transformTypesWorker(src, dest, options, callback) {
77
125
  var tsconfig = options.tsconfig;
@@ -92,52 +140,122 @@ function transformTypesWorker(src, dest, options, callback) {
92
140
  callback(err);
93
141
  return;
94
142
  }
95
- var compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
96
- var config = {
97
- fileNames: entries.map(function(entry) {
98
- return entry.fullPath;
99
- }),
100
- options: _object_spread_props(_object_spread({}, compilerOptions.options), {
101
- outDir: dest,
102
- noEmit: false,
103
- allowJs: true,
104
- declaration: true,
105
- emitDeclarationOnly: true,
106
- listEmittedFiles: true
107
- }),
108
- projectReferences: tsconfig.config.references
109
- };
110
- var fileNames = config.fileNames, _$options = config.options, projectReferences = config.projectReferences;
111
- var host = ts.createCompilerHostWorker(_$options, /*setParentNodes*/ undefined, ts.sys);
112
- var programOptions = {
113
- rootNames: fileNames,
114
- options: _$options,
115
- projectReferences: projectReferences,
116
- host: host,
117
- configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({
118
- fileNames: fileNames,
119
- options: _$options
120
- })
121
- };
122
- var program = ts.createProgram(programOptions);
123
- var res = program.emit();
124
- // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037
125
- if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {
126
- res.emittedFiles.forEach(function(file) {
127
- if ((0, _compatts.stringEndsWith)(file, '.d.ts') || (0, _compatts.stringEndsWith)(file, '.d.cts') || (0, _compatts.stringEndsWith)(file, '.d.mts')) {
128
- try {
129
- var content = _fs.default.readFileSync(file, 'utf8');
130
- var updated = (0, _rewriteExtensionsts.rewriteExtensions)(content);
131
- if (updated !== content) {
132
- _fs.default.writeFileSync(file, updated, 'utf8');
143
+ // Step 1: Stat all source files to get their modes (async)
144
+ var sourceModes = new Map();
145
+ var statQueue = new _queuecb.default();
146
+ entries.forEach(function(entry) {
147
+ statQueue.defer(function(cb) {
148
+ _fs.default.stat(entry.fullPath, function(statErr, stats) {
149
+ if (!statErr) sourceModes.set(entry.fullPath, stats.mode);
150
+ cb(); // Continue even on error
151
+ });
152
+ });
153
+ });
154
+ statQueue.await(function(statErr) {
155
+ if (statErr) {
156
+ callback(statErr);
157
+ return;
158
+ }
159
+ // Step 2: TypeScript emit (inherently sync - cannot change)
160
+ var compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
161
+ var config = {
162
+ fileNames: entries.map(function(entry) {
163
+ return entry.fullPath;
164
+ }),
165
+ options: _object_spread_props(_object_spread({}, compilerOptions.options), {
166
+ outDir: dest,
167
+ noEmit: false,
168
+ allowJs: true,
169
+ declaration: true,
170
+ emitDeclarationOnly: true,
171
+ listEmittedFiles: true
172
+ }),
173
+ projectReferences: tsconfig.config.references
174
+ };
175
+ var fileNames = config.fileNames, _$options = config.options, projectReferences = config.projectReferences;
176
+ var host = ts.createCompilerHostWorker(_$options, /*setParentNodes*/ undefined, ts.sys);
177
+ var programOptions = {
178
+ rootNames: fileNames,
179
+ options: _$options,
180
+ projectReferences: projectReferences,
181
+ host: host,
182
+ configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({
183
+ fileNames: fileNames,
184
+ options: _$options
185
+ })
186
+ };
187
+ var program = ts.createProgram(programOptions);
188
+ var res = program.emit();
189
+ // Step 3: Post-process emitted files (async)
190
+ var postQueue = new _queuecb.default();
191
+ if (res.emittedFiles) {
192
+ res.emittedFiles.forEach(function(file) {
193
+ // 3a: Rewrite extensions (convert from sync to async)
194
+ // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037
195
+ if (compilerOptions.options.rewriteRelativeImportExtensions) {
196
+ if ((0, _compatts.stringEndsWith)(file, '.d.ts') || (0, _compatts.stringEndsWith)(file, '.d.cts') || (0, _compatts.stringEndsWith)(file, '.d.mts')) {
197
+ postQueue.defer(function(cb) {
198
+ _fs.default.readFile(file, 'utf8', function(readErr, content) {
199
+ if (readErr) return cb(); // Ignore errors, continue
200
+ var updated = (0, _rewriteExtensionsts.rewriteExtensions)(content);
201
+ if (updated !== content) {
202
+ _fs.default.writeFile(file, updated, 'utf8', function() {
203
+ return cb();
204
+ }); // Ignore write errors
205
+ } else {
206
+ cb();
207
+ }
208
+ });
209
+ });
133
210
  }
134
- } catch (_err) {
135
- // Ignore errors
136
211
  }
137
- }
212
+ // 3b: Apply executable permissions from source files
213
+ if ((0, _compatts.stringEndsWith)(file, '.d.ts') || (0, _compatts.stringEndsWith)(file, '.d.cts') || (0, _compatts.stringEndsWith)(file, '.d.mts')) {
214
+ var relativePath = _path.default.relative(dest, file);
215
+ var baseName = relativePath.replace(/\.d\.(ts|mts|cts)$/, '');
216
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
217
+ try {
218
+ var _loop = function() {
219
+ var _step_value = _sliced_to_array(_step.value, 2), srcPath = _step_value[0], mode = _step_value[1];
220
+ var srcRelative = _path.default.relative(src, srcPath);
221
+ var srcBase = srcRelative.replace(/\.(ts|tsx|mts|cts)$/, '');
222
+ if (baseName === srcBase) {
223
+ var execBits = mode & 73;
224
+ if (execBits) {
225
+ postQueue.defer(function(cb) {
226
+ _fs.default.chmod(file, 420 | execBits, function() {
227
+ return cb();
228
+ }); // Ignore chmod errors
229
+ });
230
+ }
231
+ return "break";
232
+ }
233
+ };
234
+ for(var _iterator = sourceModes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
235
+ var _ret = _loop();
236
+ if (_ret === "break") break;
237
+ }
238
+ } catch (err) {
239
+ _didIteratorError = true;
240
+ _iteratorError = err;
241
+ } finally{
242
+ try {
243
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
244
+ _iterator.return();
245
+ }
246
+ } finally{
247
+ if (_didIteratorError) {
248
+ throw _iteratorError;
249
+ }
250
+ }
251
+ }
252
+ }
253
+ });
254
+ }
255
+ postQueue.await(function() {
256
+ return callback(null, res.emittedFiles);
138
257
  });
139
- }
140
- callback(null, res.emittedFiles);
258
+ });
141
259
  });
142
260
  }
143
261
  /* 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/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\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): undefined {\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): undefined => {\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): undefined => {\n if (err) {\n callback(err);\n return;\n }\n\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 // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {\n res.emittedFiles.forEach((file) => {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n try {\n const content = fs.readFileSync(file, 'utf8');\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFileSync(file, updated, 'utf8');\n }\n } catch (_err) {\n // Ignore errors\n }\n }\n });\n }\n callback(null, res.emittedFiles);\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","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","emittedFiles","rewriteRelativeImportExtensions","file","stringEndsWith","content","fs","readFileSync","updated","rewriteExtensions","writeFileSync","_err"],"mappings":";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T,OAAtBS;QAC5B,IAAME,OAAO7B,GAAG8B,wBAAwB,CAACnC,WAAS,gBAAgB,GAAGoC,WAAW/B,GAAGgC,GAAG;QACtF,IAAMC,iBAAiB;YACrBC,WAAWf;YACXxB,SAAAA;YACAgC,mBAAAA;YACAE,MAAAA;YACAM,8BAA8BnC,GAAGoC,+BAA+B,CAAC;gBAAEjB,WAAAA;gBAAWxB,SAAAA;YAAQ;QACxF;QACA,IAAM0C,UAAUrC,GAAGsC,aAAa,CAACL;QACjC,IAAMM,MAAMF,QAAQG,IAAI;QAExB,8EAA8E;QAC9E,IAAID,IAAIE,YAAY,IAAIzB,gBAAgBrB,OAAO,CAAC+C,+BAA+B,EAAE;YAC/EH,IAAIE,YAAY,CAACrC,OAAO,CAAC,SAACuC;gBACxB,IAAIC,IAAAA,wBAAc,EAACD,MAAM,YAAYC,IAAAA,wBAAc,EAACD,MAAM,aAAaC,IAAAA,wBAAc,EAACD,MAAM,WAAW;oBACrG,IAAI;wBACF,IAAME,UAAUC,WAAE,CAACC,YAAY,CAACJ,MAAM;wBACtC,IAAMK,UAAUC,IAAAA,sCAAiB,EAACJ;wBAClC,IAAIG,YAAYH,SAAS;4BACvBC,WAAE,CAACI,aAAa,CAACP,MAAMK,SAAS;wBAClC;oBACF,EAAE,OAAOG,MAAM;oBACb,gBAAgB;oBAClB;gBACF;YACF;QACF;QACAvD,SAAS,MAAM2C,IAAIE,YAAY;IACjC;AAEJ"}
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): undefined {\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): undefined => {\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): undefined => {\n if (err) {\n callback(err);\n return;\n }\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) {\n callback(statErr);\n return;\n }\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","sr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 0.8+
6
6
  * - Uses native startsWith on Node 4.0+ / ES2015+
7
7
  * - Falls back to indexOf on Node 0.8-3.x
8
- */ var hasStartsWith = typeof String.prototype.startsWith === 'function';
8
+ */ const hasStartsWith = typeof String.prototype.startsWith === 'function';
9
9
  export function stringStartsWith(str, search, position) {
10
10
  if (hasStartsWith) {
11
11
  return str.startsWith(search, position);
@@ -17,12 +17,12 @@ export function stringStartsWith(str, search, position) {
17
17
  * String.prototype.endsWith wrapper for Node.js 0.8+
18
18
  * - Uses native endsWith on Node 4.0+ / ES2015+
19
19
  * - Falls back to lastIndexOf on Node 0.8-3.x
20
- */ var hasEndsWith = typeof String.prototype.endsWith === 'function';
20
+ */ const hasEndsWith = typeof String.prototype.endsWith === 'function';
21
21
  export function stringEndsWith(str, search, position) {
22
22
  if (hasEndsWith) {
23
23
  return str.endsWith(search, position);
24
24
  }
25
- var len = position === undefined ? str.length : position;
25
+ const len = position === undefined ? str.length : position;
26
26
  return str.lastIndexOf(search) === len - search.length;
27
27
  }
28
28
  /**
@@ -30,13 +30,13 @@ export function stringEndsWith(str, search, position) {
30
30
  * - Uses native replaceAll on Node 15.0+ / ES2021+
31
31
  * - Falls back to regex replace on older versions
32
32
  */ // biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll
33
- var hasReplaceAll = typeof String.prototype.replaceAll === 'function';
33
+ const hasReplaceAll = typeof String.prototype.replaceAll === 'function';
34
34
  export function stringReplaceAll(str, search, replace) {
35
35
  if (hasReplaceAll) {
36
36
  // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available
37
37
  return str.replaceAll(search, replace);
38
38
  }
39
39
  // Escape special regex characters
40
- var escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
40
+ const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
41
41
  return str.replace(new RegExp(escaped, 'g'), replace);
42
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nvar hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nvar hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n var len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nvar hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n var escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["hasStartsWith","String","prototype","startsWith","stringStartsWith","str","search","position","indexOf","hasEndsWith","endsWith","stringEndsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","stringReplaceAll","replace","escaped","RegExp"],"mappings":"AAAA;;;CAGC,GAED;;;;CAIC,GACD,IAAIA,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAE3D,OAAO,SAASC,iBAAiBC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIP,eAAe;QACjB,OAAOK,IAAIF,UAAU,CAACG,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,IAAIE,cAAc,OAAOR,OAAOC,SAAS,CAACQ,QAAQ,KAAK;AAEvD,OAAO,SAASC,eAAeN,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAIK,MAAML,aAAaM,YAAYR,IAAIS,MAAM,GAAGP;IAChD,OAAOF,IAAIU,WAAW,CAACT,YAAYM,MAAMN,OAAOQ,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAIE,gBAAgB,OAAO,AAACf,OAAOC,SAAS,CAASe,UAAU,KAAK;AAEpE,OAAO,SAASC,iBAAiBb,GAAW,EAAEC,MAAc,EAAEa,OAAe;IAC3E,IAAIH,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACX,IAAYY,UAAU,CAACX,QAAQa;IACzC;IACA,kCAAkC;IAClC,IAAIC,UAAUd,OAAOa,OAAO,CAAC,uBAAuB;IACpD,OAAOd,IAAIc,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["hasStartsWith","String","prototype","startsWith","stringStartsWith","str","search","position","indexOf","hasEndsWith","endsWith","stringEndsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","stringReplaceAll","replace","escaped","RegExp"],"mappings":"AAAA;;;CAGC,GAED;;;;CAIC,GACD,MAAMA,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAE7D,OAAO,SAASC,iBAAiBC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIP,eAAe;QACjB,OAAOK,IAAIF,UAAU,CAACG,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,MAAME,cAAc,OAAOR,OAAOC,SAAS,CAACQ,QAAQ,KAAK;AAEzD,OAAO,SAASC,eAAeN,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,MAAMK,MAAML,aAAaM,YAAYR,IAAIS,MAAM,GAAGP;IAClD,OAAOF,IAAIU,WAAW,CAACT,YAAYM,MAAMN,OAAOQ,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,MAAME,gBAAgB,OAAO,AAACf,OAAOC,SAAS,CAASe,UAAU,KAAK;AAEtE,OAAO,SAASC,iBAAiBb,GAAW,EAAEC,MAAc,EAAEa,OAAe;IAC3E,IAAIH,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACX,IAAYY,UAAU,CAACX,QAAQa;IACzC;IACA,kCAAkC;IAClC,MAAMC,UAAUd,OAAOa,OAAO,CAAC,uBAAuB;IACtD,OAAOd,IAAIc,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
@@ -1,4 +1,4 @@
1
- export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
1
+ export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
2
2
  import type { Output } from '@swc/core';
3
3
  import type { Entry } from 'fs-iterator';
4
4
  import type { ConfigOptions } from '../types.js';
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.js';
3
3
  // https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
4
- export const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
4
+ export const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
5
5
  export default function patchCJS(entry, output, options) {
6
6
  const rewrite = (options.tsconfig.config.compilerOptions || {}).rewriteRelativeImportExtensions;
7
7
  if (rewrite) output.code = rewriteExtensionsCJS(output.code);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensionsCJS","interop","patchCJS","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,yBAAyB;AAEhF,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAW3R,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGX,qBAAqBI,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIV;IAEf,OAAOF,iBAAiBD,KAAKc,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensionsCJS","interop","patchCJS","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,yBAAyB;AAEhF,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAW3R,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGX,qBAAqBI,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIV;IAEf,OAAOF,iBAAiBD,KAAKc,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
@@ -30,14 +30,30 @@ export default function transformFile(entry, dest, type, options, callback) {
30
30
  ...ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
31
31
  filename: entry.basename
32
32
  }).then((output)=>{
33
- const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
34
- const ext = path.extname(entry.path);
35
- const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
36
- mkdirp(path.dirname(outPath), ()=>{
37
- const queue = new Queue();
38
- queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
39
- if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
40
- queue.await((err)=>err ? callback(err) : callback(null, outPath));
33
+ // Get source file mode to preserve executable permissions
34
+ fs.stat(entry.fullPath, (statErr, stats)=>{
35
+ if (statErr) return callback(statErr);
36
+ const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
37
+ const ext = path.extname(entry.path);
38
+ const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
39
+ mkdirp(path.dirname(outPath), ()=>{
40
+ const queue = new Queue();
41
+ queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
42
+ if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
43
+ queue.await((err)=>{
44
+ if (err) return callback(err);
45
+ // Preserve executable permissions from source (only +x bits, not full mode)
46
+ const execBits = stats.mode & 0o111;
47
+ if (execBits) {
48
+ fs.chmod(outPath, 0o644 | execBits, (_chmodErr)=>{
49
+ // Ignore chmod errors (e.g., on Windows)
50
+ callback(null, outPath);
51
+ });
52
+ } else {
53
+ callback(null, outPath);
54
+ }
55
+ });
56
+ });
41
57
  });
42
58
  }).catch(callback);
43
59
  }
@@ -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): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n 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 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) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","ext","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","map","sourceMaps","await","err","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcP,OAAOQ,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAI1F,eAAe,SAASG,cAAcC,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW;YAAE,GAAGA,QAAQ;QAAC;QACzBA,SAASC,MAAM,GAAG;YAAE,GAAGD,SAASC,MAAM;QAAC;QACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;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"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n // Get source file mode to preserve executable permissions\n fs.stat(entry.fullPath, (statErr, stats) => {\n if (statErr) return callback(statErr);\n\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => {\n if (err) return callback(err);\n\n // Preserve executable permissions from source (only +x bits, not full mode)\n const execBits = stats.mode & 0o111;\n if (execBits) {\n fs.chmod(outPath, 0o644 | execBits, (_chmodErr) => {\n // Ignore chmod errors (e.g., on Windows)\n callback(null, outPath);\n });\n } else {\n callback(null, outPath);\n }\n });\n });\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","ext","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","stat","statErr","stats","extTarget","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","map","sourceMaps","await","err","execBits","mode","chmod","_chmodErr","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcP,OAAOQ,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAI1F,eAAe,SAASG,cAAcC,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW;YAAE,GAAGA,QAAQ;QAAC;QACzBA,SAASC,MAAM,GAAG;YAAE,GAAGD,SAASC,MAAM;QAAC;QACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;YAAE,GAAIF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAC;QAAE;QAC/EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,C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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"}
@@ -5,16 +5,16 @@ import path from 'path';
5
5
  import url from 'url';
6
6
  import { stringReplaceAll } from '../compat.js';
7
7
  // ESM-compatible require
8
- var _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
8
+ const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
9
9
  // URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x
10
10
  // biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class
11
- var URLClass = url.URL;
11
+ let URLClass = url.URL;
12
12
  if (!URLClass) {
13
13
  URLClass = _require('core-js-pure/actual/url/index.js');
14
14
  }
15
15
  const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
16
16
  export function fileURLToPath(urlInput) {
17
- var parsedUrl;
17
+ let parsedUrl;
18
18
  if (typeof urlInput === 'string') {
19
19
  parsedUrl = new URLClass(urlInput);
20
20
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nvar _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nvar URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n var parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["Module","path","url","stringReplaceAll","_require","require","createRequire","URLClass","URL","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","urlInput","parsedUrl","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,eAAe;AAEhD,yBAAyB;AACzB,IAAIC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYJ,GAAG,IAAIG;AAExF,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIE,WAAuB,AAACL,IAAYM,GAAG;AAC3C,IAAI,CAACD,UAAU;IACbA,WAAWH,SAAS;AACtB;AAEA,MAAMK,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,QAAsB;IAClD,IAAIC;IACJ,IAAI,OAAOD,aAAa,UAAU;QAChCC,YAAY,IAAIV,SAASS;IAC3B,OAAO;QACLC,YAAYD;IACd;IAEA,IAAIC,UAAUC,QAAQ,KAAK,SAAS;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIV,WAAW;QACb,IAAI,WAAWG,IAAI,CAACK,UAAUG,QAAQ,GAAG;YACvC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,UAAUI,QAAQ,EAAE;YACtB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAOP,IAAI,CAACK,UAAUG,QAAQ,GAAG;YACnC,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,MAAMC,WAAWnB,KAAKqB,SAAS,CAACC,mBAAmBN,UAAUG,QAAQ;IAErE,IAAIX,WAAW;QACb,IAAIQ,UAAUI,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAEJ,UAAUI,QAAQ,GAAGD,UAAU;QAErE,MAAMI,SAASJ,SAASK,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAMJ,SAASK,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIN,MAAM;QAClB;QAEA,OAAOC,SAASM,KAAK,CAAC;IACxB;IAEA,OAAON;AACT;AAEA,OAAO,SAASO,cAAcP,QAAgB;IAC5C,IAAIQ,WAAW3B,KAAK4B,OAAO,CAACT;IAE5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAInB,aAAaW,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWzB,iBAAiByB,UAAU,KAAK,QAAQ,gBAAgB;IACnEA,WAAWzB,iBAAiByB,UAAU,KAAK;IAC3CA,WAAWzB,iBAAiByB,UAAU,KAAK;IAC3CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAE5C,IAAI,CAACnB,WAAW;QACdmB,WAAWzB,iBAAiByB,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,CAAC,KAAK,EAAEqB,UAAU;AACxC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nlet URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n let parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["Module","path","url","stringReplaceAll","_require","require","createRequire","URLClass","URL","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","urlInput","parsedUrl","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,eAAe;AAEhD,yBAAyB;AACzB,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYJ,GAAG,IAAIG;AAE1F,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIE,WAAuB,AAACL,IAAYM,GAAG;AAC3C,IAAI,CAACD,UAAU;IACbA,WAAWH,SAAS;AACtB;AAEA,MAAMK,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,QAAsB;IAClD,IAAIC;IACJ,IAAI,OAAOD,aAAa,UAAU;QAChCC,YAAY,IAAIV,SAASS;IAC3B,OAAO;QACLC,YAAYD;IACd;IAEA,IAAIC,UAAUC,QAAQ,KAAK,SAAS;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIV,WAAW;QACb,IAAI,WAAWG,IAAI,CAACK,UAAUG,QAAQ,GAAG;YACvC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,UAAUI,QAAQ,EAAE;YACtB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAOP,IAAI,CAACK,UAAUG,QAAQ,GAAG;YACnC,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,MAAMC,WAAWnB,KAAKqB,SAAS,CAACC,mBAAmBN,UAAUG,QAAQ;IAErE,IAAIX,WAAW;QACb,IAAIQ,UAAUI,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAEJ,UAAUI,QAAQ,GAAGD,UAAU;QAErE,MAAMI,SAASJ,SAASK,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAMJ,SAASK,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIN,MAAM;QAClB;QAEA,OAAOC,SAASM,KAAK,CAAC;IACxB;IAEA,OAAON;AACT;AAEA,OAAO,SAASO,cAAcP,QAAgB;IAC5C,IAAIQ,WAAW3B,KAAK4B,OAAO,CAACT;IAE5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAInB,aAAaW,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWzB,iBAAiByB,UAAU,KAAK,QAAQ,gBAAgB;IACnEA,WAAWzB,iBAAiByB,UAAU,KAAK;IAC3CA,WAAWzB,iBAAiByB,UAAU,KAAK;IAC3CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAE5C,IAAI,CAACnB,WAAW;QACdmB,WAAWzB,iBAAiByB,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,CAAC,KAAK,EAAEqB,UAAU;AACxC"}
@@ -1,6 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import Iterator from 'fs-iterator';
3
3
  import Module from 'module';
4
+ import path from 'path';
5
+ import Queue from 'queue-cb';
4
6
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
5
7
  import { stringEndsWith } from '../compat.js';
6
8
  import { typeFileRegEx } from '../constants.js';
@@ -25,50 +27,93 @@ export default function transformTypesWorker(src, dest, options, callback) {
25
27
  callback(err);
26
28
  return;
27
29
  }
28
- const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
29
- const config = {
30
- fileNames: entries.map((entry)=>entry.fullPath),
31
- options: {
32
- ...compilerOptions.options,
33
- outDir: dest,
34
- noEmit: false,
35
- allowJs: true,
36
- declaration: true,
37
- emitDeclarationOnly: true,
38
- listEmittedFiles: true
39
- },
40
- projectReferences: tsconfig.config.references
41
- };
42
- const { fileNames, options, projectReferences } = config;
43
- const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);
44
- const programOptions = {
45
- rootNames: fileNames,
46
- options,
47
- projectReferences,
48
- host,
49
- configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({
50
- fileNames,
51
- options
52
- })
53
- };
54
- const program = ts.createProgram(programOptions);
55
- const res = program.emit();
56
- // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037
57
- if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {
58
- res.emittedFiles.forEach((file)=>{
59
- if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {
60
- try {
61
- const content = fs.readFileSync(file, 'utf8');
62
- const updated = rewriteExtensions(content);
63
- if (updated !== content) {
64
- fs.writeFileSync(file, updated, 'utf8');
30
+ // Step 1: Stat all source files to get their modes (async)
31
+ const sourceModes = new Map();
32
+ const statQueue = new Queue();
33
+ entries.forEach((entry)=>{
34
+ statQueue.defer((cb)=>{
35
+ fs.stat(entry.fullPath, (statErr, stats)=>{
36
+ if (!statErr) sourceModes.set(entry.fullPath, stats.mode);
37
+ cb(); // Continue even on error
38
+ });
39
+ });
40
+ });
41
+ statQueue.await((statErr)=>{
42
+ if (statErr) {
43
+ callback(statErr);
44
+ return;
45
+ }
46
+ // Step 2: TypeScript emit (inherently sync - cannot change)
47
+ const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');
48
+ const config = {
49
+ fileNames: entries.map((entry)=>entry.fullPath),
50
+ options: {
51
+ ...compilerOptions.options,
52
+ outDir: dest,
53
+ noEmit: false,
54
+ allowJs: true,
55
+ declaration: true,
56
+ emitDeclarationOnly: true,
57
+ listEmittedFiles: true
58
+ },
59
+ projectReferences: tsconfig.config.references
60
+ };
61
+ const { fileNames, options, projectReferences } = config;
62
+ const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);
63
+ const programOptions = {
64
+ rootNames: fileNames,
65
+ options,
66
+ projectReferences,
67
+ host,
68
+ configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({
69
+ fileNames,
70
+ options
71
+ })
72
+ };
73
+ const program = ts.createProgram(programOptions);
74
+ const res = program.emit();
75
+ // Step 3: Post-process emitted files (async)
76
+ const postQueue = new Queue();
77
+ if (res.emittedFiles) {
78
+ res.emittedFiles.forEach((file)=>{
79
+ // 3a: Rewrite extensions (convert from sync to async)
80
+ // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037
81
+ if (compilerOptions.options.rewriteRelativeImportExtensions) {
82
+ if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {
83
+ postQueue.defer((cb)=>{
84
+ fs.readFile(file, 'utf8', (readErr, content)=>{
85
+ if (readErr) return cb(); // Ignore errors, continue
86
+ const updated = rewriteExtensions(content);
87
+ if (updated !== content) {
88
+ fs.writeFile(file, updated, 'utf8', ()=>cb()); // Ignore write errors
89
+ } else {
90
+ cb();
91
+ }
92
+ });
93
+ });
65
94
  }
66
- } catch (_err) {
67
- // Ignore errors
68
95
  }
69
- }
70
- });
71
- }
72
- callback(null, res.emittedFiles);
96
+ // 3b: Apply executable permissions from source files
97
+ if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {
98
+ const relativePath = path.relative(dest, file);
99
+ const baseName = relativePath.replace(/\.d\.(ts|mts|cts)$/, '');
100
+ for (const [srcPath, mode] of sourceModes){
101
+ const srcRelative = path.relative(src, srcPath);
102
+ const srcBase = srcRelative.replace(/\.(ts|tsx|mts|cts)$/, '');
103
+ if (baseName === srcBase) {
104
+ const execBits = mode & 0o111;
105
+ if (execBits) {
106
+ postQueue.defer((cb)=>{
107
+ fs.chmod(file, 0o644 | execBits, ()=>cb()); // Ignore chmod errors
108
+ });
109
+ }
110
+ break;
111
+ }
112
+ }
113
+ }
114
+ });
115
+ }
116
+ postQueue.await(()=>callback(null, res.emittedFiles));
117
+ });
73
118
  });
74
119
  }
@@ -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';\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): undefined {\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): undefined => {\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): undefined => {\n if (err) {\n callback(err);\n return;\n }\n\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 // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {\n res.emittedFiles.forEach((file) => {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n try {\n const content = fs.readFileSync(file, 'utf8');\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFileSync(file, updated, 'utf8');\n }\n } catch (_err) {\n // Ignore errors\n }\n }\n });\n }\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["fs","Iterator","Module","_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","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","emittedFiles","rewriteRelativeImportExtensions","file","content","readFileSync","updated","writeFileSync","_err"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,cAA8B,cAAc;AACnD,OAAOC,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,cAAc,QAAQ,eAAe;AAC9C,SAASC,aAAa,QAAQ,kBA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AGkC,+BAA+B,CAAC;gBAAEjB;gBAAWrB;YAAQ;QACxF;QACA,MAAMuC,UAAUnC,GAAGoC,aAAa,CAACL;QACjC,MAAMM,MAAMF,QAAQG,IAAI;QAExB,8EAA8E;QAC9E,IAAID,IAAIE,YAAY,IAAIzB,gBAAgBlB,OAAO,CAAC4C,+BAA+B,EAAE;YAC/EH,IAAIE,YAAY,CAACpC,OAAO,CAAC,CAACsC;gBACxB,IAAIpD,eAAeoD,MAAM,YAAYpD,eAAeoD,MAAM,aAAapD,eAAeoD,MAAM,WAAW;oBACrG,IAAI;wBACF,MAAMC,UAAU5D,GAAG6D,YAAY,CAACF,MAAM;wBACtC,MAAMG,UAAUpD,kBAAkBkD;wBAClC,IAAIE,YAAYF,SAAS;4BACvB5D,GAAG+D,aAAa,CAACJ,MAAMG,SAAS;wBAClC;oBACF,EAAE,OAAOE,MAAM;oBACb,gBAAgB;oBAClB;gBACF;YACF;QACF;QACAjD,SAAS,MAAMwC,IAAIE,YAAY;IACjC;AAEJ"}
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): undefined {\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): undefined => {\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): undefined => {\n if (err) {\n callback(err);\n return;\n }\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) {\n callback(statErr);\n return;\n }\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,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AAqD;oBACrD,IAAI7B,eAAe8D,MAAM,YAAY9D,eAAe8D,MAAM,aAAa9D,eAAe8D,MAAM,WAAW;wBACrG,MAAMO,eAAe3E,KAAK4E,QAAQ,CAAChE,MAAMwD;wBACzC,MAAMS,WAAWF,aAAaG,OAAO,CAAC,sBAAsB;wBAE5D,KAAK,MAAM,CAACC,SAASxC,KAAK,IAAIR,YAAa;4BACzC,MAAMiD,cAAchF,KAAK4E,QAAQ,CAACjE,KAAKoE;4BACvC,MAAME,UAAUD,YAAYF,OAAO,CAAC,uBAAuB;4BAC3D,IAAID,aAAaI,SAAS;gCACxB,MAAMC,WAAW3C,OAAO;gCACxB,IAAI2C,UAAU;oCACZhB,UAAUhC,KAAK,CAAC,CAACC;wCACftC,GAAGsF,KAAK,CAACf,MAAM,QAAQc,UAAU,IAAM/C,OAAO,sBAAsB;oCACtE;gCACF;gCACA;4BACF;wBACF;oBACF;gBACF;YACF;YAEA+B,UAAU1B,KAAK,CAAC,IAAM1B,SAAS,MAAMkD,IAAIG,YAAY;QACvD;IACF;AAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-swc-transform",
3
- "version": "2.7.6",
3
+ "version": "2.7.8",
4
4
  "description": "Typescript transformers for swc. Supports Node >= 0.8",
5
5
  "keywords": [
6
6
  "matcher",
@@ -44,35 +44,35 @@
44
44
  "version": "tsds version"
45
45
  },
46
46
  "dependencies": {
47
- "@swc/core": "*",
48
- "core-js-pure": "*",
49
- "exit": "*",
50
- "fs-iterator": "*",
51
- "install-optional": "*",
52
- "is-absolute": "*",
53
- "lodash.debounce": "*",
54
- "lodash.find": "*",
55
- "mkdirp-classic": "*",
56
- "node-version-call": "*",
57
- "queue-cb": "*",
58
- "read-tsconfig-sync": "*",
59
- "resolve": "*",
60
- "test-match": "*",
61
- "ts-node": "*",
62
- "typescript": "*"
47
+ "@swc/core": "^1.15.3",
48
+ "core-js-pure": "^3.47.0",
49
+ "exit-compat": "^1.0.1",
50
+ "fs-iterator": "^6.1.10",
51
+ "install-optional": "^1.0.18",
52
+ "is-absolute": "^1.0.0",
53
+ "lodash.debounce": "^4.0.8",
54
+ "lodash.find": "^4.6.0",
55
+ "mkdirp-classic": "^0.5.3",
56
+ "node-version-call": "^1.9.19",
57
+ "queue-cb": "^1.6.1",
58
+ "read-tsconfig-sync": "^1.1.7",
59
+ "resolve": "^1.22.11",
60
+ "test-match": "^1.1.2",
61
+ "ts-node": "^10.9.2",
62
+ "typescript": "^5.9.3"
63
63
  },
64
64
  "devDependencies": {
65
- "@types/mocha": "*",
66
- "@types/node": "*",
67
- "core-js": "*",
68
- "cr": "*",
69
- "cross-spawn-cb": "*",
70
- "fs-remove-compat": "*",
71
- "node-version-use": "*",
72
- "pinkie-promise": "*",
73
- "react": "*",
74
- "ts-dev-stack": "*",
75
- "tsds-config": "*"
65
+ "@types/mocha": "^10.0.10",
66
+ "@types/node": "^25.0.1",
67
+ "core-js": "^3.47.0",
68
+ "cr": "^0.1.0",
69
+ "cross-spawn-cb": "^2.4.12",
70
+ "fs-remove-compat": "^0.2.1",
71
+ "node-version-use": "^2.1.5",
72
+ "pinkie-promise": "^2.0.1",
73
+ "react": "^19.2.3",
74
+ "ts-dev-stack": "^1.21.3",
75
+ "tsds-config": "^0.2.1"
76
76
  },
77
77
  "engines": {
78
78
  "node": ">=0.8"