ts-swc-transform 2.0.18 → 2.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/makeReplacements.d.cts +3 -0
- package/dist/cjs/lib/makeReplacements.d.ts +3 -0
- package/dist/cjs/lib/makeReplacements.js +47 -0
- package/dist/cjs/lib/makeReplacements.js.map +1 -0
- package/dist/cjs/lib/parseSpecifiers.d.cts +5 -0
- package/dist/cjs/lib/parseSpecifiers.d.ts +5 -0
- package/dist/cjs/lib/parseSpecifiers.js +37 -0
- package/dist/cjs/lib/parseSpecifiers.js.map +1 -0
- package/dist/cjs/lib/patchCJS.d.cts +4 -1
- package/dist/cjs/lib/patchCJS.d.ts +4 -1
- package/dist/cjs/lib/patchCJS.js +10 -8
- package/dist/cjs/lib/patchCJS.js.map +1 -1
- package/dist/cjs/lib/patchESM.d.cts +4 -1
- package/dist/cjs/lib/patchESM.d.ts +4 -1
- package/dist/cjs/lib/patchESM.js +28 -6
- package/dist/cjs/lib/patchESM.js.map +1 -1
- package/dist/cjs/lib/swcPrepareOptions.d.cts +6 -1
- package/dist/cjs/lib/swcPrepareOptions.d.ts +6 -1
- package/dist/cjs/lib/swcPrepareOptions.js.map +1 -1
- package/dist/cjs/lib/transformFile.d.cts +3 -1
- package/dist/cjs/lib/transformFile.d.ts +3 -1
- package/dist/cjs/lib/transformFile.js.map +1 -1
- package/dist/cjs/loadTsConfig.js.map +1 -1
- package/dist/cjs/resolveFileSync.d.cts +1 -1
- package/dist/cjs/resolveFileSync.d.ts +1 -1
- package/dist/cjs/resolveFileSync.js.map +1 -1
- package/dist/cjs/toPath.d.cts +1 -1
- package/dist/cjs/toPath.d.ts +1 -1
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/cjs/transformDirectory.d.cts +2 -2
- package/dist/cjs/transformDirectory.d.ts +2 -2
- package/dist/cjs/transformDirectory.js +1 -1
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/types.d.cts +10 -0
- package/dist/cjs/types.d.ts +10 -0
- package/dist/cjs/workers/transformDirectory.d.cts +2 -1
- package/dist/cjs/workers/transformDirectory.d.ts +2 -1
- package/dist/cjs/workers/transformDirectory.js +4 -1
- package/dist/cjs/workers/transformDirectory.js.map +1 -1
- package/dist/cjs/workers/transformSync.d.cts +2 -1
- package/dist/cjs/workers/transformSync.d.ts +2 -1
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/cjs/workers/transformTypes.d.cts +2 -1
- package/dist/cjs/workers/transformTypes.d.ts +2 -1
- package/dist/cjs/workers/transformTypes.js +6 -2
- package/dist/cjs/workers/transformTypes.js.map +1 -1
- package/dist/esm/lib/makeReplacements.d.ts +3 -0
- package/dist/esm/lib/makeReplacements.js +29 -0
- package/dist/esm/lib/makeReplacements.js.map +1 -0
- package/dist/esm/lib/parseSpecifiers.d.ts +5 -0
- package/dist/esm/lib/parseSpecifiers.js +26 -0
- package/dist/esm/lib/parseSpecifiers.js.map +1 -0
- package/dist/esm/lib/patchCJS.d.ts +4 -1
- package/dist/esm/lib/patchCJS.js +10 -8
- package/dist/esm/lib/patchCJS.js.map +1 -1
- package/dist/esm/lib/patchESM.d.ts +4 -1
- package/dist/esm/lib/patchESM.js +29 -7
- package/dist/esm/lib/patchESM.js.map +1 -1
- package/dist/esm/lib/swcPrepareOptions.d.ts +6 -1
- package/dist/esm/lib/swcPrepareOptions.js.map +1 -1
- package/dist/esm/lib/transformFile.d.ts +3 -1
- package/dist/esm/lib/transformFile.js.map +1 -1
- package/dist/esm/loadTsConfig.js.map +1 -1
- package/dist/esm/resolveFileSync.d.ts +1 -1
- package/dist/esm/resolveFileSync.js.map +1 -1
- package/dist/esm/toPath.d.ts +1 -1
- package/dist/esm/toPath.js.map +1 -1
- package/dist/esm/transformDirectory.d.ts +2 -2
- package/dist/esm/transformDirectory.js +3 -1
- package/dist/esm/transformDirectory.js.map +1 -1
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/workers/transformDirectory.d.ts +2 -1
- package/dist/esm/workers/transformDirectory.js +4 -1
- package/dist/esm/workers/transformDirectory.js.map +1 -1
- package/dist/esm/workers/transformSync.d.ts +2 -1
- package/dist/esm/workers/transformSync.js.map +1 -1
- package/dist/esm/workers/transformTypes.d.ts +2 -1
- package/dist/esm/workers/transformTypes.js +6 -2
- package/dist/esm/workers/transformTypes.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return makeReplacements;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
var _lodashfind = /*#__PURE__*/ _interop_require_default(require("lodash.find"));
|
|
13
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
+
var _constants = require("../constants");
|
|
15
|
+
var _parseSpecifiers = /*#__PURE__*/ _interop_require_default(require("./parseSpecifiers"));
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function makeReplacements(entry, code, regex, extensions, extension, options) {
|
|
22
|
+
var src = options.src;
|
|
23
|
+
var parsed = (0, _parseSpecifiers.default)(code, regex);
|
|
24
|
+
return parsed.map(function(parsed) {
|
|
25
|
+
if (!parsed.isSpecifier) return parsed.content;
|
|
26
|
+
var specifier = parsed.content;
|
|
27
|
+
if (_constants.moduleRegEx.test(specifier)) return specifier;
|
|
28
|
+
var ext = _path.default.extname(specifier);
|
|
29
|
+
if (ext && extensions.indexOf(ext) < 0) return specifier;
|
|
30
|
+
if (!ext) {
|
|
31
|
+
try {
|
|
32
|
+
var basename = _path.default.basename(specifier);
|
|
33
|
+
var fullPath = _path.default.join(src, _path.default.dirname(entry.path), specifier);
|
|
34
|
+
var files = _fs.default.readdirSync(_path.default.dirname(fullPath), {
|
|
35
|
+
withFileTypes: true
|
|
36
|
+
});
|
|
37
|
+
var found = (0, _lodashfind.default)(files, function(x) {
|
|
38
|
+
return x.name === basename;
|
|
39
|
+
});
|
|
40
|
+
if (found && found.isDirectory()) return specifier;
|
|
41
|
+
} catch (_err) {}
|
|
42
|
+
}
|
|
43
|
+
var stripped = ext ? specifier.slice(0, -ext.length) : specifier;
|
|
44
|
+
return "".concat(stripped).concat(extension);
|
|
45
|
+
}).join('');
|
|
46
|
+
}
|
|
47
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/makeReplacements.ts"],"sourcesContent":["import fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport find from 'lodash.find';\nimport path from 'path';\nimport { moduleRegEx } from '../constants';\nimport type { ConfigOptionsInternal } from '../types.js';\nimport parseSpecifiers from './parseSpecifiers';\n\nexport default function makeReplacements(entry: Entry, code: string, regex: RegExp, extensions: string[], extension: string, options: ConfigOptionsInternal): string {\n const { src } = options;\n const parsed = parseSpecifiers(code, regex);\n\n return parsed\n .map((parsed) => {\n if (!parsed.isSpecifier) return parsed.content;\n const specifier = parsed.content;\n if (moduleRegEx.test(specifier)) return specifier;\n\n const ext = path.extname(specifier);\n if (ext && extensions.indexOf(ext) < 0) return specifier;\n if (!ext) {\n try {\n const basename = path.basename(specifier);\n const fullPath = path.join(src, path.dirname(entry.path), specifier);\n const files = fs.readdirSync(path.dirname(fullPath), { withFileTypes: true });\n const found = find(files, (x) => x.name === basename);\n if (found && found.isDirectory()) return specifier;\n } catch (_err) {}\n }\n const stripped = ext ? specifier.slice(0, -ext.length) : specifier;\n return `${stripped}${extension}`;\n })\n .join('');\n}\n"],"names":["makeReplacements","entry","code","regex","extensions","extension","options","src","parsed","parseSpecifiers","map","isSpecifier","content","specifier","moduleRegEx","test","ext","path","extname","indexOf","basename","fullPath","join","dirname","files","fs","readdirSync","withFileTypes","found","find","x","name","isDirectory","_err","stripped","slice","length"],"mappings":";;;;+BAQA;;;eAAwBA;;;yDART;iEAEE;2DACA;yBACW;sEAEA;;;;;;AAEb,SAASA,iBAAiBC,KAAY,EAAEC,IAAY,EAAEC,KAAa,EAAEC,UAAoB,EAAEC,SAAiB,EAAEC,OAA8B;IACzJ,IAAM,AAAEC,MAAQD,QAARC;IACR,IAAMC,SAASC,IAAAA,wBAAe,EAACP,MAAMC;IAErC,OAAOK,OACJE,GAAG,CAAC,SAACF;QACJ,IAAI,CAACA,OAAOG,WAAW,EAAE,OAAOH,OAAOI,OAAO;QAC9C,IAAMC,YAAYL,OAAOI,OAAO;QAChC,IAAIE,sBAAW,CAACC,IAAI,CAACF,YAAY,OAAOA;QAExC,IAAMG,MAAMC,aAAI,CAACC,OAAO,CAACL;QACzB,IAAIG,OAAOZ,WAAWe,OAAO,CAACH,OAAO,GAAG,OAAOH;QAC/C,IAAI,CAACG,KAAK;YACR,IAAI;gBACF,IAAMI,WAAWH,aAAI,CAACG,QAAQ,CAACP;gBAC/B,IAAMQ,WAAWJ,aAAI,CAACK,IAAI,CAACf,KAAKU,aAAI,CAACM,OAAO,CAACtB,MAAMgB,IAAI,GAAGJ;gBAC1D,IAAMW,QAAQC,WAAE,CAACC,WAAW,CAACT,aAAI,CAACM,OAAO,CAACF,WAAW;oBAAEM,eAAe;gBAAK;gBAC3E,IAAMC,QAAQC,IAAAA,mBAAI,EAACL,OAAO,SAACM;2BAAMA,EAAEC,IAAI,KAAKX;;gBAC5C,IAAIQ,SAASA,MAAMI,WAAW,IAAI,OAAOnB;YAC3C,EAAE,OAAOoB,MAAM,CAAC;QAClB;QACA,IAAMC,WAAWlB,MAAMH,UAAUsB,KAAK,CAAC,GAAG,CAACnB,IAAIoB,MAAM,IAAIvB;QACzD,OAAO,AAAC,GAAaR,OAAX6B,UAAqB,OAAV7B;IACvB,GACCiB,IAAI,CAAC;AACV"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parser;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function parser(code, regex) {
|
|
12
|
+
var parsed = [];
|
|
13
|
+
var offset = 0;
|
|
14
|
+
var match = regex.exec(code);
|
|
15
|
+
while(match){
|
|
16
|
+
var dependency = match[1] || match[2] || match[3] || match[4];
|
|
17
|
+
parsed.push({
|
|
18
|
+
content: code.substring(offset, match.index + match[0].lastIndexOf(dependency)),
|
|
19
|
+
isSpecifier: false
|
|
20
|
+
});
|
|
21
|
+
offset += parsed[parsed.length - 1].content.length;
|
|
22
|
+
parsed.push({
|
|
23
|
+
content: dependency,
|
|
24
|
+
isSpecifier: true
|
|
25
|
+
});
|
|
26
|
+
offset += parsed[parsed.length - 1].content.length;
|
|
27
|
+
match = regex.exec(code);
|
|
28
|
+
}
|
|
29
|
+
if (offset < code.length) {
|
|
30
|
+
parsed.push({
|
|
31
|
+
content: code.substring(offset, code.length),
|
|
32
|
+
isSpecifier: false
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/parseSpecifiers.ts"],"sourcesContent":["export interface Parsed {\n content: string;\n isSpecifier: boolean;\n}\n\nexport default function parser(code: string, regex: RegExp): Parsed[] {\n const parsed: 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":";;;;+BAKA;;;eAAwBA;;;AAAT,SAASA,OAAOC,IAAY,EAAEC,KAAa;IACxD,IAAMC,SAAmB,EAAE;IAC3B,IAAIC,SAAS;IACb,IAAIC,QAAQH,MAAMI,IAAI,CAACL;IACvB,MAAOI,MAAO;QACZ,IAAME,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"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
2
|
-
|
|
2
|
+
import type { Output } from '@swc/core';
|
|
3
|
+
import type { Entry } from 'fs-iterator';
|
|
4
|
+
import type { ConfigOptionsInternal } from '../types.js';
|
|
5
|
+
export default function patchCJS(entry: Entry, output: Output, options: ConfigOptionsInternal): string;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
2
|
-
|
|
2
|
+
import type { Output } from '@swc/core';
|
|
3
|
+
import type { Entry } from 'fs-iterator';
|
|
4
|
+
import type { ConfigOptionsInternal } from '../types.js';
|
|
5
|
+
export default function patchCJS(entry: Entry, output: Output, options: ConfigOptionsInternal): string;
|
package/dist/cjs/lib/patchCJS.js
CHANGED
|
@@ -16,20 +16,22 @@ _export(exports, {
|
|
|
16
16
|
return interop;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
var
|
|
19
|
+
var _constants = require("../constants");
|
|
20
|
+
var _makeReplacements = /*#__PURE__*/ _interop_require_default(require("./makeReplacements"));
|
|
20
21
|
function _interop_require_default(obj) {
|
|
21
22
|
return obj && obj.__esModule ? obj : {
|
|
22
23
|
default: obj
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
var interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
var DEFAULT_EXTENSION = '.js';
|
|
28
|
+
function patchCJS(entry, output, options) {
|
|
29
|
+
var cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
|
|
30
|
+
var rewrite = (options.tsconfig.config.compilerOptions || {}).rewriteRelativeImportExtensions;
|
|
31
|
+
if (rewrite) {
|
|
32
|
+
output.code = (0, _makeReplacements.default)(entry, output.code, _constants.requireRegEx, _constants.extensions, cjsExtension, options);
|
|
33
|
+
}
|
|
31
34
|
output.code += interop;
|
|
32
|
-
|
|
33
|
-
return EXTENSIONS.indexOf(ext) >= 0 ? '.js' : ext;
|
|
35
|
+
return cjsExtension;
|
|
34
36
|
}
|
|
35
37
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\nconst DEFAULT_EXTENSION = '.js';\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptionsInternal } from '../types.js';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptionsInternal): string {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) {\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n }\n output.code += interop;\n\n return cjsExtension;\n}\n"],"names":["patchCJS","interop","DEFAULT_EXTENSION","entry","output","options","cjsExtension","extensions","cjs","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","makeReplacements","requireRegEx"],"mappings":";;;;;;;;;;;QAgBA;eAAwBA;;QAZXC;eAAAA;;;yBAJ4B;uEACZ;;;;;;AAGtB,IAAMA,UAAU;AACvB,IAAMC,oBAAoB;AAWX,SAASF,SAASG,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,IAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACC,GAAG,GAAGN,iBAAgB,KAAMA;IAC1F,IAAMO,UAAU,AAAEJ,CAAAA,QAAQK,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAAS;QACXL,OAAOU,IAAI,GAAGC,IAAAA,yBAAgB,EAACZ,OAAOC,OAAOU,IAAI,EAAEE,uBAAY,EAAET,qBAAU,EAAED,cAAcD;IAC7F;IACAD,OAAOU,IAAI,IAAIb;IAEf,OAAOK;AACT"}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Output } from '@swc/core';
|
|
2
|
+
import type { Entry } from 'fs-iterator';
|
|
3
|
+
import type { ConfigOptionsInternal } from '../types.js';
|
|
4
|
+
export default function patchESM(entry: Entry, output: Output, options: ConfigOptionsInternal): string;
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Output } from '@swc/core';
|
|
2
|
+
import type { Entry } from 'fs-iterator';
|
|
3
|
+
import type { ConfigOptionsInternal } from '../types.js';
|
|
4
|
+
export default function patchESM(entry: Entry, output: Output, options: ConfigOptionsInternal): string;
|
package/dist/cjs/lib/patchESM.js
CHANGED
|
@@ -9,17 +9,39 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
|
+
var _constants = require("../constants");
|
|
13
|
+
var _makeReplacements = /*#__PURE__*/ _interop_require_default(require("./makeReplacements"));
|
|
12
14
|
function _interop_require_default(obj) {
|
|
13
15
|
return obj && obj.__esModule ? obj : {
|
|
14
16
|
default: obj
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
|
-
var EXTENSIONS =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
var EXTENSIONS = {
|
|
20
|
+
cjs: [
|
|
21
|
+
'.cjs',
|
|
22
|
+
'.cts'
|
|
23
|
+
],
|
|
24
|
+
esm: [
|
|
25
|
+
'.js',
|
|
26
|
+
'.ts',
|
|
27
|
+
'.tsx',
|
|
28
|
+
'.mts',
|
|
29
|
+
'.mjs'
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
var DEFAULT_EXTENSION_CJS = '.cjs';
|
|
33
|
+
var DEFAULT_EXTENSION_EMS = '.js';
|
|
34
|
+
function patchESM(entry, output, options) {
|
|
35
|
+
var cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION_CJS) || DEFAULT_EXTENSION_CJS;
|
|
36
|
+
var esmExtension = (options.extensions ? options.extensions.esm : DEFAULT_EXTENSION_EMS) || DEFAULT_EXTENSION_EMS;
|
|
37
|
+
var rewrite = (options.tsconfig.config.compilerOptions || {}).rewriteRelativeImportExtensions;
|
|
38
|
+
if (rewrite) {
|
|
39
|
+
output.code = (0, _makeReplacements.default)(entry, output.code, _constants.importRegEx, EXTENSIONS.esm, esmExtension, options);
|
|
40
|
+
output.code = (0, _makeReplacements.default)(entry, output.code, _constants.importRegEx, EXTENSIONS.cjs, cjsExtension, options);
|
|
41
|
+
}
|
|
22
42
|
var ext = _path.default.extname(entry.basename);
|
|
23
|
-
|
|
43
|
+
if (EXTENSIONS.esm.indexOf(ext) >= 0) ext = esmExtension;
|
|
44
|
+
else if (EXTENSIONS.cjs.indexOf(ext) >= 0) ext = cjsExtension;
|
|
45
|
+
return ext;
|
|
24
46
|
}
|
|
25
47
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchESM.ts"],"sourcesContent":["import path from 'path';\n\nconst EXTENSIONS = ['.ts', '.tsx'];\n\nexport default function patchESM(entry,
|
|
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 = '.js';\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptionsInternal } from '../types.js';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchESM(entry: Entry, output: Output, options: ConfigOptionsInternal): string {\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 const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) {\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\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":["patchESM","EXTENSIONS","cjs","esm","DEFAULT_EXTENSION_CJS","DEFAULT_EXTENSION_EMS","entry","output","options","cjsExtension","extensions","esmExtension","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","makeReplacements","importRegEx","ext","path","extname","basename","indexOf"],"mappings":";;;;+BAoBA;;;eAAwBA;;;2DApBP;yBACW;uEACC;;;;;;AAE7B,IAAMC,aAAa;IACjBC,KAAK;QAAC;QAAQ;KAAO;IACrBC,KAAK;QAAC;QAAO;QAAO;QAAQ;QAAQ;KAAO;AAC7C;AACA,IAAMC,wBAAwB;AAC9B,IAAMC,wBAAwB;AAWf,SAASL,SAASM,KAAY,EAAEC,MAAc,EAAEC,OAA8B;IAC3F,IAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACR,GAAG,GAAGE,qBAAoB,KAAMA;IAC9F,IAAMO,eAAe,AAACH,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACP,GAAG,GAAGE,qBAAoB,KAAMA;IAE9F,IAAMO,UAAU,AAAEJ,CAAAA,QAAQK,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAAS;QACXL,OAAOU,IAAI,GAAGC,IAAAA,yBAAgB,EAACZ,OAAOC,OAAOU,IAAI,EAAEE,sBAAW,EAAElB,WAAWE,GAAG,EAAEQ,cAAcH;QAC9FD,OAAOU,IAAI,GAAGC,IAAAA,yBAAgB,EAACZ,OAAOC,OAAOU,IAAI,EAAEE,sBAAW,EAAElB,WAAWC,GAAG,EAAEO,cAAcD;IAChG;IAEA,IAAIY,MAAMC,aAAI,CAACC,OAAO,CAAChB,MAAMiB,QAAQ;IACrC,IAAItB,WAAWE,GAAG,CAACqB,OAAO,CAACJ,QAAQ,GAAGA,MAAMT;SACvC,IAAIV,WAAWC,GAAG,CAACsB,OAAO,CAACJ,QAAQ,GAAGA,MAAMX;IACjD,OAAOW;AACT"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import type { Options } from '@swc/core';
|
|
1
2
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
2
|
-
export
|
|
3
|
+
export interface TranspilerOptions {
|
|
4
|
+
tsxOptions: Options;
|
|
5
|
+
nonTsxOptions: Options;
|
|
6
|
+
}
|
|
7
|
+
export default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import type { Options } from '@swc/core';
|
|
1
2
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
2
|
-
export
|
|
3
|
+
export interface TranspilerOptions {
|
|
4
|
+
tsxOptions: Options;
|
|
5
|
+
nonTsxOptions: Options;
|
|
6
|
+
}
|
|
7
|
+
export default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import { installSync } from 'install-optional';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","tsconfig","installSync","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import type { Options } from '@swc/core';\nimport { installSync } from 'install-optional';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport interface TranspilerOptions {\n tsxOptions: Options;\n nonTsxOptions: Options;\n}\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult): TranspilerOptions {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {} as TranspilerOptions;\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","tsconfig","installSync","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAgBA;;;eAAwBA;;;+BAfI;6DACT;2DACF;0DACD;;;;;;AAEhB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AASnF,SAASV,kBAAkBW,QAAwB;IAChEC,IAAAA,4BAAW,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI,GAAI;QAAEC,KAAKX;IAAU;IACjF,IAAI;QACF,IAAMY,KAAKhB,SAAS;QACpB,IAAMiB,MAAMjB,SAAS;QACrB,IAAMkB,aAAalB,SAAS;QAC5B,IAAMmB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEjB,aAAI,CAACC,OAAO,CAACI,SAASL,IAAI;QAChG,OAAOa,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Entry } from 'fs-iterator';
|
|
2
|
+
import type { ConfigOptionsInternal, TargetType, TransformFileCallback } from '../types.js';
|
|
3
|
+
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptionsInternal, callback: TransformFileCallback): undefined;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Entry } from 'fs-iterator';
|
|
2
|
+
import type { ConfigOptionsInternal, TargetType, TransformFileCallback } from '../types.js';
|
|
3
|
+
export default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptionsInternal, callback: TransformFileCallback): undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.js';\nimport patchESM from '../lib/patchESM.js';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\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 = _require('@swc/core');\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":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.js';\nimport patchESM from '../lib/patchESM.js';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptionsInternal, TargetType, TransformFileCallback } from '../types.js';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptionsInternal, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\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: 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":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;+DACG;+DACA;wEACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAASF,cAAcK,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAA8B,EAAEC,QAA+B;IACjJ,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,MAAMhB,SAAS;IAErBgB,IACGjB,aAAa,CAACK,MAAMa,QAAQ,EAAE,wCACzBb,MAAMc,QAAQ,CAACC,QAAQ,CAAC,WAAWf,MAAMc,QAAQ,CAACC,QAAQ,CAAC,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QACzHC,UAAUlB,MAAMc,QAAQ;QAEzBK,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYnB,SAAS,QAAQoB,IAAAA,iBAAQ,EAACtB,OAAOoB,QAAQjB,WAAWoB,IAAAA,iBAAQ,EAACvB,OAAOoB,QAAQjB;QAC9F,IAAMqB,MAAMC,aAAI,CAACC,OAAO,CAAC1B,MAAMyB,IAAI;QACnC,IAAME,UAAUF,aAAI,CAACG,IAAI,CAAC3B,MAAM,AAACuB,CAAAA,MAAMxB,MAAMyB,IAAI,CAACI,KAAK,CAAC,GAAG,CAACL,IAAIM,MAAM,IAAI9B,MAAMyB,IAAI,AAAD,IAAKJ;QAExFU,IAAAA,sBAAM,EAACN,aAAI,CAACO,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASP,OAAOmB,IAAI,EAAE;YAC1D,CAACpC,QAAQqC,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOP,OAAOqB,GAAG,EAAE;YACzFR,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMvC,SAASuC,OAAOvC,SAAS,MAAMuB;;QAC7D;IACF,GACCiB,KAAK,CAACxC;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/loadTsConfig.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport type { ConfigOptions } from './types.js';\n\nexport default function loadTsConfig(options: ConfigOptions, name: string) {\n let tsconfig = options.tsconfig;\n if (!tsconfig) tsconfig = getTS.getTsconfig(options.cwd || process.cwd());\n\n if (typeof tsconfig !== 'object') throw new Error(`${name}: missing valid tsconfig`);\n if (tsconfig.path === undefined) throw new Error(`${name}: expecting tsconfig.path`);\n if (tsconfig.config === undefined) throw new Error(`${name}: expecting tsconfig.config`);\n return tsconfig;\n}\n"],"names":["loadTsConfig","options","name","tsconfig","getTS","getTsconfig","cwd","process","Error","path","undefined","config"],"mappings":";;;;+BAGA;;;eAAwBA;;;yEAHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGR,SAASA,aAAaC,OAAsB,EAAEC,IAAY;IACvE,IAAIC,WAAWF,QAAQE,QAAQ;IAC/B,IAAI,CAACA,UAAUA,WAAWC,mBAAMC,WAAW,CAACJ,QAAQK,GAAG,IAAIC,QAAQD,GAAG;IAEtE,IAAI,CAAA,OAAOH,yCAAP,SAAOA,SAAO,MAAM,UAAU,MAAM,IAAIK,MAAM,AAAC,GAAO,OAALN,MAAK;IAC1D,IAAIC,SAASM,IAAI,KAAKC,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IACzD,IAAIC,SAASQ,MAAM,KAAKD,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IAC3D,OAAOC;AACT"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/loadTsConfig.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport type { ConfigOptions } from './types.js';\n\nexport default function loadTsConfig(options: ConfigOptions, name: string): getTS.TsConfigResult {\n let tsconfig = options.tsconfig;\n if (!tsconfig) tsconfig = getTS.getTsconfig(options.cwd || process.cwd());\n\n if (typeof tsconfig !== 'object') throw new Error(`${name}: missing valid tsconfig`);\n if (tsconfig.path === undefined) throw new Error(`${name}: expecting tsconfig.path`);\n if (tsconfig.config === undefined) throw new Error(`${name}: expecting tsconfig.config`);\n return tsconfig;\n}\n"],"names":["loadTsConfig","options","name","tsconfig","getTS","getTsconfig","cwd","process","Error","path","undefined","config"],"mappings":";;;;+BAGA;;;eAAwBA;;;yEAHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGR,SAASA,aAAaC,OAAsB,EAAEC,IAAY;IACvE,IAAIC,WAAWF,QAAQE,QAAQ;IAC/B,IAAI,CAACA,UAAUA,WAAWC,mBAAMC,WAAW,CAACJ,QAAQK,GAAG,IAAIC,QAAQD,GAAG;IAEtE,IAAI,CAAA,OAAOH,yCAAP,SAAOA,SAAO,MAAM,UAAU,MAAM,IAAIK,MAAM,AAAC,GAAO,OAALN,MAAK;IAC1D,IAAIC,SAASM,IAAI,KAAKC,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IACzD,IAAIC,SAASQ,MAAM,KAAKD,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IAC3D,OAAOC;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Context } from './types.js';
|
|
2
|
-
export default function resolveFileSync(specifier: string, context?: Context):
|
|
2
|
+
export default function resolveFileSync(specifier: string, context?: Context): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Context } from './types.js';
|
|
2
|
-
export default function resolveFileSync(specifier: string, context?: Context):
|
|
2
|
+
export default function resolveFileSync(specifier: string, context?: Context): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport find from 'lodash.find';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.js';\nimport toPath from './toPath.js';\nimport type { Context } from './types.js';\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 = find(items, (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 = find(items, (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":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","length","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;iEACE;2DACA;yBACsC;6DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,qBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,UAAUS,QAAQ,CAAC,MAAM;YAC3D,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOC,IAAAA,mBAAI,EAACH,OAAO,SAACX;uBAAMH,gBAAgBkB,OAAO,CAACf,MAAM;;YAC9D,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,sBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACS,OAAO,CAACtB;YAC1C,IAAMU,QAAOC,IAAAA,mBAAI,EAACH,QAAO,SAACX;gBACxB,IAAI0B,wBAAa,CAACP,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM2B,UAAUX,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM4B,eAAeD,UAAUX,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACI,QAAQH,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaM;YACtB;YACA,IAAIf,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACS,OAAO,CAACtB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport find from 'lodash.find';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.js';\nimport toPath from './toPath.js';\nimport type { Context } from './types.js';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context): string {\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 = find(items, (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 = find(items, (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":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","length","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;iEACE;2DACA;yBACsC;6DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,qBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,UAAUS,QAAQ,CAAC,MAAM;YAC3D,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOC,IAAAA,mBAAI,EAACH,OAAO,SAACX;uBAAMH,gBAAgBkB,OAAO,CAACf,MAAM;;YAC9D,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,sBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACS,OAAO,CAACtB;YAC1C,IAAMU,QAAOC,IAAAA,mBAAI,EAACH,QAAO,SAACX;gBACxB,IAAI0B,wBAAa,CAACP,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM2B,UAAUX,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM4B,eAAeD,UAAUX,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACI,QAAQH,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaM;YACtB;YACA,IAAIf,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACS,OAAO,CAACtB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/cjs/toPath.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Context } from './types.js';
|
|
2
|
-
export default function toPath(specifier: string, context?: Context):
|
|
2
|
+
export default function toPath(specifier: string, context?: Context): string;
|
package/dist/cjs/toPath.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Context } from './types.js';
|
|
2
|
-
export default function toPath(specifier: string, context?: Context):
|
|
2
|
+
export default function toPath(specifier: string, context?: Context): string;
|
package/dist/cjs/toPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport resolveCJS from 'resolve';\nimport url from 'url';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants.js';\nimport * as urlPolyfills from './lib/url-file-url.js';\nimport type { Context } from './types.js';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryURL","resolveESM","_","entryPath","resolveCJS","sync","basedir","extensions"],"mappings":";;;;+BAoBA;;;eAAwBA;;;iEApBD;6DACJ;2DACF;8DACM;0DACP;oCAEsB;yBACV;kEACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,YAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,YAAaC,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACZ,OAAOS,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASf,OAAOgB,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOb,cAAcY;IACxD,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,sBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,6BAAU,EAACP,WAAWT,cAAcG;gBACrD,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAYC,gBAAU,CAACC,IAAI,CAACX,WAAW;YAC3CY,SAASlB;YACTmB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIJ,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport resolveCJS from 'resolve';\nimport url from 'url';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants.js';\nimport * as urlPolyfills from './lib/url-file-url.js';\nimport type { Context } from './types.js';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context): string {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryURL","resolveESM","_","entryPath","resolveCJS","sync","basedir","extensions"],"mappings":";;;;+BAoBA;;;eAAwBA;;;iEApBD;6DACJ;2DACF;8DACM;0DACP;oCAEsB;yBACV;kEACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,YAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,YAAaC,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACZ,OAAOS,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASf,OAAOgB,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOb,cAAcY;IACxD,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,sBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,6BAAU,EAACP,WAAWT,cAAcG;gBACrD,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAYC,gBAAU,CAACC,IAAI,CAACX,WAAW;YAC3CY,SAASlB;YACTmB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIJ,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ConfigOptions, TransformDirectoryCallback } from './types.js';
|
|
2
|
-
export default function transformDirectory(src: string, dest: string, type:
|
|
1
|
+
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.js';
|
|
2
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ConfigOptions, TransformDirectoryCallback } from './types.js';
|
|
2
|
-
export default function transformDirectory(src: string, dest: string, type:
|
|
1
|
+
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.js';
|
|
2
|
+
export default function transformDirectory(src: string, dest: string, type: TargetType, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]>;
|
|
@@ -80,7 +80,7 @@ function transformDirectory(src, dest, type, options, callback) {
|
|
|
80
80
|
if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback);
|
|
81
81
|
return new Promise(function(resolve, reject) {
|
|
82
82
|
return dispatch(version, src, dest, type, options, function(err, result) {
|
|
83
|
-
|
|
83
|
+
err ? reject(err) : resolve(result);
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\
|
|
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.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformDirectoryCallback } from './types.js';\n\nfunction dispatch(version: string, src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nexport default function transformDirectory(src: string, dest: string, type: TargetType, 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 dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n dispatch(version, src, dest, type, options as ConfigOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BAwBA;;;eAAwBA;;;2DAxBP;0DACD;mEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,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;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI1F,SAASG,SAASb,OAAe,EAAEc,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IAC1I,IAAIlB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMT,SAAS,qBAAqB;YAAET,SAAAA;YAASmB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAEe,SAAS1B,mBAAmBoB,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAoD,EAAEC,QAAqC;IACjL,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAC9C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMK,WAAWC,IAAAA,qBAAY,EAAC;YAAEC,KAAKV;WAAQG,UAAW;QACxDA,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,SAACC,SAASC;mBAC3Bd,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAA0B,SAACG,KAAKQ;gBACjER,MAAMO,OAAOP,OAAOM,QAAQE;YAC9B;;IAEJ,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
|
package/dist/cjs/types.d.cts
CHANGED
|
@@ -3,11 +3,21 @@ export interface Context {
|
|
|
3
3
|
parentPath?: string;
|
|
4
4
|
}
|
|
5
5
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
6
|
+
export interface Extensions {
|
|
7
|
+
cjs?: string;
|
|
8
|
+
esm?: string;
|
|
9
|
+
}
|
|
6
10
|
export interface ConfigOptions {
|
|
7
11
|
tsconfig?: TsConfigResult;
|
|
8
12
|
cwd?: string;
|
|
13
|
+
sourceMaps?: boolean;
|
|
14
|
+
extensions?: Extensions;
|
|
15
|
+
}
|
|
16
|
+
export interface ConfigOptionsInternal extends ConfigOptions {
|
|
17
|
+
src: string;
|
|
9
18
|
}
|
|
10
19
|
export type TransformDirectoryCallback = (err?: Error, filePaths?: string[]) => void;
|
|
11
20
|
export type TransformFileCallback = (err?: Error, destFilePath?: string) => void;
|
|
12
21
|
export type TransformTypesCallback = (err?: Error, filePaths?: string[]) => void;
|
|
13
22
|
export type Matcher = (filePath: string) => boolean;
|
|
23
|
+
export type TargetType = 'cjs' | 'esm';
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -3,11 +3,21 @@ export interface Context {
|
|
|
3
3
|
parentPath?: string;
|
|
4
4
|
}
|
|
5
5
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
6
|
+
export interface Extensions {
|
|
7
|
+
cjs?: string;
|
|
8
|
+
esm?: string;
|
|
9
|
+
}
|
|
6
10
|
export interface ConfigOptions {
|
|
7
11
|
tsconfig?: TsConfigResult;
|
|
8
12
|
cwd?: string;
|
|
13
|
+
sourceMaps?: boolean;
|
|
14
|
+
extensions?: Extensions;
|
|
15
|
+
}
|
|
16
|
+
export interface ConfigOptionsInternal extends ConfigOptions {
|
|
17
|
+
src: string;
|
|
9
18
|
}
|
|
10
19
|
export type TransformDirectoryCallback = (err?: Error, filePaths?: string[]) => void;
|
|
11
20
|
export type TransformFileCallback = (err?: Error, destFilePath?: string) => void;
|
|
12
21
|
export type TransformTypesCallback = (err?: Error, filePaths?: string[]) => void;
|
|
13
22
|
export type Matcher = (filePath: string) => boolean;
|
|
23
|
+
export type TargetType = 'cjs' | 'esm';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
|
|
2
|
+
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ConfigOptions, TargetType, TransformDirectoryCallback } from '../types.js';
|
|
2
|
+
export default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined;
|
|
@@ -85,7 +85,10 @@ function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
|
85
85
|
if (ext && _constants.extensions.indexOf(ext) < 0) return;
|
|
86
86
|
entries.push(entry);
|
|
87
87
|
}, function(err) {
|
|
88
|
-
if (err)
|
|
88
|
+
if (err) {
|
|
89
|
+
callback(err);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
89
92
|
var results = [];
|
|
90
93
|
options = _object_spread_props(_object_spread({}, options), {
|
|
91
94
|
tsconfig: tsconfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from '../lib/transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from '../lib/transformFile.js';\n\nimport type { ConfigOptions, ConfigOptionsInternal, TargetType, TransformDirectoryCallback } from '../types.js';\n\nexport default function transformDirectoryWorker(src: string, dest: string, type: TargetType, options: ConfigOptions, callback: TransformDirectoryCallback): undefined {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries: Entry[] = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err): undefined => {\n if (err) {\n callback(err);\n return;\n }\n const results = [];\n options = { ...options, tsconfig, src, dest } as ConfigOptionsInternal;\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options as ConfigOptionsInternal, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","err","results","queue","Queue","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BAUA;;;eAAwBA;;;iEAVa;2DACpB;8DACC;yBAEwB;oEAChB;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIX,SAASA,yBAAyBC,GAAW,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAAoC;IACxJ,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,sBAAa,EAACF;IAE9B,IAAMG,UAAmB,EAAE;IAC3B,IAAMC,WAAW,IAAIC,mBAAQ,CAACV;IAC9BS,SAASE,OAAO,CACd,SAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIC,wBAAa,CAACC,IAAI,CAACL,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACT,QAAQM,MAAMM,QAAQ,GAAG;QAC9B,IAAMC,MAAMC,aAAI,CAACC,OAAO,CAACT,MAAMG,QAAQ;QACvC,IAAII,OAAOG,qBAAU,CAACC,OAAO,CAACJ,OAAO,GAAG;QACxCX,QAAQgB,IAAI,CAACZ;IACf,GACA,SAACa;QACC,IAAIA,KAAK;YACPrB,SAASqB;YACT;QACF;QACA,IAAMC,UAAU,EAAE;QAClBvB,UAAU,wCAAKA;YAASE,UAAAA;YAAUL,KAAAA;YAAKC,MAAAA;;QAEvC,IAAM0B,QAAQ,IAAIC,gBAAK;QACvBpB,QAAQG,OAAO,CAAC,SAACC;YACfe,MAAME,KAAK,CAAC,SAACC;uBACXC,IAAAA,sBAAa,EAACnB,OAAOX,MAAMC,MAAMC,SAAkC,SAACsB,KAAKO;oBACvE,IAAIP,KAAK,OAAOK,GAAGL;oBACnBC,QAAQF,IAAI,CAACJ,aAAI,CAACa,SAAS,CAACD;oBAC5B,IAAI7B,QAAQ+B,UAAU,EAAER,QAAQF,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACa,SAAS,CAACD,UAAS;oBAChEF;gBACF;;QAEJ;QACAH,MAAMQ,KAAK,CAAC,SAACV;mBAASA,MAAMrB,SAASqB,OAAOrB,SAAS,MAAMsB;;IAC7D;AAEJ"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { Output } from '@swc/core';
|
|
1
2
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
2
|
-
export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult):
|
|
3
|
+
export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { Output } from '@swc/core';
|
|
1
2
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
2
|
-
export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult):
|
|
3
|
+
export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","contents","fileName","tsconfig","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport Module from 'module';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","contents","fileName","tsconfig","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAOA;;;eAAwBA;;;6DANL;wEACW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,oBAAoBK,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,IAAMC,aAAaC,IAAAA,0BAAiB,EAACF;IACrC,IAAMG,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACN,UAAU,wCAC7BC,SAASM,QAAQ,CAAC,WAAWN,SAASM,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUT;;AAEd"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ConfigOptions, TransformTypesCallback } from '../types.js';
|
|
2
|
+
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): undefined;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ConfigOptions, TransformTypesCallback } from '../types.js';
|
|
2
|
+
export default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): undefined;
|