ts-swc-transform 1.15.58 → 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 +4 -4
- 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
|
@@ -1 +0,0 @@
|
|
|
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';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformFile(entry, dest, type, options, callback) {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAYA;;;eAAwBA;;;yDAZT;2DACE;oEACE;8DACD;+DAEG;+DACA;wEACS;6DAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE3E,SAASF,cAAcK,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,MAAMhB,SAAS;IAErBgB,IACGjB,aAAa,CAACK,MAAMa,QAAQ,EAAE,wCACzBb,MAAMc,QAAQ,CAACC,QAAQ,CAAC,WAAWf,MAAMc,QAAQ,CAACC,QAAQ,CAAC,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QACzHC,UAAUlB,MAAMc,QAAQ;QAEzBK,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYnB,SAAS,QAAQoB,IAAAA,iBAAQ,EAACtB,OAAOoB,QAAQjB,WAAWoB,IAAAA,iBAAQ,EAACvB,OAAOoB,QAAQjB;QAC9F,IAAMqB,MAAMC,aAAI,CAACC,OAAO,CAAC1B,MAAMyB,IAAI;QACnC,IAAME,UAAUF,aAAI,CAACG,IAAI,CAAC3B,MAAM,AAACuB,CAAAA,MAAMxB,MAAMyB,IAAI,CAACI,KAAK,CAAC,GAAG,CAACL,IAAIM,MAAM,IAAI9B,MAAMyB,IAAI,AAAD,IAAKJ;QAExFU,IAAAA,sBAAM,EAACN,aAAI,CAACO,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASP,OAAOmB,IAAI,EAAE;YAC1D,CAACpC,QAAQqC,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOP,OAAOqB,GAAG,EAAE;YACzFR,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMvC,SAASuC,OAAOvC,SAAS,MAAMuB;;QAC7D;IACF,GACCiB,KAAK,CAACxC;AACX"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\n\nexport default function loadTsConfig(options: ConfigOptions, name: string) {\n let tsconfig = options.tsconfig;\n if (!tsconfig) tsconfig = getTS.getTsconfig(options.cwd || process.cwd());\n\n if (typeof tsconfig !== 'object') throw new Error(`${name}: missing valid tsconfig`);\n if (tsconfig.path === undefined) throw new Error(`${name}: expecting tsconfig.path`);\n if (tsconfig.config === undefined) throw new Error(`${name}: expecting tsconfig.config`);\n return tsconfig;\n}\n"],"names":["loadTsConfig","options","name","tsconfig","getTS","getTsconfig","cwd","process","Error","path","undefined","config"],"mappings":";;;;+BAGA;;;eAAwBA;;;yEAHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGR,SAASA,aAAaC,OAAsB,EAAEC,IAAY;IACvE,IAAIC,WAAWF,QAAQE,QAAQ;IAC/B,IAAI,CAACA,UAAUA,WAAWC,mBAAMC,WAAW,CAACJ,QAAQK,GAAG,IAAIC,QAAQD,GAAG;IAEtE,IAAI,CAAA,OAAOH,yCAAP,SAAOA,SAAO,MAAM,UAAU,MAAM,IAAIK,MAAM,AAAC,GAAO,OAALN,MAAK;IAC1D,IAAIC,SAASM,IAAI,KAAKC,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IACzD,IAAIC,SAASQ,MAAM,KAAKD,WAAW,MAAM,IAAIF,MAAM,AAAC,GAAO,OAALN,MAAK;IAC3D,OAAOC;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = find(items, (x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = find(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","length","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;2DACE;iEACA;yBACsC;6DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,qBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,UAAUS,QAAQ,CAAC,MAAM;YAC3D,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOC,IAAAA,mBAAI,EAACH,OAAO,SAACX;uBAAMH,gBAAgBkB,OAAO,CAACf,MAAM;;YAC9D,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,sBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACS,OAAO,CAACtB;YAC1C,IAAMU,QAAOC,IAAAA,mBAAI,EAACH,QAAO,SAACX;gBACxB,IAAI0B,wBAAa,CAACP,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM2B,UAAUX,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM4B,eAAeD,UAAUX,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACI,QAAQH,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaM;YACtB;YACA,IAAIf,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACS,OAAO,CAACtB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/cjs/toPath.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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';\nimport * as urlPolyfills from './lib/url-file-url';\nimport type { Context } from './types';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryURL","resolveESM","_","entryPath","resolveCJS","sync","basedir","extensions"],"mappings":";;;;+BAoBA;;;eAAwBA;;;6DApBL;2DACF;0DACD;iEACO;8DACA;oCAEe;yBACV;kEACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,YAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,YAAaC,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACZ,OAAOS,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASf,OAAOgB,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOb,cAAcY;IACxD,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,sBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,6BAAU,EAACP,WAAWT,cAAcG;gBACrD,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAYC,gBAAU,CAACC,IAAI,CAACX,WAAW;YAC3CY,SAASlB;YACTmB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIJ,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs');\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":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BAsBA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DA9BP;0DACD;mEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAGhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3D,IAAIlB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,MAAMC,SAASC;IAC/E,IAAI;QACFA,SAAS,MAAMT,SAAS,qBAAqB;YAAET,SAAAA;YAASmB,WAAW;QAAK,GAAGZ,YAAYO,KAAKC,MAAMC,MAAMC;IAC1G,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAWe,SAAS1B,mBAAmBoB,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAoD,EAAEC,QAAqC;IAC7K,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAC9C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMK,WAAWC,IAAAA,qBAAY,EAAC;YAAEC,KAAKV;WAAQG,UAAW;QACxDA,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,SAACC,SAASC;mBAAWd,SAASb,SAASc,KAAKC,MAAMC,MAAMC,SAAS,SAACG,KAAKQ;uBAAYR,MAAMO,OAAOP,OAAOM,QAAQE;;;IACpI,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\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":["transformSync","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","contents","fileName","tsconfig","Error","getTS","getTsconfig","cwd"],"mappings":";;;;+BAmBA;;;;;CAKC,GACD;;;eAAwBA;;;2DAzBP;0DACD;yEACO;6DAOJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAGhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAIhB,YAAY,SAAS,OAAOS,SAASF,YAAYO,UAAUC,UAAUC;IACzE,OAAOP,SAAS,qBAAqBT,SAASO,YAAYO,UAAUC,UAAUC;AAChF;AAUe,SAAStB,cAAcoB,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,CAACvB,QAAQwB,GAAG;IACvD,OAAOP,SAASb,SAASc,UAAUC,UAAUC;AAC/C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.cjs');\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":["transformTypes","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","src","dest","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BAsBA;;;;;;CAMC,GACD;;;eAAwBA;;;2DA7BP;0DACD;mEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAGhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACrD,IAAIjB,YAAY,SAAS,OAAOS,SAASF,YAAYO,KAAKC,MAAMC,SAASC;IACzE,IAAI;QACFA,SAAS,MAAMR,SAAS,qBAAqB;YAAET,SAAAA;YAASkB,WAAW;QAAK,GAAGX,YAAYO,KAAKC,MAAMC;IACpG,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAUe,SAASzB,eAAeoB,GAAW,EAAEC,IAAY,EAAEC,OAAgD,EAAEC,QAAiC;IACnJ,IAAI;QACF,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIM,MAAM;QAC7C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMK,WAAWC,IAAAA,qBAAY,EAAC;YAAEC,KAAKT;WAAQE,UAAW;QACxDA,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOJ,SAASb,SAASc,KAAKC,MAAMC,SAASC;QACjF,OAAO,IAAIO,QAAQ,SAACC,SAASC;mBAAWb,SAASb,SAASc,KAAKC,MAAMC,SAAS,SAACG,KAAKQ;uBAAYR,MAAMO,OAAOP,OAAOM,QAAQE;;;IAC9H,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { extensions, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport transformFile from '../lib/transformFile';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (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}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","rimraf2","disableGlob","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","err","results","queue","Queue","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BASA;;;eAAwBA;;;2DATP;iEACI;8DACH;8DACE;yBAEsB;oEAChB;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEX,SAASA,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,sBAAa,EAACF;IAE9BG,IAAAA,gBAAO,EAACP,MAAM;QAAEQ,aAAa;IAAK,GAAG;QACnC,IAAMC,UAAU,EAAE;QAClB,IAAMC,WAAW,IAAIC,mBAAQ,CAACZ;QAC9BW,SAASE,OAAO,CACd,SAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;YAC/B,IAAIC,wBAAa,CAACC,IAAI,CAACL,MAAMG,QAAQ,GAAG;YACxC,IAAI,CAACX,QAAQQ,MAAMM,QAAQ,GAAG;YAC9B,IAAMC,MAAMC,aAAI,CAACC,OAAO,CAACT,MAAMG,QAAQ;YACvC,IAAII,OAAOG,qBAAU,CAACC,OAAO,CAACJ,OAAO,GAAG;YACxCX,QAAQgB,IAAI,CAACZ;QACf,GACA,SAACa;YACC,IAAIA,KAAK,OAAOvB,SAASuB;YACzB,IAAMC,UAAU,EAAE;YAClBzB,UAAU,wCAAKA;gBAASE,UAAAA;gBAAUL,KAAAA;gBAAKC,MAAAA;;YAEvC,IAAM4B,QAAQ,IAAIC,gBAAK;YACvBpB,QAAQG,OAAO,CAAC,SAACC;gBACfe,MAAME,KAAK,CAAC,SAACC;2BACXC,IAAAA,sBAAa,EAACnB,OAAOb,MAAMC,MAAMC,SAAS,SAACwB,KAAKO;wBAC9C,IAAIP,KAAK,OAAOK,GAAGL;wBACnBC,QAAQF,IAAI,CAACJ,aAAI,CAACa,SAAS,CAACD;wBAC5B,IAAI/B,QAAQiC,UAAU,EAAER,QAAQF,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACa,SAAS,CAACD,UAAS;wBAChEF;oBACF;;YAEJ;YACAH,MAAMQ,KAAK,CAAC,SAACV;uBAASA,MAAMvB,SAASuB,OAAOvB,SAAS,MAAMwB;;QAC7D;IAEJ;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions';\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":["transformSyncWorker","_require","require","Module","createRequire","contents","fileName","tsconfig","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAMA;;;eAAwBA;;;wEANM;6DAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,oBAAoBK,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,IAAMC,aAAaC,IAAAA,0BAAiB,EAACF;IACrC,IAAMG,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACN,UAAU,wCAC7BC,SAASM,QAAQ,CAAC,WAAWN,SAASM,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUT;;AAEd"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator from 'fs-iterator';\nimport rimraf2 from 'rimraf2';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\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 rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (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}\n"],"names":["transformTypesWorker","_require","require","Module","createRequire","src","dest","options","callback","tsconfig","matcher","createMatcher","ts","rimraf2","disableGlob","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","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":";;;;+BASA;;;eAAwBA;;;iEATH;8DACD;6DAED;yBAGW;oEACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAH1B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAK3E,SAASF,qBAAqBK,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACvE,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,sBAAa,EAACF;IAC9B,IAAMG,KAAKX,SAAS;IAEpBY,IAAAA,gBAAO,EAACP,MAAM;QAAEQ,aAAa;IAAK,GAAG;QACnC,IAAMC,UAAU,EAAE;QAClB,IAAMC,WAAW,IAAIC,mBAAQ,CAACZ;QAC9BW,SAASE,OAAO,CACd,SAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;YAC/B,IAAIC,wBAAa,CAACC,IAAI,CAACL,MAAMG,QAAQ,GAAG;YACxC,IAAI,CAACZ,QAAQS,MAAMM,QAAQ,GAAG;YAC9BV,QAAQW,IAAI,CAACP;QACf,GACA;YAAEQ,aAAaC;QAAS,GACxB,SAACC;YACC,IAAIA,KAAK,OAAOrB,SAASqB;YAEzB,IAAMC,SAAS;gBACbC,WAAWhB,QAAQiB,GAAG,CAAC,SAACb;2BAAUA,MAAMM,QAAQ;;gBAChDlB,SAAS,wCACHE,SAASwB,eAAe,IAAI,CAAC;oBACjCC,QAAQ5B;oBACR6B,SAAS;oBACTC,aAAa;oBACbC,qBAAqB;oBACrBC,kBAAkB;;gBAEpBC,mBAAmB9B,SAASqB,MAAM,CAACU,UAAU;YAC/C;YACA,IAAQT,YAA0CD,OAA1CC,WAAWxB,YAA+BuB,OAA/BvB,SAASgC,oBAAsBT,OAAtBS;YAC5B,IAAME,OAAO7B,GAAG8B,wBAAwB,CAACnC,WAAS,gBAAgB,GAAGoC,WAAW/B,GAAGgC,GAAG;YACtF,IAAMC,iBAAiB;gBACrBC,WAAWf;gBACXxB,SAAAA;gBACAgC,mBAAAA;gBACAE,MAAAA;gBACAM,8BAA8BnC,GAAGoC,+BAA+B,CAAC;oBAAEjB,WAAAA;oBAAWxB,SAAAA;gBAAQ;YACxF;YACA,IAAM0C,UAAUrC,GAAGsC,aAAa,CAACL;YACjC,IAAMM,MAAMF,QAAQG,IAAI;YACxB5C,SAAS,MAAM2C,IAAIE,YAAY;QACjC;IAEJ;AACF"}
|
|
@@ -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":["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,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,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.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as createMatcher } from './createMatcher.mjs';
|
|
2
|
-
export * as constants from './constants.mjs';
|
|
3
|
-
export { default as resolveFileSync } from './resolveFileSync.mjs';
|
|
4
|
-
export { default as toPath } from './toPath.mjs';
|
|
5
|
-
export { default as transformDirectory } from './transformDirectory.mjs';
|
|
6
|
-
export { default as transformSync } from './transformSync.mjs';
|
|
7
|
-
export { default as transformTypes } from './transformTypes.mjs';
|
package/dist/esm/index.mjs.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":["default","createMatcher","constants","resolveFileSync","toPath","transformDirectory","transformSync","transformTypes"],"mappings":"AACA,SAASA,WAAWC,aAAa,QAAQ,kBAAkB;AAC3D,OAAO,KAAKC,SAAS,MAAM,cAAc;AACzC,SAASF,WAAWG,eAAe,QAAQ,oBAAoB;AAC/D,SAASH,WAAWI,MAAM,QAAQ,WAAW;AAE7C,SAASJ,WAAWK,kBAAkB,QAAQ,uBAAuB;AACrE,SAASL,WAAWM,aAAa,QAAQ,kBAAkB;AAC3D,SAASN,WAAWO,cAAc,QAAQ,mBAAmB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function makeReplacements(entry: any, code: any, regex: any, extensions: any, extension: any, options: any): string;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import find from 'lodash.find';
|
|
4
|
-
import { moduleRegEx } from '../constants.mjs';
|
|
5
|
-
import parseSpecifiers from './parseSpecifiers.mjs';
|
|
6
|
-
export default function makeReplacements(entry, code, regex, extensions, extension, options) {
|
|
7
|
-
const { src } = options;
|
|
8
|
-
const parsed = parseSpecifiers(code, regex);
|
|
9
|
-
return parsed.map((parsed)=>{
|
|
10
|
-
if (!parsed.isSpecifier) return parsed.content;
|
|
11
|
-
const specifier = parsed.content;
|
|
12
|
-
if (moduleRegEx.test(specifier)) return specifier;
|
|
13
|
-
const ext = path.extname(specifier);
|
|
14
|
-
if (ext && extensions.indexOf(ext) < 0) return specifier;
|
|
15
|
-
if (!ext) {
|
|
16
|
-
try {
|
|
17
|
-
const basename = path.basename(specifier);
|
|
18
|
-
const fullPath = path.join(src, path.dirname(entry.path), specifier);
|
|
19
|
-
const files = fs.readdirSync(path.dirname(fullPath), {
|
|
20
|
-
withFileTypes: true
|
|
21
|
-
});
|
|
22
|
-
const found = find(files, (x)=>x.name === basename);
|
|
23
|
-
if (found && found.isDirectory()) return specifier;
|
|
24
|
-
} catch (_err) {}
|
|
25
|
-
}
|
|
26
|
-
const stripped = ext ? specifier.slice(0, -ext.length) : specifier;
|
|
27
|
-
return `${stripped}${extension}`;
|
|
28
|
-
}).join('');
|
|
29
|
-
}
|
|
@@ -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":["fs","path","find","moduleRegEx","parseSpecifiers","makeReplacements","entry","code","regex","extensions","extension","options","src","parsed","map","isSpecifier","content","specifier","test","ext","extname","indexOf","basename","fullPath","join","dirname","files","readdirSync","withFileTypes","found","x","name","isDirectory","_err","stripped","slice","length"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,cAAc;AAC/B,SAASC,WAAW,QAAQ,eAAe;AAC3C,OAAOC,qBAAqB,oBAAoB;AAEhD,eAAe,SAASC,iBAAiBC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO;IACzF,MAAM,EAAEC,GAAG,EAAE,GAAGD;IAChB,MAAME,SAAST,gBAAgBG,MAAMC;IAErC,OAAOK,OACJC,GAAG,CAAC,CAACD;QACJ,IAAI,CAACA,OAAOE,WAAW,EAAE,OAAOF,OAAOG,OAAO;QAC9C,MAAMC,YAAYJ,OAAOG,OAAO;QAChC,IAAIb,YAAYe,IAAI,CAACD,YAAY,OAAOA;QAExC,MAAME,MAAMlB,KAAKmB,OAAO,CAACH;QACzB,IAAIE,OAAOV,WAAWY,OAAO,CAACF,OAAO,GAAG,OAAOF;QAC/C,IAAI,CAACE,KAAK;YACR,IAAI;gBACF,MAAMG,WAAWrB,KAAKqB,QAAQ,CAACL;gBAC/B,MAAMM,WAAWtB,KAAKuB,IAAI,CAACZ,KAAKX,KAAKwB,OAAO,CAACnB,MAAML,IAAI,GAAGgB;gBAC1D,MAAMS,QAAQ1B,GAAG2B,WAAW,CAAC1B,KAAKwB,OAAO,CAACF,WAAW;oBAAEK,eAAe;gBAAK;gBAC3E,MAAMC,QAAQ3B,KAAKwB,OAAO,CAACI,IAAMA,EAAEC,IAAI,KAAKT;gBAC5C,IAAIO,SAASA,MAAMG,WAAW,IAAI,OAAOf;YAC3C,EAAE,OAAOgB,MAAM,CAAC;QAClB;QACA,MAAMC,WAAWf,MAAMF,UAAUkB,KAAK,CAAC,GAAG,CAAChB,IAAIiB,MAAM,IAAInB;QACzD,OAAO,GAAGiB,WAAWxB,WAAW;IAClC,GACCc,IAAI,CAAC;AACV"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function parser(code: any, regex: any): any[];
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export default function parser(code, regex) {
|
|
2
|
-
const parsed = [];
|
|
3
|
-
let offset = 0;
|
|
4
|
-
let match = regex.exec(code);
|
|
5
|
-
while(match){
|
|
6
|
-
const dependency = match[1] || match[2] || match[3] || match[4];
|
|
7
|
-
parsed.push({
|
|
8
|
-
content: code.substring(offset, match.index + match[0].lastIndexOf(dependency)),
|
|
9
|
-
isSpecifier: false
|
|
10
|
-
});
|
|
11
|
-
offset += parsed[parsed.length - 1].content.length;
|
|
12
|
-
parsed.push({
|
|
13
|
-
content: dependency,
|
|
14
|
-
isSpecifier: true
|
|
15
|
-
});
|
|
16
|
-
offset += parsed[parsed.length - 1].content.length;
|
|
17
|
-
match = regex.exec(code);
|
|
18
|
-
}
|
|
19
|
-
if (offset < code.length) {
|
|
20
|
-
parsed.push({
|
|
21
|
-
content: code.substring(offset, code.length),
|
|
22
|
-
isSpecifier: false
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return parsed;
|
|
26
|
-
}
|
|
@@ -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":"AAAA,eAAe,SAASA,OAAOC,IAAI,EAAEC,KAAK;IACxC,MAAMC,SAAS,EAAE;IACjB,IAAIC,SAAS;IACb,IAAIC,QAAQH,MAAMI,IAAI,CAACL;IACvB,MAAOI,MAAO;QACZ,MAAME,aAAaF,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE;QAC/DF,OAAOK,IAAI,CAAC;YAAEC,SAASR,KAAKS,SAAS,CAACN,QAAQC,MAAMM,KAAK,GAAGN,KAAK,CAAC,EAAE,CAACO,WAAW,CAACL;YAAcM,aAAa;QAAM;QAClHT,UAAUD,MAAM,CAACA,OAAOW,MAAM,GAAG,EAAE,CAACL,OAAO,CAACK,MAAM;QAClDX,OAAOK,IAAI,CAAC;YAAEC,SAASF;YAAYM,aAAa;QAAK;QACrDT,UAAUD,MAAM,CAACA,OAAOW,MAAM,GAAG,EAAE,CAACL,OAAO,CAACK,MAAM;QAClDT,QAAQH,MAAMI,IAAI,CAACL;IACrB;IAEA,IAAIG,SAASH,KAAKa,MAAM,EAAE;QACxBX,OAAOK,IAAI,CAAC;YAAEC,SAASR,KAAKS,SAAS,CAACN,QAAQH,KAAKa,MAAM;YAAGD,aAAa;QAAM;IACjF;IACA,OAAOV;AACT"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { extensions, requireRegEx } from '../constants.mjs';
|
|
2
|
-
import makeReplacements from './makeReplacements.mjs';
|
|
3
|
-
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
4
|
-
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; }";
|
|
5
|
-
const DEFAULT_EXTENSION = '.cjs';
|
|
6
|
-
export default function patchCJS(entry, output, options) {
|
|
7
|
-
const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
|
|
8
|
-
output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);
|
|
9
|
-
output.code += interop;
|
|
10
|
-
return cjsExtension;
|
|
11
|
-
}
|
|
@@ -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":["extensions","requireRegEx","makeReplacements","interop","DEFAULT_EXTENSION","patchCJS","entry","output","options","cjsExtension","cjs","code"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,eAAe;AACxD,OAAOC,sBAAsB,qBAAqB;AAElD,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAE3R,MAAMC,oBAAoB;AAE1B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQR,UAAU,GAAGQ,QAAQR,UAAU,CAACU,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FG,OAAOI,IAAI,GAAGT,iBAAiBI,OAAOC,OAAOI,IAAI,EAAEV,cAAcD,YAAYS,cAAcD;IAC3FD,OAAOI,IAAI,IAAIR;IAEf,OAAOM;AACT"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { importRegEx } from '../constants.mjs';
|
|
3
|
-
import makeReplacements from './makeReplacements.mjs';
|
|
4
|
-
const EXTENSIONS = {
|
|
5
|
-
cjs: [
|
|
6
|
-
'.cjs',
|
|
7
|
-
'.cts'
|
|
8
|
-
],
|
|
9
|
-
esm: [
|
|
10
|
-
'.js',
|
|
11
|
-
'.ts',
|
|
12
|
-
'.tsx',
|
|
13
|
-
'.mts',
|
|
14
|
-
'.mjs'
|
|
15
|
-
]
|
|
16
|
-
};
|
|
17
|
-
const DEFAULT_EXTENSION_CJS = '.cjs';
|
|
18
|
-
const DEFAULT_EXTENSION_EMS = '.mjs';
|
|
19
|
-
export default function patchESM(entry, output, options) {
|
|
20
|
-
const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION_CJS) || DEFAULT_EXTENSION_CJS;
|
|
21
|
-
const esmExtension = (options.extensions ? options.extensions.esm : DEFAULT_EXTENSION_EMS) || DEFAULT_EXTENSION_EMS;
|
|
22
|
-
output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.esm, esmExtension, options);
|
|
23
|
-
output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.cjs, cjsExtension, options);
|
|
24
|
-
let ext = path.extname(entry.basename);
|
|
25
|
-
if (EXTENSIONS.esm.indexOf(ext) >= 0) ext = esmExtension;
|
|
26
|
-
else if (EXTENSIONS.cjs.indexOf(ext) >= 0) ext = cjsExtension;
|
|
27
|
-
return ext;
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchESM.ts"],"sourcesContent":["import path from 'path';\nimport { importRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\nconst EXTENSIONS = {\n cjs: ['.cjs', '.cts'],\n esm: ['.js', '.ts', '.tsx', '.mts', '.mjs'],\n};\nconst DEFAULT_EXTENSION_CJS = '.cjs';\nconst DEFAULT_EXTENSION_EMS = '.mjs';\n\nexport default function patchESM(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION_CJS) || DEFAULT_EXTENSION_CJS;\n const esmExtension = (options.extensions ? options.extensions.esm : DEFAULT_EXTENSION_EMS) || DEFAULT_EXTENSION_EMS;\n\n output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.esm, esmExtension, options);\n output.code = makeReplacements(entry, output.code, importRegEx, EXTENSIONS.cjs, cjsExtension, options);\n\n let ext = path.extname(entry.basename);\n if (EXTENSIONS.esm.indexOf(ext) >= 0) ext = esmExtension;\n else if (EXTENSIONS.cjs.indexOf(ext) >= 0) ext = cjsExtension;\n return ext;\n}\n"],"names":["path","importRegEx","makeReplacements","EXTENSIONS","cjs","esm","DEFAULT_EXTENSION_CJS","DEFAULT_EXTENSION_EMS","patchESM","entry","output","options","cjsExtension","extensions","esmExtension","code","ext","extname","basename","indexOf"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,eAAe;AAC3C,OAAOC,sBAAsB,qBAAqB;AAElD,MAAMC,aAAa;IACjBC,KAAK;QAAC;QAAQ;KAAO;IACrBC,KAAK;QAAC;QAAO;QAAO;QAAQ;QAAQ;KAAO;AAC7C;AACA,MAAMC,wBAAwB;AAC9B,MAAMC,wBAAwB;AAE9B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACT,GAAG,GAAGE,qBAAoB,KAAMA;IAC9F,MAAMQ,eAAe,AAACH,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACR,GAAG,GAAGE,qBAAoB,KAAMA;IAE9FG,OAAOK,IAAI,GAAGb,iBAAiBO,OAAOC,OAAOK,IAAI,EAAEd,aAAaE,WAAWE,GAAG,EAAES,cAAcH;IAC9FD,OAAOK,IAAI,GAAGb,iBAAiBO,OAAOC,OAAOK,IAAI,EAAEd,aAAaE,WAAWC,GAAG,EAAEQ,cAAcD;IAE9F,IAAIK,MAAMhB,KAAKiB,OAAO,CAACR,MAAMS,QAAQ;IACrC,IAAIf,WAAWE,GAAG,CAACc,OAAO,CAACH,QAAQ,GAAGA,MAAMF;SACvC,IAAIX,WAAWC,GAAG,CAACe,OAAO,CAACH,QAAQ,GAAGA,MAAMJ;IACjD,OAAOI;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\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,kBAAkB;AACvC,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,uBAAuB,2BAA2B;AAEzD,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"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\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"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = 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,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,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.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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';\nimport * as urlPolyfills from './lib/url-file-url';\nimport type { Context } from './types';\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,cAAc;AAC1C,YAAYC,kBAAkB,qBAAqB;AAGnD,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs');\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,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,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"}
|
|
@@ -1 +0,0 @@
|
|
|
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';\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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.cjs');\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,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,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"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import Iterator from 'fs-iterator';
|
|
3
|
-
import Queue from 'queue-cb';
|
|
4
|
-
import rimraf2 from 'rimraf2';
|
|
5
|
-
import { extensions, typeFileRegEx } from '../constants.mjs';
|
|
6
|
-
import createMatcher from '../createMatcher.mjs';
|
|
7
|
-
import transformFile from '../lib/transformFile.mjs';
|
|
8
|
-
export default function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
9
|
-
const tsconfig = options.tsconfig;
|
|
10
|
-
const matcher = createMatcher(tsconfig);
|
|
11
|
-
rimraf2(dest, {
|
|
12
|
-
disableGlob: true
|
|
13
|
-
}, ()=>{
|
|
14
|
-
const entries = [];
|
|
15
|
-
const iterator = new Iterator(src);
|
|
16
|
-
iterator.forEach((entry)=>{
|
|
17
|
-
if (!entry.stats.isFile()) return;
|
|
18
|
-
if (entry.basename[0] === '.') return;
|
|
19
|
-
if (typeFileRegEx.test(entry.basename)) return;
|
|
20
|
-
if (!matcher(entry.fullPath)) return;
|
|
21
|
-
const ext = path.extname(entry.basename);
|
|
22
|
-
if (ext && extensions.indexOf(ext) < 0) return;
|
|
23
|
-
entries.push(entry);
|
|
24
|
-
}, (err)=>{
|
|
25
|
-
if (err) return callback(err);
|
|
26
|
-
const results = [];
|
|
27
|
-
options = {
|
|
28
|
-
...options,
|
|
29
|
-
tsconfig,
|
|
30
|
-
src,
|
|
31
|
-
dest
|
|
32
|
-
};
|
|
33
|
-
const queue = new Queue();
|
|
34
|
-
entries.forEach((entry)=>{
|
|
35
|
-
queue.defer((cb)=>transformFile(entry, dest, type, options, (err, outPath)=>{
|
|
36
|
-
if (err) return cb(err);
|
|
37
|
-
results.push(path.normalize(outPath));
|
|
38
|
-
if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);
|
|
39
|
-
cb();
|
|
40
|
-
}));
|
|
41
|
-
});
|
|
42
|
-
queue.await((err)=>err ? callback(err) : callback(null, results));
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { extensions, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport transformFile from '../lib/transformFile';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (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}\n"],"names":["path","Iterator","Queue","rimraf2","extensions","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","disableGlob","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;AAC7B,OAAOC,aAAa,UAAU;AAE9B,SAASC,UAAU,EAAEC,aAAa,QAAQ,eAAe;AACzD,OAAOC,mBAAmB,mBAAmB;AAC7C,OAAOC,mBAAmB,uBAAuB;AAEjD,eAAe,SAASC,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUT,cAAcQ;IAE9BX,QAAQO,MAAM;QAAEM,aAAa;IAAK,GAAG;QACnC,MAAMC,UAAU,EAAE;QAClB,MAAMC,WAAW,IAAIjB,SAASQ;QAC9BS,SAASC,OAAO,CACd,CAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;YAC/B,IAAIlB,cAAcmB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;YACxC,IAAI,CAACR,QAAQK,MAAMK,QAAQ,GAAG;YAC9B,MAAMC,MAAM1B,KAAK2B,OAAO,CAACP,MAAMG,QAAQ;YACvC,IAAIG,OAAOtB,WAAWwB,OAAO,CAACF,OAAO,GAAG;YACxCT,QAAQY,IAAI,CAACT;QACf,GACA,CAACU;YACC,IAAIA,KAAK,OAAOjB,SAASiB;YACzB,MAAMC,UAAU,EAAE;YAClBnB,UAAU;gBAAE,GAAGA,OAAO;gBAAEE;gBAAUL;gBAAKC;YAAK;YAE5C,MAAMsB,QAAQ,IAAI9B;YAClBe,QAAQE,OAAO,CAAC,CAACC;gBACfY,MAAMC,KAAK,CAAC,CAACC,KACX3B,cAAca,OAAOV,MAAMC,MAAMC,SAAS,CAACkB,KAAKK;wBAC9C,IAAIL,KAAK,OAAOI,GAAGJ;wBACnBC,QAAQF,IAAI,CAAC7B,KAAKoC,SAAS,CAACD;wBAC5B,IAAIvB,QAAQyB,UAAU,EAAEN,QAAQF,IAAI,CAAC,GAAG7B,KAAKoC,SAAS,CAACD,SAAS,IAAI,CAAC;wBACrED;oBACF;YAEJ;YACAF,MAAMM,KAAK,CAAC,CAACR,MAASA,MAAMjB,SAASiB,OAAOjB,SAAS,MAAMkB;QAC7D;IAEJ;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions';\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,2BAA2B;AAEzD,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"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import Iterator from 'fs-iterator';
|
|
2
|
-
import rimraf2 from 'rimraf2';
|
|
3
|
-
import Module from 'module';
|
|
4
|
-
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
5
|
-
import { typeFileRegEx } from '../constants.mjs';
|
|
6
|
-
import createMatcher from '../createMatcher.mjs';
|
|
7
|
-
export default function transformTypesWorker(src, dest, options, callback) {
|
|
8
|
-
const tsconfig = options.tsconfig;
|
|
9
|
-
const matcher = createMatcher(tsconfig);
|
|
10
|
-
const ts = _require('typescript');
|
|
11
|
-
rimraf2(dest, {
|
|
12
|
-
disableGlob: true
|
|
13
|
-
}, ()=>{
|
|
14
|
-
const entries = [];
|
|
15
|
-
const iterator = new Iterator(src);
|
|
16
|
-
iterator.forEach((entry)=>{
|
|
17
|
-
if (!entry.stats.isFile()) return;
|
|
18
|
-
if (entry.basename[0] === '.') return;
|
|
19
|
-
if (typeFileRegEx.test(entry.basename)) return;
|
|
20
|
-
if (!matcher(entry.fullPath)) return;
|
|
21
|
-
entries.push(entry);
|
|
22
|
-
}, {
|
|
23
|
-
concurrency: Infinity
|
|
24
|
-
}, (err)=>{
|
|
25
|
-
if (err) return callback(err);
|
|
26
|
-
const config = {
|
|
27
|
-
fileNames: entries.map((entry)=>entry.fullPath),
|
|
28
|
-
options: {
|
|
29
|
-
...tsconfig.compilerOptions || {},
|
|
30
|
-
outDir: dest,
|
|
31
|
-
allowJs: true,
|
|
32
|
-
declaration: true,
|
|
33
|
-
emitDeclarationOnly: true,
|
|
34
|
-
listEmittedFiles: true
|
|
35
|
-
},
|
|
36
|
-
projectReferences: tsconfig.config.references
|
|
37
|
-
};
|
|
38
|
-
const { fileNames, options, projectReferences } = config;
|
|
39
|
-
const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);
|
|
40
|
-
const programOptions = {
|
|
41
|
-
rootNames: fileNames,
|
|
42
|
-
options,
|
|
43
|
-
projectReferences,
|
|
44
|
-
host,
|
|
45
|
-
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({
|
|
46
|
-
fileNames,
|
|
47
|
-
options
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
const program = ts.createProgram(programOptions);
|
|
51
|
-
const res = program.emit();
|
|
52
|
-
callback(null, res.emittedFiles);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator from 'fs-iterator';\nimport rimraf2 from 'rimraf2';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\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 rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (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}\n"],"names":["Iterator","rimraf2","Module","_require","require","createRequire","url","typeFileRegEx","createMatcher","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","disableGlob","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;AACnC,OAAOC,aAAa,UAAU;AAE9B,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,aAAa,QAAQ,eAAe;AAC7C,OAAOC,mBAAmB,mBAAmB;AAE7C,eAAe,SAASC,qBAAqBC,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACvE,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUP,cAAcM;IAC9B,MAAME,KAAKb,SAAS;IAEpBF,QAAQU,MAAM;QAAEM,aAAa;IAAK,GAAG;QACnC,MAAMC,UAAU,EAAE;QAClB,MAAMC,WAAW,IAAInB,SAASU;QAC9BS,SAASC,OAAO,CACd,CAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;YAC/B,IAAIjB,cAAckB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;YACxC,IAAI,CAACT,QAAQM,MAAMK,QAAQ,GAAG;YAC9BR,QAAQS,IAAI,CAACN;QACf,GACA;YAAEO,aAAaC;QAAS,GACxB,CAACC;YACC,IAAIA,KAAK,OAAOjB,SAASiB;YAEzB,MAAMC,SAAS;gBACbC,WAAWd,QAAQe,GAAG,CAAC,CAACZ,QAAUA,MAAMK,QAAQ;gBAChDd,SAAS;oBACP,GAAIE,SAASoB,eAAe,IAAI,CAAC,CAAC;oBAClCC,QAAQxB;oBACRyB,SAAS;oBACTC,aAAa;oBACbC,qBAAqB;oBACrBC,kBAAkB;gBACpB;gBACAC,mBAAmB1B,SAASiB,MAAM,CAACU,UAAU;YAC/C;YACA,MAAM,EAAET,SAAS,EAAEpB,OAAO,EAAE4B,iBAAiB,EAAE,GAAGT;YAClD,MAAMW,OAAO1B,GAAG2B,wBAAwB,CAAC/B,SAAS,gBAAgB,GAAGgC,WAAW5B,GAAG6B,GAAG;YACtF,MAAMC,iBAAiB;gBACrBC,WAAWf;gBACXpB;gBACA4B;gBACAE;gBACAM,8BAA8BhC,GAAGiC,+BAA+B,CAAC;oBAAEjB;oBAAWpB;gBAAQ;YACxF;YACA,MAAMsC,UAAUlC,GAAGmC,aAAa,CAACL;YACjC,MAAMM,MAAMF,QAAQG,IAAI;YACxBxC,SAAS,MAAMuC,IAAIE,YAAY;QACjC;IAEJ;AACF"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|