ts-swc-transform 1.3.1 → 1.3.2
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/toPath.js +5 -5
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/cjs/transformDirectory.js +4 -4
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformFile.js +2 -2
- package/dist/cjs/transformFile.js.map +1 -1
- package/dist/cjs/transformSync.js +2 -2
- package/dist/cjs/transformSync.js.map +1 -1
- package/dist/esm/toPath.mjs +2 -3
- package/dist/esm/toPath.mjs.map +1 -1
- package/dist/esm/transformDirectory.mjs +0 -2
- package/dist/esm/transformDirectory.mjs.map +1 -1
- package/dist/esm/transformFile.mjs +0 -1
- package/dist/esm/transformFile.mjs.map +1 -1
- package/dist/esm/transformSync.mjs +1 -2
- package/dist/esm/transformSync.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/cjs/lib/process.js +0 -3
- package/dist/cjs/lib/process.js.map +0 -1
- package/dist/esm/lib/process.cjs +0 -1
- package/dist/esm/lib/process.cjs.map +0 -1
- package/dist/types/lib/process.d.cts +0 -1
package/dist/cjs/toPath.js
CHANGED
|
@@ -11,10 +11,10 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
13
|
var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
|
|
14
|
+
var _process = /*#__PURE__*/ _interop_require_default(require("process"));
|
|
14
15
|
var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
|
|
15
|
-
var _fileURLToPath = /*#__PURE__*/ _interop_require_default(require("./lib/fileURLToPath.js"));
|
|
16
|
-
var _processcjs = /*#__PURE__*/ _interop_require_default(require("./lib/process.js"));
|
|
17
16
|
var _constants = require("./constants.js");
|
|
17
|
+
var _fileURLToPath = /*#__PURE__*/ _interop_require_default(require("./lib/fileURLToPath.js"));
|
|
18
18
|
function _interop_require_default(obj) {
|
|
19
19
|
return obj && obj.__esModule ? obj : {
|
|
20
20
|
default: obj
|
|
@@ -22,17 +22,17 @@ function _interop_require_default(obj) {
|
|
|
22
22
|
}
|
|
23
23
|
function getParentPath(context) {
|
|
24
24
|
if (context.parentPath) return _path.default.dirname(context.parentPath);
|
|
25
|
-
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) :
|
|
25
|
+
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : _process.default.cwd();
|
|
26
26
|
}
|
|
27
27
|
function toPath(specifier, context) {
|
|
28
28
|
if (specifier.startsWith('file:')) return (0, _fileURLToPath.default)(specifier);
|
|
29
29
|
if ((0, _isabsolute.default)(specifier)) return specifier;
|
|
30
30
|
if (specifier[0] === '.') {
|
|
31
|
-
var parentPath = context ? getParentPath(context) :
|
|
31
|
+
var parentPath = context ? getParentPath(context) : _process.default.cwd();
|
|
32
32
|
return _path.default.resolve(parentPath, specifier);
|
|
33
33
|
}
|
|
34
34
|
if (_constants.moduleRegEx.test(specifier)) {
|
|
35
|
-
var parentPath1 = context ? getParentPath(context) :
|
|
35
|
+
var parentPath1 = context ? getParentPath(context) : _process.default.cwd();
|
|
36
36
|
var pkg = null;
|
|
37
37
|
var main = _resolve.default.sync(specifier, {
|
|
38
38
|
basedir: parentPath1,
|
package/dist/cjs/toPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport
|
|
1
|
+
{"version":3,"sources":["toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport process from 'process';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants.js';\nimport fileURLToPath from './lib/fileURLToPath.js';\nimport type { Context } from './types.js';\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.resolve(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.resolve(pkg.dir, pkg.json.module);\n const mainPath = path.resolve(pkg.dir, pkg.json.main);\n const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !fs.existsSync(moduleResolved) ? main : moduleResolved;\n }\n\n return specifier;\n}\n"],"names":["toPath","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","fileURLToPath","isAbsolute","resolve","moduleRegEx","test","pkg","main","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace","fs","existsSync"],"mappings":";;;;+BAcA;;;eAAwBA;;;yDAdT;2DACE;iEACM;8DACH;8DACA;yBACQ;oEACF;;;;;;AAG1B,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACL,OAAOE,QAAQI,SAAS,KAAKC,gBAAO,CAACC,GAAG;AAClF;AAEe,SAASR,O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IM,IAAI,CAACG,IAAI,EAAE,OAAO,KAAK,CAACO,WAAE,CAACC,UAAU,CAACL,kBAAkBX,OAAOW;IACrH;IAEA,OAAOnB;AACT"}
|
|
@@ -18,8 +18,8 @@ Object.defineProperty(exports, /**
|
|
|
18
18
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
19
19
|
var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
|
|
20
20
|
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_default(require("get-tsconfig-compat"));
|
|
21
|
-
var
|
|
22
|
-
var
|
|
21
|
+
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("./createMatcher.js"));
|
|
22
|
+
var _transformFile = /*#__PURE__*/ _interop_require_default(require("./transformFile.js"));
|
|
23
23
|
function _define_property(obj, key, value) {
|
|
24
24
|
if (key in obj) {
|
|
25
25
|
Object.defineProperty(obj, key, {
|
|
@@ -87,7 +87,7 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
87
87
|
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
88
88
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
89
89
|
var tsconfig = options.tsconfig ? options.tsconfig : _gettsconfigcompat.default.getTsconfig(src);
|
|
90
|
-
var matcher = (0,
|
|
90
|
+
var matcher = (0, _createMatcher.default)(tsconfig);
|
|
91
91
|
options = _object_spread_props(_object_spread({}, options), {
|
|
92
92
|
tsconfig: tsconfig
|
|
93
93
|
});
|
|
@@ -95,7 +95,7 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
95
95
|
iterator.forEach(function(entry, cb) {
|
|
96
96
|
if (!entry.stats.isFile()) return cb();
|
|
97
97
|
if (!matcher(entry.fullPath)) return cb();
|
|
98
|
-
(0,
|
|
98
|
+
(0, _transformFile.default)(entry.fullPath, _path.default.dirname(_path.default.join(dest, entry.path)), type, options, cb);
|
|
99
99
|
}, {
|
|
100
100
|
callbacks: true,
|
|
101
101
|
concurrency: options.concurrency || 1024
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\nimport createMatcher from './createMatcher.js';\nimport transformFile from './transformFile.js';\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n options = { ...options, tsconfig };\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry, cb) => {\n if (!entry.stats.isFile()) return cb();\n if (!matcher(entry.fullPath)) return cb();\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);\n },\n { callbacks: true, concurrency: options.concurrency || 1024 },\n callback\n );\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformDirectory","transformDirectoryCallback","src","dest","type","options","callback","Error","tsconfig","getTS","getTsconfig","matcher","createMatcher","iterator","Iterator","forEach","entry","cb","stats","isFile","fullPath","transformFile","path","dirname","join","callbacks","concurrency","Promise","resolve","reject","compileCallback","err","result"],"mappings":";;;;+BAkCA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DA1CP;iEACI;wEACH;oEAEQ;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,SAASC,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,IAAMC,WAAWH,QAAQG,QAAQ,GAAGH,QAAQG,QAAQ,GAAGC,0BAAK,CAACC,WAAW,CAACR;IACzE,IAAMS,UAAUC,IAAAA,sBAAa,EAACJ;IAE9BH,UAAU,wCAAKA;QAASG,UAAAA;;IACxB,IAAMK,WAAW,IAAIC,mBAAQ,CAACZ;IAC9BW,SAASE,OAAO,CACd,SAACC,OAAOC;QACN,IAAI,CAACD,MAAME,KAAK,CAACC,MAAM,IAAI,OAAOF;QAClC,IAAI,CAACN,QAAQK,MAAMI,QAAQ,GAAG,OAAOH;QACrCI,IAAAA,sBAAa,EAACL,MAAMI,QAAQ,EAAEE,aAAI,CAACC,OAAO,CAACD,aAAI,CAACE,IAAI,CAACrB,MAAMa,MAAMM,IAAI,IAAIlB,MAAMC,SAASY;IAC1F,GACA;QAAEQ,WAAW;QAAMC,aAAarB,QAAQqB,WAAW,IAAI;IAAK,GAC5DpB;AAEJ;AAUe,SAASN,mBAAmBE,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3E,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,2BAA2BC,KAAKC,MAAMC,MAAMC,SAASC;IAChG,OAAO,IAAIqB,QAAQ,SAACC,SAASC;QAC3B5B,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASyB,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -21,7 +21,7 @@ var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn")
|
|
|
21
21
|
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_default(require("get-tsconfig-compat"));
|
|
22
22
|
var _mkdirp = /*#__PURE__*/ _interop_require_default(require("mkdirp"));
|
|
23
23
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
24
|
-
var
|
|
24
|
+
var _transformSync = /*#__PURE__*/ _interop_require_default(require("./transformSync.js"));
|
|
25
25
|
function _define_property(obj, key, value) {
|
|
26
26
|
if (key in obj) {
|
|
27
27
|
Object.defineProperty(obj, key, {
|
|
@@ -126,7 +126,7 @@ function transformFileCallback(src, dest, type, options, callback) {
|
|
|
126
126
|
tsconfig.config.compilerOptions.target = 'ES5';
|
|
127
127
|
}
|
|
128
128
|
var basename = _path.default.basename(src);
|
|
129
|
-
var output = (0,
|
|
129
|
+
var output = (0, _transformSync.default)(contents, basename, tsconfig);
|
|
130
130
|
// infer extension and patch .mjs imports
|
|
131
131
|
var ext = _path.default.extname(basename);
|
|
132
132
|
if (type === 'esm') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp';\nimport Queue from 'queue-cb';\n\
|
|
1
|
+
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nfunction transformFileCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(tsconfig.config || {}) };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const basename = path.basename(src);\n const output = transformSync(contents, basename, tsconfig);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write the file to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.\n * @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.\n */\nexport default function transformFile(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformFileCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformFile","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","dependency","match","ext","find","x","slice","length","matches","push","exec","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileCallback","src","dest","type","options","callback","Error","fs","readFile","err","contents","once","tsconfig","getTS","getTsconfig","config","compilerOptions","module","target","basename","path","output","transformSync","extname","destFilePath","join","replace","mkdirp","dirname","queue","Queue","defer","writeFile","bind","sourceMaps","map","await","Promise","resolve","reject","compileCallback","result"],"mappings":";;;;+BAgGA;;;;;;;CAOC,GACD;;;eAAwBA;;;yDAxGT;2DACE;iEACA;wEACC;6DACC;8DACD;oEAEQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMC,eAAe;AACrB,IAAMC,eAAe;AACrB,IAAMC,WAAW,IAAIC,OAAO,AAAC,uBAAsDH,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa,UAAQ;AACxG,IAAMI,WAAW,IAAID,OAAO,AAAC,GAAuBF,OAArBC,UAAS,cAAqCF,OAAzBC,cAAa,cAAuCA,OAA3BD,cAAa,gBAAuCA,OAAzBC,cAAa,cAAyB,OAAbD,cAAa,OAAK;AAEnJ,IAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ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/ _interop_require_default(require("path"));
|
|
16
16
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
17
|
+
var _process = /*#__PURE__*/ _interop_require_default(require("process"));
|
|
17
18
|
var _lazycjs = /*#__PURE__*/ _interop_require_default(require("./lib/lazy.js"));
|
|
18
|
-
var _processcjs = /*#__PURE__*/ _interop_require_default(require("./lib/process.js"));
|
|
19
19
|
function _interop_require_default(obj) {
|
|
20
20
|
return obj && obj.__esModule ? obj : {
|
|
21
21
|
default: obj
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
var major = +
|
|
24
|
+
var major = +_process.default.versions.node.split('.')[0];
|
|
25
25
|
var version = major >= 14 ? 'local' : 'lts';
|
|
26
26
|
var filename = typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString());
|
|
27
27
|
var worker = _path.default.resolve(_path.default.dirname(filename), 'workers', "transformSync".concat(_path.default.extname(filename) === '.mjs' ? '.cjs' : '.js'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n\nimport process from 'process';\n// @ts-ignore\nimport lazy from './lib/lazy.cjs';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst filename = typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url);\nconst worker = path.resolve(path.dirname(filename), 'workers', `transformSync${path.extname(filename) === '.mjs' ? '.cjs' : '.js'}`);\nconst call = lazy('node-version-call');\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nexport default function transformSync(contents, fileName, config) {\n return call()(version, worker, contents, fileName, config);\n}\n"],"names":["transformSync","major","process","versions","node","split","version","filename","__filename","url","fileURLToPath","worker","path","resolve","dirname","extname","call","lazy","contents","fileName","config"],"mappings":";;;;+BAaA;;;;CAIC,GACD;;;eAAwBA;;;2DAlBP;0DACD;8DAEI;8DAEH;;;;;;AAEjB,IAAMC,QAAQ,CAACC,gBAAO,CAACC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,SAAS,KAAK,UAAU;AACxC,IAAMM,WAAW,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AACpF,IAAMC,SAASC,aAAI,CAACC,OAAO,CAACD,aAAI,CAACE,OAAO,CAACP,WAAW,WAAW,AAAC,gBAAkE,OAAnDK,aAAI,CAACG,OAAO,CAACR,cAAc,SAAS,SAAS;AAC5H,IAAMS,OAAOC,IAAAA,gBAAI,EAAC;AAOH,SAASjB,cAAckB,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAOV,SAASK,QAAQO,UAAUC,UAAUC;AACrD"}
|
package/dist/esm/toPath.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import isAbsolute from 'is-absolute';
|
|
4
|
+
import process from 'process';
|
|
4
5
|
import resolve from 'resolve';
|
|
5
|
-
import fileURLToPath from './lib/fileURLToPath.mjs';
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import process from './lib/process.cjs';
|
|
8
6
|
import { moduleRegEx } from './constants.mjs';
|
|
7
|
+
import fileURLToPath from './lib/fileURLToPath.mjs';
|
|
9
8
|
function getParentPath(context) {
|
|
10
9
|
if (context.parentPath) return path.dirname(context.parentPath);
|
|
11
10
|
return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
|
package/dist/esm/toPath.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport
|
|
1
|
+
{"version":3,"sources":["toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport process from 'process';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants.js';\nimport fileURLToPath from './lib/fileURLToPath.js';\nimport type { Context } from './types.js';\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.resolve(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.resolve(pkg.dir, pkg.json.module);\n const mainPath = path.resolve(pkg.dir, pkg.json.main);\n const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !fs.existsSync(moduleResolved) ? main : moduleResolved;\n }\n\n return specifier;\n}\n"],"names":["fs","path","isAbsolute","process","resolve","moduleRegEx","fileURLToPath","getParentPath","context","parentPath","dirname","parentURL","toPath","cwd","specifier","startsWith","test","pkg","main","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace","existsSync"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAO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IAAI,CAACE,MAAM;QACxD,MAAMG,WAAW3B,KAAKG,OAAO,CAACa,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACL,IAAI;QACpD,MAAMW,iBAAiB5B,KAAKG,OAAO,CAACuB,YAAY1B,KAAK6B,QAAQ,CAACF,UAAUV;QACxE,OAAOW,eAAeE,OAAO,CAACjB,UAAUkB,OAAO,CAACf,IAAIM,IAAI,CAACG,IAAI,EAAE,OAAO,KAAK,CAAC1B,GAAGiC,UAAU,CAACJ,kBAAkBX,OAAOW;IACrH;IAEA,OAAOf;AACT"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import Iterator from 'fs-iterator';
|
|
3
3
|
import getTS from 'get-tsconfig-compat';
|
|
4
|
-
// @ts-ignore
|
|
5
4
|
import createMatcher from './createMatcher.mjs';
|
|
6
|
-
// @ts-ignore
|
|
7
5
|
import transformFile from './transformFile.mjs';
|
|
8
6
|
function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
9
7
|
if (typeof options === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\nimport createMatcher from './createMatcher.js';\nimport transformFile from './transformFile.js';\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n options = { ...options, tsconfig };\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry, cb) => {\n if (!entry.stats.isFile()) return cb();\n if (!matcher(entry.fullPath)) return cb();\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);\n },\n { callbacks: true, concurrency: options.concurrency || 1024 },\n callback\n );\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["path","Iterator","getTS","createMatcher","transformFile","transformDirectoryCallback","src","dest","type","options","callback","Error","tsconfig","getTsconfig","matcher","iterator","forEach","entry","cb","stats","isFile","fullPath","dirname","join","callbacks","concurrency","transformDirectory","Promise","resolve","reject","compileCallback","err","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,OAAOC,WAAW,sBAAsB;AAExC,OAAOC,mBAAmB,qBAAqB;AAC/C,OAAOC,mBAAmB,qBAAqB;AAE/C,SAASC,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,MAAMC,WAAWH,QAAQG,QAAQ,GAAGH,QAAQG,QAAQ,GAAGV,MAAMW,WAAW,CAACP;IACzE,MAAMQ,UAAUX,cAAcS;IAE9BH,UAAU;QAAE,GAAGA,OAAO;QAAEG;IAAS;IACjC,MAAMG,WAAW,IAAId,SAASK;IAC9BS,SAASC,OAAO,CACd,CAACC,OAAOC;QACN,IAAI,CAACD,MAAME,KAAK,CAACC,MAAM,IAAI,OAAOF;QAClC,IAAI,CAACJ,QAAQG,MAAMI,QAAQ,GAAG,OAAOH;QACrCd,cAAca,MAAMI,QAAQ,EAAErB,KAAKsB,OAAO,CAACtB,KAAKuB,IAAI,CAAChB,MAAMU,MAAMjB,IAAI,IAAIQ,MAAMC,SAASS;IAC1F,GACA;QAAEM,WAAW;QAAMC,aAAahB,QAAQgB,WAAW,IAAI;IAAK,GAC5Df;AAEJ;AAEA;;;;;;;CAOC,GACD,eAAe,SAASgB,mBAAmBpB,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3E,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,2BAA2BC,KAAKC,MAAMC,MAAMC,SAASC;IAChG,OAAO,IAAIiB,QAAQ,CAACC,SAASC;QAC3BxB,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASqB,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -4,7 +4,6 @@ import once from 'call-once-fn';
|
|
|
4
4
|
import getTS from 'get-tsconfig-compat';
|
|
5
5
|
import mkdirp from 'mkdirp';
|
|
6
6
|
import Queue from 'queue-cb';
|
|
7
|
-
// @ts-ignore
|
|
8
7
|
import transformSync from './transformSync.mjs';
|
|
9
8
|
const matchingDeps = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
10
9
|
const matchingName = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp';\nimport Queue from 'queue-cb';\n\
|
|
1
|
+
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nfunction transformFileCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.tsconfig = { ...(tsconfig.config || {}) };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'CommonJS';\n tsconfig.config.compilerOptions.target = 'ES5';\n }\n\n const basename = path.basename(src);\n const output = transformSync(contents, basename, tsconfig);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write the file to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.\n * @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.\n */\nexport default function transformFile(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformFileCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["fs","path","once","getTS","mkdirp","Queue","transformSync","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","matches","match","exec","dependency","ext","find","x","slice","length","push","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileCallback","src","dest","type","options","callback","Error","readFile","err","contents","tsconfig","getTsconfig","config","compilerOptions","module","target","basename","output","extname","destFilePath","join","replace","dirname","queue","defer","writeFile","bind","sourceMaps","map","await","transformFile","Promise","resolve","reject","compileCallback","result"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,eAAe;AAChC,OAAOC,WAAW,sBAAsB;AACxC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,WAAW,WAAW;AAE7B,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,eAAe;AACrB,MAAMC,eAAe;AACrB,MAAMC,WAAW,IAAIC,OA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sBAAsBC,KAAKC,MAAMC,MAAMC,SAAS,SAAS8B,gBAAgB1B,GAAG,EAAE2B,MAAM;YAClF3B,MAAMyB,OAAOzB,OAAOwB,QAAQG;QAC9B;IACF;AACF"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import url from 'url';
|
|
3
|
+
import process from 'process';
|
|
3
4
|
// @ts-ignore
|
|
4
5
|
import lazy from './lib/lazy.cjs';
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import process from './lib/process.cjs';
|
|
7
6
|
const major = +process.versions.node.split('.')[0];
|
|
8
7
|
const version = major >= 14 ? 'local' : 'lts';
|
|
9
8
|
const filename = typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n\nimport process from 'process';\n// @ts-ignore\nimport lazy from './lib/lazy.cjs';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst filename = typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url);\nconst worker = path.resolve(path.dirname(filename), 'workers', `transformSync${path.extname(filename) === '.mjs' ? '.cjs' : '.js'}`);\nconst call = lazy('node-version-call');\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nexport default function transformSync(contents, fileName, config) {\n return call()(version, worker, contents, fileName, config);\n}\n"],"names":["path","url","process","lazy","major","versions","node","split","version","filename","__filename","fileURLToPath","worker","resolve","dirname","extname","call","transformSync","contents","fileName","config"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,OAAOC,aAAa,UAAU;AAC9B,aAAa;AACb,OAAOC,UAAU,iBAAiB;AAElC,MAAMC,QAAQ,CAACF,QAAQG,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUJ,SAAS,KAAK,UAAU;AACxC,MAAMK,WAAW,OAAOC,eAAe,cAAcA,aAAaT,IAAIU,aAAa,CAAC,YAAYV,GAAG;AACnG,MAAMW,SAASZ,KAAKa,OAAO,CAACb,KAAKc,OAAO,CAACL,WAAW,WAAW,CAAC,aAAa,EAAET,KAAKe,OAAO,CAACN,cAAc,SAAS,SAAS,OAAO;AACnI,MAAMO,OAAOb,KAAK;AAElB;;;;CAIC,GACD,eAAe,SAASc,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAOR,SAASI,QAAQM,UAAUC,UAAUC;AACrD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"mkdirp": "^0.5.6",
|
|
62
62
|
"node-version-call": "^1.1.1",
|
|
63
63
|
"path-posix": "^1.0.0",
|
|
64
|
+
"process": "^0.11.10",
|
|
64
65
|
"queue-cb": "^1.4.3",
|
|
65
66
|
"resolve": "^1.22.9",
|
|
66
67
|
"temp-suffix": "^0.1.1",
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"cr": "^0.1.0",
|
|
78
79
|
"react": "^19.0.0",
|
|
79
80
|
"rimraf2": "^2.8.2",
|
|
80
|
-
"ts-dev-stack": "^1.2.
|
|
81
|
+
"ts-dev-stack": "^1.2.3",
|
|
81
82
|
"ts-node": "^10.8.2",
|
|
82
83
|
"typescript": "^5.7.2"
|
|
83
84
|
},
|
package/dist/cjs/lib/process.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = process;
|
|
3
|
-
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["process.cts"],"sourcesContent":["module.exports = process;\n"],"names":["module","exports","process"],"mappings":";AAAAA,OAAOC,OAAO,GAAGC"}
|
package/dist/esm/lib/process.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = process;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["process.cts"],"sourcesContent":["module.exports = process;\n"],"names":["module","exports","process"],"mappings":"AAAAA,OAAOC,OAAO,GAAGC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|