ts-swc-transform 1.4.2 → 1.5.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/cjs/transformDirectory.js +59 -0
- package/dist/cjs/cjs/transformDirectory.js.map +1 -0
- package/dist/cjs/cjs/transformFile.js +59 -0
- package/dist/cjs/cjs/transformFile.js.map +1 -0
- package/dist/cjs/{transformSync.js → cjs/transformSync.js} +6 -7
- package/dist/cjs/cjs/transformSync.js.map +1 -0
- package/dist/cjs/esm/transformDirectory.js +49 -0
- package/dist/cjs/esm/transformDirectory.js.map +1 -0
- package/dist/cjs/esm/transformFile.js +49 -0
- package/dist/cjs/esm/transformFile.js.map +1 -0
- package/dist/cjs/esm/transformSync.js +17 -0
- package/dist/cjs/esm/transformSync.js.map +1 -0
- package/dist/cjs/index.cjs.js +46 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/existsSync.js +5 -4
- package/dist/cjs/lib/existsSync.js.map +1 -1
- package/dist/cjs/lib/install-module/index.js +40 -0
- package/dist/cjs/lib/install-module/index.js.map +1 -0
- package/dist/cjs/lib/install-module/lib/ensureCached.js +114 -0
- package/dist/cjs/lib/install-module/lib/ensureCached.js.map +1 -0
- package/dist/cjs/lib/install-module/lib/parseInstallString.js +48 -0
- package/dist/cjs/lib/install-module/lib/parseInstallString.js.map +1 -0
- package/dist/cjs/lib/installBindings.js +3 -80
- package/dist/cjs/lib/installBindings.js.map +1 -1
- package/dist/cjs/lib/loadSWC.js +9 -2
- package/dist/cjs/lib/loadSWC.js.map +1 -1
- package/dist/cjs/{transformDirectory.js → workers/transformDirectory.js} +21 -41
- package/dist/cjs/workers/transformDirectory.js.map +1 -0
- package/dist/cjs/{transformFile.js → workers/transformFile.js} +25 -51
- package/dist/cjs/workers/transformFile.js.map +1 -0
- package/dist/cjs/workers/transformSync.js +6 -4
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/esm/{transformDirectory.mjs → cjs/transformDirectory.mjs} +20 -26
- package/dist/esm/cjs/transformDirectory.mjs.map +1 -0
- package/dist/esm/cjs/transformFile.mjs +44 -0
- package/dist/esm/cjs/transformFile.mjs.map +1 -0
- package/dist/esm/{transformSync.mjs → cjs/transformSync.mjs} +6 -8
- package/dist/esm/cjs/transformSync.mjs.map +1 -0
- package/dist/esm/esm/transformDirectory.mjs +34 -0
- package/dist/esm/esm/transformDirectory.mjs.map +1 -0
- package/dist/esm/esm/transformFile.mjs +34 -0
- package/dist/esm/esm/transformFile.mjs.map +1 -0
- package/dist/esm/esm/transformSync.mjs +1 -0
- package/dist/esm/esm/transformSync.mjs.map +1 -0
- package/dist/esm/index.cjs.mjs +7 -0
- package/dist/esm/index.cjs.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/existsSync.mjs +4 -3
- package/dist/esm/lib/existsSync.mjs.map +1 -1
- package/dist/esm/lib/install-module/index.mjs +24 -0
- package/dist/esm/lib/install-module/index.mjs.map +1 -0
- package/dist/esm/lib/install-module/lib/ensureCached.mjs +37 -0
- package/dist/esm/lib/install-module/lib/ensureCached.mjs.map +1 -0
- package/dist/esm/lib/install-module/lib/parseInstallString.mjs +13 -0
- package/dist/esm/lib/install-module/lib/parseInstallString.mjs.map +1 -0
- package/dist/esm/lib/installBindings.mjs +4 -44
- package/dist/esm/lib/installBindings.mjs.map +1 -1
- package/dist/esm/lib/loadSWC.mjs +9 -2
- package/dist/esm/lib/loadSWC.mjs.map +1 -1
- package/dist/esm/workers/transformDirectory.mjs +28 -0
- package/dist/esm/workers/transformDirectory.mjs.map +1 -0
- package/dist/esm/{transformFile.mjs → workers/transformFile.mjs} +22 -48
- package/dist/esm/workers/transformFile.mjs.map +1 -0
- package/dist/esm/workers/transformSync.mjs +6 -3
- package/dist/esm/workers/transformSync.mjs.map +1 -1
- package/dist/types/cjs/transformDirectory.d.ts +9 -0
- package/dist/types/cjs/transformFile.d.ts +9 -0
- package/dist/types/{transformSync.d.ts → cjs/transformSync.d.ts} +3 -1
- package/dist/types/esm/transformFile.d.ts +9 -0
- package/dist/types/esm/transformSync.d.ts +1 -0
- package/dist/types/index.cjs.d.ts +8 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/lib/existsSync.d.ts +3 -1
- package/dist/types/lib/install-module/index.d.ts +1 -0
- package/dist/types/lib/install-module/lib/ensureCached.d.ts +2 -0
- package/dist/types/lib/install-module/lib/parseInstallString.d.ts +4 -0
- package/dist/types/lib/loadSWC.d.ts +2 -1
- package/dist/types/workers/transformDirectory.d.ts +1 -0
- package/dist/types/workers/transformFile.d.ts +1 -0
- package/dist/types/workers/transformSync.d.ts +1 -1
- package/package.json +7 -6
- package/dist/cjs/transformDirectory.js.map +0 -1
- package/dist/cjs/transformFile.js.map +0 -1
- package/dist/cjs/transformSync.js.map +0 -1
- package/dist/esm/transformDirectory.mjs.map +0 -1
- package/dist/esm/transformFile.mjs.map +0 -1
- package/dist/esm/transformSync.mjs.map +0 -1
- package/dist/types/transformFile.d.ts +0 -9
- /package/dist/types/{transformDirectory.d.ts → esm/transformDirectory.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nimport * as transpiler from 'ts-node/transpilers/swc';\nimport
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nimport * as transpiler from 'ts-node/transpilers/swc';\n// @ts-ignore\nimport lazy from '../lib/lazy.cjs';\n// @ts-ignore\nimport loadSWC from '../lib/loadSWC.js';\nconst lazyTS = lazy('typescript');\n\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult, callback) {\n loadSWC((err, swc) => {\n if (err) return callback(err);\n const ts = lazyTS();\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n const transpile = transpiler.create({ swc: swc, service: { config: { options: parsed.options } } });\n const res = transpile.transpile(contents, { fileName });\n callback(null, { code: res.outputText, map: res.sourceMapText });\n });\n}\n"],"names":["path","transpiler","lazy","loadSWC","lazyTS","transformSyncWorker","contents","fileName","tsconfig","callback","err","swc","ts","parsed","parseJsonConfigFileContent","config","sys","dirname","transpile","create","service","options","res","code","outputText","map","sourceMapText"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,YAAYC,gBAAgB,0BAA0B;AACtD,aAAa;AACb,OAAOC,UAAU,kBAAkB;AACnC,aAAa;AACb,OAAOC,aAAa,oBAAoB;AACxC,MAAMC,SAASF,KAAK;AAEpB,eAAe,SAASG,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB,EAAEC,QAAQ;IAChHN,QAAQ,CAACO,KAAKC;QACZ,IAAID,KAAK,OAAOD,SAASC;QACzB,MAAME,KAAKR;QACX,MAAMS,SAASD,GAAGE,0BAA0B,CAACN,SAASO,MAAM,EAAEH,GAAGI,GAAG,EAAEhB,KAAKiB,OAAO,CAACT,SAASR,IAAI;QAChG,MAAMkB,YAAYjB,WAAWkB,MAAM,CAAC;YAAER,KAAKA;YAAKS,SAAS;gBAAEL,QAAQ;oBAAEM,SAASR,OAAOQ,OAAO;gBAAC;YAAE;QAAE;QACjG,MAAMC,MAAMJ,UAAUA,SAAS,CAACZ,UAAU;YAAEC;QAAS;QACrDE,SAAS,MAAM;YAAEc,MAAMD,IAAIE,UAAU;YAAEC,KAAKH,IAAII,aAAa;QAAC;IAChE;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} src The source directory to traverse.
|
|
3
|
+
* @param {string} dest The output directory to write files to.
|
|
4
|
+
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
5
|
+
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
6
|
+
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
7
|
+
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
8
|
+
*/
|
|
9
|
+
export default function transformDirectory(src: any, dest: any, type: any, options: any, callback: any): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} src The source directory to traverse.
|
|
3
|
+
* @param {string} dest The output directory to write files to.
|
|
4
|
+
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
5
|
+
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
6
|
+
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
7
|
+
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
8
|
+
*/
|
|
9
|
+
export default function transformFile(src: any, dest: any, type: any, options: any, callback: any): any;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
1
2
|
/**
|
|
2
3
|
* @param {string} contents The file contents.
|
|
3
4
|
* @param {string} fileName The filename.
|
|
5
|
+
* @param {TsConfigResult} tsconfig The configuration.
|
|
4
6
|
* @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.
|
|
5
7
|
*/
|
|
6
|
-
export default function transformSync(contents:
|
|
8
|
+
export default function transformSync(contents: string, fileName: string, tsconfig: TsConfigResult): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} src The source directory to traverse.
|
|
3
|
+
* @param {string} dest The output directory to write files to.
|
|
4
|
+
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
5
|
+
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
6
|
+
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
7
|
+
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
8
|
+
*/
|
|
9
|
+
export default function transformFile(src: any, dest: any, type: any, options: any, callback: any): void | Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../cjs/transformSync.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type * from './types.js';
|
|
2
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
3
|
+
export { default as extensions } from './extensions.js';
|
|
4
|
+
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
5
|
+
export { default as toPath } from './toPath.js';
|
|
6
|
+
export { default as transformFile } from './cjs/transformFile.js';
|
|
7
|
+
export { default as transformDirectory } from './cjs/transformDirectory.js';
|
|
8
|
+
export { default as transformSync } from './cjs/transformSync.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export { default as createMatcher } from './createMatcher.js';
|
|
|
3
3
|
export { default as extensions } from './extensions.js';
|
|
4
4
|
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
5
5
|
export { default as toPath } from './toPath.js';
|
|
6
|
-
export { default as transformFile } from './transformFile.js';
|
|
7
|
-
export { default as transformDirectory } from './transformDirectory.js';
|
|
8
|
-
export { default as transformSync } from './transformSync.js';
|
|
6
|
+
export { default as transformFile } from './esm/transformFile.js';
|
|
7
|
+
export { default as transformDirectory } from './esm/transformDirectory.js';
|
|
8
|
+
export { default as transformSync } from './esm/transformSync.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function installModule(installString: any, installedAt: any, callback: any): void;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare const _default: any;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function transformDirectoryWorker(src: any, dest: any, type: any, options: any, callback: any): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function transformFileWorker(src: any, dest: any, type: any, options: any, callback: any): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { TsConfigResult } from 'get-tsconfig-compat';
|
|
2
|
-
export default function
|
|
2
|
+
export default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult, callback: any): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"import": "./dist/esm/index.mjs",
|
|
27
|
-
"require": "./dist/cjs/index.js",
|
|
27
|
+
"require": "./dist/cjs/index.cjs.js",
|
|
28
28
|
"types": "./dist/types/index.d.ts"
|
|
29
29
|
},
|
|
30
30
|
"./*": "./*"
|
|
31
31
|
},
|
|
32
|
-
"main": "dist/cjs/index.js",
|
|
32
|
+
"main": "dist/cjs/index.cjs.js",
|
|
33
33
|
"module": "dist/dist/esm/index.mjs",
|
|
34
34
|
"types": "dist/types/index.d.ts",
|
|
35
35
|
"bin": {
|
|
@@ -52,17 +52,18 @@
|
|
|
52
52
|
"call-once-fn": "^1.0.1",
|
|
53
53
|
"cross-spawn-cb": "^1.1.3",
|
|
54
54
|
"exit": "^0.1.2",
|
|
55
|
-
"fs-access-
|
|
55
|
+
"fs-access-compat": "^1.0.3",
|
|
56
56
|
"fs-iterator": "^5.1.1",
|
|
57
57
|
"get-tsconfig-compat": "^1.1.1",
|
|
58
58
|
"is-absolute": "^1.0.0",
|
|
59
59
|
"lazy-cache": "^2.0.2",
|
|
60
60
|
"minimatch": "^3.1.2",
|
|
61
61
|
"mkdirp-classic": "^0.5.3",
|
|
62
|
-
"node-version-call": "^1.2.
|
|
62
|
+
"node-version-call": "^1.2.4",
|
|
63
63
|
"path-posix": "^1.0.0",
|
|
64
64
|
"queue-cb": "^1.4.4",
|
|
65
65
|
"resolve": "^1.22.10",
|
|
66
|
+
"resolve-once-cb": "^0.1.2",
|
|
66
67
|
"rimraf2": "^2.8.2",
|
|
67
68
|
"temp-suffix": "^0.1.1",
|
|
68
69
|
"ts-node": "*",
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"core-js": "^3.39.0",
|
|
78
79
|
"cr": "^0.1.0",
|
|
79
80
|
"react": "^19.0.0",
|
|
80
|
-
"ts-dev-stack": "^1.4.
|
|
81
|
+
"ts-dev-stack": "^1.4.5",
|
|
81
82
|
"ts-node": "^10.8.2",
|
|
82
83
|
"typescript": "^5.7.2"
|
|
83
84
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\nimport createMatcher from './createMatcher.js';\nimport transformFile from './transformFile.js';\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\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 const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n options = { ...options, tsconfig };\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry, cb) => {\n if (!entry.stats.isFile()) return cb();\n if (!matcher(entry.fullPath)) return cb();\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);\n },\n { callbacks: true, concurrency: options.concurrency || 1024 },\n callback\n );\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformDirectory","transformDirectoryCallback","src","dest","type","options","callback","Error","tsconfig","getTS","getTsconfig","matcher","createMatcher","iterator","Iterator","forEach","entry","cb","stats","isFile","fullPath","transformFile","path","dirname","join","callbacks","concurrency","Promise","resolve","reject","compileCallback","err","result"],"mappings":";;;;+BAkCA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DA1CP;iEACI;wEACH;oEAEQ;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,SAASC,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,IAAMC,WAAWH,QAAQG,QAAQ,GAAGH,QAAQG,QAAQ,GAAGC,0BAAK,CAACC,WAAW,CAACR;IACzE,IAAMS,UAAUC,IAAAA,sBAAa,EAACJ;IAE9BH,UAAU,wCAAKA;QAASG,UAAAA;;IACxB,IAAMK,WAAW,IAAIC,mBAAQ,CAACZ;IAC9BW,SAASE,OAAO,CACd,SAACC,OAAOC;QACN,IAAI,CAACD,MAAME,KAAK,CAACC,MAAM,IAAI,OAAOF;QAClC,IAAI,CAACN,QAAQK,MAAMI,QAAQ,GAAG,OAAOH;QACrCI,IAAAA,sBAAa,EAACL,MAAMI,QAAQ,EAAEE,aAAI,CAACC,OAAO,CAACD,aAAI,CAACE,IAAI,CAACrB,MAAMa,MAAMM,IAAI,IAAIlB,MAAMC,SAASY;IAC1F,GACA;QAAEQ,WAAW;QAAMC,aAAarB,QAAQqB,WAAW,IAAI;IAAK,GAC5DpB;AAEJ;AAUe,SAASN,mBAAmBE,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3E,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,2BAA2BC,KAAKC,MAAMC,MAAMC,SAASC;IAChG,OAAO,IAAIqB,QAAQ,SAACC,SAASC;QAC3B5B,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASyB,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nfunction transformFileCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(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 basename = path.basename(src);\n const output = transformSync(contents, basename, tsconfig);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write the file 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 | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.\n * @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.\n */\nexport default function transformFile(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformFileCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformFile","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","dependency","match","ext","find","x","slice","length","matches","push","exec","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileCallback","src","dest","type","options","callback","Error","fs","readFile","err","contents","once","tsconfig","getTS","getTsconfig","config","compilerOptions","module","target","basename","path","output","transformSync","extname","destFilePath","join","replace","mkdirp","dirname","queue","Queue","defer","writeFile","bind","sourceMaps","map","await","Promise","resolve","reject","compileCallback","result"],"mappings":";;;;+BAgGA;;;;;;;CAOC,GACD;;;eAAwBA;;;yDAxGT;2DACE;iEACA;wEACC;oEACC;8DACD;oEAEQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMC,eAAe;AACrB,IAAMC,eAAe;AACrB,IAAMC,WAAW,IAAIC,OAAO,AAAC,uBAAsDH,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa,UAAQ;AACxG,IAAMI,WAAW,IAAID,OAAO,AAAC,GAAuBF,OAArBC,UAAS,cAAqCF,OAAzBC,cAAa,cAAuCA,OAA3BD,cAAa,gBAAuCA,OAAzBC,cAAa,cAAyB,OAAbD,cAAa,OAAK;AAEnJ,IAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ;IAAQ;CAAO;AAC/D,IAAMC,mBAAmB;IAAC;CAAO;AACjC,IAAMC,mBAAmB;IAAC;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;CAAO;AAExE,SAASC,iBAAiBC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,SAAS;;QAIxD,IAAMC,aAAaC,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE;QAC/D,IAAMC,MAAMJ,WAAWK,IAAI,CAAC,SAACC;mBAAMJ,WAAWK,KAAK,CAAC,CAACD,EAAEE,MAAM,MAAMF;;QACnE,IAAIF,KAAKK,QAAQC,IAAI,CAAC;YAAEN,KAAAA;YAAKD,OAAAA;YAAOD,YAAAA;QAAW;QAC/CC,QAAQJ,MAAMY,IAAI,CAACb;IACrB;IAPA,IAAIW,UAAU,EAAE;IAChB,IAAIN,QAAQJ,MAAMY,IAAI,CAACb;IACvB,MAAOK;IAOPM,UAAUA,QAAQG,OAAO;IACzB,IAA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C1D;QACF,EAAE,OAAOf,KAAK;YACZJ,SAASI;QACX;IACF;AACF;AAUe,SAASvC,cAAc+B,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACtE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,sBAAsBC,KAAKC,MAAMC,MAAMC,SAASC;IAC3F,OAAO,IAAIgC,QAAQ,SAACC,SAASC;QAC3BvC,sBAAsBC,KAAKC,MAAMC,MAAMC,SAAS,SAASoC,gBAAgB/B,GAAG,EAAEgC,MAAM;YAClFhC,MAAM8B,OAAO9B,OAAO6B,QAAQG;QAC9B;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n\n// @ts-ignore\nimport lazy from './lib/lazy.cjs';\nimport packageRoot from './lib/packageRoot.js';\n// @ts-ignore\nimport process from './lib/process.cjs';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? '14' : 'local';\nconst root = packageRoot(__dirname);\nconst worker = path.resolve(root, 'dist', 'cjs', 'workers', 'transformSync.js');\nconst call = lazy('node-version-call');\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\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, fileName, config) {\n return call()({ version, callbacks: true }, worker, contents, fileName, config);\n}\n"],"names":["transformSync","__dirname","path","dirname","__filename","url","fileURLToPath","major","process","versions","node","split","version","root","packageRoot","worker","resolve","call","lazy","contents","fileName","config","callbacks"],"mappings":";;;;+BAgBA;;;;CAIC,GACD;;;eAAwBA;;;2DArBP;0DACD;8DAGC;kEACO;iEAEJ;;;;;;AAEpB,IAAMC,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAClG,IAAMC,QAAQ,CAACC,mBAAO,CAACC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,OAAO;AACpC,IAAMM,OAAOC,IAAAA,oBAAW,EAACb;AACzB,IAAMc,SAASb,aAAI,CAACc,OAAO,CAACH,MAAM,QAAQ,OAAO,WAAW;AAC5D,IAAMI,OAAOC,IAAAA,gBAAI,EAAC;AAOH,SAASlB,cAAcmB,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAO;QAAEL,SAAAA;QAASU,WAAW;IAAK,GAAGP,QAAQI,UAAUC,UAAUC;AAC1E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\nimport createMatcher from './createMatcher.js';\nimport transformFile from './transformFile.js';\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\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 const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n options = { ...options, tsconfig };\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry, cb) => {\n if (!entry.stats.isFile()) return cb();\n if (!matcher(entry.fullPath)) return cb();\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);\n },\n { callbacks: true, concurrency: options.concurrency || 1024 },\n callback\n );\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["path","Iterator","getTS","createMatcher","transformFile","transformDirectoryCallback","src","dest","type","options","callback","Error","tsconfig","getTsconfig","matcher","iterator","forEach","entry","cb","stats","isFile","fullPath","dirname","join","callbacks","concurrency","transformDirectory","Promise","resolve","reject","compileCallback","err","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,OAAOC,WAAW,sBAAsB;AAExC,OAAOC,mBAAmB,qBAAqB;AAC/C,OAAOC,mBAAmB,qBAAqB;AAE/C,SAASC,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,MAAMC,WAAWH,QAAQG,QAAQ,GAAGH,QAAQG,QAAQ,GAAGV,MAAMW,WAAW,CAACP;IACzE,MAAMQ,UAAUX,cAAcS;IAE9BH,UAAU;QAAE,GAAGA,OAAO;QAAEG;IAAS;IACjC,MAAMG,WAAW,IAAId,SAASK;IAC9BS,SAASC,OAAO,CACd,CAACC,OAAOC;QACN,IAAI,CAACD,MAAME,KAAK,CAACC,MAAM,IAAI,OAAOF;QAClC,IAAI,CAACJ,QAAQG,MAAMI,QAAQ,GAAG,OAAOH;QACrCd,cAAca,MAAMI,QAAQ,EAAErB,KAAKsB,OAAO,CAACtB,KAAKuB,IAAI,CAAChB,MAAMU,MAAMjB,IAAI,IAAIQ,MAAMC,SAASS;IAC1F,GACA;QAAEM,WAAW;QAAMC,aAAahB,QAAQgB,WAAW,IAAI;IAAK,GAC5Df;AAEJ;AAEA;;;;;;;CAOC,GACD,eAAe,SAASgB,mBAAmBpB,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3E,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,2BAA2BC,KAAKC,MAAMC,MAAMC,SAASC;IAChG,OAAO,IAAIiB,QAAQ,CAACC,SAASC;QAC3BxB,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASqB,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nfunction transformFileCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(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 basename = path.basename(src);\n const output = transformSync(contents, basename, tsconfig);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write the file 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 | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.\n * @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.\n */\nexport default function transformFile(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformFileCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["fs","path","once","getTS","mkdirp","Queue","transformSync","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","matches","match","exec","dependency","ext","find","x","slice","length","push","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileCallback","src","dest","type","options","callback","Error","readFile","err","contents","tsconfig","getTsconfig","config","compilerOptions","module","target","basename","output","extname","destFilePath","join","replace","dirname","queue","defer","writeFile","bind","sourceMaps","map","await","transformFile","Promise","resolve","reject","compileCallback","result"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,eAAe;AAChC,OAAOC,WAAW,sBAAsB;AACxC,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,eAAe;AACrB,MAAMC,eAAe;AACrB,MAAMC,WAAW,IAAIC,OAAO,CAAC,oBAAoB,EAAEF,aAAa,iBAAiB,EAAED,aAAa,KAAK,CAAC,EAAE;AACxG,MAAMI,WAAW,IAAID,OAAO,GAAGD,SAAS,UAAU,EAAED,aAAa,UAAU,EAAED,aAAa,YAAY,EAAEC,aAAa,UAAU,EAAED,aAAa,EAAE,CAAC,EAAE;AAEnJ,MAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ;IAAQ;CAAO;AAC/D,MAAMC,mBAAmB;IAAC;CAAO;AACjC,MAAMC,mBAAmB;IAAC;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;CAAO;AAExE,SAASC,iBAAiBC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,SAAS;IAC1D,IAAIC,UAAU,EAAE;IAChB,IAAIC,QAAQJ,MAAMK,IAAI,CAACN;IACvB,MAAOK,MAAO;QACZ,MAAME,aAAaF,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE;QAC/D,MAAMG,MAAMN,WAAWO,IAAI,CAAC,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K,CAAC5D,GAAG6D,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGP,aAAa,IAAI,CAAC,EAAEF,OAAOW,GAAG,EAAE;gBAC9FL,MAAMM,KAAK,CAAC,IAAOrB,MAAMH,SAASG,OAAOH,SAAS,MAAMc;YAC1D;QACF,EAAE,OAAOX,KAAK;YACZH,SAASG;QACX;IACF;AACF;AAEA;;;;;;;CAOC,GACD,eAAe,SAASsB,cAAc7B,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACtE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,sBAAsBC,KAAKC,MAAMC,MAAMC,SAASC;IAC3F,OAAO,IAAI0B,QAAQ,CAACC,SAASC;QAC3BjC,sBAAsBC,KAAKC,MAAMC,MAAMC,SAAS,SAAS8B,gBAAgB1B,GAAG,EAAE2B,MAAM;YAClF3B,MAAMyB,OAAOzB,OAAOwB,QAAQG;QAC9B;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n\n// @ts-ignore\nimport lazy from './lib/lazy.cjs';\nimport packageRoot from './lib/packageRoot.js';\n// @ts-ignore\nimport process from './lib/process.cjs';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? '14' : 'local';\nconst root = packageRoot(__dirname);\nconst worker = path.resolve(root, 'dist', 'cjs', 'workers', 'transformSync.js');\nconst call = lazy('node-version-call');\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\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, fileName, config) {\n return call()({ version, callbacks: true }, worker, contents, fileName, config);\n}\n"],"names":["path","url","lazy","packageRoot","process","__dirname","dirname","__filename","fileURLToPath","major","versions","node","split","version","root","worker","resolve","call","transformSync","contents","fileName","config","callbacks"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,aAAa;AACb,OAAOC,UAAU,iBAAiB;AAClC,OAAOC,iBAAiB,uBAAuB;AAC/C,aAAa;AACb,OAAOC,aAAa,oBAAoB;AAExC,MAAMC,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AACjH,MAAMQ,QAAQ,CAACL,QAAQM,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUJ,QAAQ,KAAK,OAAO;AACpC,MAAMK,OAAOX,YAAYE;AACzB,MAAMU,SAASf,KAAKgB,OAAO,CAACF,MAAM,QAAQ,OAAO,WAAW;AAC5D,MAAMG,OAAOf,KAAK;AAElB;;;;CAIC,GACD,eAAe,SAASgB,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAO;QAAEJ;QAASS,WAAW;IAAK,GAAGP,QAAQI,UAAUC,UAAUC;AAC1E"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {string} src The source directory to traverse.
|
|
3
|
-
* @param {string} dest The output directory to write the file to.
|
|
4
|
-
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
5
|
-
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
6
|
-
* @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.
|
|
7
|
-
* @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.
|
|
8
|
-
*/
|
|
9
|
-
export default function transformFile(src: any, dest: any, type: any, options: any, callback: any): void | Promise<unknown>;
|
|
File without changes
|