ts-swc-transform 2.0.14 → 2.0.15
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/constants.js +1 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/swcPrepareOptions.js +2 -2
- package/dist/cjs/lib/swcPrepareOptions.js.map +1 -1
- package/dist/cjs/lib/transformFile.js +2 -2
- package/dist/cjs/lib/transformFile.js.map +1 -1
- package/dist/cjs/lib/url-file-url.js +1 -1
- package/dist/cjs/lib/url-file-url.js.map +1 -1
- package/dist/cjs/resolveFileSync.js +1 -1
- package/dist/cjs/resolveFileSync.js.map +1 -1
- package/dist/cjs/toPath.js +2 -2
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformSync.js +1 -1
- package/dist/cjs/transformSync.js.map +1 -1
- package/dist/cjs/transformTypes.js.map +1 -1
- package/dist/cjs/workers/transformDirectory.js +1 -1
- package/dist/cjs/workers/transformDirectory.js.map +1 -1
- package/dist/cjs/workers/transformSync.js +1 -1
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/cjs/workers/transformTypes.js.map +1 -1
- package/dist/esm/constants.js +2 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/swcPrepareOptions.js +2 -2
- package/dist/esm/lib/swcPrepareOptions.js.map +1 -1
- package/dist/esm/lib/transformFile.js +2 -2
- package/dist/esm/lib/transformFile.js.map +1 -1
- package/dist/esm/lib/url-file-url.js +1 -1
- package/dist/esm/lib/url-file-url.js.map +1 -1
- package/dist/esm/resolveFileSync.js +1 -1
- package/dist/esm/resolveFileSync.js.map +1 -1
- package/dist/esm/toPath.js +2 -2
- package/dist/esm/toPath.js.map +1 -1
- package/dist/esm/transformDirectory.js.map +1 -1
- package/dist/esm/transformSync.js +1 -1
- package/dist/esm/transformSync.js.map +1 -1
- package/dist/esm/transformTypes.js.map +1 -1
- package/dist/esm/workers/transformDirectory.js +1 -1
- package/dist/esm/workers/transformDirectory.js.map +1 -1
- package/dist/esm/workers/transformSync.js +1 -1
- package/dist/esm/workers/transformSync.js.map +1 -1
- package/dist/esm/workers/transformTypes.js.map +1 -1
- package/package.json +5 -5
package/dist/cjs/constants.js
CHANGED
|
@@ -31,7 +31,7 @@ _export(exports, {
|
|
|
31
31
|
return typeFileRegEx;
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
var moduleRegEx = /^[
|
|
34
|
+
var moduleRegEx = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
35
35
|
var typeFileRegEx = /^[^.]+\.d\.[cm]?ts$/;
|
|
36
36
|
var moduleDependencyRegEx = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
37
37
|
var moduleNameRegEx = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/constants.ts"],"sourcesContent":["export const moduleRegEx = /^[
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/constants.ts"],"sourcesContent":["export const moduleRegEx = /^[^./]|^\\.[^./]|^\\.\\.[^/]/;\nexport const typeFileRegEx = /^[^.]+\\.d\\.[cm]?ts$/;\n\nexport const moduleDependencyRegEx = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\n// biome-ignore lint/suspicious/noTemplateCurlyInString: Valid regex\nexport const moduleNameRegEx = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nexport const requireRegEx = new RegExp(`(?:(?:var|const|let)${moduleNameRegEx}=\\\\s*)?require\\\\(${moduleDependencyRegEx}\\\\)?`, 'g');\nexport const importRegEx = new RegExp(`${requireRegEx}|import(?:${moduleNameRegEx}from\\\\s*)?${moduleDependencyRegEx};?|export(?:${moduleNameRegEx}from\\\\s*)?${moduleDependencyRegEx}?`, 'g');\nexport const extensions = ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts', '.es6', '.es'];\n"],"names":["extensions","importRegEx","moduleDependencyRegEx","moduleNameRegEx","moduleRegEx","requireRegEx","typeFileRegEx","RegExp"],"mappings":";;;;;;;;;;;QAQaA;eAAAA;;QADAC;eAAAA;;QAJAC;eAAAA;;QAEAC;eAAAA;;QALAC;eAAAA;;QAMAC;eAAAA;;QALAC;eAAAA;;;AADN,IAAMF,cAAc;AACpB,IAAME,gBAAgB;AAEtB,IAAMJ,wBAAwB;AAE9B,IAAMC,kBAAkB;AACxB,IAAME,eAAe,IAAIE,OAAO,AAAC,uBAAyDL,OAAnCC,iBAAgB,qBAAyC,OAAtBD,uBAAsB,SAAO;AACvH,IAAMD,cAAc,IAAIM,OAAO,AAAC,GAA2BJ,OAAzBE,cAAa,cAAwCH,OAA5BC,iBAAgB,cAAgDA,OAApCD,uBAAsB,gBAA0CA,OAA5BC,iBAAgB,cAAkC,OAAtBD,uBAAsB,MAAI;AACjL,IAAMF,aAAa;IAAC;IAAO;IAAQ;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;IAAQ;IAAQ;CAAM"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type * from './types.js';
|
|
2
|
-
export { default as createMatcher } from './createMatcher.js';
|
|
3
1
|
export * as constants from './constants.js';
|
|
2
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
4
3
|
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
5
4
|
export { default as toPath } from './toPath.js';
|
|
6
5
|
export { default as transformDirectory } from './transformDirectory.js';
|
|
7
6
|
export { default as transformSync } from './transformSync.js';
|
|
8
7
|
export { default as transformTypes } from './transformTypes.js';
|
|
8
|
+
export type * from './types.js';
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type * from './types.js';
|
|
2
|
-
export { default as createMatcher } from './createMatcher.js';
|
|
3
1
|
export * as constants from './constants.js';
|
|
2
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
4
3
|
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
5
4
|
export { default as toPath } from './toPath.js';
|
|
6
5
|
export { default as transformDirectory } from './transformDirectory.js';
|
|
7
6
|
export { default as transformSync } from './transformSync.js';
|
|
8
7
|
export { default as transformTypes } from './transformTypes.js';
|
|
8
|
+
export type * from './types.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,8 +31,8 @@ _export(exports, {
|
|
|
31
31
|
return _transformTypes.default;
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("./createMatcher.js"));
|
|
35
34
|
var _constants = /*#__PURE__*/ _interop_require_wildcard(require("./constants.js"));
|
|
35
|
+
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("./createMatcher.js"));
|
|
36
36
|
var _resolveFileSync = /*#__PURE__*/ _interop_require_default(require("./resolveFileSync.js"));
|
|
37
37
|
var _toPath = /*#__PURE__*/ _interop_require_default(require("./toPath.js"));
|
|
38
38
|
var _transformDirectory = /*#__PURE__*/ _interop_require_default(require("./transformDirectory.js"));
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/index.ts"],"sourcesContent":["export * as constants from './constants.js';\nexport { default as createMatcher } from './createMatcher.js';\nexport { default as resolveFileSync } from './resolveFileSync.js';\nexport { default as toPath } from './toPath.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\nexport { default as transformTypes } from './transformTypes.js';\nexport type * from './types.js';\n"],"names":["constants","createMatcher","resolveFileSync","toPath","transformDirectory","transformSync","transformTypes"],"mappings":";;;;;;;;;;;QAAYA;;;QACQC;eAAAA,sBAAa;;QACbC;eAAAA,wBAAe;;QACfC;eAAAA,eAAM;;QACNC;eAAAA,2BAAkB;;QAClBC;eAAAA,sBAAa;;QACbC;eAAAA,uBAAc;;;iEANP;oEACc;sEACE;6DACT;yEACY;oEACL;qEACC"}
|
|
@@ -8,10 +8,10 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return swcPrepareOptions;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
|
-
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
13
11
|
var _installoptional = require("install-optional");
|
|
14
12
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
13
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
17
17
|
default: obj
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import { installSync } from 'install-optional';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","tsconfig","installSync","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BASA;;;eAAwBA;;;+BATI;6DACT;2DACF;0DACD;;;;;;AAEhB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAGnF,SAASV,kBAAkBW,QAAwB;IAChEC,IAAAA,4BAAW,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI,GAAI;QAAEC,KAAKX;IAAU;IACjF,IAAI;QACF,IAAMY,KAAKhB,SAAS;QACpB,IAAMiB,MAAMjB,SAAS;QACrB,IAAMkB,aAAalB,SAAS;QAC5B,IAAMmB,SAASH,GAAGI,0BAA0B,CAACV,SAASW,MAAM,EAAEL,GAAGM,GAAG,EAAEjB,aAAI,CAACC,OAAO,CAACI,SAASL,IAAI;QAChG,OAAOa,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -9,13 +9,13 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
12
|
var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
|
|
13
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
14
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
15
16
|
var _patchCJS = /*#__PURE__*/ _interop_require_default(require("../lib/patchCJS.js"));
|
|
16
17
|
var _patchESM = /*#__PURE__*/ _interop_require_default(require("../lib/patchESM.js"));
|
|
17
18
|
var _swcPrepareOptions = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.js"));
|
|
18
|
-
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
19
19
|
function _define_property(obj, key, value) {
|
|
20
20
|
if (key in obj) {
|
|
21
21
|
Object.defineProperty(obj, key, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.js';\nimport patchESM from '../lib/patchESM.js';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformFile(entry, dest, type, options, callback) {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAWA;;;eAAwBA;;;yDAXT;oEACI;6DACA;2DACF;8DACC;+DACG;+DACA;wEACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE3E,SAASF,cAAcK,KAAK,EAAEC,IAAI,EAAEC,IAA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U,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"}
|
|
@@ -18,9 +18,9 @@ _export(exports, {
|
|
|
18
18
|
return pathToFileURL;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
22
21
|
var _replaceall = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/string/replace-all.js"));
|
|
23
22
|
var _index = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/url/index.js"));
|
|
23
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
24
24
|
function _interop_require_default(obj) {
|
|
25
25
|
return obj && obj.__esModule ? obj : {
|
|
26
26
|
default: obj
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport replaceAll from 'core-js-pure/actual/string/replace-all.js';\nimport URL from 'core-js-pure/actual/url/index.js';\nimport path from 'path';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(url: string | URL): string {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n\n if (url.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (url.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(url.pathname));\n\n if (isWindows) {\n if (url.hostname) return `\\\\\\\\${url.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = replaceAll(resolved, '%', '%25'); // Must be first\n resolved = replaceAll(resolved, '#', '%23');\n resolved = replaceAll(resolved, '?', '%3f');\n resolved = replaceAll(resolved, '\\n', '%0a');\n resolved = replaceAll(resolved, '\\r', '%0d');\n resolved = replaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = replaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URL(`file:${resolved}`);\n}\n"],"names":["fileURLToPath","pathToFileURL","isWindows","process","platform","test","env","OSTYPE","url","URL","protocol","Error","pathname","hostname","path","normalize","decodeURIComponent","letter","charCodeAt","slice","resolved","resolve","length","replaceAll"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;;;;;;;;;;;;QAQjEA;eAAAA;;QAwCAC;eAAAA;;;iEA9CO;4DACP;2DACC;;;;;;AAEjB,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAA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EAACH,UAAU,KAAK;IACrCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,KAAK;IACrCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACtCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACtCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IAEtC,IAAI,CAAClB,WAAW;QACdkB,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACxC;IAEA,OAAO,IAAIX,cAAG,CAAC,AAAC,QAAgB,OAATW;AACzB"}
|
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
12
|
var _lodashfind = /*#__PURE__*/ _interop_require_default(require("lodash.find"));
|
|
13
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
14
|
var _constants = require("./constants.js");
|
|
15
15
|
var _toPath = /*#__PURE__*/ _interop_require_default(require("./toPath.js"));
|
|
16
16
|
function _interop_require_default(obj) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport find from 'lodash.find';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.js';\nimport toPath from './toPath.js';\nimport type { Context } from './types.js';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = find(items, (x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = find(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","length","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;iEACE;2DACA;yBACsC;6DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,qBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,UAAUS,QAAQ,CAAC,MAAM;YAC3D,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOC,IAAAA,mBAAI,EAACH,OAAO,SAACX;uBAAMH,gBAAgBkB,OAAO,CAACf,MAAM;;YAC9D,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,sBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACS,OAAO,CAACtB;YAC1C,IAAMU,QAAOC,IAAAA,mBAAI,EAACH,QAAO,SAACX;gBACxB,IAAI0B,wBAAa,CAACP,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM2B,UAAUX,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM4B,eAAeD,UAAUX,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACI,QAAQH,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaM;YACtB;YACA,IAAIf,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACS,OAAO,CAACtB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/cjs/toPath.js
CHANGED
|
@@ -8,11 +8,11 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return toPath;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
|
|
11
12
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
12
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
-
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
14
|
-
var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
|
|
15
14
|
var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
|
|
15
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
16
16
|
var _importmetaresolvecjs = require("../../assets/import-meta-resolve.cjs");
|
|
17
17
|
var _constants = require("./constants.js");
|
|
18
18
|
var _urlfileurl = /*#__PURE__*/ _interop_require_wildcard(require("./lib/url-file-url.js"));
|
package/dist/cjs/toPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport resolveCJS from 'resolve';\nimport url from 'url';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants.js';\nimport * as urlPolyfills from './lib/url-file-url.js';\nimport type { Context } from './types.js';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryURL","resolveESM","_","entryPath","resolveCJS","sync","basedir","extensions"],"mappings":";;;;+BAoBA;;;eAAwBA;;;iEApBD;6DACJ;2DACF;8DACM;0DACP;oCAEsB;yBACV;kEACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,YAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,YAAaC,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACZ,OAAOS,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASf,OAAOgB,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOb,cAAcY;IACxD,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,sBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,6BAAU,EAACP,WAAWT,cAAcG;gBACrD,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAYC,gBAAU,CAACC,IAAI,CAACX,WAAW;YAC3CY,SAASlB;YACTmB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIJ,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types.js';\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":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types.js';\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":";;;;+BAuBA;;;eAAwBA;;;2DAvBP;0DACD;mEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;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;AAGe,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"}
|
|
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformSync;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_wildcard(require("get-tsconfig-compat"));
|
|
11
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
13
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
13
|
-
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_wildcard(require("get-tsconfig-compat"));
|
|
14
14
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport path from 'path';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\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';\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":";;;;+BAoBA;;;eAAwBA;;;yEApBD;2DACN;0DACD;6DAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;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;AAIe,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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.js';\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":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\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.js';\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":";;;;+BAuBA;;;eAAwBA;;;2DAvBP;0DACD;mEACS;6DAON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;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;AAGe,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"}
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return transformDirectoryWorker;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
11
|
var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
|
|
12
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
13
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
14
14
|
var _constants = require("../constants.js");
|
|
15
15
|
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("../createMatcher.js"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from '../lib/transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","err","results","queue","Queue","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BAQA;;;eAAwBA;;;iEARa;2DACpB;8DACC;yBAEwB;oEAChB;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEX,SAASA,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAA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__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.js"));
|
|
12
11
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
12
|
+
var _swcPrepareOptions = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.js"));
|
|
13
13
|
function _define_property(obj, key, value) {
|
|
14
14
|
if (key in obj) {
|
|
15
15
|
Object.defineProperty(obj, key, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","contents","fileName","tsconfig","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAMA;;;eAAwBA;;;6DANL;wEACW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,oBAAoBK,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,IAAMC,aAAaC,IAAAA,0BAAiB,EAACF;IACrC,IAAMG,MAAMT,SAAS;IACrB,OAAOS,IAAIC,aAAa,CAACN,UAAU,wCAC7BC,SAASM,QAAQ,CAAC,WAAWN,SAASM,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUT;;AAEd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...(tsconfig.compilerOptions || {}),\n outDir: dest,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["transformTypesWorker","_require","require","Module","createRequire","src","dest","options","callback","tsconfig","matcher","createMatcher","ts","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":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...(tsconfig.compilerOptions || {}),\n outDir: dest,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["transformTypesWorker","_require","require","Module","createRequire","src","dest","options","callback","tsconfig","matcher","createMatcher","ts","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;;;iEATa;6DAElB;yBAIW;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;IAEpB,IAAMY,UAAU,EAAE;IAClB,IAAMC,WAAW,IAAIC,mBAAQ,CAACV;IAC9BS,SAASE,OAAO,CACd,SAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIC,wBAAa,CAACC,IAAI,CAACL,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACV,QAAQO,MAAMM,QAAQ,GAAG;QAC9BV,QAAQW,IAAI,CAACP;IACf,GACA;QAAEQ,aAAaC;IAAS,GACxB,SAACC;QACC,IAAIA,KAAK,OAAOnB,SAASmB;QAEzB,IAAMC,SAAS;YACbC,WAAWhB,QAAQiB,GAAG,CAAC,SAACb;uBAAUA,MAAMM,QAAQ;;YAChDhB,SAAS,wCACHE,SAASsB,eAAe,IAAI,CAAC;gBACjCC,QAAQ1B;gBACR2B,SAAS;gBACTC,aAAa;gBACbC,qBAAqB;gBACrBC,kBAAkB;;YAEpBC,mBAAmB5B,SAASmB,MAAM,CAACU,UAAU;QAC/C;QACA,IAAQT,YAA0CD,OAA1CC,WAAWtB,YAA+BqB,OAA/BrB,SAAS8B,oBAAsBT,OAAtBS;QAC5B,IAAME,OAAO3B,GAAG4B,wBAAwB,CAACjC,WAAS,gBAAgB,GAAGkC,WAAW7B,GAAG8B,GAAG;QACtF,IAAMC,iBAAiB;YACrBC,WAAWf;YACXtB,SAAAA;YACA8B,mBAAAA;YACAE,MAAAA;YACAM,8BAA8BjC,GAAGkC,+BAA+B,CAAC;gBAAEjB,WAAAA;gBAAWtB,SAAAA;YAAQ;QACxF;QACA,IAAMwC,UAAUnC,GAAGoC,aAAa,CAACL;QACjC,IAAMM,MAAMF,QAAQG,IAAI;QACxB1C,SAAS,MAAMyC,IAAIE,YAAY;IACjC;AAEJ"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export const moduleRegEx = /^[
|
|
1
|
+
export const moduleRegEx = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
2
2
|
export const typeFileRegEx = /^[^.]+\.d\.[cm]?ts$/;
|
|
3
3
|
export const moduleDependencyRegEx = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
4
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: Valid regex
|
|
4
5
|
export const moduleNameRegEx = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
5
6
|
export const requireRegEx = new RegExp(`(?:(?:var|const|let)${moduleNameRegEx}=\\s*)?require\\(${moduleDependencyRegEx}\\)?`, 'g');
|
|
6
7
|
export const importRegEx = new RegExp(`${requireRegEx}|import(?:${moduleNameRegEx}from\\s*)?${moduleDependencyRegEx};?|export(?:${moduleNameRegEx}from\\s*)?${moduleDependencyRegEx}?`, 'g');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/constants.ts"],"sourcesContent":["export const moduleRegEx = /^[
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/constants.ts"],"sourcesContent":["export const moduleRegEx = /^[^./]|^\\.[^./]|^\\.\\.[^/]/;\nexport const typeFileRegEx = /^[^.]+\\.d\\.[cm]?ts$/;\n\nexport const moduleDependencyRegEx = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\n// biome-ignore lint/suspicious/noTemplateCurlyInString: Valid regex\nexport const moduleNameRegEx = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nexport const requireRegEx = new RegExp(`(?:(?:var|const|let)${moduleNameRegEx}=\\\\s*)?require\\\\(${moduleDependencyRegEx}\\\\)?`, 'g');\nexport const importRegEx = new RegExp(`${requireRegEx}|import(?:${moduleNameRegEx}from\\\\s*)?${moduleDependencyRegEx};?|export(?:${moduleNameRegEx}from\\\\s*)?${moduleDependencyRegEx}?`, 'g');\nexport const extensions = ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts', '.es6', '.es'];\n"],"names":["moduleRegEx","typeFileRegEx","moduleDependencyRegEx","moduleNameRegEx","requireRegEx","RegExp","importRegEx","extensions"],"mappings":"AAAA,OAAO,MAAMA,cAAc,4BAA4B;AACvD,OAAO,MAAMC,gBAAgB,sBAAsB;AAEnD,OAAO,MAAMC,wBAAwB,iCAAiC;AACtE,oEAAoE;AACpE,OAAO,MAAMC,kBAAkB,6BAA6B;AAC5D,OAAO,MAAMC,eAAe,IAAIC,OAAO,CAAC,oBAAoB,EAAEF,gBAAgB,iBAAiB,EAAED,sBAAsB,IAAI,CAAC,EAAE,KAAK;AACnI,OAAO,MAAMI,cAAc,IAAID,OAAO,GAAGD,aAAa,UAAU,EAAED,gBAAgB,UAAU,EAAED,sBAAsB,YAAY,EAAEC,gBAAgB,UAAU,EAAED,sBAAsB,CAAC,CAAC,EAAE,KAAK;AAC7L,OAAO,MAAMK,aAAa;IAAC;IAAO;IAAQ;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;IAAQ;IAAQ;CAAM,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type * from './types.js';
|
|
2
|
-
export { default as createMatcher } from './createMatcher.js';
|
|
3
1
|
export * as constants from './constants.js';
|
|
2
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
4
3
|
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
5
4
|
export { default as toPath } from './toPath.js';
|
|
6
5
|
export { default as transformDirectory } from './transformDirectory.js';
|
|
7
6
|
export { default as transformSync } from './transformSync.js';
|
|
8
7
|
export { default as transformTypes } from './transformTypes.js';
|
|
8
|
+
export type * from './types.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { default as createMatcher } from './createMatcher.js';
|
|
2
1
|
export * as constants from './constants.js';
|
|
2
|
+
export { default as createMatcher } from './createMatcher.js';
|
|
3
3
|
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
4
4
|
export { default as toPath } from './toPath.js';
|
|
5
5
|
export { default as transformDirectory } from './transformDirectory.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/index.ts"],"sourcesContent":["export * as constants from './constants.js';\nexport { default as createMatcher } from './createMatcher.js';\nexport { default as resolveFileSync } from './resolveFileSync.js';\nexport { default as toPath } from './toPath.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\nexport { default as transformTypes } from './transformTypes.js';\nexport type * from './types.js';\n"],"names":["constants","default","createMatcher","resolveFileSync","toPath","transformDirectory","transformSync","transformTypes"],"mappings":"AAAA,OAAO,KAAKA,SAAS,MAAM,iBAAiB;AAC5C,SAASC,WAAWC,aAAa,QAAQ,qBAAqB;AAC9D,SAASD,WAAWE,eAAe,QAAQ,uBAAuB;AAClE,SAASF,WAAWG,MAAM,QAAQ,cAAc;AAChD,SAASH,WAAWI,kBAAkB,QAAQ,0BAA0B;AACxE,SAASJ,WAAWK,aAAa,QAAQ,qBAAqB;AAC9D,SAASL,WAAWM,cAAc,QAAQ,sBAAsB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import url from 'url';
|
|
3
1
|
import { installSync } from 'install-optional';
|
|
4
2
|
import Module from 'module';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import url from 'url';
|
|
5
5
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
6
6
|
const __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
|
|
7
7
|
export default function swcPrepareOptions(tsconfig) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import { installSync } from 'install-optional';\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`, { cwd: __dirname });\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["installSync","Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","swcPrepareOptions","tsconfig","process","platform","arch","cwd","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AAGjH,eAAe,SAASQ,kBAAkBC,QAAwB;IAChEZ,YAAY,aAAa,GAAGa,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE;QAAEC,KAAKT;IAAU;IACjF,IAAI;QACF,MAAMU,KAAKb,SAAS;QACpB,MAAMc,MAAMd,SAAS;QACrB,MAAMe,aAAaf,SAAS;QAC5B,MAAMgB,SAASH,GAAGI,0BAA0B,CAACT,SAASU,MAAM,EAAEL,GAAGM,GAAG,EAAErB,KAAKM,OAAO,CAACI,SAASV,IAAI;QAChG,OAAOiB,WAAWK,gBAAgB,CAACJ,OAAOK,OAAO,EAAEC,WAAWR,KAAK;IACrE,EAAE,OAAOS,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
2
|
import mkdirp from 'mkdirp-classic';
|
|
3
|
+
import Module from 'module';
|
|
4
|
+
import path from 'path';
|
|
4
5
|
import Queue from 'queue-cb';
|
|
5
6
|
import patchCJS from '../lib/patchCJS.js';
|
|
6
7
|
import patchESM from '../lib/patchESM.js';
|
|
7
8
|
import swcPrepareOptions from '../lib/swcPrepareOptions.js';
|
|
8
|
-
import Module from 'module';
|
|
9
9
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
10
10
|
export default function transformFile(entry, dest, type, options, callback) {
|
|
11
11
|
let tsconfig = options.tsconfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.js';\nimport patchESM from '../lib/patchESM.js';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformFile(entry, dest, type, options, callback) {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","swcPrepareOptions","_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,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcP,OAAOQ,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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github.com/holepunchto/url-file-url/blob/main/LICENSE
|
|
3
|
-
import path from 'path';
|
|
4
3
|
import replaceAll from 'core-js-pure/actual/string/replace-all.js';
|
|
5
4
|
import URL from 'core-js-pure/actual/url/index.js';
|
|
5
|
+
import path from 'path';
|
|
6
6
|
const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
7
7
|
export function fileURLToPath(url) {
|
|
8
8
|
if (typeof url === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport replaceAll from 'core-js-pure/actual/string/replace-all.js';\nimport URL from 'core-js-pure/actual/url/index.js';\nimport path from 'path';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(url: string | URL): string {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n\n if (url.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (url.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(url.pathname));\n\n if (isWindows) {\n if (url.hostname) return `\\\\\\\\${url.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = replaceAll(resolved, '%', '%25'); // Must be first\n resolved = replaceAll(resolved, '#', '%23');\n resolved = replaceAll(resolved, '?', '%3f');\n resolved = replaceAll(resolved, '\\n', '%0a');\n resolved = replaceAll(resolved, '\\r', '%0d');\n resolved = replaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = replaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URL(`file:${resolved}`);\n}\n"],"names":["replaceAll","URL","path","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","url","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,gBAAgB,4CAA4C;AACnE,OAAOC,SAAS,mCAAmC;AACnD,OAAOC,UAAU,OAAO;AAExB,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,GAAiB;IAC7C,IAAI,OAAOA,QAAQ,UAAU;QAC3BA,MAAM,IAAIT,IAAIS;IAChB;IAEA,IAAIA,IAAIC,QAAQ,KAAK,SAAS;QAC5B,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACI,IAAIG,QAAQ,GAAG;YACjC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,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
3
2
|
import find from 'lodash.find';
|
|
3
|
+
import path from 'path';
|
|
4
4
|
import { extensions, moduleRegEx, typeFileRegEx } from './constants.js';
|
|
5
5
|
import toPath from './toPath.js';
|
|
6
6
|
const indexExtensions = extensions.map((x)=>`index${x}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport find from 'lodash.find';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.js';\nimport toPath from './toPath.js';\nimport type { Context } from './types.js';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = find(items, (x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = find(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","find","path","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","endsWith","items","readdirSync","item","indexOf","join","test","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AC,GAAG,CAACG,QAAQF,MAAM,IAAI3B,KAAKyB,QAAQ,CAAClB;gBAC1F,OAAOkB,aAAaK;YACtB;YACA,IAAIX,MAAM,OAAOnB,KAAKqB,IAAI,CAACrB,KAAK4B,OAAO,CAACjB,WAAWQ;QACrD;QACA,wBAAwB;QACxB,OAAOP,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/esm/toPath.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import isAbsolute from 'is-absolute';
|
|
1
2
|
import module from 'module';
|
|
2
3
|
import path from 'path';
|
|
3
|
-
import url from 'url';
|
|
4
|
-
import isAbsolute from 'is-absolute';
|
|
5
4
|
import resolveCJS from 'resolve';
|
|
5
|
+
import url from 'url';
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
import { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';
|
|
8
8
|
import { moduleRegEx } from './constants.js';
|
package/dist/esm/toPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport resolveCJS from 'resolve';\nimport url from 'url';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants.js';\nimport * as urlPolyfills from './lib/url-file-url.js';\nimport type { Context } from './types.js';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = resolveESM(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["isAbsolute","module","path","resolveCJS","url","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,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,gBAAgB,UAAU;AACjC,OAAOC,SAAS,MAAM;AACtB,aAAa;AACb,SAASC,WAAWC,UAAU,QAAQ,uCAAuC;AAC7E,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,YAAYC,kBAAkB,wBAAwB;AAGtD,MAAMC,SAAS,CAACR,OAAOS,aAAa;AACpC,MAAMC,gBAAgBP,IAAIO,aAAa,IAAIH,aAAaG,aAAa;AACrE,MAAMC,gBAAgBR,IAAIQ,aAAa,IAAIJ,aAAaI,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOb,KAAKc,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGf,KAAKc,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,IAAIrB,WAAWqB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOlB,KAAKqB,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,YAAYxB,WAAWyB,IAAI,CAACP,WAAW;YAC3CQ,SAASd;YACTe,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIH,WAAW,OAAOA;IACxB;IAEA,OAAON;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\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.js';\nexport default function transformDirectory(src: string, dest: string, type: string, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) => dispatch(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;AAE7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, type, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types.js';\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;AACt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AI,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,6 +1,6 @@
|
|
|
1
|
+
import * as getTS from 'get-tsconfig-compat';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import url from 'url';
|
|
3
|
-
import * as getTS from 'get-tsconfig-compat';
|
|
4
4
|
const major = +process.versions.node.split('.')[0];
|
|
5
5
|
const version = major < 14 ? 'stable' : 'local';
|
|
6
6
|
const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import * as getTS from 'get-tsconfig-compat';\nimport path from 'path';\nimport url from 'url';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\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';\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":["getTS","path","url","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,YAAYA,WAAW,sBAAsB;AAC7C,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYR,KAAKS,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAaZ,KAAKa,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;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,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,WAAWtB,MAAMyB,WAAW,CAACrB,QAAQsB,GAAG;IACvD,OAAOP,SAASX,SAASY,UAAUC,UAAUC;AAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, src, dest, options, callback) {\n if (version === 'local') return _require(workerPath)(src, dest, options, callback);\n try {\n callback(null, _require('node-version-call')({ version, callbacks: true }, workerPath, src, dest, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformTypesCallback } from './types.js';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformTypes');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","options","callback","callbacks","err","transformTypes","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;AAE7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformTypes.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig.js';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformTypes.js');\n\nimport Module from 'module';\n\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.js';\nexport default function transformTypes(src: string, dest: string, options?: ConfigOptions | TransformTypesCallback, callback?: TransformTypesCallback): undefined | Promise<string[]> {\n try {\n if (typeof src !== 'string') throw new Error('transformTypes: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformTypes: unexpected destination directory');\n\n if (typeof options === 'function') {\n callback = options as TransformTypesCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformTypes');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","src","dest","options","callback","callbacks","err","transformTypes","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,oBAAoB;AAE7C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,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,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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\nimport path from 'path';\nimport Queue from 'queue-cb';\n\nimport { extensions, typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from '../lib/transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry: Entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n}\n"],"names":["Iterator","path","Queue","extensions","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","ext","extname","indexOf","push","err","results","queue","defer","cb","outPath","normalize","sourceMaps","await"],"mappings":"AAAA,OAAOA,cAA8B,cAAc;AACnD,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAE7B,SAASC,UAAU,EAAEC,aAAa,QAAQ,kBAAkB;AAC5D,OAAOC,mBAAmB,sBAAsB;AAChD,OAAOC,mBAAmB,0BAA0B;AAEpD,eAAe,SAASC,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUT,cAAcQ;IAE9B,MAAME,UAAU,EAAE;IAClB,MAAMC,WAAW,IAAIhB,SAASQ;IAC9BQ,SAASC,OAAO,CACd,CAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;QAC/B,IAAIjB,cAAckB,IAAI,CAACJ,MAAMG,QAAQ,GAAG;QACxC,IAAI,CAACP,QAAQI,MAAMK,QAAQ,GAAG;QAC9B,MAAMC,MAAMvB,KAAKwB,OAAO,CAACP,MAAMG,QAAQ;QACvC,IAAIG,OAAOrB,WAAWuB,OAAO,CAACF,OAAO,GAAG;QACxCT,QAAQY,IAAI,CAACT;IACf,GACA,CAACU;QACC,IAAIA,KAAK,OAAOhB,SAASgB;QACzB,MAAMC,UAAU,EAAE;QAClBlB,UAAU;YAAE,GAAGA,OAAO;YAAEE;YAAUL;YAAKC;QAAK;QAE5C,MAAMqB,QAAQ,IAAI5B;QAClBa,QAAQE,OAAO,CAAC,CAACC;YACfY,MAAMC,KAAK,CAAC,CAACC,KACX1B,cAAcY,OAAOT,MAAMC,MAAMC,SAAS,CAACiB,KAAKK;oBAC9C,IAAIL,KAAK,OAAOI,GAAGJ;oBACnBC,QAAQF,IAAI,CAAC1B,KAAKiC,SAAS,CAACD;oBAC5B,IAAItB,QAAQwB,UAAU,EAAEN,QAAQF,IAAI,CAAC,GAAG1B,KAAKiC,SAAS,CAACD,SAAS,IAAI,CAAC;oBACrED;gBACF;QAEJ;QACAF,MAAMM,KAAK,CAAC,CAACR,MAASA,MAAMhB,SAASgB,OAAOhB,SAAS,MAAMiB;IAC7D;AAEJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import swcPrepareOptions from '../lib/swcPrepareOptions.js';
|
|
2
1
|
import Module from 'module';
|
|
2
|
+
import swcPrepareOptions from '../lib/swcPrepareOptions.js';
|
|
3
3
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
4
4
|
export default function transformSyncWorker(contents, fileName, tsconfig) {
|
|
5
5
|
const swcOptions = swcPrepareOptions(tsconfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import Module from 'module';\nimport swcPrepareOptions from '../lib/swcPrepareOptions.js';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = _require('@swc/core');\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["Module","swcPrepareOptions","_require","require","createRequire","url","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,MAAMC,aAAaT,kBAAkBQ;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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...(tsconfig.compilerOptions || {}),\n outDir: dest,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["Iterator","Module","_require","require","createRequire","url","typeFileRegEx","createMatcher","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","push","concurrency","Infinity","err","config","fileNames","map","compilerOptions","outDir","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","emittedFiles"],"mappings":"AAAA,OAAOA,cAA8B,cAAc;AAEnD,OAAOC,YAAY,SAAS;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import Iterator, { type Entry } from 'fs-iterator';\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\n\nexport default function transformTypesWorker(src, dest, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err) => {\n if (err) return callback(err);\n\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...(tsconfig.compilerOptions || {}),\n outDir: dest,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["Iterator","Module","_require","require","createRequire","url","typeFileRegEx","createMatcher","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","push","concurrency","Infinity","err","config","fileNames","map","compilerOptions","outDir","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","emittedFiles"],"mappings":"AAAA,OAAOA,cAA8B,cAAc;AAEnD,OAAOC,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,aAAa,QAAQ,kBAAkB;AAChD,OAAOC,mBAAmB,sBAAsB;AAEhD,eAAe,SAASC,qBAAqBC,GAAG,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACvE,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,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0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsds build",
|
|
40
|
-
"format": "biome check --write --unsafe
|
|
40
|
+
"format": "biome check --write --unsafe",
|
|
41
41
|
"test": "tsds test:node --no-timeouts",
|
|
42
42
|
"test:engines": "nvu engines npm test",
|
|
43
43
|
"version": "tsds version"
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"exit": "^0.1.2",
|
|
49
49
|
"fs-iterator": "^6.0.0",
|
|
50
50
|
"get-tsconfig-compat": "^2.0.3",
|
|
51
|
-
"install-optional": "^0.1.
|
|
51
|
+
"install-optional": "^0.1.64",
|
|
52
52
|
"is-absolute": "^1.0.0",
|
|
53
53
|
"lodash.find": "^4.6.0",
|
|
54
54
|
"minimatch": "^3.1.2",
|
|
55
55
|
"mkdirp-classic": "^0.5.3",
|
|
56
|
-
"node-version-call": "^1.7.
|
|
56
|
+
"node-version-call": "^1.7.12",
|
|
57
57
|
"path-posix": "^1.0.0",
|
|
58
|
-
"queue-cb": "^1.5.
|
|
58
|
+
"queue-cb": "^1.5.3",
|
|
59
59
|
"resolve": "^1.22.10",
|
|
60
60
|
"rimraf2": "^2.8.2",
|
|
61
61
|
"ts-node": "*",
|