ts-swc-transform 1.15.57 → 2.0.0
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.d.cts +1 -1
- package/dist/cjs/{createMatcher.cjs → createMatcher.js} +1 -1
- package/dist/cjs/createMatcher.js.map +1 -0
- package/dist/cjs/index.d.cts +8 -8
- package/dist/cjs/{index.cjs → index.js} +7 -7
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/patchCJS.d.cts +1 -1
- package/dist/cjs/lib/{patchCJS.cjs → patchCJS.js} +8 -7
- package/dist/cjs/lib/patchCJS.js.map +1 -0
- package/dist/cjs/lib/patchESM.d.cts +1 -1
- package/dist/cjs/lib/patchESM.js +25 -0
- package/dist/cjs/lib/patchESM.js.map +1 -0
- package/dist/cjs/lib/{transformFile.cjs → transformFile.js} +3 -3
- package/dist/cjs/lib/transformFile.js.map +1 -0
- package/dist/cjs/loadTsConfig.d.cts +1 -1
- package/dist/cjs/loadTsConfig.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resolveFileSync.d.cts +1 -1
- package/dist/cjs/{resolveFileSync.cjs → resolveFileSync.js} +2 -2
- package/dist/cjs/resolveFileSync.js.map +1 -0
- package/dist/cjs/toPath.d.cts +1 -1
- package/dist/cjs/{toPath.cjs → toPath.js} +2 -2
- package/dist/cjs/toPath.js.map +1 -0
- package/dist/cjs/{transformDirectory.cjs → transformDirectory.js} +2 -2
- package/dist/cjs/transformDirectory.js.map +1 -0
- package/dist/cjs/{transformSync.cjs → transformSync.js} +1 -1
- package/dist/cjs/transformSync.js.map +1 -0
- package/dist/cjs/{transformTypes.cjs → transformTypes.js} +2 -2
- package/dist/cjs/transformTypes.js.map +1 -0
- package/dist/cjs/workers/{transformDirectory.cjs → transformDirectory.js} +32 -37
- package/dist/cjs/workers/transformDirectory.js.map +1 -0
- package/dist/cjs/workers/{transformSync.cjs → transformSync.js} +1 -1
- package/dist/cjs/workers/transformSync.js.map +1 -0
- package/dist/cjs/workers/{transformTypes.cjs → transformTypes.js} +42 -47
- package/dist/cjs/workers/transformTypes.js.map +1 -0
- package/dist/esm/createMatcher.d.mts +1 -1
- package/dist/esm/{createMatcher.mjs → createMatcher.js} +1 -1
- package/dist/esm/createMatcher.js.map +1 -0
- package/dist/esm/index.d.mts +8 -8
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/patchCJS.d.mts +1 -1
- package/dist/esm/lib/patchCJS.js +12 -0
- package/dist/esm/lib/patchCJS.js.map +1 -0
- package/dist/esm/lib/patchESM.d.mts +1 -1
- package/dist/esm/lib/patchESM.js +9 -0
- package/dist/esm/lib/patchESM.js.map +1 -0
- package/dist/esm/lib/{transformFile.mjs → transformFile.js} +3 -3
- package/dist/esm/lib/transformFile.js.map +1 -0
- package/dist/esm/loadTsConfig.d.mts +1 -1
- package/dist/esm/loadTsConfig.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/resolveFileSync.d.mts +1 -1
- package/dist/esm/{resolveFileSync.mjs → resolveFileSync.js} +2 -2
- package/dist/esm/resolveFileSync.js.map +1 -0
- package/dist/esm/toPath.d.mts +1 -1
- package/dist/esm/{toPath.mjs → toPath.js} +2 -2
- package/dist/esm/toPath.js.map +1 -0
- package/dist/esm/{transformDirectory.mjs → transformDirectory.js} +2 -2
- package/dist/esm/transformDirectory.js.map +1 -0
- package/dist/esm/{transformSync.mjs → transformSync.js} +1 -1
- package/dist/esm/transformSync.js.map +1 -0
- package/dist/esm/{transformTypes.mjs → transformTypes.js} +2 -2
- package/dist/esm/transformTypes.js.map +1 -0
- package/dist/esm/workers/transformDirectory.js +40 -0
- package/dist/esm/workers/transformDirectory.js.map +1 -0
- package/dist/esm/workers/{transformSync.mjs → transformSync.js} +1 -1
- package/dist/esm/workers/transformSync.js.map +1 -0
- package/dist/esm/workers/transformTypes.js +50 -0
- package/dist/esm/workers/transformTypes.js.map +1 -0
- package/package.json +6 -6
- package/dist/cjs/createMatcher.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/lib/makeReplacements.cjs +0 -47
- package/dist/cjs/lib/makeReplacements.cjs.map +0 -1
- package/dist/cjs/lib/makeReplacements.d.cts +0 -1
- package/dist/cjs/lib/parseSpecifiers.cjs +0 -37
- package/dist/cjs/lib/parseSpecifiers.cjs.map +0 -1
- package/dist/cjs/lib/parseSpecifiers.d.cts +0 -1
- package/dist/cjs/lib/patchCJS.cjs.map +0 -1
- package/dist/cjs/lib/patchESM.cjs +0 -44
- package/dist/cjs/lib/patchESM.cjs.map +0 -1
- package/dist/cjs/lib/transformFile.cjs.map +0 -1
- package/dist/cjs/loadTsConfig.cjs.map +0 -1
- package/dist/cjs/resolveFileSync.cjs.map +0 -1
- package/dist/cjs/toPath.cjs.map +0 -1
- package/dist/cjs/transformDirectory.cjs.map +0 -1
- package/dist/cjs/transformSync.cjs.map +0 -1
- package/dist/cjs/transformTypes.cjs.map +0 -1
- package/dist/cjs/workers/transformDirectory.cjs.map +0 -1
- package/dist/cjs/workers/transformSync.cjs.map +0 -1
- package/dist/cjs/workers/transformTypes.cjs.map +0 -1
- package/dist/esm/createMatcher.mjs.map +0 -1
- package/dist/esm/index.mjs +0 -7
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/lib/makeReplacements.d.mts +0 -1
- package/dist/esm/lib/makeReplacements.mjs +0 -29
- package/dist/esm/lib/makeReplacements.mjs.map +0 -1
- package/dist/esm/lib/parseSpecifiers.d.mts +0 -1
- package/dist/esm/lib/parseSpecifiers.mjs +0 -26
- package/dist/esm/lib/parseSpecifiers.mjs.map +0 -1
- package/dist/esm/lib/patchCJS.mjs +0 -11
- package/dist/esm/lib/patchCJS.mjs.map +0 -1
- package/dist/esm/lib/patchESM.mjs +0 -28
- package/dist/esm/lib/patchESM.mjs.map +0 -1
- package/dist/esm/lib/transformFile.mjs.map +0 -1
- package/dist/esm/loadTsConfig.mjs.map +0 -1
- package/dist/esm/resolveFileSync.mjs.map +0 -1
- package/dist/esm/toPath.mjs.map +0 -1
- package/dist/esm/transformDirectory.mjs.map +0 -1
- package/dist/esm/transformSync.mjs.map +0 -1
- package/dist/esm/transformTypes.mjs.map +0 -1
- package/dist/esm/workers/transformDirectory.mjs +0 -45
- package/dist/esm/workers/transformDirectory.mjs.map +0 -1
- package/dist/esm/workers/transformSync.mjs.map +0 -1
- package/dist/esm/workers/transformTypes.mjs +0 -55
- package/dist/esm/workers/transformTypes.mjs.map +0 -1
- /package/dist/cjs/{constants.cjs → constants.js} +0 -0
- /package/dist/cjs/{constants.cjs.map → constants.js.map} +0 -0
- /package/dist/cjs/lib/{swcPrepareOptions.cjs → swcPrepareOptions.js} +0 -0
- /package/dist/cjs/lib/{swcPrepareOptions.cjs.map → swcPrepareOptions.js.map} +0 -0
- /package/dist/cjs/lib/{url-file-url.cjs → url-file-url.js} +0 -0
- /package/dist/cjs/lib/{url-file-url.cjs.map → url-file-url.js.map} +0 -0
- /package/dist/cjs/{loadTsConfig.cjs → loadTsConfig.js} +0 -0
- /package/dist/cjs/{types.cjs → types.js} +0 -0
- /package/dist/cjs/{types.cjs.map → types.js.map} +0 -0
- /package/dist/esm/{constants.mjs → constants.js} +0 -0
- /package/dist/esm/{constants.mjs.map → constants.js.map} +0 -0
- /package/dist/esm/lib/{swcPrepareOptions.mjs → swcPrepareOptions.js} +0 -0
- /package/dist/esm/lib/{swcPrepareOptions.mjs.map → swcPrepareOptions.js.map} +0 -0
- /package/dist/esm/lib/{url-file-url.mjs → url-file-url.js} +0 -0
- /package/dist/esm/lib/{url-file-url.mjs.map → url-file-url.js.map} +0 -0
- /package/dist/esm/{loadTsConfig.mjs → loadTsConfig.js} +0 -0
- /package/dist/esm/{types.mjs → types.js} +0 -0
- /package/dist/esm/{types.mjs.map → types.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig.js';\nimport type { Matcher } from './types.js';\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 // @ts-ignore\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 (filePath.endsWith('.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":["minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AACA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,oBAAoB;AAG7C,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,aAAa;YACb,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,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWd,QAAQc;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type * from './types';
|
|
2
|
-
export { default as createMatcher } from './createMatcher';
|
|
3
|
-
export * as constants from './constants';
|
|
4
|
-
export { default as resolveFileSync } from './resolveFileSync';
|
|
5
|
-
export { default as toPath } from './toPath';
|
|
6
|
-
export { default as transformDirectory } from './transformDirectory';
|
|
7
|
-
export { default as transformSync } from './transformSync';
|
|
8
|
-
export { default as transformTypes } from './transformTypes';
|
|
1
|
+
export type * from './types.js';
|
|
2
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
3
|
+
export * as constants from './constants.js';
|
|
4
|
+
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
5
|
+
export { default as toPath } from './toPath.js';
|
|
6
|
+
export { default as transformDirectory } from './transformDirectory.js';
|
|
7
|
+
export { default as transformSync } from './transformSync.js';
|
|
8
|
+
export { default as transformTypes } from './transformTypes.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
2
|
+
export * as constants from './constants.js';
|
|
3
|
+
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
4
|
+
export { default as toPath } from './toPath.js';
|
|
5
|
+
export { default as transformDirectory } from './transformDirectory.js';
|
|
6
|
+
export { default as transformSync } from './transformSync.js';
|
|
7
|
+
export { default as transformTypes } from './transformTypes.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/index.ts"],"sourcesContent":["export type * from './types.js';\nexport { default as createMatcher } from './createMatcher.js';\nexport * as constants from './constants.js';\nexport { default as resolveFileSync } from './resolveFileSync.js';\nexport { default as toPath } from './toPath.js';\n\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\nexport { default as transformTypes } from './transformTypes.js';\n"],"names":["default","createMatcher","constants","resolveFileSync","toPath","transformDirectory","transformSync","transformTypes"],"mappings":"AACA,SAASA,WAAWC,aAAa,QAAQ,qBAAqB;AAC9D,OAAO,KAAKC,SAAS,MAAM,iBAAiB;AAC5C,SAASF,WAAWG,eAAe,QAAQ,uBAAuB;AAClE,SAASH,WAAWI,MAAM,QAAQ,cAAc;AAEhD,SAASJ,WAAWK,kBAAkB,QAAQ,0BAA0B;AACxE,SAASL,WAAWM,aAAa,QAAQ,qBAAqB;AAC9D,SAASN,WAAWO,cAAc,QAAQ,sBAAsB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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
|
-
export default function patchCJS(entry: any, output: any,
|
|
2
|
+
export default function patchCJS(entry: any, output: any, _options: any): any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
3
|
+
export const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
4
|
+
const EXTENSIONS = [
|
|
5
|
+
'.ts',
|
|
6
|
+
'.tsx'
|
|
7
|
+
];
|
|
8
|
+
export default function patchCJS(entry, output, _options) {
|
|
9
|
+
output.code += interop;
|
|
10
|
+
const ext = path.extname(entry.basename);
|
|
11
|
+
return EXTENSIONS.indexOf(ext) >= 0 ? '.js' : ext;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst EXTENSIONS = ['.ts', '.tsx'];\n\nexport default function patchCJS(entry, output, _options) {\n output.code += interop;\n const ext = path.extname(entry.basename);\n return EXTENSIONS.indexOf(ext) >= 0 ? '.js' : ext;\n}\n"],"names":["path","interop","EXTENSIONS","patchCJS","entry","output","_options","code","ext","extname","basename","indexOf"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAE3R,MAAMC,aAAa;IAAC;IAAO;CAAO;AAElC,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,QAAQ;IACtDD,OAAOE,IAAI,IAAIN;IACf,MAAMO,MAAMR,KAAKS,OAAO,CAACL,MAAMM,QAAQ;IACvC,OAAOR,WAAWS,OAAO,CAACH,QAAQ,IAAI,QAAQA;AAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function patchESM(entry: any,
|
|
1
|
+
export default function patchESM(entry: any, _output: any, _options: any): any;
|
|
@@ -0,0 +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, _output, _options) {\n const ext = path.extname(entry.basename);\n return EXTENSIONS.indexOf(ext) >= 0 ? '.js' : ext;\n}\n"],"names":["path","EXTENSIONS","patchESM","entry","_output","_options","ext","extname","basename","indexOf"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,MAAMC,aAAa;IAAC;IAAO;CAAO;AAElC,eAAe,SAASC,SAASC,KAAK,EAAEC,OAAO,EAAEC,QAAQ;IACvD,MAAMC,MAAMN,KAAKO,OAAO,CAACJ,MAAMK,QAAQ;IACvC,OAAOP,WAAWQ,OAAO,CAACH,QAAQ,IAAI,QAAQA;AAChD"}
|
|
@@ -2,9 +2,9 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import mkdirp from 'mkdirp-classic';
|
|
4
4
|
import Queue from 'queue-cb';
|
|
5
|
-
import patchCJS from '../lib/patchCJS.
|
|
6
|
-
import patchESM from '../lib/patchESM.
|
|
7
|
-
import swcPrepareOptions from '../lib/swcPrepareOptions.
|
|
5
|
+
import patchCJS from '../lib/patchCJS.js';
|
|
6
|
+
import patchESM from '../lib/patchESM.js';
|
|
7
|
+
import swcPrepareOptions from '../lib/swcPrepareOptions.js';
|
|
8
8
|
import Module from 'module';
|
|
9
9
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
10
10
|
export default function transformFile(entry, dest, type, options, callback) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS.js';\nimport patchESM from '../lib/patchESM.js';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nimport Module from 'module';\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":["fs","path","mkdirp","Queue","patchCJS","patchESM","swcPrepareOptions","Module","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","ext","extname","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,eAAe,SAASG,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,aAAajB,kBAAkBY;IACrC,MAAMM,MAAMhB,SAAS;IAErBgB,IACGZ,aAAa,CAACC,MAAMY,QAAQ,EAAE;QAC7B,GAAIZ,MAAMa,QAAQ,CAACC,QAAQ,CAAC,WAAWd,MAAMa,QAAQ,CAACC,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QACzHC,UAAUjB,MAAMa,QAAQ;IAC1B,GACCK,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYlB,SAAS,QAAQV,SAASQ,OAAOmB,QAAQhB,WAAWZ,SAASS,OAAOmB,QAAQhB;QAC9F,MAAMkB,MAAMjC,KAAKkC,OAAO,CAACtB,MAAMZ,IAAI;QACnC,MAAMmC,UAAUnC,KAAKoC,IAAI,CAACvB,MAAM,AAACoB,CAAAA,MAAMrB,MAAMZ,IAAI,CAACqC,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAI1B,MAAMZ,IAAI,AAAD,IAAKgC;QAExF/B,OAAOD,KAAKuC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAItC;YAClBsC,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC7B,QAAQ8B,UAAU,IAAIL,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMmB;QAC7D;IACF,GACCc,KAAK,CAACjC;AACX"}
|
|
@@ -0,0 +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":["getTS","loadTsConfig","options","name","tsconfig","getTsconfig","cwd","process","Error","path","undefined","config"],"mappings":"AAAA,YAAYA,WAAW,sBAAsB;AAG7C,eAAe,SAASC,aAAaC,OAAsB,EAAEC,IAAY;IACvE,IAAIC,WAAWF,QAAQE,QAAQ;IAC/B,IAAI,CAACA,UAAUA,WAAWJ,MAAMK,WAAW,CAACH,QAAQI,GAAG,IAAIC,QAAQD,GAAG;IAEtE,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAII,MAAM,GAAGL,KAAK,wBAAwB,CAAC;IACnF,IAAIC,SAASK,IAAI,KAAKC,WAAW,MAAM,IAAIF,MAAM,GAAGL,KAAK,yBAAyB,CAAC;IACnF,IAAIC,SAASO,MAAM,KAAKD,WAAW,MAAM,IAAIF,MAAM,GAAGL,KAAK,2BAA2B,CAAC;IACvF,OAAOC;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Context } from './types';
|
|
1
|
+
import type { Context } from './types.js';
|
|
2
2
|
export default function resolveFileSync(specifier: string, context?: Context): any;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import find from 'lodash.find';
|
|
4
|
-
import { extensions, moduleRegEx, typeFileRegEx } from './constants.
|
|
5
|
-
import toPath from './toPath.
|
|
4
|
+
import { extensions, moduleRegEx, typeFileRegEx } from './constants.js';
|
|
5
|
+
import toPath from './toPath.js';
|
|
6
6
|
const indexExtensions = extensions.map((x)=>`index${x}`);
|
|
7
7
|
export default function resolveFileSync(specifier, context) {
|
|
8
8
|
const filePath = toPath(specifier, context);
|
|
@@ -0,0 +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 find from 'lodash.find';\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":["fs","path","find","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","endsWith","items","readdirSync","item","indexOf","join","test","ext","extname","basename","slice","length","dirname","extTest","basenameTest"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,cAAc;AAC/B,SAASC,UAAU,EAAEC,WAAW,EAAEC,aAAa,QAAQ,iBAAiB;AACxE,OAAOC,YAAY,cAAc;AAGjC,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,MAAON,UAAUO,QAAQ,CAAC,MAAM;YAC3D,MAAMC,QAAQnB,GAAGoB,WAAW,CAACP;YAC7B,MAAMQ,OAAOnB,KAAKiB,OAAO,CAACV,IAAMF,gBAAgBe,OAAO,CAACb,MAAM;YAC9D,IAAIY,MAAM,OAAOpB,KAAKsB,IAAI,CAACV,UAAUQ;QACvC,OAAO,IAAI,CAACP,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,MAAMM,QAAQnB,GAAGoB,WAAW,CAACnB,KAAK6B,OAAO,CAACjB;YAC1C,MAAMQ,OAAOnB,KAAKiB,OAAO,CAACV;gBACxB,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,IAAIX,MAAM,OAAOpB,KAAKsB,IAAI,CAACtB,KAAK6B,OAAO,CAACjB,WAAWQ;QACrD;QACA,wBAAwB;QACxB,OAAOP,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/esm/toPath.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Context } from './types';
|
|
1
|
+
import type { Context } from './types.js';
|
|
2
2
|
export default function toPath(specifier: string, context?: Context): any;
|
|
@@ -5,8 +5,8 @@ import isAbsolute from 'is-absolute';
|
|
|
5
5
|
import resolveCJS from 'resolve';
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
import { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';
|
|
8
|
-
import { moduleRegEx } from './constants.
|
|
9
|
-
import * as urlPolyfills from './lib/url-file-url.
|
|
8
|
+
import { moduleRegEx } from './constants.js';
|
|
9
|
+
import * as urlPolyfills from './lib/url-file-url.js';
|
|
10
10
|
const useCJS = !module.createRequire;
|
|
11
11
|
const fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;
|
|
12
12
|
const pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import module from 'module';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolveCJS from 'resolve';\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":["module","path","url","isAbsolute","resolveCJS","resolve","resolveESM","moduleRegEx","urlPolyfills","useCJS","createRequire","fileURLToPath","pathToFileURL","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","startsWith","join","test","entryURL","_","entryPath","sync","basedir","extensions"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,gBAAgB,UAAU;AACjC,aAAa;AACb,SAASC,WAAWC,UAAU,QAAQ,uCAAuC;AAC7E,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,YAAYC,kBAAkB,wBAAwB;AAGtD,MAAMC,SAAS,CAACT,OAAOU,aAAa;AACpC,MAAMC,gBAAgBT,IAAIS,aAAa,IAAIH,aAAaG,aAAa;AACrE,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIJ,aAAaI,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOd,KAAKe,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGhB,KAAKe,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOX,cAAcU;IACxD,IAAIlB,WAAWkB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOnB,KAAKsB,IAAI,CAACR,YAAYM;IAC/B;IACA,IAAId,YAAYiB,IAAI,CAACH,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACX,QAAQ;YACX,IAAI;gBACF,MAAMgB,WAAWnB,WAAWe,WAAWT,cAAcG;gBACrD,IAAIU,UAAU,OAAOd,cAAcc;YACrC,EAAE,OAAOC,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,MAAMC,YAAYvB,WAAWwB,IAAI,CAACP,WAAW;YAC3CQ,SAASd;YACTe,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIH,WAAW,OAAOA;IACxB;IAEA,OAAON;AACT"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import url from 'url';
|
|
3
|
-
import loadTsConfig from './loadTsConfig.
|
|
3
|
+
import loadTsConfig from './loadTsConfig.js';
|
|
4
4
|
const major = +process.versions.node.split('.')[0];
|
|
5
5
|
const version = major < 14 ? 'stable' : 'local';
|
|
6
6
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
|
-
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.
|
|
7
|
+
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');
|
|
8
8
|
import Module from 'module';
|
|
9
9
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
10
10
|
function dispatch(version, src, dest, type, options, callback) {
|
|
@@ -0,0 +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';\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\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src: string, dest: string, type: string, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) => dispatch(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;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,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYjB,GAAG,IAAIgB;AAE1F,SAASE,SAASX,OAAO,EAAEY,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3D,IAAIhB,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAER;YAASiB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGA;;;;;;;CAOC,GACD,eAAe,SAASC,mBAAmBP,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAoD,EAAEC,QAAqC;IAC7K,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAC9C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMM,WAAW3B,aAAa;YAAE4B,KAAKV;YAAK,GAAGG,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,CAACC,SAASC,SAAWd,SAASX,SAASY,KAAKC,MAAMC,MAAMC,SAAS,CAACG,KAAKQ,SAAYR,MAAMO,OAAOP,OAAOM,QAAQE;IACpI,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
|
|
@@ -4,7 +4,7 @@ import * as getTS from 'get-tsconfig-compat';
|
|
|
4
4
|
const major = +process.versions.node.split('.')[0];
|
|
5
5
|
const version = major < 14 ? 'stable' : 'local';
|
|
6
6
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
|
-
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.
|
|
7
|
+
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');
|
|
8
8
|
import Module from 'module';
|
|
9
9
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
10
10
|
function dispatch(version, contents, fileName, tsconfig) {
|
|
@@ -0,0 +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.js');\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(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","_require","require","createRequire","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,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYjB,GAAG,IAAIgB;AAE1F,SAASE,SAASX,OAAO,EAAEY,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAId,YAAY,SAAS,OAAOQ,SAASH,YAAYO,UAAUC,UAAUC;IACzE,OAAON,SAAS,qBAAqBR,SAASK,YAAYO,UAAUC,UAAUC;AAChF;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,WAAWpB,MAAMuB,WAAW,CAACrB,QAAQsB,GAAG;IACvD,OAAOP,SAASX,SAASY,UAAUC,UAAUC;AAC/C"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import url from 'url';
|
|
3
|
-
import loadTsConfig from './loadTsConfig.
|
|
3
|
+
import loadTsConfig from './loadTsConfig.js';
|
|
4
4
|
const major = +process.versions.node.split('.')[0];
|
|
5
5
|
const version = major < 14 ? 'stable' : 'local';
|
|
6
6
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
7
|
-
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.
|
|
7
|
+
const workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');
|
|
8
8
|
import Module from 'module';
|
|
9
9
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
10
10
|
function dispatch(version, src, dest, options, callback) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.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', 'transformTypes.js');\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types';\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {{tsconfig: TsConfigResult}} options Options.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformTypes');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","options","callback","callbacks","err","transformTypes","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;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,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYjB,GAAG,IAAIgB;AAE1F,SAASE,SAASX,OAAO,EAAEY,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIf,YAAY,SAAS,OAAOQ,SAASH,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMP,SAAS,qBAAqB;YAAER;YAASgB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGA;;;;;;CAMC,GACD,eAAe,SAASC,eAAeN,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMM,WAAW1B,aAAa;YAAE2B,KAAKT;YAAK,GAAGE,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASX,SAASY,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIO,QAAQ,CAACC,SAASC,SAAWb,SAASX,SAASY,KAAKC,MAAMC,SAAS,CAACG,KAAKQ,SAAYR,MAAMO,OAAOP,OAAOM,QAAQE;IAC9H,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import Iterator from 'fs-iterator';
|
|
3
|
+
import Queue from 'queue-cb';
|
|
4
|
+
import { extensions, typeFileRegEx } from '../constants.js';
|
|
5
|
+
import createMatcher from '../createMatcher.js';
|
|
6
|
+
import transformFile from '../lib/transformFile.js';
|
|
7
|
+
export default function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
8
|
+
const tsconfig = options.tsconfig;
|
|
9
|
+
const matcher = createMatcher(tsconfig);
|
|
10
|
+
const entries = [];
|
|
11
|
+
const iterator = new Iterator(src);
|
|
12
|
+
iterator.forEach((entry)=>{
|
|
13
|
+
if (!entry.stats.isFile()) return;
|
|
14
|
+
if (entry.basename[0] === '.') return;
|
|
15
|
+
if (typeFileRegEx.test(entry.basename)) return;
|
|
16
|
+
if (!matcher(entry.fullPath)) return;
|
|
17
|
+
const ext = path.extname(entry.basename);
|
|
18
|
+
if (ext && extensions.indexOf(ext) < 0) return;
|
|
19
|
+
entries.push(entry);
|
|
20
|
+
}, (err)=>{
|
|
21
|
+
if (err) return callback(err);
|
|
22
|
+
const results = [];
|
|
23
|
+
options = {
|
|
24
|
+
...options,
|
|
25
|
+
tsconfig,
|
|
26
|
+
src,
|
|
27
|
+
dest
|
|
28
|
+
};
|
|
29
|
+
const queue = new Queue();
|
|
30
|
+
entries.forEach((entry)=>{
|
|
31
|
+
queue.defer((cb)=>transformFile(entry, dest, type, options, (err, outPath)=>{
|
|
32
|
+
if (err) return cb(err);
|
|
33
|
+
results.push(path.normalize(outPath));
|
|
34
|
+
if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);
|
|
35
|
+
cb();
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
queue.await((err)=>err ? callback(err) : callback(null, results));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\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) => {\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) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(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":["path","Iterator","Queue","extensions","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","ext","extname","indexOf","push","err","results","queue","defer","cb","outPath","normalize","sourceMaps","await"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,OAAOC,WAAW,WAAW;AAE7B,SAASC,UAAU,EAAEC,aAAa,QAAQ,kBAAkB;AAC5D,OAAOC,mBAAmB,sBAAsB;AAChD,OAAOC,mBAAmB,0BAA0B;AAEpD,eAAe,SAASC,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUT,cAAcQ;IAE9B,MAAME,UAAU,EAAE;IAClB,MAAMC,WAAW,IAAIf,SAASO;IAC9BQ,SAASC,OAAO,CACd,CAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIjB,cAAckB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACP,QAAQI,MAAMK,QAAQ,GAAG;QAC9B,MAAMC,MAAMxB,KAAKyB,OAAO,CAACP,MAAMG,QAAQ;QACvC,IAAIG,OAAOrB,WAAWuB,OAAO,CAACF,OAAO,GAAG;QACxCT,QAAQY,IAAI,CAACT;IACf,GACA,CAACU;QACC,IAAIA,KAAK,OAAOhB,SAASgB;QACzB,MAAMC,UAAU,EAAE;QAClBlB,UAAU;YAAE,GAAGA,OAAO;YAAEE;YAAUL;YAAKC;QAAK;QAE5C,MAAMqB,QAAQ,IAAI5B;QAClBa,QAAQE,OAAO,CAAC,CAACC;YACfY,MAAMC,KAAK,CAAC,CAACC,KACX1B,cAAcY,OAAOT,MAAMC,MAAMC,SAAS,CAACiB,KAAKK;oBAC9C,IAAIL,KAAK,OAAOI,GAAGJ;oBACnBC,QAAQF,IAAI,CAAC3B,KAAKkC,SAAS,CAACD;oBAC5B,IAAItB,QAAQwB,UAAU,EAAEN,QAAQF,IAAI,CAAC,GAAG3B,KAAKkC,SAAS,CAACD,SAAS,IAAI,CAAC;oBACrED;gBACF;QAEJ;QACAF,MAAMM,KAAK,CAAC,CAACR,MAASA,MAAMhB,SAASgB,OAAOhB,SAAS,MAAMiB;IAC7D;AAEJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import swcPrepareOptions from '../lib/swcPrepareOptions.
|
|
1
|
+
import swcPrepareOptions from '../lib/swcPrepareOptions.js';
|
|
2
2
|
import Module from 'module';
|
|
3
3
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
4
4
|
export default function transformSyncWorker(contents, fileName, tsconfig) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nimport Module from 'module';\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":["swcPrepareOptions","Module","_require","require","createRequire","url","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":"AAAA,OAAOA,uBAAuB,8BAA8B;AAE5D,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,MAAMC,aAAaV,kBAAkBS;IACrC,MAAME,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACL,UAAU;QACjC,GAAIC,SAASK,QAAQ,CAAC,WAAWL,SAASK,QAAQ,CAAC,UAAUH,WAAWI,UAAU,GAAGJ,WAAWK,aAAa;QAC7GC,UAAUR;IACZ;AACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Iterator from 'fs-iterator';
|
|
2
|
+
import Module from 'module';
|
|
3
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
4
|
+
import { typeFileRegEx } from '../constants.js';
|
|
5
|
+
import createMatcher from '../createMatcher.js';
|
|
6
|
+
export default function transformTypesWorker(src, dest, options, callback) {
|
|
7
|
+
const tsconfig = options.tsconfig;
|
|
8
|
+
const matcher = createMatcher(tsconfig);
|
|
9
|
+
const ts = _require('typescript');
|
|
10
|
+
const entries = [];
|
|
11
|
+
const iterator = new Iterator(src);
|
|
12
|
+
iterator.forEach((entry)=>{
|
|
13
|
+
if (!entry.stats.isFile()) return;
|
|
14
|
+
if (entry.basename[0] === '.') return;
|
|
15
|
+
if (typeFileRegEx.test(entry.basename)) return;
|
|
16
|
+
if (!matcher(entry.fullPath)) return;
|
|
17
|
+
entries.push(entry);
|
|
18
|
+
}, {
|
|
19
|
+
concurrency: Infinity
|
|
20
|
+
}, (err)=>{
|
|
21
|
+
if (err) return callback(err);
|
|
22
|
+
const config = {
|
|
23
|
+
fileNames: entries.map((entry)=>entry.fullPath),
|
|
24
|
+
options: {
|
|
25
|
+
...tsconfig.compilerOptions || {},
|
|
26
|
+
outDir: dest,
|
|
27
|
+
allowJs: true,
|
|
28
|
+
declaration: true,
|
|
29
|
+
emitDeclarationOnly: true,
|
|
30
|
+
listEmittedFiles: true
|
|
31
|
+
},
|
|
32
|
+
projectReferences: tsconfig.config.references
|
|
33
|
+
};
|
|
34
|
+
const { fileNames, options, projectReferences } = config;
|
|
35
|
+
const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);
|
|
36
|
+
const programOptions = {
|
|
37
|
+
rootNames: fileNames,
|
|
38
|
+
options,
|
|
39
|
+
projectReferences,
|
|
40
|
+
host,
|
|
41
|
+
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({
|
|
42
|
+
fileNames,
|
|
43
|
+
options
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
const program = ts.createProgram(programOptions);
|
|
47
|
+
const res = program.emit();
|
|
48
|
+
callback(null, res.emittedFiles);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator from 'fs-iterator';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...(tsconfig.compilerOptions || {}),\n outDir: dest,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["Iterator","Module","_require","require","createRequire","url","typeFileRegEx","createMatcher","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","push","concurrency","Infinity","err","config","fileNames","map","compilerOptions","outDir","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","emittedFiles"],"mappings":"AAAA,OAAOA,cAAc,cAAc;AAEnC,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,aAAa,QAAQ,kBAAkB;AAChD,OAAOC,mBAAmB,sBAAsB;AAEhD,eAAe,SAASC,qBAAqBC,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACvE,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUP,cAAcM;IAC9B,MAAME,KAAKb,SAAS;IAEpB,MAAMc,UAAU,EAAE;IAClB,MAAMC,WAAW,IAAIjB,SAASS;IAC9BQ,SAASC,OAAO,CACd,CAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIhB,cAAciB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACR,QAAQK,MAAMK,QAAQ,GAAG;QAC9BR,QAAQS,IAAI,CAACN;IACf,GACA;QAAEO,aAAaC;IAAS,GACxB,CAACC;QACC,IAAIA,KAAK,OAAOhB,SAASgB;QAEzB,MAAMC,SAAS;YACbC,WAAWd,QAAQe,GAAG,CAAC,CAACZ,QAAUA,MAAMK,QAAQ;YAChDb,SAAS;gBACP,GAAIE,SAASmB,eAAe,IAAI,CAAC,CAAC;gBAClCC,QAAQvB;gBACRwB,SAAS;gBACTC,aAAa;gBACbC,qBAAqB;gBACrBC,kBAAkB;YACpB;YACAC,mBAAmBzB,SAASgB,MAAM,CAACU,UAAU;QAC/C;QACA,MAAM,EAAET,SAAS,EAAEnB,OAAO,EAAE2B,iBAAiB,EAAE,GAAGT;QAClD,MAAMW,OAAOzB,GAAG0B,wBAAwB,CAAC9B,SAAS,gBAAgB,GAAG+B,WAAW3B,GAAG4B,GAAG;QACtF,MAAMC,iBAAiB;YACrBC,WAAWf;YACXnB;YACA2B;YACAE;YACAM,8BAA8B/B,GAAGgC,+BAA+B,CAAC;gBAAEjB;gBAAWnB;YAAQ;QACxF;QACA,MAAMqC,UAAUjC,GAAGkC,aAAa,CAACL;QACjC,MAAMM,MAAMF,QAAQG,IAAI;QACxBvC,SAAS,MAAMsC,IAAIE,YAAY;IACjC;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"import": "./dist/esm/index.
|
|
27
|
-
"require": "./dist/cjs/index.
|
|
26
|
+
"import": "./dist/esm/index.js",
|
|
27
|
+
"require": "./dist/cjs/index.js"
|
|
28
28
|
},
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
31
|
-
"main": "dist/cjs/index.
|
|
31
|
+
"main": "dist/cjs/index.js",
|
|
32
32
|
"types": "dist/cjs/index.d.cts",
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"exit": "^0.1.2",
|
|
49
49
|
"fs-iterator": "^5.2.27",
|
|
50
50
|
"get-tsconfig-compat": "^2.0.3",
|
|
51
|
-
"install-optional": "^0.1.
|
|
51
|
+
"install-optional": "^0.1.54",
|
|
52
52
|
"is-absolute": "^1.0.0",
|
|
53
53
|
"lodash.find": "^4.6.0",
|
|
54
54
|
"minimatch": "^3.1.2",
|
|
55
55
|
"mkdirp-classic": "^0.5.3",
|
|
56
|
-
"node-version-call": "^1.6.
|
|
56
|
+
"node-version-call": "^1.6.55",
|
|
57
57
|
"path-posix": "^1.0.0",
|
|
58
58
|
"queue-cb": "^1.4.17",
|
|
59
59
|
"resolve": "^1.22.10",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\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 // @ts-ignore\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 (filePath.endsWith('.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":";;;;+BAOA;;;eAAwBA;;;gEANF;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,aAAa;YACb,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,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,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"}
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/index.ts"],"sourcesContent":["export type * from './types';\nexport { default as createMatcher } from './createMatcher';\nexport * as constants from './constants';\nexport { default as resolveFileSync } from './resolveFileSync';\nexport { default as toPath } from './toPath';\n\nexport { default as transformDirectory } from './transformDirectory';\nexport { default as transformSync } from './transformSync';\nexport { default as transformTypes } from './transformTypes';\n"],"names":["constants","createMatcher","resolveFileSync","toPath","transformDirectory","transformSync","transformTypes"],"mappings":";;;;;;;;;;;IAEYA,SAAS;;;IADDC,aAAa;eAAbA,sBAAa;;IAEbC,eAAe;eAAfA,wBAAe;;IACfC,MAAM;eAANA,eAAM;;IAENC,kBAAkB;eAAlBA,2BAAkB;;IAClBC,aAAa;eAAbA,sBAAa;;IACbC,cAAc;eAAdA,uBAAc;;;oEAPO;iEACd;sEACgB;6DACT;yEAEY;oEACL;qEACC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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 _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
-
var _lodashfind = /*#__PURE__*/ _interop_require_default(require("lodash.find"));
|
|
14
|
-
var _constants = require("../constants.cjs");
|
|
15
|
-
var _parseSpecifiers = /*#__PURE__*/ _interop_require_default(require("./parseSpecifiers.cjs"));
|
|
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; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/makeReplacements.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport find from 'lodash.find';\nimport { moduleRegEx } from '../constants';\nimport parseSpecifiers from './parseSpecifiers';\n\nexport default function makeReplacements(entry, code, regex, extensions, extension, options) {\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":";;;;+BAMA;;;eAAwBA;;;yDANT;2DACE;iEACA;yBACW;sEACA;;;;;;AAEb,SAASA,iBAAiBC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO;IACzF,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function makeReplacements(entry: any, code: any, regex: any, extensions: any, extension: any, options: any): string;
|
|
@@ -1,37 +0,0 @@
|
|
|
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; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/parseSpecifiers.ts"],"sourcesContent":["export default function parser(code, regex) {\n const parsed = [];\n let offset = 0;\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n parsed.push({ content: code.substring(offset, match.index + match[0].lastIndexOf(dependency)), isSpecifier: false });\n offset += parsed[parsed.length - 1].content.length;\n parsed.push({ content: dependency, isSpecifier: true });\n offset += parsed[parsed.length - 1].content.length;\n match = regex.exec(code);\n }\n\n if (offset < code.length) {\n parsed.push({ content: code.substring(offset, code.length), isSpecifier: false });\n }\n return parsed;\n}\n"],"names":["parser","code","regex","parsed","offset","match","exec","dependency","push","content","substring","index","lastIndexOf","isSpecifier","length"],"mappings":";;;;+BAAA;;;eAAwBA;;;AAAT,SAASA,OAAOC,IAAI,EAAEC,KAAK;IACxC,IAAMC,SAAS,EAAE;IACjB,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 +0,0 @@
|
|
|
1
|
-
export default function parser(code: any, regex: any): any[];
|
|
@@ -1 +0,0 @@
|
|
|
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; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interop;\n\n return cjsExtension;\n}\n"],"names":["patchCJS","interop","DEFAULT_EXTENSION","entry","output","options","cjsExtension","extensions","cjs","code","makeReplacements","requireRegEx"],"mappings":";;;;;;;;;;;IAQA,OAOC;eAPuBA;;IAJXC,OAAO;eAAPA;;;yBAJ4B;uEACZ;;;;;;AAGtB,IAAMA,UAAU;AAEvB,IAAMC,oBAAoB;AAEX,SAASF,SAASG,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,IAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACC,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FE,OAAOK,IAAI,GAAGC,IAAAA,yBAAgB,EAACP,OAAOC,OAAOK,IAAI,EAAEE,uBAAY,EAAEJ,qBAAU,EAAED,cAAcD;IAC3FD,OAAOK,IAAI,IAAIR;IAEf,OAAOK;AACT"}
|