ts-swc-transform 1.12.11 → 1.13.1
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/createMatcher.cjs +2 -1
- package/dist/cjs/createMatcher.cjs.map +1 -1
- package/dist/cjs/lib/swcPrepareOptions.cjs +2 -0
- package/dist/cjs/lib/swcPrepareOptions.cjs.map +1 -1
- package/dist/cjs/lib/transformFile.cjs +2 -1
- package/dist/cjs/lib/transformFile.cjs.map +1 -1
- package/dist/cjs/resolveFileSync.cjs +2 -1
- package/dist/cjs/resolveFileSync.cjs.map +1 -1
- package/dist/cjs/transformSync.cjs +3 -3
- package/dist/cjs/transformSync.cjs.map +1 -1
- package/dist/cjs/workers/transformSync.cjs +2 -1
- package/dist/cjs/workers/transformSync.cjs.map +1 -1
- package/dist/esm/createMatcher.mjs +2 -1
- package/dist/esm/createMatcher.mjs.map +1 -1
- package/dist/esm/lib/swcPrepareOptions.mjs +2 -0
- package/dist/esm/lib/swcPrepareOptions.mjs.map +1 -1
- package/dist/esm/lib/transformFile.mjs +2 -1
- package/dist/esm/lib/transformFile.mjs.map +1 -1
- package/dist/esm/resolveFileSync.mjs +2 -1
- package/dist/esm/resolveFileSync.mjs.map +1 -1
- package/dist/esm/transformSync.mjs +3 -3
- package/dist/esm/transformSync.mjs.map +1 -1
- package/dist/esm/workers/transformSync.mjs +2 -1
- package/dist/esm/workers/transformSync.mjs.map +1 -1
- package/package.json +6 -8
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return createMatcher;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
|
|
11
12
|
var _minimatch = /*#__PURE__*/ _interop_require_default(require("minimatch"));
|
|
12
13
|
var _pathposix = /*#__PURE__*/ _interop_require_default(require("path-posix"));
|
|
13
14
|
var _unixify = /*#__PURE__*/ _interop_require_default(require("unixify"));
|
|
@@ -32,7 +33,7 @@ function createMatcher(tsConfig) {
|
|
|
32
33
|
var includes = (tsconfig.config.include || []).map(matchFn);
|
|
33
34
|
var excludes = (tsconfig.config.exclude || []).map(matchFn);
|
|
34
35
|
return function matcher(filePath) {
|
|
35
|
-
if (
|
|
36
|
+
if ((0, _lodashendswith.default)(filePath, '.json')) return false;
|
|
36
37
|
filePath = (0, _unixify.default)(filePath);
|
|
37
38
|
for(var i = 0; i < excludes.length; ++i){
|
|
38
39
|
if (excludes[i](filePath)) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport endsWith from 'lodash.endswith';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (endsWith(filePath, '.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsConfig","tsconfig","loadTsConfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAQA;;;eAAwBA;;;qEAPH;gEACC;gEACL;8DACG;mEACK;;;;;;AAGV,SAASA,cAAcC,QAAwB;IAC5D,IAAMC,WAAWC,IAAAA,qBAAY,EAAC;QAAED,UAAUD;IAAS,GAAG;IACtD,IAAMG,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACL,SAASG,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACf,CAAAA,SAASgB,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACrD,IAAMa,WAAW,AAACnB,CAAAA,SAASgB,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAErD,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIS,IAAAA,uBAAQ,EAACT,UAAU,UAAU,OAAO;QAExCA,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
|
|
@@ -21,6 +21,7 @@ var tsLazy = (0, _lazycache.default)(_require)('typescript');
|
|
|
21
21
|
var swcLazy = (0, _lazycache.default)(_require)('@swc/core');
|
|
22
22
|
var transpilerLazy = (0, _lazycache.default)(_require)('ts-node/transpilers/swc');
|
|
23
23
|
function swcPrepareOptions(tsconfig) {
|
|
24
|
+
console.log('tsconfig', tsconfig);
|
|
24
25
|
try {
|
|
25
26
|
var ts = tsLazy();
|
|
26
27
|
var swc = swcLazy();
|
|
@@ -29,6 +30,7 @@ function swcPrepareOptions(tsconfig) {
|
|
|
29
30
|
return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
|
|
30
31
|
} catch (err) {
|
|
31
32
|
console.log("swcPrepareOptions failed: ".concat(err.message));
|
|
33
|
+
return {};
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
/* 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/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\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 }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","tsLazy","lazy","swcLazy","transpilerLazy","tsconfig","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n console.log('tsconfig', tsconfig);\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\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","tsLazy","lazy","swcLazy","transpilerLazy","tsconfig","console","log","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","message"],"mappings":";;;;+BAWA;;;eAAwBA;;;2DAXP;6DAEE;gEACF;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,SAASC,IAAAA,kBAAI,EAACL,UAAU;AAC9B,IAAMM,UAAUD,IAAAA,kBAAI,EAACL,UAAU;AAC/B,IAAMO,iBAAiBF,IAAAA,kBAAI,EAACL,UAAU;AAIvB,SAASD,kBAAkBS,QAAwB;IAChEC,QAAQC,GAAG,CAAC,YAAYF;IACxB,IAAI;QACF,IAAMG,KAAKP;QACX,IAAMQ,MAAMN;QACZ,IAAMO,aAAaN;QACnB,IAAMO,SAASH,GAAGI,0BAA0B,CAACP,SAASQ,MAAM,EAAEL,GAAGM,GAAG,EAAEC,aAAI,CAACC,OAAO,CAACX,SAASU,IAAI;QAChG,OAAOL,WAAWO,gBAAgB,CAACN,OAAOO,OAAO,EAAEC,WAAWV,KAAK;IACrE,EAAE,OAAOW,KAAK;QACZd,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZa,IAAIC,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
|
|
13
14
|
var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
|
|
14
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
15
16
|
var _patchCJS = /*#__PURE__*/ _interop_require_default(require("../lib/patchCJS.cjs"));
|
|
@@ -88,7 +89,7 @@ function transformFile(entry, dest, type, options, callback) {
|
|
|
88
89
|
}
|
|
89
90
|
var swcOptions = (0, _swcPrepareOptions.default)(tsconfig);
|
|
90
91
|
var swc = swcLazy();
|
|
91
|
-
swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, entry.basename
|
|
92
|
+
swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, (0, _lodashendswith.default)(entry.basename, '.tsx') || (0, _lodashendswith.default)(entry.basename, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
|
|
92
93
|
filename: entry.basename
|
|
93
94
|
})).then(function(output) {
|
|
94
95
|
var extTarget = type === 'esm' ? (0, _patchESM.default)(entry, output, options) : (0, _patchCJS.default)(entry, output, options);
|
|
@@ -1 +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
|
|
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 endsWith from 'lodash.endswith';\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 ...(endsWith(entry.basename, '.tsx') || endsWith(entry.basename, '.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","swcLazy","lazy","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","endsWith","basename","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;;;yDAfT;2DACE;qEACI;oEACF;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,cAAcO,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACxE,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;IAEZc,IACGnB,aAAa,CAACO,MAAMa,QAAQ,EAAE,wCACzBC,IAAAA,uBAAQ,EAACd,MAAMe,QAAQ,EAAE,WAAWD,IAAAA,uBAAQ,EAACd,MAAMe,QAAQ,EAAE,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QAC3HC,UAAUlB,MAAMe,QAAQ;QAEzBI,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"}
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
|
|
13
14
|
var _constants = require("./constants.cjs");
|
|
14
15
|
var _toPath = /*#__PURE__*/ _interop_require_default(require("./toPath.cjs"));
|
|
15
16
|
function _interop_require_default(obj) {
|
|
@@ -27,7 +28,7 @@ function resolveFileSync(specifier, context) {
|
|
|
27
28
|
stat = _fs.default.statSync(filePath);
|
|
28
29
|
} catch (_err) {}
|
|
29
30
|
try {
|
|
30
|
-
if (stat && stat.isDirectory() ||
|
|
31
|
+
if (stat && stat.isDirectory() || (0, _lodashendswith.default)(specifier, '/')) {
|
|
31
32
|
var items = _fs.default.readdirSync(filePath);
|
|
32
33
|
var item = items.find(function(x) {
|
|
33
34
|
return indexExtensions.indexOf(x) >= 0;
|
|
@@ -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 { extensions, moduleRegEx, typeFileRegEx } from './constants';\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()) ||
|
|
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 endsWith from 'lodash.endswith';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants';\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()) || endsWith(specifier, '/')) {\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":["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;2DACE;qEACI;yBACkC;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,MAAOC,IAAAA,uBAAQ,EAACT,WAAW,MAAM;YAC5D,IAAMU,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOF,MAAMG,IAAI,CAAC,SAACd;uBAAMH,gBAAgBkB,OAAO,CAACf,MAAM;;YAC7D,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,QAAOF,OAAMG,IAAI,CAAC,SAACd;gBACvB,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"}
|
|
@@ -71,9 +71,9 @@ var workerPath = _path.default.join(__dirname, '..', 'cjs', 'workers', 'transfor
|
|
|
71
71
|
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
72
72
|
var callLazy = (0, _lazycache.default)(_require)('node-version-call');
|
|
73
73
|
var workerLazy = (0, _lazycache.default)(_require)(workerPath);
|
|
74
|
-
function dispatch(version,
|
|
75
|
-
if (version === 'local') return workerLazy()(
|
|
76
|
-
return callLazy()(version, workerPath,
|
|
74
|
+
function dispatch(version, contents, fileName, tsconfig) {
|
|
75
|
+
if (version === 'local') return workerLazy()(contents, fileName, tsconfig);
|
|
76
|
+
return callLazy()(version, workerPath, contents, fileName, tsconfig);
|
|
77
77
|
}
|
|
78
78
|
function transformSync(contents, fileName, tsconfig) {
|
|
79
79
|
if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport * as getTS from 'get-tsconfig-compat';\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', 'transformSync.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport * as getTS from 'get-tsconfig-compat';\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', 'transformSync.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return workerLazy()(contents, fileName, tsconfig);\n return callLazy()(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @param {TsConfigResult} tsconfig The configuration.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nexport default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');\n if (!tsconfig) tsconfig = getTS.getTsconfig(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["transformSync","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","callLazy","lazy","workerLazy","dispatch","contents","fileName","tsconfig","Error","getTS","getTsconfig","cwd"],"mappings":";;;;+BAsBA;;;;;CAKC,GACD;;;eAAwBA;;;2DA5BP;0DACD;yEACO;6DAOJ;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANjB,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;AAC1F,IAAMG,WAAWC,IAAAA,kBAAI,EAACL,UAAU;AAChC,IAAMM,aAAaD,IAAAA,kBAAI,EAACL,UAAUF;AAElC,SAASS,SAAShB,OAAO,EAAEiB,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAInB,YAAY,SAAS,OAAOe,aAAaE,UAAUC,UAAUC;IACjE,OAAON,WAAWb,SAASO,YAAYU,UAAUC,UAAUC;AAC7D;AAUe,SAASzB,cAAcuB,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IAChG,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIE,MAAM;IAClD,IAAI,CAACD,UAAUA,WAAWE,mBAAMC,WAAW,CAAC1B,QAAQ2B,GAAG;IACvD,OAAOP,SAAShB,SAASiB,UAAUC,UAAUC;AAC/C"}
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformSyncWorker;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
|
|
11
12
|
var _installBindings = require("../lib/installBindings.cjs");
|
|
12
13
|
var _swcPrepareOptions = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.cjs"));
|
|
13
14
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
@@ -76,7 +77,7 @@ function transformSyncWorker(contents, fileName, tsconfig) {
|
|
|
76
77
|
(0, _installBindings.sync)(target);
|
|
77
78
|
var swcOptions = (0, _swcPrepareOptions.default)(tsconfig);
|
|
78
79
|
var swc = swcLazy();
|
|
79
|
-
return swc.transformSync(contents, _object_spread_props(_object_spread({},
|
|
80
|
+
return swc.transformSync(contents, _object_spread_props(_object_spread({}, (0, _lodashendswith.default)(fileName, '.tsx') || (0, _lodashendswith.default)(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
|
|
80
81
|
filename: fileName
|
|
81
82
|
}));
|
|
82
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import { sync as installBindingsSync } from '../lib/installBindings';\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');\nconst target = `${process.platform}-${process.arch}`;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n installBindingsSync(target);\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import endsWith from 'lodash.endswith';\nimport { sync as installBindingsSync } from '../lib/installBindings';\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');\nconst target = `${process.platform}-${process.arch}`;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n installBindingsSync(target);\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(endsWith(fileName, '.tsx') || endsWith(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","swcLazy","lazy","target","process","platform","arch","contents","fileName","tsconfig","installBindingsSync","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAWA;;;eAAwBA;;;qEAXH;+BACuB;wEACd;6DAEX;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,UAAUC,IAAAA,kBAAI,EAACL,UAAU;AAC/B,IAAMM,SAAS,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;AAGnC,SAASV,oBAAoBW,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtGC,IAAAA,qBAAmB,EAACP;IAEpB,IAAMQ,aAAaC,IAAAA,0BAAiB,EAACH;IACrC,IAAMI,MAAMZ;IACZ,OAAOY,IAAIC,aAAa,CAACP,UAAU,wCAC7BQ,IAAAA,uBAAQ,EAACP,UAAU,WAAWO,IAAAA,uBAAQ,EAACP,UAAU,UAAUG,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC/GC,UAAUV;;AAEd"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import endsWith from 'lodash.endswith';
|
|
1
2
|
import minimatch from 'minimatch';
|
|
2
3
|
import path from 'path-posix';
|
|
3
4
|
import unixify from 'unixify';
|
|
@@ -17,7 +18,7 @@ export default function createMatcher(tsConfig) {
|
|
|
17
18
|
const includes = (tsconfig.config.include || []).map(matchFn);
|
|
18
19
|
const excludes = (tsconfig.config.exclude || []).map(matchFn);
|
|
19
20
|
return function matcher(filePath) {
|
|
20
|
-
if (
|
|
21
|
+
if (endsWith(filePath, '.json')) return false;
|
|
21
22
|
filePath = unixify(filePath);
|
|
22
23
|
for(let i = 0; i < excludes.length; ++i){
|
|
23
24
|
if (excludes[i](filePath)) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport endsWith from 'lodash.endswith';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (endsWith(filePath, '.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["endsWith","minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","i","length","j"],"mappings":"AACA,OAAOA,cAAc,kBAAkB;AACvC,OAAOC,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,iBAAiB;AAG1C,eAAe,SAASC,cAAcC,QAAwB;IAC5D,MAAMC,WAAWH,aAAa;QAAEG,UAAUD;IAAS,GAAG;IACtD,MAAME,eAAeN,KAAKO,OAAO,CAACN,QAAQI,SAASL,IAAI;IAEvD,SAASQ,QAAQC,SAAS;QACxB,IAAIC,UAAUT,QAAQQ;QACtB,IAAI,CAACT,KAAKW,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUV,KAAKa,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYX,UAAUgB,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,SAASY,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACrD,MAAMY,WAAW,AAACf,CAAAA,SAASY,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAErD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIjB,SAASiB,UAAU,UAAU,OAAO;QAExCA,WAAWd,QAAQc;QACnB,IAAK,IAAIQ,IAAI,GAAGA,IAAIH,SAASI,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIH,QAAQ,CAACG,EAAE,CAACR,WAAW,OAAO;QACpC;QACA,IAAK,IAAIU,IAAI,GAAGA,IAAIT,SAASQ,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIT,QAAQ,CAACS,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASQ,MAAM;IACzB;AACF"}
|
|
@@ -6,6 +6,7 @@ const tsLazy = lazy(_require)('typescript');
|
|
|
6
6
|
const swcLazy = lazy(_require)('@swc/core');
|
|
7
7
|
const transpilerLazy = lazy(_require)('ts-node/transpilers/swc');
|
|
8
8
|
export default function swcPrepareOptions(tsconfig) {
|
|
9
|
+
console.log('tsconfig', tsconfig);
|
|
9
10
|
try {
|
|
10
11
|
const ts = tsLazy();
|
|
11
12
|
const swc = swcLazy();
|
|
@@ -14,5 +15,6 @@ export default function swcPrepareOptions(tsconfig) {
|
|
|
14
15
|
return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');
|
|
15
16
|
} catch (err) {
|
|
16
17
|
console.log(`swcPrepareOptions failed: ${err.message}`);
|
|
18
|
+
return {};
|
|
17
19
|
}
|
|
18
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\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 }\n}\n"],"names":["path","Module","lazy","_require","require","createRequire","url","tsLazy","swcLazy","transpilerLazy","swcPrepareOptions","tsconfig","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","dirname","createSwcOptions","options","undefined","err","
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n console.log('tsconfig', tsconfig);\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\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":["path","Module","lazy","_require","require","createRequire","url","tsLazy","swcLazy","transpilerLazy","swcPrepareOptions","tsconfig","console","log","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","dirname","createSwcOptions","options","undefined","err","message"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,SAASL,KAAKC,UAAU;AAC9B,MAAMK,UAAUN,KAAKC,UAAU;AAC/B,MAAMM,iBAAiBP,KAAKC,UAAU;AAItC,eAAe,SAASO,kBAAkBC,QAAwB;IAChEC,QAAQC,GAAG,CAAC,YAAYF;IACxB,IAAI;QACF,MAAMG,KAAKP;QACX,MAAMQ,MAAMP;QACZ,MAAMQ,aAAaP;QACnB,MAAMQ,SAASH,GAAGI,0BAA0B,CAACP,SAASQ,MAAM,EAAEL,GAAGM,GAAG,EAAEpB,KAAKqB,OAAO,CAACV,SAASX,IAAI;QAChG,OAAOgB,WAAWM,gBAAgB,CAACL,OAAOM,OAAO,EAAEC,WAAWT,KAAK;IACrE,EAAE,OAAOU,KAAK;QACZb,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEY,IAAIC,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import endsWith from 'lodash.endswith';
|
|
3
4
|
import mkdirp from 'mkdirp-classic';
|
|
4
5
|
import Queue from 'queue-cb';
|
|
5
6
|
import patchCJS from '../lib/patchCJS.mjs';
|
|
@@ -28,7 +29,7 @@ export default function transformFile(entry, dest, type, options, callback) {
|
|
|
28
29
|
const swcOptions = swcPrepareOptions(tsconfig);
|
|
29
30
|
const swc = swcLazy();
|
|
30
31
|
swc.transformFile(entry.fullPath, {
|
|
31
|
-
...entry.basename
|
|
32
|
+
...endsWith(entry.basename, '.tsx') || endsWith(entry.basename, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
|
|
32
33
|
filename: entry.basename
|
|
33
34
|
}).then((output)=>{
|
|
34
35
|
const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
|
|
@@ -1 +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
|
|
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 endsWith from 'lodash.endswith';\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 ...(endsWith(entry.basename, '.tsx') || endsWith(entry.basename, '.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","endsWith","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","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,cAAc,kBAAkB;AACvC,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,GAAI1B,SAASc,MAAMa,QAAQ,EAAE,WAAW3B,SAASc,MAAMa,QAAQ,EAAE,UAAUH,WAAWI,UAAU,GAAGJ,WAAWK,aAAa;QAC3HC,UAAUhB,MAAMa,QAAQ;IAC1B,GACCI,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYjB,SAAS,QAAQZ,SAASU,OAAOkB,QAAQf,WAAWd,SAASW,OAAOkB,QAAQf;QAC9F,MAAMiB,MAAMnC,KAAKoC,OAAO,CAACrB,MAAMf,IAAI;QACnC,MAAMqC,UAAUrC,KAAKsC,IAAI,CAACtB,MAAM,AAACmB,CAAAA,MAAMpB,MAAMf,IAAI,CAACuC,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAIzB,MAAMf,IAAI,AAAD,IAAKkC;QAExFhC,OAAOF,KAAKyC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIvC;YAClBuC,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC5B,QAAQ6B,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,MAAM/B,SAAS+B,OAAO/B,SAAS,MAAMkB;QAC7D;IACF,GACCc,KAAK,CAAChC;AACX"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import endsWith from 'lodash.endswith';
|
|
3
4
|
import { extensions, moduleRegEx, typeFileRegEx } from './constants.mjs';
|
|
4
5
|
import toPath from './toPath.mjs';
|
|
5
6
|
const indexExtensions = extensions.map((x)=>`index${x}`);
|
|
@@ -10,7 +11,7 @@ export default function resolveFileSync(specifier, context) {
|
|
|
10
11
|
stat = fs.statSync(filePath);
|
|
11
12
|
} catch (_err) {}
|
|
12
13
|
try {
|
|
13
|
-
if (stat && stat.isDirectory() ||
|
|
14
|
+
if (stat && stat.isDirectory() || endsWith(specifier, '/')) {
|
|
14
15
|
const items = fs.readdirSync(filePath);
|
|
15
16
|
const item = items.find((x)=>indexExtensions.indexOf(x) >= 0);
|
|
16
17
|
if (item) return path.join(filePath, item);
|
|
@@ -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 { extensions, moduleRegEx, typeFileRegEx } from './constants';\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()) ||
|
|
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 endsWith from 'lodash.endswith';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants';\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()) || endsWith(specifier, '/')) {\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","endsWith","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","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,OAAOC,cAAc,kBAAkB;AACvC,SAASC,UAAU,EAAEC,WAAW,EAAEC,aAAa,QAAQ,cAAc;AACrE,OAAOC,YAAY,WAAW;AAG9B,MAAMC,kBAAkBJ,WAAWK,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,OAAOd,GAAGe,QAAQ,CAACF;IACrB,EAAE,OAAOG,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACF,QAAQA,KAAKG,WAAW,MAAOf,SAASS,WAAW,MAAM;YAC5D,MAAMO,QAAQlB,GAAGmB,WAAW,CAACN;YAC7B,MAAMO,OAAOF,MAAMG,IAAI,CAAC,CAACZ,IAAMF,gBAAgBe,OAAO,CAACb,MAAM;YAC7D,IAAIW,MAAM,OAAOnB,KAAKsB,IAAI,CAACV,UAAUO;QACvC,OAAO,IAAI,CAACN,QAAQ,CAACV,YAAYoB,IAAI,CAACb,YAAY;YAChD,MAAMc,MAAMxB,KAAKyB,OAAO,CAACb;YACzB,MAAMc,WAAWF,MAAMxB,KAAK0B,QAAQ,CAACd,UAAUe,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAI5B,KAAK0B,QAAQ,CAACd;YACrF,MAAMK,QAAQlB,GAAGmB,WAAW,CAAClB,KAAK6B,OAAO,CAACjB;YAC1C,MAAMO,OAAOF,MAAMG,IAAI,CAAC,CAACZ;gBACvB,IAAIJ,cAAcmB,IAAI,CAACf,IAAI,OAAO;gBAClC,MAAMsB,UAAU9B,KAAKyB,OAAO,CAACjB;gBAC7B,MAAMuB,eAAeD,UAAU9B,KAAK0B,QAAQ,CAAClB,GAAGmB,KAAK,CAAC,GAAG,CAACG,QAAQF,MAAM,IAAI5B,KAAK0B,QAAQ,CAAClB;gBAC1F,OAAOkB,aAAaK;YACtB;YACA,IAAIZ,MAAM,OAAOnB,KAAKsB,IAAI,CAACtB,KAAK6B,OAAO,CAACjB,WAAWO;QACrD;QACA,wBAAwB;QACxB,OAAON,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
|
|
@@ -10,9 +10,9 @@ import lazy from 'lazy-cache';
|
|
|
10
10
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
11
11
|
const callLazy = lazy(_require)('node-version-call');
|
|
12
12
|
const workerLazy = lazy(_require)(workerPath);
|
|
13
|
-
function dispatch(version,
|
|
14
|
-
if (version === 'local') return workerLazy()(
|
|
15
|
-
return callLazy()(version, workerPath,
|
|
13
|
+
function dispatch(version, contents, fileName, tsconfig) {
|
|
14
|
+
if (version === 'local') return workerLazy()(contents, fileName, tsconfig);
|
|
15
|
+
return callLazy()(version, workerPath, contents, fileName, tsconfig);
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* @param {string} contents The file contents.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport * as getTS from 'get-tsconfig-compat';\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', 'transformSync.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport * as getTS from 'get-tsconfig-compat';\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', 'transformSync.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return workerLazy()(contents, fileName, tsconfig);\n return callLazy()(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @param {TsConfigResult} tsconfig The configuration.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nexport default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): Output {\n if (typeof contents !== 'string') throw new Error('transformTypes: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformTypes: unexpected fileName');\n if (!tsconfig) tsconfig = getTS.getTsconfig(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["path","url","getTS","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","lazy","_require","require","createRequire","callLazy","workerLazy","dispatch","contents","fileName","tsconfig","transformSync","Error","getTsconfig","cwd"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,YAAYC,WAAW,sBAAsB;AAE7C,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,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYlB,GAAG,IAAIiB;AAC1F,MAAME,WAAWJ,KAAKC,UAAU;AAChC,MAAMI,aAAaL,KAAKC,UAAUJ;AAElC,SAASS,SAASd,OAAO,EAAEe,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAIjB,YAAY,SAAS,OAAOa,aAAaE,UAAUC,UAAUC;IACjE,OAAOL,WAAWZ,SAASK,YAAYU,UAAUC,UAAUC;AAC7D;AAIA;;;;;CAKC,GACD,eAAe,SAASC,cAAcH,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IAChG,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAII,MAAM;IAClD,IAAI,OAAOH,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,CAACF,UAAUA,WAAWvB,MAAM0B,WAAW,CAACxB,QAAQyB,GAAG;IACvD,OAAOP,SAASd,SAASe,UAAUC,UAAUC;AAC/C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import endsWith from 'lodash.endswith';
|
|
1
2
|
import { sync as installBindingsSync } from '../lib/installBindings.mjs';
|
|
2
3
|
import swcPrepareOptions from '../lib/swcPrepareOptions.mjs';
|
|
3
4
|
import Module from 'module';
|
|
@@ -10,7 +11,7 @@ export default function transformSyncWorker(contents, fileName, tsconfig) {
|
|
|
10
11
|
const swcOptions = swcPrepareOptions(tsconfig);
|
|
11
12
|
const swc = swcLazy();
|
|
12
13
|
return swc.transformSync(contents, {
|
|
13
|
-
...
|
|
14
|
+
...endsWith(fileName, '.tsx') || endsWith(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
|
|
14
15
|
filename: fileName
|
|
15
16
|
});
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import { sync as installBindingsSync } from '../lib/installBindings';\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');\nconst target = `${process.platform}-${process.arch}`;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n installBindingsSync(target);\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import endsWith from 'lodash.endswith';\nimport { sync as installBindingsSync } from '../lib/installBindings';\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');\nconst target = `${process.platform}-${process.arch}`;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n installBindingsSync(target);\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(endsWith(fileName, '.tsx') || endsWith(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["endsWith","sync","installBindingsSync","swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","target","process","platform","arch","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","tsxOptions","nonTsxOptions","filename"],"mappings":"AAAA,OAAOA,cAAc,kBAAkB;AACvC,SAASC,QAAQC,mBAAmB,QAAQ,yBAAyB;AACrE,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;AAC/B,MAAMK,SAAS,GAAGC,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;AAGpD,eAAe,SAASC,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtGhB,oBAAoBS;IAEpB,MAAMQ,aAAahB,kBAAkBe;IACrC,MAAME,MAAMV;IACZ,OAAOU,IAAIC,aAAa,CAACL,UAAU;QACjC,GAAIhB,SAASiB,UAAU,WAAWjB,SAASiB,UAAU,UAAUE,WAAWG,UAAU,GAAGH,WAAWI,aAAa;QAC/GC,UAAUP;IACZ;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -38,22 +38,20 @@
|
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsds build",
|
|
41
|
-
"deploy": "tsds deploy",
|
|
42
|
-
"docs": "tsds docs",
|
|
43
41
|
"format": "biome check --write --unsafe src/ test/",
|
|
44
42
|
"test": "tsds test:node --no-timeouts",
|
|
45
43
|
"test:engines": "nvu engines npm test",
|
|
46
|
-
"version": ""
|
|
47
|
-
"version2": "tsds version"
|
|
44
|
+
"version": "tsds version"
|
|
48
45
|
},
|
|
49
46
|
"dependencies": {
|
|
50
47
|
"@swc/core": "*",
|
|
51
48
|
"exit": "^0.1.2",
|
|
52
49
|
"fs-iterator": "^5.2.10",
|
|
53
50
|
"get-tsconfig-compat": "^2.0.3",
|
|
54
|
-
"install-module-linked": "^1.1.
|
|
51
|
+
"install-module-linked": "^1.1.6",
|
|
55
52
|
"is-absolute": "^1.0.0",
|
|
56
53
|
"lazy-cache": "^2.0.2",
|
|
54
|
+
"lodash.endswith": "^4.2.1",
|
|
57
55
|
"minimatch": "^3.1.2",
|
|
58
56
|
"mkdirp-classic": "^0.5.3",
|
|
59
57
|
"node-version-call": "^1.5.6",
|
|
@@ -70,9 +68,9 @@
|
|
|
70
68
|
"@biomejs/biome": "^1.9.4",
|
|
71
69
|
"@swc/core": "^1.9.3",
|
|
72
70
|
"@types/mocha": "^10.0.10",
|
|
73
|
-
"@types/node": "^22.10.
|
|
71
|
+
"@types/node": "^22.10.5",
|
|
74
72
|
"cr": "^0.1.0",
|
|
75
|
-
"cross-spawn-cb": "^2.0
|
|
73
|
+
"cross-spawn-cb": "^2.1.0",
|
|
76
74
|
"es6-map": "^0.1.5",
|
|
77
75
|
"es6-symbol": "^3.1.4",
|
|
78
76
|
"lodash.difference": "^4.5.0",
|