ts-swc-transform 1.11.2 → 1.11.4
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/index.cjs +0 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/makeReplacements.cjs +26 -26
- package/dist/cjs/lib/makeReplacements.cjs.map +1 -1
- package/dist/cjs/lib/parseSpecifiers.cjs +37 -0
- package/dist/cjs/lib/parseSpecifiers.cjs.map +1 -0
- package/dist/cjs/lib/patchCJS.cjs +4 -4
- package/dist/cjs/lib/patchCJS.cjs.map +1 -1
- package/dist/cjs/lib/patchESM.cjs +23 -20
- package/dist/cjs/lib/patchESM.cjs.map +1 -1
- package/dist/cjs/{workers → lib}/transformFile.cjs +7 -7
- package/dist/cjs/lib/transformFile.cjs.map +1 -0
- package/dist/cjs/resolveFileSync.cjs +7 -3
- package/dist/cjs/resolveFileSync.cjs.map +1 -1
- package/dist/cjs/transformDirectory.cjs +1 -1
- package/dist/cjs/transformDirectory.cjs.map +1 -1
- package/dist/cjs/transformTypes.cjs +2 -2
- package/dist/cjs/transformTypes.cjs.map +1 -1
- package/dist/cjs/workers/transformDirectory.cjs +5 -4
- package/dist/cjs/workers/transformDirectory.cjs.map +1 -1
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/makeReplacements.mjs +24 -26
- package/dist/esm/lib/makeReplacements.mjs.map +1 -1
- package/dist/esm/lib/parseSpecifiers.mjs +26 -0
- package/dist/esm/lib/parseSpecifiers.mjs.map +1 -0
- package/dist/esm/lib/patchCJS.mjs +4 -3
- package/dist/esm/lib/patchCJS.mjs.map +1 -1
- package/dist/esm/lib/patchESM.mjs +23 -19
- package/dist/esm/lib/patchESM.mjs.map +1 -1
- package/dist/esm/{workers → lib}/transformFile.mjs +7 -7
- package/dist/esm/lib/transformFile.mjs.map +1 -0
- package/dist/esm/resolveFileSync.mjs +9 -3
- package/dist/esm/resolveFileSync.mjs.map +1 -1
- package/dist/esm/transformDirectory.mjs +1 -3
- package/dist/esm/transformDirectory.mjs.map +1 -1
- package/dist/esm/transformTypes.mjs +2 -4
- package/dist/esm/transformTypes.mjs.map +1 -1
- package/dist/esm/workers/transformDirectory.mjs +5 -4
- package/dist/esm/workers/transformDirectory.mjs.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/lib/makeReplacements.d.ts +1 -1
- package/dist/types/lib/parseSpecifiers.d.ts +1 -0
- package/dist/types/lib/patchCJS.d.ts +1 -1
- package/dist/types/lib/patchESM.d.ts +1 -1
- package/dist/types/lib/transformFile.d.ts +1 -0
- package/package.json +3 -3
- package/dist/cjs/transformFile.cjs +0 -87
- package/dist/cjs/transformFile.cjs.map +0 -1
- package/dist/cjs/workers/transformFile.cjs.map +0 -1
- package/dist/esm/transformFile.mjs +0 -43
- package/dist/esm/transformFile.mjs.map +0 -1
- package/dist/esm/workers/transformFile.mjs.map +0 -1
- package/dist/types/transformFile.d.ts +0 -10
- package/dist/types/workers/transformFile.d.ts +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default function parser(code, regex) {
|
|
2
|
+
const parsed = [];
|
|
3
|
+
let offset = 0;
|
|
4
|
+
let match = regex.exec(code);
|
|
5
|
+
while(match){
|
|
6
|
+
const dependency = match[1] || match[2] || match[3] || match[4];
|
|
7
|
+
parsed.push({
|
|
8
|
+
content: code.substring(offset, match.index + match[0].lastIndexOf(dependency)),
|
|
9
|
+
isSpecifier: false
|
|
10
|
+
});
|
|
11
|
+
offset += parsed[parsed.length - 1].content.length;
|
|
12
|
+
parsed.push({
|
|
13
|
+
content: dependency,
|
|
14
|
+
isSpecifier: true
|
|
15
|
+
});
|
|
16
|
+
offset += parsed[parsed.length - 1].content.length;
|
|
17
|
+
match = regex.exec(code);
|
|
18
|
+
}
|
|
19
|
+
if (offset < code.length) {
|
|
20
|
+
parsed.push({
|
|
21
|
+
content: code.substring(offset, code.length),
|
|
22
|
+
isSpecifier: false
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/parseSpecifiers.ts"],"sourcesContent":["export default function parser(code, regex) {\n const parsed = [];\n let offset = 0;\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n parsed.push({ content: code.substring(offset, match.index + match[0].lastIndexOf(dependency)), isSpecifier: false });\n offset += parsed[parsed.length - 1].content.length;\n parsed.push({ content: dependency, isSpecifier: true });\n offset += parsed[parsed.length - 1].content.length;\n match = regex.exec(code);\n }\n\n if (offset < code.length) {\n parsed.push({ content: code.substring(offset, code.length), isSpecifier: false });\n }\n return parsed;\n}\n"],"names":["parser","code","regex","parsed","offset","match","exec","dependency","push","content","substring","index","lastIndexOf","isSpecifier","length"],"mappings":"AAAA,eAAe,SAASA,OAAOC,IAAI,EAAEC,KAAK;IACxC,MAAMC,SAAS,EAAE;IACjB,IAAIC,SAAS;IACb,IAAIC,QAAQH,MAAMI,IAAI,CAACL;IACvB,MAAOI,MAAO;QACZ,MAAME,aAAaF,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE;QAC/DF,OAAOK,IAAI,CAAC;YAAEC,SAASR,KAAKS,SAAS,CAACN,QAAQC,MAAMM,KAAK,GAAGN,KAAK,CAAC,EAAE,CAACO,WAAW,CAACL;YAAcM,aAAa;QAAM;QAClHT,UAAUD,MAAM,CAACA,OAAOW,MAAM,GAAG,EAAE,CAACL,OAAO,CAACK,MAAM;QAClDX,OAAOK,IAAI,CAAC;YAAEC,SAASF;YAAYM,aAAa;QAAK;QACrDT,UAAUD,MAAM,CAACA,OAAOW,MAAM,GAAG,EAAE,CAACL,OAAO,CAACK,MAAM;QAClDT,QAAQH,MAAMI,IAAI,CAACL;IACrB;IAEA,IAAIG,SAASH,KAAKa,MAAM,EAAE;QACxBX,OAAOK,IAAI,CAAC;YAAEC,SAASR,KAAKS,SAAS,CAACN,QAAQH,KAAKa,MAAM;YAAGD,aAAa;QAAM;IACjF;IACA,OAAOV;AACT"}
|
|
@@ -3,9 +3,10 @@ import extensions from '../extensions.mjs';
|
|
|
3
3
|
import makeReplacements from './makeReplacements.mjs';
|
|
4
4
|
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
5
5
|
const 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; }";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const DEFAULT_EXTENSION = '.cjs';
|
|
7
|
+
export default function patchCJS(entry, output, options) {
|
|
8
|
+
const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
|
|
9
|
+
output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);
|
|
9
10
|
output.code += interopClientDefaultExport;
|
|
10
11
|
return cjsExtension;
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { requireRegEx } from '../constants';\nimport extensions from '../extensions';\nimport makeReplacements from './makeReplacements';\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 patchCJS(output, options
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { requireRegEx } from '../constants';\nimport extensions from '../extensions';\nimport makeReplacements from './makeReplacements';\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\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interopClientDefaultExport;\n\n return cjsExtension;\n}\n"],"names":["requireRegEx","extensions","makeReplacements","interopClientDefaultExport","DEFAULT_EXTENSION","patchCJS","entry","output","options","cjsExtension","cjs","code"],"mappings":"AAAA,SAASA,YAAY,QAAQ,eAAe;AAC5C,OAAOC,gBAAgB,gBAAgB;AACvC,OAAOC,sBAAsB,qBAAqB;AAElD,0HAA0H;AAC1H,MAAMC,6BAA6B;AAEnC,MAAMC,oBAAoB;AAE1B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQP,UAAU,GAAGO,QAAQP,UAAU,CAACS,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FG,OAAOI,IAAI,GAAGT,iBAAiBI,OAAOC,OAAOI,IAAI,EAAEX,cAAcC,YAAYQ,cAAcD;IAC3FD,OAAOI,IAAI,IAAIR;IAEf,OAAOM;AACT"}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { importRegEx } from '../constants.mjs';
|
|
3
3
|
import makeReplacements from './makeReplacements.mjs';
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
const EXTENSIONS = {
|
|
5
|
+
cjs: [
|
|
6
|
+
'.cjs',
|
|
7
|
+
'.cts'
|
|
8
|
+
],
|
|
9
|
+
esm: [
|
|
10
|
+
'.js',
|
|
11
|
+
'.ts',
|
|
12
|
+
'.tsx',
|
|
13
|
+
'.mts',
|
|
14
|
+
'.mjs'
|
|
15
|
+
]
|
|
16
|
+
};
|
|
17
|
+
const DEFAULT_EXTENSION_CJS = '.cjs';
|
|
18
|
+
const DEFAULT_EXTENSION_EMS = '.mjs';
|
|
19
|
+
export default function patchESM(entry, output, options) {
|
|
20
|
+
const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION_CJS) || DEFAULT_EXTENSION_CJS;
|
|
21
|
+
const esmExtension = (options.extensions ? options.extensions.esm : DEFAULT_EXTENSION_EMS) || DEFAULT_EXTENSION_EMS;
|
|
22
|
+
output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.esm, esmExtension, options);
|
|
23
|
+
output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.cjs, cjsExtension, options);
|
|
24
|
+
let ext = path.extname(entry.basename);
|
|
25
|
+
if (EXTENSIONS.esm.indexOf(ext) >= 0) ext = esmExtension;
|
|
26
|
+
else if (EXTENSIONS.cjs.indexOf(ext) >= 0) ext = cjsExtension;
|
|
23
27
|
return ext;
|
|
24
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchESM.ts"],"sourcesContent":["import path from 'path';\nimport { importRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\nconst
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchESM.ts"],"sourcesContent":["import path from 'path';\nimport { importRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\nconst EXTENSIONS = {\n cjs: ['.cjs', '.cts'],\n esm: ['.js', '.ts', '.tsx', '.mts', '.mjs'],\n};\nconst DEFAULT_EXTENSION_CJS = '.cjs';\nconst DEFAULT_EXTENSION_EMS = '.mjs';\n\nexport default function patchESM(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION_CJS) || DEFAULT_EXTENSION_CJS;\n const esmExtension = (options.extensions ? options.extensions.esm : DEFAULT_EXTENSION_EMS) || DEFAULT_EXTENSION_EMS;\n\n output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.esm, esmExtension, options);\n output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.cjs, cjsExtension, options);\n\n let ext = path.extname(entry.basename);\n if (EXTENSIONS.esm.indexOf(ext) >= 0) ext = esmExtension;\n else if (EXTENSIONS.cjs.indexOf(ext) >= 0) ext = cjsExtension;\n return ext;\n}\n"],"names":["path","importRegEx","makeReplacements","EXTENSIONS","cjs","esm","DEFAULT_EXTENSION_CJS","DEFAULT_EXTENSION_EMS","patchESM","entry","output","options","cjsExtension","extensions","esmExtension","code","ext","extname","basename","indexOf"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,eAAe;AAC3C,OAAOC,sBAAsB,qBAAqB;AAElD,MAAMC,aAAa;IACjBC,KAAK;QAAC;QAAQ;KAAO;IACrBC,KAAK;QAAC;QAAO;QAAO;QAAQ;QAAQ;KAAO;AAC7C;AACA,MAAMC,wBAAwB;AAC9B,MAAMC,wBAAwB;AAE9B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACT,GAAG,GAAGE,qBAAoB,KAAMA;IAC9F,MAAMQ,eAAe,AAACH,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACR,GAAG,GAAGE,qBAAoB,KAAMA;IAE9FG,OAAOK,IAAI,GAAGb,iBAAiBO,OAAOC,OAAOK,IAAI,EAAEd,aAAaE,WAAWE,GAAG,EAAES,cAAcH;IAC9FD,OAAOK,IAAI,GAAGb,iBAAiBO,OAAOC,OAAOK,IAAI,EAAEd,aAAaE,WAAWC,GAAG,EAAEQ,cAAcD;IAE9F,IAAIK,MAAMhB,KAAKiB,OAAO,CAACR,MAAMS,QAAQ;IACrC,IAAIf,WAAWE,GAAG,CAACc,OAAO,CAACH,QAAQ,GAAGA,MAAMF;SACvC,IAAIX,WAAWC,GAAG,CAACe,OAAO,CAACH,QAAQ,GAAGA,MAAMJ;IACjD,OAAOI;AACT"}
|
|
@@ -9,7 +9,7 @@ import Module from 'module';
|
|
|
9
9
|
import lazy from 'lazy-cache';
|
|
10
10
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
11
11
|
const swcLazy = lazy(_require)('@swc/core');
|
|
12
|
-
export default function
|
|
12
|
+
export default function transformFile(entry, dest, type, options, callback) {
|
|
13
13
|
let tsconfig = options.tsconfig;
|
|
14
14
|
// overrides for cjs
|
|
15
15
|
if (type === 'cjs') {
|
|
@@ -27,13 +27,13 @@ export default function transformFileWorker(src, dest, type, options, callback)
|
|
|
27
27
|
}
|
|
28
28
|
const swcOptions = swcPrepareOptions(tsconfig);
|
|
29
29
|
const swc = swcLazy();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
filename: basename
|
|
30
|
+
swc.transformFile(entry.fullPath, {
|
|
31
|
+
...entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
|
|
32
|
+
filename: entry.basename
|
|
34
33
|
}).then((output)=>{
|
|
35
|
-
const
|
|
36
|
-
const
|
|
34
|
+
const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
|
|
35
|
+
const ext = path.extname(entry.path);
|
|
36
|
+
const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
|
|
37
37
|
mkdirp(path.dirname(outPath), ()=>{
|
|
38
38
|
const queue = new Queue();
|
|
39
39
|
queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFile(entry, dest, type, options, callback) {\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((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 !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","path","mkdirp","Queue","patchCJS","patchESM","swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","ext","extname","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,uBAAuB,2BAA2B;AAEzD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,UAAUL,KAAKC,UAAU;AAE/B,eAAe,SAASK,cAAcC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACxE,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,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,MAAMC,aAAanB,kBAAkBc;IACrC,MAAMM,MAAMb;IAEZa,IACGZ,aAAa,CAACC,MAAMY,QAAQ,EAAE;QAC7B,GAAIZ,MAAMa,QAAQ,CAACC,QAAQ,CAAC,WAAWd,MAAMa,QAAQ,CAACC,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QACzHC,UAAUjB,MAAMa,QAAQ;IAC1B,GACCK,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYlB,SAAS,QAAQZ,SAASU,OAAOmB,QAAQhB,WAAWd,SAASW,OAAOmB,QAAQhB;QAC9F,MAAMkB,MAAMnC,KAAKoC,OAAO,CAACtB,MAAMd,IAAI;QACnC,MAAMqC,UAAUrC,KAAKsC,IAAI,CAACvB,MAAM,AAACoB,CAAAA,MAAMrB,MAAMd,IAAI,CAACuC,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAI1B,MAAMd,IAAI,AAAD,IAAKkC;QAExFjC,OAAOD,KAAKyC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIxC;YAClBwC,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC7B,QAAQ8B,UAAU,IAAIL,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMmB;QAC7D;IACF,GACCc,KAAK,CAACjC;AACX"}
|
|
@@ -11,14 +11,20 @@ export default function resolveFileSync(specifier, context) {
|
|
|
11
11
|
stat = fs.statSync(filePath);
|
|
12
12
|
} catch (_err) {}
|
|
13
13
|
try {
|
|
14
|
-
if (stat
|
|
14
|
+
if (stat && stat.isDirectory() || specifier.endsWith('/')) {
|
|
15
15
|
const items = fs.readdirSync(filePath);
|
|
16
16
|
const item = items.find((x)=>indexExtensions.indexOf(x) >= 0);
|
|
17
17
|
if (item) return path.join(filePath, item);
|
|
18
18
|
} else if (!stat && !moduleRegEx.test(specifier)) {
|
|
19
|
-
const
|
|
19
|
+
const ext = path.extname(filePath);
|
|
20
|
+
const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);
|
|
20
21
|
const items = fs.readdirSync(path.dirname(filePath));
|
|
21
|
-
const item = items.find((x)=>
|
|
22
|
+
const item = items.find((x)=>{
|
|
23
|
+
if (typeFileRegEx.test(x)) return false;
|
|
24
|
+
const extTest = path.extname(x);
|
|
25
|
+
const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);
|
|
26
|
+
return basename === basenameTest;
|
|
27
|
+
});
|
|
22
28
|
if (item) return path.join(path.dirname(filePath), item);
|
|
23
29
|
}
|
|
24
30
|
// return what was found
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { moduleRegEx, typeFileRegEx } from './constants';\nimport extensions from './extensions';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { moduleRegEx, typeFileRegEx } from './constants';\nimport extensions from './extensions';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","moduleRegEx","typeFileRegEx","extensions","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","join","test","ext","extname","basename","slice","length","dirname","extTest","basenameTest"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,EAAEC,aAAa,QAAQ,cAAc;AACzD,OAAOC,gBAAgB,eAAe;AACtC,OAAOC,YAAY,WAAW;AAG9B,MAAMC,kBAAkBF,WAAWG,GAAG,CAAC,CAACC,IAAM,CAAC,KAAK,EAAEA,GAAG;AAEzD,eAAe,SAASC,gBAAgBC,SAAiB,EAAEC,OAAiB;IAC1E,MAAMC,WAAWP,OAAOK,WAAWC;IACnC,IAAIE;IACJ,IAAI;QACFA,OAAOb,GAAGc,QAAQ,CAACF;IACrB,EAAE,OAAOG,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACF,QAAQA,KAAKG,WAAW,MAAON,UAAUO,QAAQ,CAAC,MAAM;YAC3D,MAAMC,QAAQlB,GAAGmB,WAAW,CAACP;YAC7B,MAAMQ,OAAOF,MAAMG,IAAI,CAAC,CAACb,IAAMF,gBAAgBgB,OAAO,CAACd,MAAM;YAC7D,IAAIY,MAAM,OAAOnB,KAAKsB,IAAI,CAACX,UAAUQ;QACvC,OAAO,IAAI,CAACP,QAAQ,CAACX,YAAYsB,IAAI,CAACd,YAAY;YAChD,MAAMe,MAAMxB,KAAKyB,OAAO,CAACd;YACzB,MAAMe,WAAWF,MAAMxB,KAAK0B,QAAQ,CAACf,UAAUgB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAI5B,KAAK0B,QAAQ,CAACf;YACrF,MAAMM,QAAQlB,GAAGmB,WAAW,CAAClB,KAAK6B,OAAO,CAAClB;YAC1C,MAAMQ,OAAOF,MAAMG,IAAI,CAAC,CAACb;gBACvB,IAAIL,cAAcqB,IAAI,CAAChB,IAAI,OAAO;gBAClC,MAAMuB,UAAU9B,KAAKyB,OAAO,CAAClB;gBAC7B,MAAMwB,eAAeD,UAAU9B,KAAK0B,QAAQ,CAACnB,GAAGoB,KAAK,CAAC,GAAG,CAACG,QAAQF,MAAM,IAAI5B,KAAK0B,QAAQ,CAACnB;gBAC1F,OAAOmB,aAAaK;YACtB;YACA,IAAIZ,MAAM,OAAOnB,KAAKsB,IAAI,CAACtB,KAAK6B,OAAO,CAAClB,WAAWQ;QACrD;QACA,wBAAwB;QACxB,OAAOP,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
|
|
@@ -32,9 +32,7 @@ const workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers',
|
|
|
32
32
|
...options
|
|
33
33
|
};
|
|
34
34
|
if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);
|
|
35
|
-
return new Promise((resolve, reject)=>workerWrapper(version, src, dest, type, options, (err, result)=>
|
|
36
|
-
err ? reject(err) : resolve(result);
|
|
37
|
-
}));
|
|
35
|
+
return new Promise((resolve, reject)=>workerWrapper(version, src, dest, type, options, (err, result)=>err ? reject(err) : resolve(result)));
|
|
38
36
|
} catch (err) {
|
|
39
37
|
console.log(err);
|
|
40
38
|
if (callback) callback(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nimport wrapWorker from './lib/wrapWorker';\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs'));\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\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?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);\n return new Promise((resolve, reject)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nimport wrapWorker from './lib/wrapWorker';\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs'));\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\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?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);\n return new Promise((resolve, reject) => workerWrapper(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n console.log(err);\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","wrapWorker","workerWrapper","resolve","transformDirectory","src","dest","type","options","callback","Error","tsconfig","cwd","Promise","reject","err","result","console","log"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,OAAOE,gBAAgB,mBAAmB;AAC1C,MAAMC,gBAAgBD,WAAWb,KAAKe,OAAO,CAACN,WAAW,MAAM,OAAO,WAAW;AAGjF;;;;;;;CAOC,GACD,eAAe,SAASO,mBAAmBC,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAoD,EAAEC,QAAqC;IAC7K,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIK,MAAM;QAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;QAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;QAE9C,IAAI,OAAOF,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMG,WAAWrB,aAAa;YAAEsB,KAAKP;YAAK,GAAGG,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEG;YAAU,GAAGH,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOP,cAAcN,SAASS,KAAKC,MAAMC,MAAMC,SAASC;QAC5F,OAAO,IAAII,QAAQ,CAACV,SAASW,SAAWZ,cAAcN,SAASS,KAAKC,MAAMC,MAAMC,SAAS,CAACO,KAAKC,SAAYD,MAAMD,OAAOC,OAAOZ,QAAQa;IACzI,EAAE,OAAOD,KAAK;QACZE,QAAQC,GAAG,CAACH;QACZ,IAAIN,UAAUA,SAASM;aAClB,OAAOF,QAAQC,MAAM,CAACC;IAC7B;AACF"}
|
|
@@ -24,15 +24,13 @@ const workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers',
|
|
|
24
24
|
const tsconfig = loadTsConfig({
|
|
25
25
|
cwd: src,
|
|
26
26
|
...options
|
|
27
|
-
}, '
|
|
27
|
+
}, 'transformTypes');
|
|
28
28
|
options = {
|
|
29
29
|
tsconfig,
|
|
30
30
|
...options
|
|
31
31
|
};
|
|
32
32
|
if (typeof callback === 'function') return workerWrapper(version, src, dest, options, callback);
|
|
33
|
-
return new Promise((resolve, reject)=>workerWrapper(version, src, dest, options, (err, result)=>
|
|
34
|
-
err ? reject(err) : resolve(result);
|
|
35
|
-
}));
|
|
33
|
+
return new Promise((resolve, reject)=>workerWrapper(version, src, dest, options, (err, result)=>err ? reject(err) : resolve(result)));
|
|
36
34
|
} catch (err) {
|
|
37
35
|
console.log(err);
|
|
38
36
|
if (callback) callback(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nimport wrapWorker from './lib/wrapWorker';\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformTypes.cjs'));\n\nimport type { ConfigOptions, TransformTypesCallback } from './types';\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?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, '
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nimport wrapWorker from './lib/wrapWorker';\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformTypes.cjs'));\n\nimport type { ConfigOptions, TransformTypesCallback } from './types';\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?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformTypes');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return workerWrapper(version, src, dest, options, callback);\n return new Promise((resolve, reject) => workerWrapper(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n console.log(err);\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","wrapWorker","workerWrapper","resolve","transformTypes","src","dest","options","callback","Error","tsconfig","cwd","Promise","reject","err","result","console","log"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,OAAOE,gBAAgB,mBAAmB;AAC1C,MAAMC,gBAAgBD,WAAWb,KAAKe,OAAO,CAACN,WAAW,MAAM,OAAO,WAAW;AAIjF;;;;;;CAMC,GACD,eAAe,SAASO,eAAeC,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAII,MAAM;QAC7C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;QAE9C,IAAI,OAAOF,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMG,WAAWpB,aAAa;YAAEqB,KAAKN;YAAK,GAAGE,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEG;YAAU,GAAGH,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAON,cAAcN,SAASS,KAAKC,MAAMC,SAASC;QACtF,OAAO,IAAII,QAAQ,CAACT,SAASU,SAAWX,cAAcN,SAASS,KAAKC,MAAMC,SAAS,CAACO,KAAKC,SAAYD,MAAMD,OAAOC,OAAOX,QAAQY;IACnI,EAAE,OAAOD,KAAK;QACZE,QAAQC,GAAG,CAACH;QACZ,IAAIN,UAAUA,SAASM;aAClB,OAAOF,QAAQC,MAAM,CAACC;IAC7B;AACF"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import Iterator from 'fs-iterator';
|
|
3
2
|
import Queue from 'queue-cb';
|
|
4
3
|
import rimraf2 from 'rimraf2';
|
|
5
4
|
import { SKIPS, typeFileRegEx } from '../constants.mjs';
|
|
6
5
|
import createMatcher from '../createMatcher.mjs';
|
|
7
|
-
import transformFile from '
|
|
6
|
+
import transformFile from '../lib/transformFile.mjs';
|
|
8
7
|
export default function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
9
8
|
const tsconfig = options.tsconfig;
|
|
10
9
|
const matcher = createMatcher(tsconfig);
|
|
@@ -24,11 +23,13 @@ export default function transformDirectoryWorker(src, dest, type, options, callb
|
|
|
24
23
|
const results = [];
|
|
25
24
|
options = {
|
|
26
25
|
...options,
|
|
27
|
-
tsconfig
|
|
26
|
+
tsconfig,
|
|
27
|
+
src,
|
|
28
|
+
dest
|
|
28
29
|
};
|
|
29
30
|
const queue = new Queue();
|
|
30
31
|
entries.forEach((entry)=>{
|
|
31
|
-
queue.defer((cb)=>transformFile(entry
|
|
32
|
+
queue.defer((cb)=>transformFile(entry, dest, type, options, (err, outPath)=>{
|
|
32
33
|
if (err) return cb(err);
|
|
33
34
|
results.push(outPath);
|
|
34
35
|
if (options.sourceMaps) results.push(`${outPath}.map`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport transformFile from '
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { SKIPS, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport transformFile from '../lib/transformFile';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\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, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(outPath);\n if (options.sourceMaps) results.push(`${outPath}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["Iterator","Queue","rimraf2","SKIPS","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","disableGlob","entries","iterator","forEach","entry","stats","isFile","fullPath","test","basename","indexOf","push","err","results","queue","defer","cb","outPath","sourceMaps","await"],"mappings":"AACA,OAAOA,cAAc,cAAc;AACnC,OAAOC,WAAW,WAAW;AAC7B,OAAOC,aAAa,UAAU;AAE9B,SAASC,KAAK,EAAEC,aAAa,QAAQ,eAAe;AACpD,OAAOC,mBAAmB,mBAAmB;AAC7C,OAAOC,mBAAmB,uBAAuB;AAEjD,eAAe,SAASC,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUT,cAAcQ;IAE9BX,QAAQO,MAAM;QAAEM,aAAa;IAAK,GAAG;QACnC,MAAMC,UAAU,EAAE;QAClB,MAAMC,WAAW,IAAIjB,SAASQ;QAC9BS,SAASC,OAAO,CACd,CAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAI,CAACP,QAAQK,MAAMG,QAAQ,GAAG;YAC9B,IAAIlB,cAAcmB,IAAI,CAACJ,MAAMK,QAAQ,GAAG;YACxC,IAAIrB,MAAMsB,OAAO,CAACN,MAAMK,QAAQ,KAAK,GAAG;YACxCR,QAAQU,IAAI,CAACP;QACf,GACA,CAACQ;YACC,IAAIA,KAAK,OAAOf,SAASe;YACzB,MAAMC,UAAU,EAAE;YAClBjB,UAAU;gBAAE,GAAGA,OAAO;gBAAEE;gBAAUL;gBAAKC;YAAK;YAE5C,MAAMoB,QAAQ,IAAI5B;YAClBe,QAAQE,OAAO,CAAC,CAACC;gBACfU,MAAMC,KAAK,CAAC,CAACC,KACXzB,cAAca,OAAOV,MAAMC,MAAMC,SAAS,CAACgB,KAAKK;wBAC9C,IAAIL,KAAK,OAAOI,GAAGJ;wBACnBC,QAAQF,IAAI,CAACM;wBACb,IAAIrB,QAAQsB,UAAU,EAAEL,QAAQF,IAAI,CAAC,GAAGM,QAAQ,IAAI,CAAC;wBACrDD;oBACF;YAEJ;YACAF,MAAMK,KAAK,CAAC,CAACP,MAASA,MAAMf,SAASe,OAAOf,SAAS,MAAMgB;QAC7D;IAEJ;AACF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export * as constants from './constants';
|
|
|
4
4
|
export { default as extensions } from './extensions';
|
|
5
5
|
export { default as resolveFileSync } from './resolveFileSync';
|
|
6
6
|
export { default as toPath } from './toPath';
|
|
7
|
-
export { default as transformFile } from './transformFile';
|
|
8
7
|
export { default as transformDirectory } from './transformDirectory';
|
|
9
8
|
export { default as transformSync } from './transformSync';
|
|
10
9
|
export { default as transformTypes } from './transformTypes';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function makeReplacements(code: any, regex: any, extensions: any, extension: any):
|
|
1
|
+
export default function makeReplacements(entry: any, code: any, regex: any, extensions: any, extension: any, options: any): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function parser(code: any, regex: any): any[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function patchCJS(
|
|
1
|
+
export default function patchCJS(entry: any, output: any, options: any): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function patchESM(
|
|
1
|
+
export default function patchESM(entry: any, output: any, options: any): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function transformFile(entry: any, dest: any, type: any, options: any, callback: any): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.4",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"typescript",
|
|
9
9
|
"transform",
|
|
10
10
|
"transformSync",
|
|
11
|
+
"transformFile",
|
|
11
12
|
"transformDirectory",
|
|
12
13
|
"directory",
|
|
13
|
-
"transformFile",
|
|
14
14
|
"file"
|
|
15
15
|
],
|
|
16
16
|
"homepage": "https://github.com/kmalakoff/ts-swc-transform",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@swc/core": "*",
|
|
54
|
-
"cross-spawn-cb": "^
|
|
54
|
+
"cross-spawn-cb": "^2.0.0",
|
|
55
55
|
"exit": "^0.1.2",
|
|
56
56
|
"fs-iterator": "^5.2.1",
|
|
57
57
|
"get-tsconfig-compat": "^2.0.3",
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, /**
|
|
6
|
-
* @param {string} src The source directory to traverse.
|
|
7
|
-
* @param {string} dest The output directory to write files to.
|
|
8
|
-
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
9
|
-
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
10
|
-
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
11
|
-
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
12
|
-
*/ "default", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function() {
|
|
15
|
-
return transformFile;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
19
|
-
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
20
|
-
var _loadTsConfig = /*#__PURE__*/ _interop_require_default(require("./loadTsConfig.cjs"));
|
|
21
|
-
var _wrapWorker = /*#__PURE__*/ _interop_require_default(require("./lib/wrapWorker.cjs"));
|
|
22
|
-
function _define_property(obj, key, value) {
|
|
23
|
-
if (key in obj) {
|
|
24
|
-
Object.defineProperty(obj, key, {
|
|
25
|
-
value: value,
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
obj[key] = value;
|
|
32
|
-
}
|
|
33
|
-
return obj;
|
|
34
|
-
}
|
|
35
|
-
function _interop_require_default(obj) {
|
|
36
|
-
return obj && obj.__esModule ? obj : {
|
|
37
|
-
default: obj
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function _object_spread(target) {
|
|
41
|
-
for(var i = 1; i < arguments.length; i++){
|
|
42
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
43
|
-
var ownKeys = Object.keys(source);
|
|
44
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
45
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
46
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
ownKeys.forEach(function(key) {
|
|
50
|
-
_define_property(target, key, source[key]);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return target;
|
|
54
|
-
}
|
|
55
|
-
var major = +process.versions.node.split('.')[0];
|
|
56
|
-
var version = major < 14 ? 'stable' : 'local';
|
|
57
|
-
var __dirname = _path.default.dirname(typeof __filename === 'undefined' ? _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
|
|
58
|
-
var workerWrapper = (0, _wrapWorker.default)(_path.default.resolve(__dirname, '..', 'cjs', 'workers', 'transformFile.cjs'));
|
|
59
|
-
function transformFile(src, dest, type, options, callback) {
|
|
60
|
-
try {
|
|
61
|
-
if (typeof src !== 'string') throw new Error('transformFile: unexpected source');
|
|
62
|
-
if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');
|
|
63
|
-
if (typeof type !== 'string') throw new Error('transformFile: unexpected type');
|
|
64
|
-
if (typeof options === 'function') {
|
|
65
|
-
callback = options;
|
|
66
|
-
options = null;
|
|
67
|
-
}
|
|
68
|
-
options = options || {};
|
|
69
|
-
var tsconfig = (0, _loadTsConfig.default)(_object_spread({
|
|
70
|
-
cwd: src
|
|
71
|
-
}, options), 'transformFile');
|
|
72
|
-
options = _object_spread({
|
|
73
|
-
tsconfig: tsconfig
|
|
74
|
-
}, options);
|
|
75
|
-
if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);
|
|
76
|
-
return new Promise(function(resolve, reject) {
|
|
77
|
-
return workerWrapper(version, src, dest, type, options, function(err, result) {
|
|
78
|
-
err ? reject(err) : resolve(result);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
} catch (err) {
|
|
82
|
-
console.log(err);
|
|
83
|
-
if (callback) callback(err);
|
|
84
|
-
else return Promise.reject(err);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformFile.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nimport wrapWorker from './lib/wrapWorker';\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformFile.cjs'));\n\nimport type { ConfigOptions, TransformFileCallback } from './types';\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 transformFile(src: string, dest: string, type: string, options?: ConfigOptions | TransformFileCallback, callback?: TransformFileCallback): undefined | Promise<string> {\n try {\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformFileCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformFile');\n options = { tsconfig, ...options };\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?: Error, result?: string) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n console.log(err);\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformFile","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerWrapper","wrapWorker","resolve","src","dest","type","options","callback","Error","tsconfig","loadTsConfig","cwd","Promise","reject","err","result","console","log"],"mappings":";;;;+BAYA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DApBP;0DACD;mEACS;iEAKF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAHvB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AAExG,IAAMG,gBAAgBC,IAAAA,mBAAU,EAACN,aAAI,CAACO,OAAO,CAACR,WAAW,MAAM,OAAO,WAAW;AAYlE,SAASP,cAAcgB,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAA+C,EAAEC,QAAgC;IAC9J,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIK,MAAM;QAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;QAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;QAE9C,IAAI,OAAOF,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMG,WAAWC,IAAAA,qBAAY,EAAC;YAAEC,KAAKR;WAAQG,UAAW;QACxDA,UAAU;YAAEG,UAAAA;WAAaH;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOP,cAAcP,SAASU,KAAKC,MAAMC,MAAMC,SAASC;QAC5F,OAAO,IAAIK,QAAQ,SAACV,SAASW;mBAC3Bb,cAAcP,SAASU,KAAKC,MAAMC,MAAMC,SAAS,SAACQ,KAAaC;gBAC7DD,MAAMD,OAAOC,OAAOZ,QAAQa;YAC9B;;IAEJ,EAAE,OAAOD,KAAK;QACZE,QAAQC,GAAG,CAACH;QACZ,IAAIP,UAAUA,SAASO;aAClB,OAAOF,QAAQC,MAAM,CAACC;IAC7B;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFileWorker(src, dest, type, options, callback) {\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n const basename = path.basename(src);\n swc\n .transformFile(src, {\n ...(basename.endsWith('.tsx') || basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: basename,\n })\n .then((output) => {\n const ext = type === 'esm' ? patchESM(output, options, basename) : patchCJS(output, options, basename);\n const outPath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !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":["transformFileWorker","_require","require","Module","createRequire","swcLazy","lazy","src","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","basename","path","transformFile","endsWith","tsxOptions","nonTsxOptions","filename","then","output","ext","patchESM","patchCJS","outPath","join","replace","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAcA;;;eAAwBA;;;yDAdT;2DACE;oEACE;8DACD;+DAEG;+DACA;wEACS;6DAEX;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,UAAUC,IAAAA,kBAAI,EAACL,UAAU;AAEhB,SAASD,oBAAoBO,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC5E,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,0BAAiB,EAACN;IACrC,IAAMO,MAAMd;IAEZ,IAAMe,WAAWC,aAAI,CAACD,QAAQ,CAACb;IAC/BY,IACGG,aAAa,CAACf,KAAK,wCACda,SAASG,QAAQ,CAAC,WAAWH,SAASG,QAAQ,CAAC,UAAUN,WAAWO,UAAU,GAAGP,WAAWQ,aAAa;QAC7GC,UAAUN;QAEXO,IAAI,CAAC,SAACC;QACL,IAAMC,MAAMpB,SAAS,QAAQqB,IAAAA,iBAAQ,EAACF,QAAQlB,SAASU,YAAYW,IAAAA,iBAAQ,EAACH,QAAQlB,SAASU;QAC7F,IAAMY,UAAUX,aAAI,CAACY,IAAI,CAACzB,MAAMY,SAASc,OAAO,CAAC,aAAa,MAAML;QAEpEM,IAAAA,sBAAM,EAACd,aAAI,CAACe,OAAO,CAACJ,UAAU;YAC5B,IAAMK,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMV,SAASJ,OAAOe,IAAI,EAAE;YAC1D,CAACjC,QAAQkC,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARV,SAAQ,SAAOJ,OAAOiB,GAAG,EAAE;YACzFR,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMpC,SAASoC,OAAOpC,SAAS,MAAMqB;;QAC7D;IACF,GACCgB,KAAK,CAACrC;AACX"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
import loadTsConfig from './loadTsConfig.mjs';
|
|
4
|
-
const major = +process.versions.node.split('.')[0];
|
|
5
|
-
const version = major < 14 ? 'stable' : 'local';
|
|
6
|
-
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
|
-
import wrapWorker from './lib/wrapWorker.mjs';
|
|
8
|
-
const workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformFile.cjs'));
|
|
9
|
-
/**
|
|
10
|
-
* @param {string} src The source directory to traverse.
|
|
11
|
-
* @param {string} dest The output directory to write files to.
|
|
12
|
-
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
13
|
-
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
14
|
-
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
15
|
-
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
16
|
-
*/ export default function transformFile(src, dest, type, options, callback) {
|
|
17
|
-
try {
|
|
18
|
-
if (typeof src !== 'string') throw new Error('transformFile: unexpected source');
|
|
19
|
-
if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');
|
|
20
|
-
if (typeof type !== 'string') throw new Error('transformFile: unexpected type');
|
|
21
|
-
if (typeof options === 'function') {
|
|
22
|
-
callback = options;
|
|
23
|
-
options = null;
|
|
24
|
-
}
|
|
25
|
-
options = options || {};
|
|
26
|
-
const tsconfig = loadTsConfig({
|
|
27
|
-
cwd: src,
|
|
28
|
-
...options
|
|
29
|
-
}, 'transformFile');
|
|
30
|
-
options = {
|
|
31
|
-
tsconfig,
|
|
32
|
-
...options
|
|
33
|
-
};
|
|
34
|
-
if (typeof callback === 'function') return workerWrapper(version, src, dest, type, options, callback);
|
|
35
|
-
return new Promise((resolve, reject)=>workerWrapper(version, src, dest, type, options, (err, result)=>{
|
|
36
|
-
err ? reject(err) : resolve(result);
|
|
37
|
-
}));
|
|
38
|
-
} catch (err) {
|
|
39
|
-
console.log(err);
|
|
40
|
-
if (callback) callback(err);
|
|
41
|
-
else return Promise.reject(err);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformFile.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nimport wrapWorker from './lib/wrapWorker';\nconst workerWrapper = wrapWorker(path.resolve(__dirname, '..', 'cjs', 'workers', 'transformFile.cjs'));\n\nimport type { ConfigOptions, TransformFileCallback } from './types';\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 transformFile(src: string, dest: string, type: string, options?: ConfigOptions | TransformFileCallback, callback?: TransformFileCallback): undefined | Promise<string> {\n try {\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformFileCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformFile');\n options = { tsconfig, ...options };\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?: Error, result?: string) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n console.log(err);\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","wrapWorker","workerWrapper","resolve","transformFile","src","dest","type","options","callback","Error","tsconfig","cwd","Promise","reject","err","result","console","log"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,OAAOE,gBAAgB,mBAAmB;AAC1C,MAAMC,gBAAgBD,WAAWb,KAAKe,OAAO,CAACN,WAAW,MAAM,OAAO,WAAW;AAIjF;;;;;;;CAOC,GACD,eAAe,SAASO,cAAcC,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAA+C,EAAEC,QAAgC;IAC9J,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIK,MAAM;QAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;QAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;QAE9C,IAAI,OAAOF,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMG,WAAWrB,aAAa;YAAEsB,KAAKP;YAAK,GAAGG,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEG;YAAU,GAAGH,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOP,cAAcN,SAASS,KAAKC,MAAMC,MAAMC,SAASC;QAC5F,OAAO,IAAII,QAAQ,CAACV,SAASW,SAC3BZ,cAAcN,SAASS,KAAKC,MAAMC,MAAMC,SAAS,CAACO,KAAaC;gBAC7DD,MAAMD,OAAOC,OAAOZ,QAAQa;YAC9B;IAEJ,EAAE,OAAOD,KAAK;QACZE,QAAQC,GAAG,CAACH;QACZ,IAAIN,UAAUA,SAASM;aAClB,OAAOF,QAAQC,MAAM,CAACC;IAC7B;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFileWorker(src, dest, type, options, callback) {\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n const basename = path.basename(src);\n swc\n .transformFile(src, {\n ...(basename.endsWith('.tsx') || basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: basename,\n })\n .then((output) => {\n const ext = type === 'esm' ? patchESM(output, options, basename) : patchCJS(output, options, basename);\n const outPath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !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","path","mkdirp","Queue","patchCJS","patchESM","swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","transformFileWorker","src","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","basename","transformFile","endsWith","tsxOptions","nonTsxOptions","filename","then","output","ext","outPath","join","replace","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,uBAAuB,2BAA2B;AAEzD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,UAAUL,KAAKC,UAAU;AAE/B,eAAe,SAASK,oBAAoBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC5E,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,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,MAAMC,aAAanB,kBAAkBc;IACrC,MAAMM,MAAMb;IAEZ,MAAMc,WAAW1B,KAAK0B,QAAQ,CAACZ;IAC/BW,IACGE,aAAa,CAACb,KAAK;QAClB,GAAIY,SAASE,QAAQ,CAAC,WAAWF,SAASE,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUL;IACZ,GACCM,IAAI,CAAC,CAACC;QACL,MAAMC,MAAMlB,SAAS,QAAQZ,SAAS6B,QAAQhB,SAASS,YAAYvB,SAAS8B,QAAQhB,SAASS;QAC7F,MAAMS,UAAUnC,KAAKoC,IAAI,CAACrB,MAAMW,SAASW,OAAO,CAAC,aAAa,MAAMH;QAEpEjC,OAAOD,KAAKsC,OAAO,CAACH,UAAU;YAC5B,MAAMI,QAAQ,IAAIrC;YAClBqC,MAAMC,KAAK,CAACzC,GAAG0C,SAAS,CAACC,IAAI,CAAC,MAAMP,SAASF,OAAOU,IAAI,EAAE;YAC1D,CAAC1B,QAAQ2B,UAAU,IAAIL,MAAMC,KAAK,CAACzC,GAAG0C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGP,QAAQ,IAAI,CAAC,EAAEF,OAAOY,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAM7B,SAAS6B,OAAO7B,SAAS,MAAMiB;QAC7D;IACF,GACCa,KAAK,CAAC9B;AACX"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ConfigOptions, TransformFileCallback } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* @param {string} src The source directory to traverse.
|
|
4
|
-
* @param {string} dest The output directory to write files to.
|
|
5
|
-
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
6
|
-
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
7
|
-
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
8
|
-
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
9
|
-
*/
|
|
10
|
-
export default function transformFile(src: string, dest: string, type: string, options?: ConfigOptions | TransformFileCallback, callback?: TransformFileCallback): undefined | Promise<string>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function transformFileWorker(src: any, dest: any, type: any, options: any, callback: any): void;
|