ts-swc-transform 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/transformDirectory.js +2 -2
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformTypes.js +2 -2
- package/dist/cjs/transformTypes.js.map +1 -1
- package/dist/cjs/workers/transformDirectory.js +16 -4
- package/dist/cjs/workers/transformDirectory.js.map +1 -1
- package/dist/cjs/workers/transformFile.js +1 -1
- package/dist/cjs/workers/transformFile.js.map +1 -1
- package/dist/cjs/workers/transformTypes.js +17 -6
- package/dist/cjs/workers/transformTypes.js.map +1 -1
- package/dist/esm/transformDirectory.mjs +2 -2
- package/dist/esm/transformDirectory.mjs.map +1 -1
- package/dist/esm/transformTypes.mjs +2 -2
- package/dist/esm/transformTypes.mjs.map +1 -1
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/workers/transformDirectory.mjs +14 -2
- package/dist/esm/workers/transformDirectory.mjs.map +1 -1
- package/dist/esm/workers/transformFile.mjs +1 -1
- package/dist/esm/workers/transformFile.mjs.map +1 -1
- package/dist/esm/workers/transformTypes.mjs +16 -3
- package/dist/esm/workers/transformTypes.mjs.map +1 -1
- package/dist/types/transformDirectory.d.ts +2 -2
- package/dist/types/transformTypes.d.ts +2 -2
- package/dist/types/types.d.ts +6 -2
- package/package.json +2 -1
|
@@ -39,8 +39,8 @@ function transformDirectory(src, dest, type, options, callback) {
|
|
|
39
39
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
40
40
|
if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);
|
|
41
41
|
return new _pinkiepromise.default(function(resolve, reject) {
|
|
42
|
-
workerWrapper(version, src, dest, type, options, function(err,
|
|
43
|
-
err ? reject(err) : resolve(
|
|
42
|
+
workerWrapper(version, src, dest, type, options, function(err, result) {
|
|
43
|
+
err ? reject(err) : resolve(result);
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js'));\n\nimport type { TransformDirectoryCallback, TransformDirectoryOptions } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src: string, dest: string, type: string, options?: TransformDirectoryOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js'));\n\nimport type { TransformDirectoryCallback, TransformDirectoryOptions, TransformResult } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src: string, dest: string, type: string, options?: TransformDirectoryOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<TransformResult[]> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n workerWrapper(version, src, dest, type, options, (err, result) => {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerWrapper","wrapWorker","resolve","src","dest","type","options","callback","Error","Promise","reject","err","result"],"mappings":";;;;+BAYA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DApBP;0DACD;oEAEI;iEACG;;;;;;AACvB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAClG,IAAMC,gBAAgBC,IAAAA,mBAAU,EAACN,aAAI,CAACO,OAAO,CAACR,WAAW,MAAM,OAAO,WAAW;AAYlE,SAASP,mBAAmBgB,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAgE,EAAEC,QAAqC;IACzL,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IACtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,IAAI,OAAOD,aAAa,YAAY,OAAOP,cAAcP,SAASU,KAAKC,MAAMC,MAAMC,SAASC;IAC5F,OAAO,IAAIE,sBAAO,CAAC,SAACP,SAASQ;QAC3BV,cAAcP,SAASU,KAAKC,MAAMC,MAAMC,SAAS,SAACK,KAAKC;YACrDD,MAAMD,OAAOC,OAAOT,QAAQU;QAC9B;IACF;AACF"}
|
|
@@ -37,8 +37,8 @@ function transformTypes(src, dest, options, callback) {
|
|
|
37
37
|
if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');
|
|
38
38
|
if (typeof callback === 'function') return workerWrapper(version, src, dest, options, callback);
|
|
39
39
|
return new _pinkiepromise.default(function(resolve, reject) {
|
|
40
|
-
workerWrapper(version, src, dest, options, function(err,
|
|
41
|
-
err ? reject(err) : resolve(
|
|
40
|
+
workerWrapper(version, src, dest, options, function(err, result) {
|
|
41
|
+
err ? reject(err) : resolve(result);
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformTypes.js'));\n\nimport type { TransformTypesCallback, TransformTypesOptions } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {{tsconfig: TsConfigResult}} options Options.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformTypes(src: string, dest: string, options?: TransformTypesOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<
|
|
1
|
+
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformTypes.js'));\n\nimport type { TransformResult, TransformTypesCallback, TransformTypesOptions } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {{tsconfig: TsConfigResult}} options Options.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformTypes(src: string, dest: string, options?: TransformTypesOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<TransformResult[]> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, options, callback);\n return new Promise((resolve, reject) => {\n workerWrapper(version, src, dest, options, (err, result) => {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformTypes","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerWrapper","wrapWorker","resolve","src","dest","options","callback","Error","Promise","reject","err","result"],"mappings":";;;;+BAYA;;;;;;CAMC,GACD;;;eAAwBA;;;2DAnBP;0DACD;oEAEI;iEACG;;;;;;AACvB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAClG,IAAMC,gBAAgBC,IAAAA,mBAAU,EAACN,aAAI,CAACO,OAAO,CAACR,WAAW,MAAM,OAAO,WAAW;AAWlE,SAASP,eAAegB,GAAW,EAAEC,IAAY,EAAEC,OAAwD,EAAEC,QAAiC;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IACtB,IAAI,OAAOF,QAAQ,UAAU,MAAM,IAAII,MAAM;IAC7C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,IAAI,OAAOD,aAAa,YAAY,OAAON,cAAcP,SAASU,KAAKC,MAAMC,SAASC;IACtF,OAAO,IAAIE,sBAAO,CAAC,SAACN,SAASO;QAC3BT,cAAcP,SAASU,KAAKC,MAAMC,SAAS,SAACK,KAAKC;YAC/CD,MAAMD,OAAOC,OAAOR,QAAQS;QAC9B;IACF;AACF"}
|
|
@@ -130,17 +130,29 @@ function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
|
130
130
|
entries.push(entry);
|
|
131
131
|
}, function(err) {
|
|
132
132
|
if (err) return callback(err);
|
|
133
|
+
var results = [];
|
|
133
134
|
options = _object_spread_props(_object_spread({}, options), {
|
|
134
135
|
tsconfig: tsconfig
|
|
135
136
|
});
|
|
136
137
|
var queue = new _queuecb.default();
|
|
137
138
|
entries.forEach(function(entry) {
|
|
138
|
-
return queue.defer(
|
|
139
|
+
return queue.defer(function(cb) {
|
|
140
|
+
return (0, _transformFile.default)(entry.fullPath, _path.default.dirname(_path.default.join(dest, entry.path)), type, options, function(err, to) {
|
|
141
|
+
if (err) return cb(err);
|
|
142
|
+
results.push({
|
|
143
|
+
from: entry,
|
|
144
|
+
to: _path.default.join(_path.default.relative(src, _path.default.dirname(entry.fullPath)), to)
|
|
145
|
+
});
|
|
146
|
+
if (options.sourceMaps) results.push({
|
|
147
|
+
from: entry,
|
|
148
|
+
to: "".concat(_path.default.join(_path.default.relative(src, _path.default.dirname(entry.fullPath)), to), ".map")
|
|
149
|
+
});
|
|
150
|
+
cb();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
139
153
|
});
|
|
140
154
|
queue.await(function(err) {
|
|
141
|
-
return err ? callback(err) : callback(null,
|
|
142
|
-
return entry.path;
|
|
143
|
-
}));
|
|
155
|
+
return err ? callback(err) : callback(null, results);
|
|
144
156
|
});
|
|
145
157
|
});
|
|
146
158
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from './transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from './transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry) =>\n queue.defer((cb) =>\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, (err, to) => {\n if (err) return cb(err);\n results.push({ from: entry, to: path.join(path.relative(src, path.dirname(entry.fullPath)), to) });\n if (options.sourceMaps) results.push({ from: entry, to: `${path.join(path.relative(src, path.dirname(entry.fullPath)), to)}.map` });\n cb();\n })\n )\n );\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","getTS","getTsconfig","matcher","createMatcher","rimraf2","disableGlob","entries","iterator","Iterator","forEach","entry","stats","isFile","fullPath","typeFileRegEx","test","basename","SKIPS","indexOf","push","err","results","queue","Queue","defer","cb","transformFile","path","dirname","join","to","from","relative","sourceMaps","await"],"mappings":";;;;+BAUA;;;eAAwBA;;;2DAVP;iEACI;yEACE;8DACL;8DACE;yBAEiB;oEACX;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEX,SAASA,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAE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AAC,GAAkE,OAAhEH,aAAI,CAACE,IAAI,CAACF,aAAI,CAACK,QAAQ,CAACtC,KAAKiC,aAAI,CAACC,OAAO,CAAClB,MAAMG,QAAQ,IAAIiB,KAAI;wBAAM;wBACjIL;oBACF;;;YAGJH,MAAMY,KAAK,CAAC,SAACd;uBAASA,MAAMtB,SAASsB,OAAOtB,SAAS,MAAMuB;;QAC7D;IAEJ;AACF"}
|
|
@@ -172,7 +172,7 @@ function transformFileWorker(src, dest, type, options, callback) {
|
|
|
172
172
|
queue.defer(_fs.default.writeFile.bind(null, destFilePath, output.code, 'utf8'));
|
|
173
173
|
!options.sourceMaps || queue.defer(_fs.default.writeFile.bind(null, "".concat(destFilePath, ".map"), output.map, 'utf8'));
|
|
174
174
|
queue.await(function() {
|
|
175
|
-
return err ? callback(err) : callback(null, destFilePath);
|
|
175
|
+
return err ? callback(err) : callback(null, _path.default.relative(dest, destFilePath));
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport * as getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* 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\nexport default function transformFileWorker(src, dest, type, options, callback) {\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(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 basename = path.basename(src);\n transformSync(contents, basename, tsconfig, (err, output) => {\n if (err) return callback(err);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n"],"names":["transformFileWorker","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","dependency","match","ext","find","x","slice","length","matches","push","exec","reverse","index","start","indexOf","substring","interopClientDefaultExport","src","dest","type","options","callback","fs","readFile","err","contents","once","tsconfig","getTS","getTsconfig","config","compilerOptions","module","target","basename","path","transformSync","output","extname","destFilePath","join","replace","mkdirp","dirname","queue","Queue","defer","writeFile","bind","sourceMaps","map","await"],"mappings":";;;;+BAwCA;;;eAAwBA;;;yDAxCT;2DACE;iEACA;yEACM;oEACJ;8DACD;oEAEQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMC,eAAe;AACrB,IAAMC,eAAe;AACrB,IAAMC,WAAW,IAAIC,OAAO,AAAC,uBAAsDH,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa,UAAQ;AACxG,IAAMI,WAAW,IAAID,OAAO,AAAC,GAAuBF,OAArBC,UAAS,cAAqCF,OAAzBC,cAAa,cAAuCA,OAA3BD,cAAa,gBAAuCA,OAAzBC,cAAa,cAAyB,OAAbD,cAAa,OAAK;AAEnJ,IAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ;IAAQ;CAAO;AAC/D,IAA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A,sBAAM,EAACP,aAAI,CAACQ,OAAO,CAACJ,eAAe;oBACjC,IAAMK,QAAQ,IAAIC,gBAAK;oBACvBD,MAAME,KAAK,CAACxB,WAAE,CAACyB,SAAS,CAACC,IAAI,CAAC,MAAMT,cAAcF,OAAOxC,IAAI,EAAE;oBAC/D,CAACuB,QAAQ6B,UAAU,IAAIL,MAAME,KAAK,CAACxB,WAAE,CAACyB,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAe,OAAbT,cAAa,SAAOF,OAAOa,GAAG,EAAE;oBAC9FN,MAAMO,KAAK,CAAC;+BAAO3B,MAAMH,SAASG,OAAOH,SAAS,
|
|
1
|
+
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport * as getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* 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\nexport default function transformFileWorker(src, dest, type, options, callback) {\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(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 basename = path.basename(src);\n transformSync(contents, basename, tsconfig, (err, output) => {\n if (err) return callback(err);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, path.relative(dest, destFilePath))));\n });\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n"],"names":["transformFileWorker","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","dependency","match","ext","find","x","slice","length","matches","push","exec","reverse","index","start","indexOf","substring","interopClientDefaultExport","src","dest","type","options","callback","fs","readFile","err","contents","once","tsconfig","getTS","getTsconfig","config","compilerOptions","module","target","basename","path","transformSync","output","extname","destFilePath","join","replace","mkdirp","dirname","queue","Queue","defer","writeFile","bind","sourceMaps","map","await","relative"],"mappings":";;;;+BAwCA;;;eAAwBA;;;yDAxCT;2DACE;iEACA;yEACM;oEACJ;8DACD;oEAEQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMC,eAAe;AACrB,IAAMC,eAAe;AACrB,IAAMC,WAAW,IAAIC,OAAO,AAAC,uBAAsDH,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa,UAAQ;AACxG,IAAMI,WAAW,IAAID,OAAO,AAAC,GAAuBF,OAArBC,UAAS,cAAqCF,OAAzBC,cAAa,cAAuCA,OAA3BD,cAAa,gBAAuCA,OAAzBC,cAAa,cAAyB,OAAbD,cAAa,OAAK;AAEnJ,IAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ;IAAQ;CAAO;AAC/D,IAAMC,mBAAmB;IAAC;CAAO;AACjC,IAAMC,mBAAmB;IAAC;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;CAAO;AAExE,SAASC,iBAAiBC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,SAAS;;QAIxD,IAAMC,aAAaC,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC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IL,MAAME,KAAK,CAACxB,WAAE,CAACyB,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAe,OAAbT,cAAa,SAAOF,OAAOa,GAAG,EAAE;oBAC9FN,MAAMO,KAAK,CAAC;+BAAO3B,MAAMH,SAASG,OAAOH,SAAS,MAAMc,aAAI,CAACiB,QAAQ,CAAClC,MAAMqB;;gBAC9E;YACF;QACF,EAAE,OAAOf,KAAK;YACZH,SAASG;QACX;IACF;AACF"}
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformTypesWorker;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
11
12
|
var _crossspawncb = /*#__PURE__*/ _interop_require_default(require("cross-spawn-cb"));
|
|
12
13
|
var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
|
|
13
14
|
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_wildcard(require("get-tsconfig-compat"));
|
|
@@ -108,12 +109,24 @@ function transformTypesWorker(src, dest, options, callback) {
|
|
|
108
109
|
}, function(err) {
|
|
109
110
|
if (err) return callback(err);
|
|
110
111
|
if (entries.length === 0) return callback();
|
|
111
|
-
var
|
|
112
|
-
|
|
112
|
+
var results = entries.map(function(entry) {
|
|
113
|
+
var result = {
|
|
114
|
+
from: _path.default.relative(src, entry.fullPath),
|
|
115
|
+
to: ''
|
|
116
|
+
};
|
|
117
|
+
var dirname = _path.default.dirname(result.from);
|
|
118
|
+
var basename = _path.default.basename(result.from);
|
|
119
|
+
var ext = _path.default.extname(basename);
|
|
120
|
+
ext = ext.replace('sx', 's');
|
|
121
|
+
ext = ext.replace('js', 'ts');
|
|
122
|
+
result.to = _path.default.join(dirname === '.' ? '' : dirname, "".concat(basename.replace(/\.[^/.]+$/, ''), ".d").concat(ext));
|
|
123
|
+
return result;
|
|
113
124
|
});
|
|
114
125
|
var args = [
|
|
115
126
|
'tsc'
|
|
116
|
-
].concat(_to_consumable_array(
|
|
127
|
+
].concat(_to_consumable_array(results.map(function(x) {
|
|
128
|
+
return _path.default.resolve(src, x.from);
|
|
129
|
+
})), [
|
|
117
130
|
'--declaration',
|
|
118
131
|
'--emitDeclarationOnly',
|
|
119
132
|
'--outDir',
|
|
@@ -122,9 +135,7 @@ function transformTypesWorker(src, dest, options, callback) {
|
|
|
122
135
|
(0, _crossspawncb.default)(args[0], args.slice(1), {
|
|
123
136
|
stdio: 'inherit'
|
|
124
137
|
}, function(err) {
|
|
125
|
-
return err ? callback(err) : callback(null,
|
|
126
|
-
return entry.path;
|
|
127
|
-
}));
|
|
138
|
+
return err ? callback(err) : callback(null, results);
|
|
128
139
|
});
|
|
129
140
|
});
|
|
130
141
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import spawn from 'cross-spawn-cb';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n const tsArgs = [];\n for (const key in tsconfig.config.compilerOptions) {\n const value = tsconfig.config.compilerOptions[key];\n tsArgs.push(`--${key}`);\n tsArgs.push(Array.isArray(value) ? value.join(',') : value);\n }\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n if (entries.length === 0) return callback();\n
|
|
1
|
+
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport spawn from 'cross-spawn-cb';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n const tsArgs = [];\n for (const key in tsconfig.config.compilerOptions) {\n const value = tsconfig.config.compilerOptions[key];\n tsArgs.push(`--${key}`);\n tsArgs.push(Array.isArray(value) ? value.join(',') : value);\n }\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n if (entries.length === 0) return callback();\n const results = entries.map((entry) => {\n const result = { from: path.relative(src, entry.fullPath), to: '' };\n const dirname = path.dirname(result.from);\n const basename = path.basename(result.from);\n let ext = path.extname(basename);\n ext = ext.replace('sx', 's');\n ext = ext.replace('js', 'ts');\n result.to = path.join(dirname === '.' ? '' : dirname, `${basename.replace(/\\.[^/.]+$/, '')}.d${ext}`);\n return result;\n });\n const args = ['tsc', ...results.map((x) => path.resolve(src, x.from)), '--declaration', '--emitDeclarationOnly', '--outDir', dest, ...tsArgs];\n spawn(args[0], args.slice(1), { stdio: 'inherit' }, (err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["transformTypesWorker","src","dest","options","callback","tsconfig","getTS","getTsconfig","matcher","createMatcher","tsArgs","key","config","compilerOptions","value","push","Array","isArray","join","rimraf2","disableGlob","entries","iterator","Iterator","forEach","entry","stats","isFile","fullPath","typeFileRegEx","test","basename","SKIPS","indexOf","err","length","results","map","result","from","path","relative","to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,IAAMa,SAAS;oBAAEC,MAAMC,aAAI,CAACC,QAAQ,CAACxC,KAAKwB,MAAMG,QAAQ;oBAAGc,IAAI;gBAAG;gBAClE,IAAMC,UAAUH,aAAI,CAACG,OAAO,CAACL,OAAOC,IAAI;gBACxC,IAAMR,WAAWS,aAAI,CAACT,QAAQ,CAACO,OAAOC,IAAI;gBAC1C,IAAIK,MAAMJ,aAAI,CAACK,OAAO,CAACd;gBACvBa,MAAMA,IAAIE,OAAO,CAAC,MAAM;gBACxBF,MAAMA,IAAIE,OAAO,CAAC,MAAM;gBACxBR,OAAOI,EAAE,GAAGF,aAAI,CAACtB,IAAI,CAACyB,YAAY,MAAM,KAAKA,SAAS,AAAC,GAAwCC,OAAtCb,SAASe,OAAO,CAAC,aAAa,KAAI,MAAQ,OAAJF;gBAC/F,OAAON;YACT;YACA,IAAMS,OAAO;gBAAC;aAA+H,CAAhI,OAAQ,qBAAGX,QAAQC,GAAG,CAAC,SAACW;uBAAMR,aAAI,CAACS,OAAO,CAAChD,KAAK+C,EAAET,IAAI;iBAAtD;gBAA0D;gBAAiB;gBAAyB;gBAAYrC;aAAgB,EAAV,qBAAGQ;YACtIwC,IAAAA,qBAAK,EAACH,IAAI,CAAC,EAAE,EAAEA,KAAKI,KAAK,CAAC,IAAI;gBAAEC,OAAO;YAAU,GAAG,SAAClB;uBAASA,MAAM9B,SAAS8B,OAAO9B,SAAS,MAAMgC;;QACrG;IAEJ;AACF"}
|
|
@@ -25,8 +25,8 @@ const workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers',
|
|
|
25
25
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
26
26
|
if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);
|
|
27
27
|
return new Promise((resolve, reject)=>{
|
|
28
|
-
workerWrapper(version, src, dest, type, options, (err,
|
|
29
|
-
err ? reject(err) : resolve(
|
|
28
|
+
workerWrapper(version, src, dest, type, options, (err, result)=>{
|
|
29
|
+
err ? reject(err) : resolve(result);
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js'));\n\nimport type { TransformDirectoryCallback, TransformDirectoryOptions } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src: string, dest: string, type: string, options?: TransformDirectoryOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js'));\n\nimport type { TransformDirectoryCallback, TransformDirectoryOptions, TransformResult } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src: string, dest: string, type: string, options?: TransformDirectoryOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<TransformResult[]> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n workerWrapper(version, src, dest, type, options, (err, result) => {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["path","url","Promise","wrapWorker","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerWrapper","resolve","transformDirectory","src","dest","type","options","callback","Error","reject","err","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,sEAAsE;AACtE,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,gBAAgB,sBAAsB;AAC7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYV,KAAKW,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaX,IAAIY,aAAa,CAAC,YAAYZ,GAAG;AACjH,MAAMa,gBAAgBX,WAAWH,KAAKe,OAAO,CAACL,WAAW,MAAM,OAAO,WAAW;AAIjF;;;;;;;CAOC,GACD,eAAe,SAASM,mBAAmBC,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAgE,EAAEC,QAAqC;IACzL,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IACtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,IAAI,OAAOD,aAAa,YAAY,OAAOP,cAAcL,SAASQ,KAAKC,MAAMC,MAAMC,SAASC;IAC5F,OAAO,IAAInB,QAAQ,CAACa,SAASQ;QAC3BT,cAAcL,SAASQ,KAAKC,MAAMC,MAAMC,SAAS,CAACI,KAAKC;YACrDD,MAAMD,OAAOC,OAAOT,QAAQU;QAC9B;IACF;AACF"}
|
|
@@ -23,8 +23,8 @@ const workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers',
|
|
|
23
23
|
if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');
|
|
24
24
|
if (typeof callback === 'function') return workerWrapper(version, src, dest, options, callback);
|
|
25
25
|
return new Promise((resolve, reject)=>{
|
|
26
|
-
workerWrapper(version, src, dest, options, (err,
|
|
27
|
-
err ? reject(err) : resolve(
|
|
26
|
+
workerWrapper(version, src, dest, options, (err, result)=>{
|
|
27
|
+
err ? reject(err) : resolve(result);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformTypes.js'));\n\nimport type { TransformTypesCallback, TransformTypesOptions } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {{tsconfig: TsConfigResult}} options Options.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformTypes(src: string, dest: string, options?: TransformTypesOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<
|
|
1
|
+
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>\nimport Promise from 'pinkie-promise';\nimport wrapWorker from './lib/wrapWorker.js';\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformTypes.js'));\n\nimport type { TransformResult, TransformTypesCallback, TransformTypesOptions } from './types.js';\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {{tsconfig: TsConfigResult}} options Options.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformTypes(src: string, dest: string, options?: TransformTypesOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<TransformResult[]> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, options, callback);\n return new Promise((resolve, reject) => {\n workerWrapper(version, src, dest, options, (err, result) => {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["path","url","Promise","wrapWorker","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerWrapper","resolve","transformTypes","src","dest","options","callback","Error","reject","err","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,sEAAsE;AACtE,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,gBAAgB,sBAAsB;AAC7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYV,KAAKW,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaX,IAAIY,aAAa,CAAC,YAAYZ,GAAG;AACjH,MAAMa,gBAAgBX,WAAWH,KAAKe,OAAO,CAACL,WAAW,MAAM,OAAO,WAAW;AAIjF;;;;;;CAMC,GACD,eAAe,SAASM,eAAeC,GAAW,EAAEC,IAAY,EAAEC,OAAwD,EAAEC,QAAiC;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IACtB,IAAI,OAAOF,QAAQ,UAAU,MAAM,IAAII,MAAM;IAC7C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,IAAI,OAAOD,aAAa,YAAY,OAAON,cAAcL,SAASQ,KAAKC,MAAMC,SAASC;IACtF,OAAO,IAAIlB,QAAQ,CAACa,SAASO;QAC3BR,cAAcL,SAASQ,KAAKC,MAAMC,SAAS,CAACI,KAAKC;YAC/CD,MAAMD,OAAOC,OAAOR,QAAQS;QAC9B;IACF;AACF"}
|
package/dist/esm/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.ts"],"sourcesContent":["export interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n\nexport interface TransformDirectoryOptions {\n cacheDirectory?: string;\n}\nexport type TransformDirectoryCallback = (err?: Error, filePaths?:
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["export interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n\nexport interface TransformResult {\n from: string;\n to: string;\n}\n\nexport interface TransformDirectoryOptions {\n cacheDirectory?: string;\n}\nexport type TransformDirectoryCallback = (err?: Error, filePaths?: TransformResult[]) => void;\n\nexport interface TransformFileOptions {\n cacheDirectory?: string;\n}\nexport type TransformFileCallback = (err?: Error, destFilePath?: string) => void;\n\nexport interface TransformTypesOptions {\n cacheDirectory?: string;\n}\nexport type TransformTypesCallback = (err?: Error, filePaths?: TransformResult[]) => void;\n"],"names":[],"mappings":"AAuBA,WAA0F"}
|
|
@@ -22,13 +22,25 @@ export default function transformDirectoryWorker(src, dest, type, options, callb
|
|
|
22
22
|
entries.push(entry);
|
|
23
23
|
}, (err)=>{
|
|
24
24
|
if (err) return callback(err);
|
|
25
|
+
const results = [];
|
|
25
26
|
options = {
|
|
26
27
|
...options,
|
|
27
28
|
tsconfig
|
|
28
29
|
};
|
|
29
30
|
const queue = new Queue();
|
|
30
|
-
entries.forEach((entry)=>queue.defer(transformFile
|
|
31
|
-
|
|
31
|
+
entries.forEach((entry)=>queue.defer((cb)=>transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, (err, to)=>{
|
|
32
|
+
if (err) return cb(err);
|
|
33
|
+
results.push({
|
|
34
|
+
from: entry,
|
|
35
|
+
to: path.join(path.relative(src, path.dirname(entry.fullPath)), to)
|
|
36
|
+
});
|
|
37
|
+
if (options.sourceMaps) results.push({
|
|
38
|
+
from: entry,
|
|
39
|
+
to: `${path.join(path.relative(src, path.dirname(entry.fullPath)), to)}.map`
|
|
40
|
+
});
|
|
41
|
+
cb();
|
|
42
|
+
})));
|
|
43
|
+
queue.await((err)=>err ? callback(err) : callback(null, results));
|
|
32
44
|
});
|
|
33
45
|
});
|
|
34
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from './transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from './transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig };\n\n const queue = new Queue();\n entries.forEach((entry) =>\n queue.defer((cb) =>\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, (err, to) => {\n if (err) return cb(err);\n results.push({ from: entry, to: path.join(path.relative(src, path.dirname(entry.fullPath)), to) });\n if (options.sourceMaps) results.push({ from: entry, to: `${path.join(path.relative(src, path.dirname(entry.fullPath)), to)}.map` });\n cb();\n })\n )\n );\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["path","Iterator","getTS","Queue","rimraf2","SKIPS","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","getTsconfig","matcher","disableGlob","entries","iterator","forEach","entry","stats","isFile","fullPath","test","basename","indexOf","push","err","results","queue","defer","cb","dirname","join","to","from","relative","sourceMaps","await"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,YAAYC,WAAW,sBAAsB;AAC7C,OAAOC,WAAW,WAAW;AAC7B,OAAOC,aAAa,UAAU;AAE9B,SAASC,KAAK,EAAEC,aAAa,QAAQ,kBAAkB;AACvD,OAAOC,mBAAmB,sBAAsB;AAChD,OAAOC,mBAAmB,qBAAqB;AAE/C,eAAe,SAASC,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,MAAMC,WAAWF,QAAQE,QAAQ,GAAGF,QAAQE,QAAQ,GAAGb,MAAMc,WAAW,CAACN;IACzE,MAAMO,UAAUV,cAAcQ;IAE9BX,QAAQO,MAAM;QAAEO,aAAa;IAAK,GAAG;QACnC,MAAMC,UAAU,EAAE;QAClB,MAAMC,WAAW,IAAInB,SAASS;QAC9BU,SAASC,OAAO,CACd,CAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAI,CAACP,QAAQK,MAAMG,QAAQ,GAAG;YAC9B,IAAInB,cAAcoB,IAAI,CAACJ,MAAMK,QAAQ,GAAG;YACxC,IAAItB,MAAMuB,OAAO,CAACN,MAAMK,QAAQ,KAAK,GAAG;YACxCR,QAAQU,IAAI,CAACP;QACf,GACA,CAACQ;YACC,IAAIA,KAAK,OAAOhB,SAASgB;YACzB,MAAMC,UAAU,EAAE;YAClBlB,UAAU;gBAAE,GAAGA,OAAO;gBAAEE;YAAS;YAEjC,MAAMiB,QAAQ,IAAI7B;YAClBgB,QAAQE,OAAO,CAAC,CAACC,QACfU,MAAMC,KAAK,CAAC,CAACC,KACX1B,cAAcc,MAAMG,QAAQ,EAAEzB,KAAKmC,OAAO,CAACnC,KAAKoC,IAAI,CAACzB,MAAMW,MAAMtB,IAAI,IAAIY,MAAMC,SAAS,CAACiB,KAAKO;wBAC5F,IAAIP,KAAK,OAAOI,GAAGJ;wBACnBC,QAAQF,IAAI,CAAC;4BAAES,MAAMhB;4BAAOe,IAAIrC,KAAKoC,IAAI,CAACpC,KAAKuC,QAAQ,CAAC7B,KAAKV,KAAKmC,OAAO,CAACb,MAAMG,QAAQ,IAAIY;wBAAI;wBAChG,IAAIxB,QAAQ2B,UAAU,EAAET,QAAQF,IAAI,CAAC;4BAAES,MAAMhB;4BAAOe,IAAI,GAAGrC,KAAKoC,IAAI,CAACpC,KAAKuC,QAAQ,CAAC7B,KAAKV,KAAKmC,OAAO,CAACb,MAAMG,QAAQ,IAAIY,IAAI,IAAI,CAAC;wBAAC;wBACjIH;oBACF;YAGJF,MAAMS,KAAK,CAAC,CAACX,MAASA,MAAMhB,SAASgB,OAAOhB,SAAS,MAAMiB;QAC7D;IAEJ;AACF"}
|
|
@@ -90,7 +90,7 @@ export default function transformFileWorker(src, dest, type, options, callback)
|
|
|
90
90
|
const queue = new Queue();
|
|
91
91
|
queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));
|
|
92
92
|
!options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));
|
|
93
|
-
queue.await(()=>err ? callback(err) : callback(null, destFilePath));
|
|
93
|
+
queue.await(()=>err ? callback(err) : callback(null, path.relative(dest, destFilePath)));
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport * as getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* 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\nexport default function transformFileWorker(src, dest, type, options, callback) {\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(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 basename = path.basename(src);\n transformSync(contents, basename, tsconfig, (err, output) => {\n if (err) return callback(err);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n"],"names":["fs","path","once","getTS","mkdirp","Queue","transformSync","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","matches","match","exec","dependency","ext","find","x","slice","length","push","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileWorker","src","dest","type","options","callback","readFile","err","contents","tsconfig","getTsconfig","config","compilerOptions","module","target","basename","output","extname","destFilePath","join","replace","dirname","queue","defer","writeFile","bind","sourceMaps","map","await"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,eAAe;AAChC,YAAYC,WAAW,sBAAsB;AAC7C,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,eAAe;AACrB,MAAMC,eAAe;AACrB,MAAMC,WAAW,IAAIC,OAAO,CAAC,oBAAoB,EAAEF,aAAa,iBAAiB,EAAED,aAAa,KAAK,CAAC,EAAE;AACxG,MAAMI,WAAW,IAAID,OAAO,GAAGD,SAAS,UAAU,EAAED,aAAa,UAAU,EAAED,aAAa,YAAY,EAAEC,aAAa,UAAU,EAAED,aAAa,EAAE,CAAC,EAAE;AAEnJ,MAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ;IAAQ;CAAO;AAC/D,MAAMC,mBAAmB;IAAC;CAAO;AACjC,MAAMC,mBAAmB;IAAC;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;CAAO;AAExE,SAASC,iBAAiBC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,SAAS;IAC1D,IAAIC,UAAU,EAAE;IAChB,IAAIC,QAAQJ,MAAMK,IAAI,CAACN;IACvB,MAAOK,MAAO;QACZ,MAAME,aAAaF,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE;QAC/D,MAAMG,MAAMN,WAAWO,IAAI,CAAC,CAACC,IAAMH,WAAWI,KAAK,CAAC,CAACD,EAAEE,MAAM,MAAMF;QACnE,IAAIF,KAAKJ,QAAQS,IAAI,CAAC;YAAEL;YAAKH;YAAOE;QAAW;QAC/CF,QAAQJ,MAAMK,IAAI,CAACN;IACrB;IAEAI,UAAUA,QAAQU,OAAO;IACzB,IAAK,MAAMC,SAASX,Q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OAAO,CAACF;gBACvB,IAAIZ,SAAS,OAAO;oBAClBf,MAAMZ,iBAAiBqB,OAAO,CAACT,QAAQ,IAAI,SAASA;oBACpD4B,OAAOpC,IAAI,GAAGD,iBAAiBqC,OAAOpC,IAAI,EAAEL,UAAUC,kBAAkB;oBACxEY,MAAMX,iBAAiBoB,OAAO,CAACT,QAAQ,IAAI,SAASA;oBACpD4B,OAAOpC,IAAI,GAAGD,iBAAiBqC,OAAOpC,IAAI,EAAEL,UAAUE,kBAAkB;gBAC1E,OAAO;oBACLW,MAAMV,iBAAiBmB,OAAO,CAACT,QAAQ,IAAI,QAAQA;oBACnD4B,OAAOpC,IAAI,GAAGD,iBAAiBqC,OAAOpC,IAAI,EAAEP,UAAUK,kBAAkB;oBACxEsC,OAAOpC,IAAI,IAAImB;gBACjB;gBACA,MAAMmB,eAAerD,KAAKsD,IAAI,CAACjB,MAAMa,SAASK,OAAO,CAAC,aAAa,MAAMhC;gBAEzEpB,OAAOH,KAAKwD,OAAO,CAACH,eAAe;oBACjC,MAAMI,QAAQ,IAAIrD;oBAClBqD,MAAMC,KAAK,CAAC3D,GAAG4D,SAAS,CAACC,IAAI,CAAC,MAAMP,cAAcF,OAAOpC,IAAI,EAAE;oBAC/D,CAACwB,QAAQsB,UAAU,IAAIJ,MAAMC,KAAK,CAAC3D,GAAG4D,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGP,aAAa,IAAI,CAAC,EAAEF,OAAOW,GAAG,EAAE;oBAC9FL,MAAMM,KAAK,CAAC,IAAOrB,MAAMF,SAASE,OAAOF,SAAS,
|
|
1
|
+
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport * as getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* 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\nexport default function transformFileWorker(src, dest, type, options, callback) {\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(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 basename = path.basename(src);\n transformSync(contents, basename, tsconfig, (err, output) => {\n if (err) return callback(err);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, path.relative(dest, destFilePath))));\n });\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n"],"names":["fs","path","once","getTS","mkdirp","Queue","transformSync","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","matches","match","exec","dependency","ext","find","x","slice","length","push","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileWorker","src","dest","type","options","callback","readFile","err","contents","tsconfig","getTsconfig","config","compilerOptions","module","target","basename","output","extname","destFilePath","join","replace","dirname","queue","defer","writeFile","bind","sourceMaps","map","await","relative"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,eAAe;AAChC,YAAYC,WAAW,sBAAsB;AAC7C,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,O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BACpD4B,OAAOpC,IAAI,GAAGD,iBAAiBqC,OAAOpC,IAAI,EAAEL,UAAUE,kBAAkB;gBAC1E,OAAO;oBACLW,MAAMV,iBAAiBmB,OAAO,CAACT,QAAQ,IAAI,QAAQA;oBACnD4B,OAAOpC,IAAI,GAAGD,iBAAiBqC,OAAOpC,IAAI,EAAEP,UAAUK,kBAAkB;oBACxEsC,OAAOpC,IAAI,IAAImB;gBACjB;gBACA,MAAMmB,eAAerD,KAAKsD,IAAI,CAACjB,MAAMa,SAASK,OAAO,CAAC,aAAa,MAAMhC;gBAEzEpB,OAAOH,KAAKwD,OAAO,CAACH,eAAe;oBACjC,MAAMI,QAAQ,IAAIrD;oBAClBqD,MAAMC,KAAK,CAAC3D,GAAG4D,SAAS,CAACC,IAAI,CAAC,MAAMP,cAAcF,OAAOpC,IAAI,EAAE;oBAC/D,CAACwB,QAAQsB,UAAU,IAAIJ,MAAMC,KAAK,CAAC3D,GAAG4D,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGP,aAAa,IAAI,CAAC,EAAEF,OAAOW,GAAG,EAAE;oBAC9FL,MAAMM,KAAK,CAAC,IAAOrB,MAAMF,SAASE,OAAOF,SAAS,MAAMxC,KAAKgE,QAAQ,CAAC3B,MAAMgB;gBAC9E;YACF;QACF,EAAE,OAAOX,KAAK;YACZF,SAASE;QACX;IACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'path';
|
|
1
2
|
import spawn from 'cross-spawn-cb';
|
|
2
3
|
import Iterator from 'fs-iterator';
|
|
3
4
|
import * as getTS from 'get-tsconfig-compat';
|
|
@@ -27,10 +28,22 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
27
28
|
}, (err)=>{
|
|
28
29
|
if (err) return callback(err);
|
|
29
30
|
if (entries.length === 0) return callback();
|
|
30
|
-
const
|
|
31
|
+
const results = entries.map((entry)=>{
|
|
32
|
+
const result = {
|
|
33
|
+
from: path.relative(src, entry.fullPath),
|
|
34
|
+
to: ''
|
|
35
|
+
};
|
|
36
|
+
const dirname = path.dirname(result.from);
|
|
37
|
+
const basename = path.basename(result.from);
|
|
38
|
+
let ext = path.extname(basename);
|
|
39
|
+
ext = ext.replace('sx', 's');
|
|
40
|
+
ext = ext.replace('js', 'ts');
|
|
41
|
+
result.to = path.join(dirname === '.' ? '' : dirname, `${basename.replace(/\.[^/.]+$/, '')}.d${ext}`);
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
31
44
|
const args = [
|
|
32
45
|
'tsc',
|
|
33
|
-
...
|
|
46
|
+
...results.map((x)=>path.resolve(src, x.from)),
|
|
34
47
|
'--declaration',
|
|
35
48
|
'--emitDeclarationOnly',
|
|
36
49
|
'--outDir',
|
|
@@ -39,7 +52,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
39
52
|
];
|
|
40
53
|
spawn(args[0], args.slice(1), {
|
|
41
54
|
stdio: 'inherit'
|
|
42
|
-
}, (err)=>err ? callback(err) : callback(null,
|
|
55
|
+
}, (err)=>err ? callback(err) : callback(null, results));
|
|
43
56
|
});
|
|
44
57
|
});
|
|
45
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import spawn from 'cross-spawn-cb';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n const tsArgs = [];\n for (const key in tsconfig.config.compilerOptions) {\n const value = tsconfig.config.compilerOptions[key];\n tsArgs.push(`--${key}`);\n tsArgs.push(Array.isArray(value) ? value.join(',') : value);\n }\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n if (entries.length === 0) return callback();\n
|
|
1
|
+
{"version":3,"sources":["transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport spawn from 'cross-spawn-cb';\nimport Iterator from 'fs-iterator';\nimport * as getTS from 'get-tsconfig-compat';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n const tsArgs = [];\n for (const key in tsconfig.config.compilerOptions) {\n const value = tsconfig.config.compilerOptions[key];\n tsArgs.push(`--${key}`);\n tsArgs.push(Array.isArray(value) ? value.join(',') : value);\n }\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (SKIPS.indexOf(entry.basename) >= 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n if (entries.length === 0) return callback();\n const results = entries.map((entry) => {\n const result = { from: path.relative(src, entry.fullPath), to: '' };\n const dirname = path.dirname(result.from);\n const basename = path.basename(result.from);\n let ext = path.extname(basename);\n ext = ext.replace('sx', 's');\n ext = ext.replace('js', 'ts');\n result.to = path.join(dirname === '.' ? '' : dirname, `${basename.replace(/\\.[^/.]+$/, '')}.d${ext}`);\n return result;\n });\n const args = ['tsc', ...results.map((x) => path.resolve(src, x.from)), '--declaration', '--emitDeclarationOnly', '--outDir', dest, ...tsArgs];\n spawn(args[0], args.slice(1), { stdio: 'inherit' }, (err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["path","spawn","Iterator","getTS","rimraf2","SKIPS","typeFileRegEx","createMatcher","transformTypesWorker","src","dest","options","callback","tsconfig","getTsconfig","matcher","tsArgs","key","config","compilerOptions","value","push","Array","isArray","join","disableGlob","entries","iterator","forEach","entry","stats","isFile","fullPath","test","basename","indexOf","err","length","results","map","result","from","relative","to","dirname","ext","extname","replace","args","x","resolve","slice","stdio"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,WAAW,iBAAiB;AACnC,OAAOC,cAAc,cAAc;AACnC,YAAYC,WAAW,sBAAsB;AAC7C,OAAOC,aAAa,UAAU;AAE9B,SAASC,KAAK,EAAEC,aAAa,QAAQ,kBAAkB;AACvD,OAAOC,mBAAmB,sBAAsB;AAEhD,eAAe,SAASC,qBAAqBC,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACvE,MAAMC,WAAWF,QAAQE,QAAQ,GAAGF,QAAQE,QAAQ,GAAGV,MAAMW,WAAW,CAACL;IACzE,MAAMM,UAAUR,cAAcM;IAE9B,MAAMG,SAAS,EAAE;IACjB,IAAK,MAAMC,OAAOJ,SAASK,MAAM,CAACC,eAAe,CAAE;QACjD,MAAMC,QAAQP,SAASK,MAAM,CAACC,eAAe,CAACF,IAAI;QAClDD,OAAOK,IAAI,CAAC,CAAC,EAAE,EAAEJ,KAAK;QACtBD,OAAOK,IAAI,CAACC,MAAMC,OAAO,CAACH,SAASA,MAAMI,IAAI,CAAC,OAAOJ;IACvD;IAEAhB,QAAQM,MAAM;QAAEe,aAAa;IAAK,GAAG;QACnC,MAAMC,UAAU,EAAE;QAClB,MAAMC,WAAW,IAAIzB,SAASO;QAC9BkB,SAASC,OAAO,CACd,CAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAI,CAAChB,QAAQc,MAAMG,QAAQ,GAAG;YAC9B,IAAI1B,cAAc2B,IAAI,CAACJ,MAAMK,QAAQ,GAAG;YACxC,IAAI7B,MAAM8B,OAAO,CAACN,MAAMK,QAAQ,KAAK,GAAG;YACxCR,QAAQL,IAAI,CAACQ;QACf,GACA,CAACO;YACC,IAAIA,KAAK,OAAOxB,SAASwB;YACzB,IAAIV,QAAQW,MAAM,KAAK,GAAG,OAAOzB;YACjC,MAAM0B,UAAUZ,QAAQa,GAAG,CAAC,CAACV;gBAC3B,MAAMW,SAAS;oBAAEC,MAAMzC,KAAK0C,QAAQ,CAACjC,KAAKoB,MAAMG,QAAQ;oBAAGW,IAAI;gBAAG;gBAClE,MAAMC,UAAU5C,KAAK4C,OAAO,CAACJ,OAAOC,IAAI;gBACxC,MAAMP,WAAWlC,KAAKkC,QAAQ,CAACM,OAAOC,IAAI;gBAC1C,IAAII,MAAM7C,KAAK8C,OAAO,CAACZ;gBACvBW,MAAMA,IAAIE,OAAO,CAAC,MAAM;gBACxBF,MAAMA,IAAIE,OAAO,CAAC,MAAM;gBACxBP,OAAOG,EAAE,GAAG3C,KAAKwB,IAAI,CAACoB,YAAY,MAAM,KAAKA,SAAS,GAAGV,SAASa,OAAO,CAAC,aAAa,IAAI,EAAE,EAAEF,KAAK;gBACpG,OAAOL;YACT;YACA,MAAMQ,OAAO;gBAAC;mBAAUV,QAAQC,GAAG,CAAC,CAACU,IAAMjD,KAAKkD,OAAO,CAACzC,KAAKwC,EAAER,IAAI;gBAAI;gBAAiB;gBAAyB;gBAAY/B;mBAASM;aAAO;YAC7If,MAAM+C,IAAI,CAAC,EAAE,EAAEA,KAAKG,KAAK,CAAC,IAAI;gBAAEC,OAAO;YAAU,GAAG,CAAChB,MAASA,MAAMxB,SAASwB,OAAOxB,SAAS,MAAM0B;QACrG;IAEJ;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Promise from 'pinkie-promise';
|
|
2
|
-
import type { TransformDirectoryCallback, TransformDirectoryOptions } from './types.js';
|
|
2
|
+
import type { TransformDirectoryCallback, TransformDirectoryOptions, TransformResult } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* @param {string} src The source directory to traverse.
|
|
5
5
|
* @param {string} dest The output directory to write files to.
|
|
@@ -8,4 +8,4 @@ import type { TransformDirectoryCallback, TransformDirectoryOptions } from './ty
|
|
|
8
8
|
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
9
9
|
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
10
10
|
*/
|
|
11
|
-
export default function transformDirectory(src: string, dest: string, type: string, options?: TransformDirectoryOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<
|
|
11
|
+
export default function transformDirectory(src: string, dest: string, type: string, options?: TransformDirectoryOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<TransformResult[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Promise from 'pinkie-promise';
|
|
2
|
-
import type { TransformTypesCallback, TransformTypesOptions } from './types.js';
|
|
2
|
+
import type { TransformResult, TransformTypesCallback, TransformTypesOptions } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* @param {string} src The source directory to traverse.
|
|
5
5
|
* @param {string} dest The output directory to write files to.
|
|
@@ -7,4 +7,4 @@ import type { TransformTypesCallback, TransformTypesOptions } from './types.js';
|
|
|
7
7
|
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
8
8
|
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
9
9
|
*/
|
|
10
|
-
export default function transformTypes(src: string, dest: string, options?: TransformTypesOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<
|
|
10
|
+
export default function transformTypes(src: string, dest: string, options?: TransformTypesOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<TransformResult[]>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -2,10 +2,14 @@ export interface Context {
|
|
|
2
2
|
parentURL?: string;
|
|
3
3
|
parentPath?: string;
|
|
4
4
|
}
|
|
5
|
+
export interface TransformResult {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
}
|
|
5
9
|
export interface TransformDirectoryOptions {
|
|
6
10
|
cacheDirectory?: string;
|
|
7
11
|
}
|
|
8
|
-
export type TransformDirectoryCallback = (err?: Error, filePaths?:
|
|
12
|
+
export type TransformDirectoryCallback = (err?: Error, filePaths?: TransformResult[]) => void;
|
|
9
13
|
export interface TransformFileOptions {
|
|
10
14
|
cacheDirectory?: string;
|
|
11
15
|
}
|
|
@@ -13,4 +17,4 @@ export type TransformFileCallback = (err?: Error, destFilePath?: string) => void
|
|
|
13
17
|
export interface TransformTypesOptions {
|
|
14
18
|
cacheDirectory?: string;
|
|
15
19
|
}
|
|
16
|
-
export type TransformTypesCallback = (err?: Error, filePaths?:
|
|
20
|
+
export type TransformTypesCallback = (err?: Error, filePaths?: TransformResult[]) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"cr": "^0.1.0",
|
|
80
80
|
"es6-map": "^0.1.5",
|
|
81
81
|
"es6-symbol": "^3.1.4",
|
|
82
|
+
"lodash.difference": "^4.5.0",
|
|
82
83
|
"object-assign": "^4.1.1",
|
|
83
84
|
"react": "^19.0.0",
|
|
84
85
|
"ts-dev-stack": "^1.5.5",
|