ts-swc-transform 1.1.0 → 1.1.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/extensions.js +24 -0
- package/dist/cjs/extensions.js.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/existsSync.js +11 -0
- package/dist/cjs/lib/existsSync.js.map +1 -0
- package/dist/cjs/lib/installBindings.js +24 -0
- package/dist/cjs/lib/installBindings.js.map +1 -0
- package/dist/cjs/lib/toPath.js +63 -0
- package/dist/cjs/lib/toPath.js.map +1 -0
- package/dist/cjs/resolveFileSync.js +50 -0
- package/dist/cjs/resolveFileSync.js.map +1 -0
- package/dist/cjs/transformDirectory.js +3 -3
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformFile.js +7 -7
- package/dist/cjs/transformFile.js.map +1 -1
- package/dist/cjs/transformSync.js +4 -4
- package/dist/cjs/transformSync.js.map +1 -1
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/workers/installBinding.js +73 -0
- package/dist/cjs/workers/installBinding.js.map +1 -0
- package/dist/cjs/workers/transformSync.js +7 -1
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/esm/extensions.mjs +13 -0
- package/dist/esm/extensions.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/existsSync.cjs +9 -0
- package/dist/esm/lib/existsSync.cjs.map +1 -0
- package/dist/esm/lib/installBindings.cjs +22 -0
- package/dist/esm/lib/installBindings.cjs.map +1 -0
- package/dist/esm/lib/toPath.mjs +48 -0
- package/dist/esm/lib/toPath.mjs.map +1 -0
- package/dist/esm/resolveFileSync.mjs +28 -0
- package/dist/esm/resolveFileSync.mjs.map +1 -0
- package/dist/esm/transformDirectory.mjs +3 -3
- package/dist/esm/transformDirectory.mjs.map +1 -1
- package/dist/esm/transformFile.mjs +10 -10
- package/dist/esm/transformFile.mjs.map +1 -1
- package/dist/esm/transformSync.mjs +2 -2
- package/dist/esm/transformSync.mjs.map +1 -1
- package/dist/esm/types.mjs +1 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/workers/installBinding.cjs +46 -0
- package/dist/esm/workers/installBinding.cjs.map +1 -0
- package/dist/esm/workers/transformSync.cjs +7 -1
- package/dist/esm/workers/transformSync.cjs.map +1 -1
- package/dist/types/extensions.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/lib/lazy.d.cts +1 -0
- package/dist/types/lib/process.d.cts +1 -0
- package/dist/types/lib/toPath.d.ts +2 -0
- package/dist/types/resolveFileSync.d.ts +2 -0
- package/dist/types/types.d.ts +4 -0
- package/dist/types/workers/installBinding.d.cts +1 -0
- package/package.json +12 -8
- /package/dist/cjs/{lazy.js → lib/lazy.js} +0 -0
- /package/dist/cjs/{lazy.js.map → lib/lazy.js.map} +0 -0
- /package/dist/cjs/{process.js → lib/process.js} +0 -0
- /package/dist/cjs/{process.js.map → lib/process.js.map} +0 -0
- /package/dist/esm/{lazy.cjs → lib/lazy.cjs} +0 -0
- /package/dist/esm/{lazy.cjs.map → lib/lazy.cjs.map} +0 -0
- /package/dist/esm/{process.cjs → lib/process.cjs} +0 -0
- /package/dist/esm/{process.cjs.map → lib/process.cjs.map} +0 -0
- /package/dist/types/{lazy.d.cts → lib/existsSync.d.cts} +0 -0
- /package/dist/types/{process.d.cts → lib/installBindings.d.cts} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _default = [
|
|
12
|
+
'.js',
|
|
13
|
+
'.jsx',
|
|
14
|
+
'.cjs',
|
|
15
|
+
'.mjs',
|
|
16
|
+
'.ts',
|
|
17
|
+
'.tsx',
|
|
18
|
+
'.cts',
|
|
19
|
+
'.mts',
|
|
20
|
+
'.json',
|
|
21
|
+
'.es6',
|
|
22
|
+
'.es'
|
|
23
|
+
];
|
|
24
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["extensions.ts"],"sourcesContent":["export default ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts', '.json', '.es6', '.es'];\n"],"names":[],"mappings":";;;;+BAAA;;;eAAA;;;IAAA,WAAe;IAAC;IAAO;IAAQ;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;IAAQ;IAAS;IAAQ;CAAM"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -12,6 +12,12 @@ _export(exports, {
|
|
|
12
12
|
createMatcher: function() {
|
|
13
13
|
return _createMatcher.default;
|
|
14
14
|
},
|
|
15
|
+
extensions: function() {
|
|
16
|
+
return _extensions.default;
|
|
17
|
+
},
|
|
18
|
+
resolveFileSync: function() {
|
|
19
|
+
return _resolveFileSync.default;
|
|
20
|
+
},
|
|
15
21
|
transformDirectory: function() {
|
|
16
22
|
return _transformDirectory.default;
|
|
17
23
|
},
|
|
@@ -22,10 +28,26 @@ _export(exports, {
|
|
|
22
28
|
return _transformSync.default;
|
|
23
29
|
}
|
|
24
30
|
});
|
|
31
|
+
_export_star(require("./types.js"), exports);
|
|
25
32
|
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("./createMatcher.js"));
|
|
33
|
+
var _extensions = /*#__PURE__*/ _interop_require_default(require("./extensions.js"));
|
|
34
|
+
var _resolveFileSync = /*#__PURE__*/ _interop_require_default(require("./resolveFileSync.js"));
|
|
26
35
|
var _transformFile = /*#__PURE__*/ _interop_require_default(require("./transformFile.js"));
|
|
27
36
|
var _transformDirectory = /*#__PURE__*/ _interop_require_default(require("./transformDirectory.js"));
|
|
28
37
|
var _transformSync = /*#__PURE__*/ _interop_require_default(require("./transformSync.js"));
|
|
38
|
+
function _export_star(from, to) {
|
|
39
|
+
Object.keys(from).forEach(function(k) {
|
|
40
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
41
|
+
Object.defineProperty(to, k, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function() {
|
|
44
|
+
return from[k];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return from;
|
|
50
|
+
}
|
|
29
51
|
function _interop_require_default(obj) {
|
|
30
52
|
return obj && obj.__esModule ? obj : {
|
|
31
53
|
default: obj
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export { default as createMatcher } from './createMatcher.js';\nexport { default as transformFile } from './transformFile.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\n"],"names":["createMatcher","transformDirectory","transformFile","transformSync"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './types.js';\nexport { default as createMatcher } from './createMatcher.js';\nexport { default as extensions } from './extensions.js';\nexport { default as resolveFileSync } from './resolveFileSync.js';\nexport { default as transformFile } from './transformFile.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\n"],"names":["createMatcher","extensions","resolveFileSync","transformDirectory","transformFile","transformSync"],"mappings":";;;;;;;;;;;IACoBA,aAAa;eAAbA,sBAAa;;IACbC,UAAU;eAAVA,mBAAU;;IACVC,eAAe;eAAfA,wBAAe;;IAEfC,kBAAkB;eAAlBA,2BAAkB;;IADlBC,aAAa;eAAbA,sBAAa;;IAEbC,aAAa;eAAbA,sBAAa;;;qBANnB;oEAC2B;iEACH;sEACK;oEACF;yEACK;oEACL"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var accessSync = require('fs-access-sync-compat');
|
|
3
|
+
module.exports = function existsSync(path) {
|
|
4
|
+
try {
|
|
5
|
+
accessSync(path);
|
|
6
|
+
return true;
|
|
7
|
+
} catch (_) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["existsSync.cts"],"sourcesContent":["const accessSync = require('fs-access-sync-compat');\n\nmodule.exports = function existsSync(path) {\n try {\n accessSync(path);\n return true;\n } catch (_) {\n return false;\n }\n};\n"],"names":["accessSync","require","module","exports","existsSync","path","_"],"mappings":";AAAA,IAAMA,aAAaC,QAAQ;AAE3BC,OAAOC,OAAO,GAAG,SAASC,WAAWC,IAAI;IACvC,IAAI;QACFL,WAAWK;QACX,OAAO;IACT,EAAE,OAAOC,GAAG;QACV,OAAO;IACT;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var existsSync = require('./existsSync.js');
|
|
4
|
+
var lazy = require('../lazy.js');
|
|
5
|
+
var major = +process.versions.node.split('.')[0];
|
|
6
|
+
var version = major >= 14 ? 'local' : 'lts';
|
|
7
|
+
var worker = path.resolve(path.dirname(__dirname), 'workers', "installBinding".concat(path.extname(__filename)));
|
|
8
|
+
var call = lazy('node-version-call');
|
|
9
|
+
var installDir = path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json'))));
|
|
10
|
+
var optionalDependencies = require('@swc/core/package.json').optionalDependencies;
|
|
11
|
+
var depKey = "".concat(process.platform, "-").concat(process.arch);
|
|
12
|
+
for(var key in optionalDependencies){
|
|
13
|
+
var depPath = path.join(installDir, key);
|
|
14
|
+
if (key.indexOf(depKey) < 0 || existsSync(depPath)) continue;
|
|
15
|
+
try {
|
|
16
|
+
call()({
|
|
17
|
+
version: version,
|
|
18
|
+
callbacks: true
|
|
19
|
+
}, worker, key, optionalDependencies[key]);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.log("Failed to install ".concat(key, "@").concat(optionalDependencies[key], ". Error: ").concat(err.message));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["installBindings.cts"],"sourcesContent":["const path = require('path');\nconst existsSync = require('./existsSync.cjs');\nconst lazy = require('../lazy.cjs');\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst worker = path.resolve(path.dirname(__dirname), 'workers', `installBinding${path.extname(__filename)}`);\nconst call = lazy('node-version-call');\n\nconst installDir = path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json'))));\nconst { optionalDependencies } = require('@swc/core/package.json');\nconst depKey = `${process.platform}-${process.arch}`;\n\nfor (const key in optionalDependencies) {\n const depPath = path.join(installDir, key);\n if (key.indexOf(depKey) < 0 || existsSync(depPath)) continue;\n\n try {\n call()({ version, callbacks: true }, worker, key, optionalDependencies[key]);\n } catch (err) {\n console.log(`Failed to install ${key}@${optionalDependencies[key]}. Error: ${err.message}`);\n }\n}\n"],"names":["path","require","existsSync","lazy","major","process","versions","node","split","version","worker","resolve","dirname","__dirname","extname","__filename","call","installDir","optionalDependencies","depKey","platform","arch","key","depPath","join","indexOf","callbacks","err","console","log","message"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,aAAaD,QAAQ;AAC3B,IAAME,OAAOF,QAAQ;AAErB,IAAMG,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,SAAS,KAAK,UAAU;AACxC,IAAMM,SAASV,KAAKW,OAAO,CAACX,KAAKY,OAAO,CAACC,YAAY,WAAW,AAAC,iBAAyC,OAAzBb,KAAKc,OAAO,CAACC;AAC9F,IAAMC,OAAOb,KAAK;AAElB,IAAMc,aAAajB,KAAKY,OAAO,CAACZ,KAAKY,OAAO,CAACZ,KAAKY,OAAO,CAACX,QAAQU,OAAO,CAAC;AAC1E,IAAM,AAAEO,uBAAyBjB,QAAQ,0BAAjCiB;AACR,IAAMC,SAAS,AAAC,GAAsBd,OAApBA,QAAQe,QAAQ,EAAC,KAAgB,OAAbf,QAAQgB,IAAI;AAElD,IAAK,IAAMC,OAAOJ,qBAAsB;IACtC,IAAMK,UAAUvB,KAAKwB,IAAI,CAACP,YAAYK;IACtC,IAAIA,IAAIG,OAAO,CAACN,UAAU,KAAKjB,WAAWqB,UAAU;IAEpD,IAAI;QACFP,OAAO;YAAEP,SAAAA;YAASiB,WAAW;QAAK,GAAGhB,QAAQY,KAAKJ,oBAAoB,CAACI,IAAI;IAC7E,EAAE,OAAOK,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,qBAA2BX,OAAPI,KAAI,KAAwCK,OAArCT,oBAAoB,CAACI,IAAI,EAAC,aAAuB,OAAZK,IAAIG,OAAO;IAC1F;AACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return toPath;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
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
|
+
var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
|
|
16
|
+
var _processcjs = /*#__PURE__*/ _interop_require_default(require("./process.js"));
|
|
17
|
+
function _interop_require_default(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var moduleRegEx = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
|
|
23
|
+
function getParentPath(context) {
|
|
24
|
+
if (context.parentPath) return _path.default.dirname(context.parentPath);
|
|
25
|
+
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : _processcjs.default.cwd();
|
|
26
|
+
}
|
|
27
|
+
function toPath(specifier, context) {
|
|
28
|
+
if (specifier.startsWith('file:')) return _url.default.parse(specifier).pathname;
|
|
29
|
+
if ((0, _isabsolute.default)(specifier)) return specifier;
|
|
30
|
+
if (specifier[0] === '.') {
|
|
31
|
+
var parentPath = context ? getParentPath(context) : _processcjs.default.cwd();
|
|
32
|
+
return _path.default.resolve(parentPath, specifier);
|
|
33
|
+
}
|
|
34
|
+
if (moduleRegEx.test(specifier)) {
|
|
35
|
+
var parentPath1 = context ? getParentPath(context) : _processcjs.default.cwd();
|
|
36
|
+
var pkg = null;
|
|
37
|
+
var main = _resolve.default.sync(specifier, {
|
|
38
|
+
basedir: parentPath1,
|
|
39
|
+
extensions: [
|
|
40
|
+
'.js',
|
|
41
|
+
'.json',
|
|
42
|
+
'.node',
|
|
43
|
+
'.mjs'
|
|
44
|
+
],
|
|
45
|
+
packageFilter: function packageFilter(json, dir) {
|
|
46
|
+
pkg = {
|
|
47
|
+
json: json,
|
|
48
|
+
dir: dir
|
|
49
|
+
};
|
|
50
|
+
return json;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (!pkg || !pkg.json.module) return main; // no modules, use main
|
|
54
|
+
if (pkg.json.name === specifier) return _path.default.resolve(pkg.dir, pkg.json.module); // the module
|
|
55
|
+
// a relative path. Only accept if it doesn't break the relative naming and it exists
|
|
56
|
+
var modulePath = _path.default.resolve(pkg.dir, pkg.json.module);
|
|
57
|
+
var mainPath = _path.default.resolve(pkg.dir, pkg.json.main);
|
|
58
|
+
var moduleResolved = _path.default.resolve(modulePath, _path.default.relative(mainPath, main));
|
|
59
|
+
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !_fs.default.existsSync(moduleResolved) ? main : moduleResolved;
|
|
60
|
+
}
|
|
61
|
+
return specifier;
|
|
62
|
+
}
|
|
63
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport type { Context } from '../types';\n// @ts-ignore\nimport process from './process.cjs';\n\nconst moduleRegEx = /^[^.\\/]|^\\.[^.\\/]|^\\.\\.[^\\/]/;\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 url.parse(specifier).pathname;\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","moduleRegEx","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","url","parse","pathname","isAbsolute","resolve","test","pkg","main","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace","fs","existsSync"],"mappings":";;;;+BAgBA;;;eAAwBA;;;yDAhBT;2DACE;0DACD;iEACO;8DACH;iEAGA;;;;;;AAEpB,IAAMC,cAAc;AAEpB,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACN,OAAOG,QAAQI,SAAS,KAAKC,mBAAO,CAACC,GAAG;AAClF;AAEe,SAAST,OAAOU,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOC,YAAG,CAACC,KAAK,CAACH,WAAWI,QAAQ;IACvE,IAAIC,IAAAA,mBAAU,EAACL,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,mBAAO,CAACC,GAAG;QACjE,OAAOJ,aAAI,CAACW,OAAO,CAACZ,YAAYM;IAClC;IACA,IAAIT,YAAYgB,IAAI,CAACP,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,mBAAO,CAACC,GAAG;QAEjE,IAAIS,MAAM;QACV,IAAMC,OAAOH,gBAAO,CAACI,IAAI,CAACV,WAAW;YACnCW,SAASjB;YACTkB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;YAC7CC,eAAAA,SAAAA,cAAcC,IAAI,EAAEC,GAAG;gBACrBP,MAAM;oBAAEM,MAAAA;oBAAMC,KAAAA;gBAAI;gBAClB,OAAOD;YACT;QACF;QACA,IAAI,CAACN,OAAO,CAACA,IAAIM,IAAI,CAACE,MAAM,EAAE,OAAOP,MAAM,uBAAuB;QAClE,IAAID,IAAIM,IAAI,CAACG,IAAI,KAAKjB,WAAW,OAAOL,aAAI,CAACW,OAAO,CAACE,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACE,MAAM,GAAG,aAAa;QAE7F,qFAAqF;QACrF,IAAME,aAAavB,aAAI,CAACW,OAAO,CAACE,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACE,MAAM;QACxD,IAAMG,WAAWxB,aAAI,CAACW,OAAO,CAACE,IAAIO,GAAG,EAAEP,IAAIM,IAAI,CAACL,IAAI;QACpD,IAAMW,iBAAiBzB,aAAI,CAACW,OAAO,CAACY,YAAYvB,aAAI,CAAC0B,QAAQ,CAACF,UAAUV;QACxE,OAAOW,eAAeE,OAAO,CAACtB,UAAUuB,OAAO,CAACf,IAAIM,IAAI,CAACG,IAAI,EAAE,OAAO,KAAK,CAACO,WAAE,CAACC,UAAU,CAACL,kBAAkBX,OAAOW;IACrH;IAEA,OAAOpB;AACT"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return resolveFileSync;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
var _extensions = /*#__PURE__*/ _interop_require_default(require("./extensions.js"));
|
|
14
|
+
var _toPath = /*#__PURE__*/ _interop_require_default(require("./lib/toPath.js"));
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
var moduleRegEx = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
|
|
21
|
+
var typeFileRegEx = /^[^.]+\.d\.[cm]?ts$/;
|
|
22
|
+
var indexExtensions = _extensions.default.map(function(x) {
|
|
23
|
+
return "index".concat(x);
|
|
24
|
+
});
|
|
25
|
+
function resolveFileSync(specifier, context) {
|
|
26
|
+
var filePath = (0, _toPath.default)(specifier, context);
|
|
27
|
+
var ext = _path.default.extname(filePath);
|
|
28
|
+
var stats;
|
|
29
|
+
try {
|
|
30
|
+
stats = _fs.default.statSync(filePath);
|
|
31
|
+
} catch (_err) {}
|
|
32
|
+
// directory
|
|
33
|
+
if ((stats === null || stats === void 0 ? void 0 : stats.isDirectory()) || specifier.endsWith('/')) {
|
|
34
|
+
var items = _fs.default.readdirSync(filePath);
|
|
35
|
+
var item = items.find(function(x) {
|
|
36
|
+
return indexExtensions.indexOf(x) >= 0;
|
|
37
|
+
});
|
|
38
|
+
if (item) return _path.default.join(filePath, item);
|
|
39
|
+
} else if (!ext && !stats || !moduleRegEx.test(specifier)) {
|
|
40
|
+
var fileName = _path.default.basename(filePath).replace(/(\.[^/.]+)+$/, '');
|
|
41
|
+
var items1 = _fs.default.readdirSync(_path.default.dirname(filePath));
|
|
42
|
+
var item1 = items1.find(function(x) {
|
|
43
|
+
return x.startsWith(fileName) && !typeFileRegEx.test(x) && _extensions.default.indexOf(_path.default.extname(x)) >= 0;
|
|
44
|
+
});
|
|
45
|
+
if (item1) return _path.default.join(_path.default.dirname(filePath), item1);
|
|
46
|
+
}
|
|
47
|
+
// return what was found
|
|
48
|
+
return stats ? filePath : null;
|
|
49
|
+
}
|
|
50
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport extensions from './extensions.js';\nimport toPath from './lib/toPath.js';\n\nimport type { Context } from './types';\n\nconst moduleRegEx = /^[^.\\/]|^\\.[^.\\/]|^\\.\\.[^\\/]/;\nconst typeFileRegEx = /^[^.]+\\.d\\.[cm]?ts$/;\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n const ext = path.extname(filePath);\n\n let stats: fs.Stats | undefined;\n try {\n stats = fs.statSync(filePath);\n } catch (_err) {}\n\n // directory\n if (stats?.isDirectory() || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n }\n\n // look up the extension\n else if ((!ext && !stats) || !moduleRegEx.test(specifier)) {\n const fileName = path.basename(filePath).replace(/(\\.[^/.]+)+$/, '');\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => x.startsWith(fileName) && !typeFileRegEx.test(x) && extensions.indexOf(path.extname(x)) >= 0);\n if (item) return path.join(path.dirname(filePath), item);\n }\n\n // return what was found\n return stats ? filePath : null;\n}\n"],"names":["resolveFileSync","moduleRegEx","typeFileRegEx","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","ext","path","extname","stats","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","join","test","fileName","basename","replace","dirname","startsWith"],"mappings":";;;;+BAWA;;;eAAwBA;;;yDAXT;2DACE;iEACM;6DACJ;;;;;;AAInB,IAAMC,cAAc;AACpB,IAAMC,gBAAgB;AACtB,IAAMC,kBAAkBC,mBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASN,gBAAgBO,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eAAM,EAACH,WAAWC;IACnC,IAAMG,MAAMC,aAAI,CAACC,OAAO,CAACJ;IAEzB,IAAIK;IACJ,IAAI;QACFA,QAAQC,WAAE,CAACC,QAAQ,CAACP;IACtB,EAAE,OAAOQ,MAAM,CAAC;IAEhB,YAAY;IACZ,IAAIH,CAAAA,kBAAAA,4BAAAA,MAAOI,WAAW,OAAMX,UAAUY,QAAQ,CAAC,MAAM;QACnD,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACZ;QAC7B,IAAMa,OAAOF,MAAMG,IAAI,CAAC,SAACjB;mBAAMH,gBAAgBqB,OAAO,CAAClB,MAAM;;QAC7D,IAAIgB,MAAM,OAAOV,aAAI,CAACa,IAAI,CAAChB,UAAUa;IACvC,OAGK,IAAI,AAAC,CAACX,OAAO,CAACG,SAAU,CAACb,YAAYyB,IAAI,CAACnB,YAAY;QACzD,IAAMoB,WAAWf,aAAI,CAACgB,QAAQ,CAACnB,UAAUoB,OAAO,CAAC,gBAAgB;QACjE,IAAMT,SAAQL,WAAE,CAACM,WAAW,CAACT,aAAI,CAACkB,OAAO,CAACrB;QAC1C,IAAMa,QAAOF,OAAMG,IAAI,CAAC,SAACjB;mBAAMA,EAAEyB,UAAU,CAACJ,aAAa,CAACzB,cAAcwB,IAAI,CAACpB,MAAMF,mBAAU,CAACoB,OAAO,CAACZ,aAAI,CAACC,OAAO,CAACP,OAAO;;QAC1H,IAAIgB,OAAM,OAAOV,aAAI,CAACa,IAAI,CAACb,aAAI,CAACkB,OAAO,CAACrB,WAAWa;IACrD;IAEA,wBAAwB;IACxB,OAAOR,QAAQL,WAAW;AAC5B"}
|
|
@@ -86,10 +86,10 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
86
86
|
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
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
|
-
var
|
|
90
|
-
var matcher = (0, _createMatcherts.default)(
|
|
89
|
+
var tsconfig = options.tsconfig ? options.tsconfig : _gettsconfigcompat.default.getTsconfig(src);
|
|
90
|
+
var matcher = (0, _createMatcherts.default)(tsconfig);
|
|
91
91
|
options = _object_spread_props(_object_spread({}, options), {
|
|
92
|
-
|
|
92
|
+
tsconfig: tsconfig
|
|
93
93
|
});
|
|
94
94
|
var iterator = new _fsiterator.default(src);
|
|
95
95
|
iterator.forEach(function(entry, cb) {
|
|
@@ -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\n// @ts-ignore\nimport createMatcher from './createMatcher.ts';\n// @ts-ignore\nimport transformFile from './transformFile.ts';\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
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\n// @ts-ignore\nimport createMatcher from './createMatcher.ts';\n// @ts-ignore\nimport transformFile from './transformFile.ts';\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":";;;;+BAoCA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DA5CP;iEACI;wEACH;sEAGQ;sEAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,KAAKC,MAAMC,MAAMC,SAAS,SAASyB,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -116,17 +116,17 @@ function transformFileCallback(src, dest, type, options, callback) {
|
|
|
116
116
|
if (err) return callback(err);
|
|
117
117
|
callback = (0, _calloncefn.default)(callback);
|
|
118
118
|
try {
|
|
119
|
-
var
|
|
119
|
+
var tsconfig = options.tsconfig ? options.tsconfig : _gettsconfigcompat.default.getTsconfig(src);
|
|
120
120
|
// overrides for cjs
|
|
121
121
|
if (type === 'cjs') {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
tsconfig = _object_spread({}, tsconfig);
|
|
123
|
+
tsconfig.tsconfig = _object_spread({}, tsconfig.config || {});
|
|
124
|
+
tsconfig.config.compilerOptions = _object_spread({}, tsconfig.config.compilerOptions || {});
|
|
125
|
+
tsconfig.config.compilerOptions.module = 'CommonJS';
|
|
126
|
+
tsconfig.config.compilerOptions.target = 'ES5';
|
|
127
127
|
}
|
|
128
128
|
var basename = _path.default.basename(src);
|
|
129
|
-
var output = (0, _transformSyncts.default)(contents, basename,
|
|
129
|
+
var output = (0, _transformSyncts.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\n// @ts-ignore\nimport transformSync from './transformSync.ts';\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
|
|
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\n// @ts-ignore\nimport transformSync from './transformSync.ts';\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":";;;;+BAiGA;;;;;;;CAOC,GACD;;;eAAwBA;;;yDAzGT;2DACE;iEACA;wEACC;6DACC;8DACD;sEAGQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMC,eAAe;AACrB,IAAMC,eAAe;AACrB,IAAMC,WAAW,IAAIC,OAAO,AAAC,uBAAsDH,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa,UAAQ;AACxG,IAAMI,WAAW,IAAID,OAAO,AAAC,GAAuBF,OAArBC,UAAS,cAAqCF,OAAzBC,cAAa,cAAuCA,OAA3BD,cAAa,gBAAuCA,OAAzBC,cAAa,cAAyB,OAAbD,cAAa,OAAK;AAEnJ,IAAMK,mBAAmB;IAAC;IAAO;IAAO;IAAQ;IAAQ;CAAO;AAC/D,IAAMC,mBAAmB;IAAC;CAAO;AACjC,IAAMC,mBAAmB;IAAC;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;CAAO;AAExE,SAASC,iBAAiBC,IAAI,EAAEC,KAAK,EAAE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CAACK,IAAI,CAACvB,MAAMiB,SAASO,OAAO,CAAC,aAAa,MAAMxC;YAEzEyC,IAAAA,eAAM,EAACP,aAAI,CAACQ,OAAO,CAACJ,eAAe;gBACjC,IAAMK,QAAQ,IAAIC,gBAAK;gBACvBD,MAAME,KAAK,CAACxB,WAAE,CAACyB,SAAS,CAACC,IAAI,CAAC,MAAMT,cAAcH,OAAOzC,IAAI,EAAE;gBAC/D,CAACwB,QAAQ8B,UAAU,IAAIL,MAAME,KAAK,CAACxB,WAAE,CAACyB,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAe,OAAbT,cAAa,SAAOH,OAAOc,GAAG,EAAE;gBAC9FN,MAAMO,KAAK,CAAC;2BAAO3B,MAAMJ,SAASI,OAAOJ,SAAS,MAAMmB;;YAC1D;QACF,EAAE,OAAOf,KAAK;YACZJ,SAASI;QACX;IACF;AACF;AAUe,SAASvC,cAAc+B,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACtE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,sBAAsBC,KAAKC,MAAMC,MAAMC,SAASC;IAC3F,OAAO,IAAIgC,QAAQ,SAACC,SAASC;QAC3BvC,sBAAsBC,KAAKC,MAAMC,MAAMC,SAAS,SAASoC,gBAAgB/B,GAAG,EAAEgC,MAAM;YAClFhC,MAAM8B,OAAO9B,OAAO6B,QAAQG;QAC9B;IACF;AACF"}
|
|
@@ -14,18 +14,18 @@ Object.defineProperty(exports, /**
|
|
|
14
14
|
});
|
|
15
15
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
16
16
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
17
|
-
var
|
|
18
|
-
var
|
|
17
|
+
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 = +_processcjs.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'));
|
|
28
|
-
var call = (0,
|
|
28
|
+
var call = (0, _lazycjs.default)('node-version-call');
|
|
29
29
|
function transformSync(contents, fileName, config) {
|
|
30
30
|
return call()(version, worker, contents, fileName, config);
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// @ts-ignore\nimport lazy from './lazy.
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// @ts-ignore\nimport lazy from './lib/lazy.cjs';\n// @ts-ignore\nimport process from './lib/process.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;8DAEC;iEAEG;;;;;;AAEpB,IAAMC,QAAQ,CAACC,mBAAO,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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_without_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
9
|
+
}
|
|
10
|
+
function _iterable_to_array(iter) {
|
|
11
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
12
|
+
}
|
|
13
|
+
function _non_iterable_spread() {
|
|
14
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
15
|
+
}
|
|
16
|
+
function _to_consumable_array(arr) {
|
|
17
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
18
|
+
}
|
|
19
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
20
|
+
if (!o) return;
|
|
21
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
22
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
23
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
24
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
25
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
26
|
+
}
|
|
27
|
+
var path = require('path');
|
|
28
|
+
var fs = require('fs');
|
|
29
|
+
var tmpdir = require('os').tmpdir;
|
|
30
|
+
var tempSuffix = require('temp-suffix');
|
|
31
|
+
var mkdirp = require('mkdirp');
|
|
32
|
+
var Queue = require('queue-cb');
|
|
33
|
+
var spawn = require('cross-spawn-cb');
|
|
34
|
+
var once = require('call-once-fn');
|
|
35
|
+
module.exports = function installBindings(name, version, callback) {
|
|
36
|
+
callback = once(callback);
|
|
37
|
+
try {
|
|
38
|
+
var tmp = path.join(tmpdir(), 'ts-swc-transform', tempSuffix());
|
|
39
|
+
var source = path.join.apply(null, [
|
|
40
|
+
tmp,
|
|
41
|
+
'node_modules'
|
|
42
|
+
].concat(_to_consumable_array(name.split('/'))));
|
|
43
|
+
var dest = path.join.apply(null, [
|
|
44
|
+
path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json'))))
|
|
45
|
+
].concat(_to_consumable_array(name.split('/'))));
|
|
46
|
+
var queue = new Queue(1);
|
|
47
|
+
queue.defer(mkdirp.bind(null, tmp));
|
|
48
|
+
queue.defer(fs.writeFile.bind(null, path.join(tmp, 'package.json'), '{}', 'utf8'));
|
|
49
|
+
queue.defer(function(cb) {
|
|
50
|
+
// remove NODE_OPTIONS from ts-dev-stack
|
|
51
|
+
// biome-ignore lint/performance/noDelete: <explanation>
|
|
52
|
+
delete process.env.NODE_OPTIONS;
|
|
53
|
+
spawn('npm', [
|
|
54
|
+
'install',
|
|
55
|
+
"".concat(name, "@").concat(version)
|
|
56
|
+
], {
|
|
57
|
+
cwd: tmp
|
|
58
|
+
}, cb);
|
|
59
|
+
});
|
|
60
|
+
queue.defer(fs.rename.bind(null, source, dest));
|
|
61
|
+
queue.await(function(err) {
|
|
62
|
+
fs.rm(tmp, {
|
|
63
|
+
recursive: true,
|
|
64
|
+
force: true
|
|
65
|
+
}, function() {
|
|
66
|
+
return callback(err);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return callback(err);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["installBinding.cts"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst { tmpdir } = require('os');\nconst tempSuffix = require('temp-suffix');\nconst mkdirp = require('mkdirp');\n\nconst Queue = require('queue-cb');\nconst spawn = require('cross-spawn-cb');\nconst once = require('call-once-fn');\n\nmodule.exports = function installBindings(name, version, callback) {\n callback = once(callback);\n try {\n const tmp = path.join(tmpdir(), 'ts-swc-transform', tempSuffix());\n const source = path.join.apply(null, [tmp, 'node_modules', ...name.split('/')]);\n const dest = path.join.apply(null, [path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json')))), ...name.split('/')]);\n\n const queue = new Queue(1);\n queue.defer(mkdirp.bind(null, tmp));\n queue.defer(fs.writeFile.bind(null, path.join(tmp, 'package.json'), '{}', 'utf8'));\n queue.defer((cb) => {\n // remove NODE_OPTIONS from ts-dev-stack\n // biome-ignore lint/performance/noDelete: <explanation>\n delete process.env.NODE_OPTIONS;\n spawn('npm', ['install', `${name}@${version}`], { cwd: tmp }, cb);\n });\n queue.defer(fs.rename.bind(null, source, dest));\n queue.await((err) => {\n fs.rm(tmp, { recursive: true, force: true }, () => callback(err));\n });\n } catch (err) {\n return callback(err);\n }\n};\n"],"names":["path","require","fs","tmpdir","tempSuffix","mkdirp","Queue","spawn","once","module","exports","installBindings","name","version","callback","tmp","join","source","apply","split","dest","dirname","resolve","queue","defer","bind","writeFile","cb","process","env","NODE_OPTIONS","cwd","rename","await","err","rm","recursive","force"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,KAAKD,QAAQ;AACnB,IAAM,AAAEE,SAAWF,QAAQ,MAAnBE;AACR,IAAMC,aAAaH,QAAQ;AAC3B,IAAMI,SAASJ,QAAQ;AAEvB,IAAMK,QAAQL,QAAQ;AACtB,IAAMM,QAAQN,QAAQ;AACtB,IAAMO,OAAOP,QAAQ;AAErBQ,OAAOC,OAAO,GAAG,SAASC,gBAAgBC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC/DA,WAAWN,KAAKM;IAChB,IAAI;QACF,IAAMC,MAAMf,KAAKgB,IAAI,CAACb,UAAU,oBAAoBC;QACpD,IAAMa,SAASjB,KAAKgB,IAAI,CAACE,KAAK,CAAC,MAAM;YAACH;YAAK;SAAmC,CAAzC,OAAsB,qBAAGH,KAAKO,KAAK,CAAC;QACzE,IAAMC,OAAOpB,KAAKgB,IAAI,CAACE,KAAK,CAAC,MAAM;YAAClB,KAAKqB,OAAO,CAACrB,KAAKqB,OAAO,CAACrB,KAAKqB,OAAO,CAACpB,QAAQqB,OAAO,CAAC;SAAiD,CAAzG,OAAsF,qBAAGV,KAAKO,KAAK,CAAC;QAEvI,IAAMI,QAAQ,IAAIjB,MAAM;QACxBiB,MAAMC,KAAK,CAACnB,OAAOoB,IAAI,CAAC,MAAMV;QAC9BQ,MAAMC,KAAK,CAACtB,GAAGwB,SAAS,CAACD,IAAI,CAAC,MAAMzB,KAAKgB,IAAI,CAACD,KAAK,iBAAiB,MAAM;QAC1EQ,MAAMC,KAAK,CAAC,SAACG;YACX,wCAAwC;YACxC,wDAAwD;YACxD,OAAOC,QAAQC,GAAG,CAACC,YAAY;YAC/BvB,MAAM,OAAO;gBAAC;gBAAY,GAAUM,OAARD,MAAK,KAAW,OAARC;aAAU,EAAE;gBAAEkB,KAAKhB;YAAI,GAAGY;QAChE;QACAJ,MAAMC,KAAK,CAACtB,GAAG8B,MAAM,CAACP,IAAI,CAAC,MAAMR,QAAQG;QACzCG,MAAMU,KAAK,CAAC,SAACC;YACXhC,GAAGiC,EAAE,CAACpB,KAAK;gBAAEqB,WAAW;gBAAMC,OAAO;YAAK,GAAG;uBAAMvB,SAASoB;;QAC9D;IACF,EAAE,OAAOA,KAAK;QACZ,OAAOpB,SAASoB;IAClB;AACF"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var path = require('path');
|
|
3
|
-
var swc
|
|
3
|
+
var swc;
|
|
4
|
+
try {
|
|
5
|
+
swc = require('@swc/core');
|
|
6
|
+
} catch (_) {
|
|
7
|
+
require('../lib/installBindings.js');
|
|
8
|
+
swc = require('@swc/core');
|
|
9
|
+
}
|
|
4
10
|
var ts = require('typescript');
|
|
5
11
|
var swcTranspiler = require('ts-node/transpilers/swc');
|
|
6
12
|
module.exports = function transformSync(contents, fileName, config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.cts"],"sourcesContent":["const path = require('path');\
|
|
1
|
+
{"version":3,"sources":["transformSync.cts"],"sourcesContent":["const path = require('path');\nlet swc: string;\ntry {\n swc = require('@swc/core');\n} catch (_) {\n require('../lib/installBindings.cjs');\n swc = require('@swc/core');\n}\nconst ts = require('typescript');\nconst swcTranspiler = require('ts-node/transpilers/swc');\n\nmodule.exports = function transformSync(contents, fileName, config) {\n const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(config.path));\n const transpile = swcTranspiler.create({ swc: swc, service: { config: { options: parsed.options } } });\n const res = transpile.transpile(contents, { fileName: fileName });\n return { code: res.outputText, map: res.sourceMapText };\n};\n"],"names":["path","require","swc","_","ts","swcTranspiler","module","exports","transformSync","contents","fileName","config","parsed","parseJsonConfigFileContent","sys","dirname","transpile","create","service","options","res","code","outputText","map","sourceMapText"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAIC;AACJ,IAAI;IACFA,MAAMD,QAAQ;AAChB,EAAE,OAAOE,GAAG;IACVF,QAAQ;IACRC,MAAMD,QAAQ;AAChB;AACA,IAAMG,KAAKH,QAAQ;AACnB,IAAMI,gBAAgBJ,QAAQ;AAE9BK,OAAOC,OAAO,GAAG,SAASC,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAChE,IAAMC,SAASR,GAAGS,0BAA0B,CAACF,OAAOA,MAAM,EAAEP,GAAGU,GAAG,EAAEd,KAAKe,OAAO,CAACJ,OAAOX,IAAI;IAC5F,IAAMgB,YAAYX,cAAcY,MAAM,CAAC;QAAEf,KAAKA;QAAKgB,SAAS;YAAEP,QAAQ;gBAAEQ,SAASP,OAAOO,OAAO;YAAC;QAAE;IAAE;IACpG,IAAMC,MAAMJ,UAAUA,SAAS,CAACP,UAAU;QAAEC,UAAUA;IAAS;IAC/D,OAAO;QAAEW,MAAMD,IAAIE,UAAU;QAAEC,KAAKH,IAAII,aAAa;IAAC;AACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["extensions.ts"],"sourcesContent":["export default ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts', '.json', '.es6', '.es'];\n"],"names":[],"mappings":"AAAA,eAAe;IAAC;IAAO;IAAQ;IAAQ;IAAQ;IAAO;IAAQ;IAAQ;IAAQ;IAAS;IAAQ;CAAM,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export * from './types.mjs';
|
|
1
2
|
export { default as createMatcher } from './createMatcher.mjs';
|
|
3
|
+
export { default as extensions } from './extensions.mjs';
|
|
4
|
+
export { default as resolveFileSync } from './resolveFileSync.mjs';
|
|
2
5
|
export { default as transformFile } from './transformFile.mjs';
|
|
3
6
|
export { default as transformDirectory } from './transformDirectory.mjs';
|
|
4
7
|
export { default as transformSync } from './transformSync.mjs';
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export { default as createMatcher } from './createMatcher.js';\nexport { default as transformFile } from './transformFile.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\n"],"names":["default","createMatcher","transformFile","transformDirectory","transformSync"],"mappings":"AAAA,SAASA,WAAWC,aAAa,QAAQ,qBAAqB;AAC9D,SAASD,WAAWE,aAAa,QAAQ,qBAAqB;AAC9D,
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './types.js';\nexport { default as createMatcher } from './createMatcher.js';\nexport { default as extensions } from './extensions.js';\nexport { default as resolveFileSync } from './resolveFileSync.js';\nexport { default as transformFile } from './transformFile.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\n"],"names":["default","createMatcher","extensions","resolveFileSync","transformFile","transformDirectory","transformSync"],"mappings":"AAAA,cAAc,aAAa;AAC3B,SAASA,WAAWC,aAAa,QAAQ,qBAAqB;AAC9D,SAASD,WAAWE,UAAU,QAAQ,kBAAkB;AACxD,SAASF,WAAWG,eAAe,QAAQ,uBAAuB;AAClE,SAASH,WAAWI,aAAa,QAAQ,qBAAqB;AAC9D,SAASJ,WAAWK,kBAAkB,QAAQ,0BAA0B;AACxE,SAASL,WAAWM,aAAa,QAAQ,qBAAqB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["existsSync.cts"],"sourcesContent":["const accessSync = require('fs-access-sync-compat');\n\nmodule.exports = function existsSync(path) {\n try {\n accessSync(path);\n return true;\n } catch (_) {\n return false;\n }\n};\n"],"names":["accessSync","require","module","exports","existsSync","path","_"],"mappings":"AAAA,MAAMA,aAAaC,QAAQ;AAE3BC,OAAOC,OAAO,GAAG,SAASC,WAAWC,IAAI;IACvC,IAAI;QACFL,WAAWK;QACX,OAAO;IACT,EAAE,OAAOC,GAAG;QACV,OAAO;IACT;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const existsSync = require('./existsSync.cjs');
|
|
3
|
+
const lazy = require('../lazy.cjs');
|
|
4
|
+
const major = +process.versions.node.split('.')[0];
|
|
5
|
+
const version = major >= 14 ? 'local' : 'lts';
|
|
6
|
+
const worker = path.resolve(path.dirname(__dirname), 'workers', `installBinding${path.extname(__filename)}`);
|
|
7
|
+
const call = lazy('node-version-call');
|
|
8
|
+
const installDir = path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json'))));
|
|
9
|
+
const { optionalDependencies } = require('@swc/core/package.json');
|
|
10
|
+
const depKey = `${process.platform}-${process.arch}`;
|
|
11
|
+
for(const key in optionalDependencies){
|
|
12
|
+
const depPath = path.join(installDir, key);
|
|
13
|
+
if (key.indexOf(depKey) < 0 || existsSync(depPath)) continue;
|
|
14
|
+
try {
|
|
15
|
+
call()({
|
|
16
|
+
version,
|
|
17
|
+
callbacks: true
|
|
18
|
+
}, worker, key, optionalDependencies[key]);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.log(`Failed to install ${key}@${optionalDependencies[key]}. Error: ${err.message}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["installBindings.cts"],"sourcesContent":["const path = require('path');\nconst existsSync = require('./existsSync.cjs');\nconst lazy = require('../lazy.cjs');\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst worker = path.resolve(path.dirname(__dirname), 'workers', `installBinding${path.extname(__filename)}`);\nconst call = lazy('node-version-call');\n\nconst installDir = path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json'))));\nconst { optionalDependencies } = require('@swc/core/package.json');\nconst depKey = `${process.platform}-${process.arch}`;\n\nfor (const key in optionalDependencies) {\n const depPath = path.join(installDir, key);\n if (key.indexOf(depKey) < 0 || existsSync(depPath)) continue;\n\n try {\n call()({ version, callbacks: true }, worker, key, optionalDependencies[key]);\n } catch (err) {\n console.log(`Failed to install ${key}@${optionalDependencies[key]}. Error: ${err.message}`);\n }\n}\n"],"names":["path","require","existsSync","lazy","major","process","versions","node","split","version","worker","resolve","dirname","__dirname","extname","__filename","call","installDir","optionalDependencies","depKey","platform","arch","key","depPath","join","indexOf","callbacks","err","console","log","message"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,MAAMC,aAAaD,QAAQ;AAC3B,MAAME,OAAOF,QAAQ;AAErB,MAAMG,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,SAAS,KAAK,UAAU;AACxC,MAAMM,SAASV,KAAKW,OAAO,CAACX,KAAKY,OAAO,CAACC,YAAY,WAAW,CAAC,cAAc,EAAEb,KAAKc,OAAO,CAACC,aAAa;AAC3G,MAAMC,OAAOb,KAAK;AAElB,MAAMc,aAAajB,KAAKY,OAAO,CAACZ,KAAKY,OAAO,CAACZ,KAAKY,OAAO,CAACX,QAAQU,OAAO,CAAC;AAC1E,MAAM,EAAEO,oBAAoB,EAAE,GAAGjB,QAAQ;AACzC,MAAMkB,SAAS,GAAGd,QAAQe,QAAQ,CAAC,CAAC,EAAEf,QAAQgB,IAAI,EAAE;AAEpD,IAAK,MAAMC,OAAOJ,qBAAsB;IACtC,MAAMK,UAAUvB,KAAKwB,IAAI,CAACP,YAAYK;IACtC,IAAIA,IAAIG,OAAO,CAACN,UAAU,KAAKjB,WAAWqB,UAAU;IAEpD,IAAI;QACFP,OAAO;YAAEP;YAASiB,WAAW;QAAK,GAAGhB,QAAQY,KAAKJ,oBAAoB,CAACI,IAAI;IAC7E,EAAE,OAAOK,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,kBAAkB,EAAEP,IAAI,CAAC,EAAEJ,oBAAoB,CAACI,IAAI,CAAC,SAAS,EAAEK,IAAIG,OAAO,EAAE;IAC5F;AACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import isAbsolute from 'is-absolute';
|
|
5
|
+
import resolve from 'resolve';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import process from './process.cjs';
|
|
8
|
+
const moduleRegEx = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
|
|
9
|
+
function getParentPath(context) {
|
|
10
|
+
if (context.parentPath) return path.dirname(context.parentPath);
|
|
11
|
+
return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
|
|
12
|
+
}
|
|
13
|
+
export default function toPath(specifier, context) {
|
|
14
|
+
if (specifier.startsWith('file:')) return url.parse(specifier).pathname;
|
|
15
|
+
if (isAbsolute(specifier)) return specifier;
|
|
16
|
+
if (specifier[0] === '.') {
|
|
17
|
+
const parentPath = context ? getParentPath(context) : process.cwd();
|
|
18
|
+
return path.resolve(parentPath, specifier);
|
|
19
|
+
}
|
|
20
|
+
if (moduleRegEx.test(specifier)) {
|
|
21
|
+
const parentPath = context ? getParentPath(context) : process.cwd();
|
|
22
|
+
let pkg = null;
|
|
23
|
+
const main = resolve.sync(specifier, {
|
|
24
|
+
basedir: parentPath,
|
|
25
|
+
extensions: [
|
|
26
|
+
'.js',
|
|
27
|
+
'.json',
|
|
28
|
+
'.node',
|
|
29
|
+
'.mjs'
|
|
30
|
+
],
|
|
31
|
+
packageFilter (json, dir) {
|
|
32
|
+
pkg = {
|
|
33
|
+
json,
|
|
34
|
+
dir
|
|
35
|
+
};
|
|
36
|
+
return json;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!pkg || !pkg.json.module) return main; // no modules, use main
|
|
40
|
+
if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module
|
|
41
|
+
// a relative path. Only accept if it doesn't break the relative naming and it exists
|
|
42
|
+
const modulePath = path.resolve(pkg.dir, pkg.json.module);
|
|
43
|
+
const mainPath = path.resolve(pkg.dir, pkg.json.main);
|
|
44
|
+
const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));
|
|
45
|
+
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !fs.existsSync(moduleResolved) ? main : moduleResolved;
|
|
46
|
+
}
|
|
47
|
+
return specifier;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport type { Context } from '../types';\n// @ts-ignore\nimport process from './process.cjs';\n\nconst moduleRegEx = /^[^.\\/]|^\\.[^.\\/]|^\\.\\.[^\\/]/;\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 url.parse(specifier).pathname;\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","url","isAbsolute","resolve","process","moduleRegEx","getParentPath","context","parentPath","dirname","parentURL","toPath","cwd","specifier","startsWith","parse","pathname","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,OAAOC,SAAS,MAAM;AACtB,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,aAAa,UAAU;AAE9B,aAAa;AACb,OAAOC,aAAa,gBAAgB;AAEpC,MAAMC,cAAc;AAEpB,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOR,KAAKS,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGV,KAAKS,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKN,QAAQQ,GAAG;AAClF;AAEA,eAAe,SAASD,OAAOE,SAAiB,EAAEN,OAAiB;IACjE,IAAIM,UAAUC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+1,28 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import extensions from './extensions.mjs';
|
|
4
|
+
import toPath from './lib/toPath.mjs';
|
|
5
|
+
const moduleRegEx = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
|
|
6
|
+
const typeFileRegEx = /^[^.]+\.d\.[cm]?ts$/;
|
|
7
|
+
const indexExtensions = extensions.map((x)=>`index${x}`);
|
|
8
|
+
export default function resolveFileSync(specifier, context) {
|
|
9
|
+
const filePath = toPath(specifier, context);
|
|
10
|
+
const ext = path.extname(filePath);
|
|
11
|
+
let stats;
|
|
12
|
+
try {
|
|
13
|
+
stats = fs.statSync(filePath);
|
|
14
|
+
} catch (_err) {}
|
|
15
|
+
// directory
|
|
16
|
+
if (stats?.isDirectory() || specifier.endsWith('/')) {
|
|
17
|
+
const items = fs.readdirSync(filePath);
|
|
18
|
+
const item = items.find((x)=>indexExtensions.indexOf(x) >= 0);
|
|
19
|
+
if (item) return path.join(filePath, item);
|
|
20
|
+
} else if (!ext && !stats || !moduleRegEx.test(specifier)) {
|
|
21
|
+
const fileName = path.basename(filePath).replace(/(\.[^/.]+)+$/, '');
|
|
22
|
+
const items = fs.readdirSync(path.dirname(filePath));
|
|
23
|
+
const item = items.find((x)=>x.startsWith(fileName) && !typeFileRegEx.test(x) && extensions.indexOf(path.extname(x)) >= 0);
|
|
24
|
+
if (item) return path.join(path.dirname(filePath), item);
|
|
25
|
+
}
|
|
26
|
+
// return what was found
|
|
27
|
+
return stats ? filePath : null;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport extensions from './extensions.js';\nimport toPath from './lib/toPath.js';\n\nimport type { Context } from './types';\n\nconst moduleRegEx = /^[^.\\/]|^\\.[^.\\/]|^\\.\\.[^\\/]/;\nconst typeFileRegEx = /^[^.]+\\.d\\.[cm]?ts$/;\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n const ext = path.extname(filePath);\n\n let stats: fs.Stats | undefined;\n try {\n stats = fs.statSync(filePath);\n } catch (_err) {}\n\n // directory\n if (stats?.isDirectory() || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n }\n\n // look up the extension\n else if ((!ext && !stats) || !moduleRegEx.test(specifier)) {\n const fileName = path.basename(filePath).replace(/(\\.[^/.]+)+$/, '');\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => x.startsWith(fileName) && !typeFileRegEx.test(x) && extensions.indexOf(path.extname(x)) >= 0);\n if (item) return path.join(path.dirname(filePath), item);\n }\n\n // return what was found\n return stats ? filePath : null;\n}\n"],"names":["fs","path","extensions","toPath","moduleRegEx","typeFileRegEx","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","ext","extname","stats","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","join","test","fileName","basename","replace","dirname","startsWith"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,gBAAgB,kBAAkB;AACzC,OAAOC,YAAY,kBAAkB;AAIrC,MAAMC,cAAc;AACpB,MAAMC,gBAAgB;AACtB,MAAMC,kBAAkBJ,WAAWK,GAAG,CAAC,CAACC,IAAM,CAAC,KAAK,EAAEA,GAAG;AAEzD,eAAe,SAASC,gBAAgBC,SAAiB,EAAEC,OAAiB;IAC1E,MAAMC,WAAWT,OAAOO,WAAWC;IACnC,MAAME,MAAMZ,KAAKa,OAAO,CAACF;IAEzB,IAAIG;IACJ,IAAI;QACFA,QAAQf,GAAGgB,QAAQ,CAACJ;IACtB,EAAE,OAAOK,MAAM,CAAC;IAEhB,YAAY;IACZ,IAAIF,OAAOG,iBAAiBR,UAAUS,QAAQ,CAAC,MAAM;QACnD,MAAMC,QAAQpB,GAAGqB,WAAW,CAACT;QAC7B,MAAMU,OAAOF,MAAMG,IAAI,CAAC,CAACf,IAAMF,gBAAgBkB,OAAO,CAAChB,MAAM;QAC7D,IAAIc,MAAM,OAAOrB,KAAKwB,IAAI,CAACb,UAAUU;IACvC,OAGK,IAAI,AAAC,CAACT,OAAO,CAACE,SAAU,CAACX,YAAYsB,IAAI,CAAChB,YAAY;QACzD,MAAMiB,WAAW1B,KAAK2B,QAAQ,CAAChB,UAAUiB,OAAO,CAAC,gBAAgB;QACjE,MAAMT,QAAQpB,GAAGqB,WAAW,CAACpB,KAAK6B,OAAO,CAAClB;QAC1C,MAAMU,OAAOF,MAAMG,IAAI,CAAC,CAACf,IAAMA,EAAEuB,UAAU,CAACJ,aAAa,CAACtB,cAAcqB,IAAI,CAAClB,MAAMN,WAAWsB,OAAO,CAACvB,KAAKa,OAAO,CAACN,OAAO;QAC1H,IAAIc,MAAM,OAAOrB,KAAKwB,IAAI,CAACxB,KAAK6B,OAAO,CAAClB,WAAWU;IACrD;IAEA,wBAAwB;IACxB,OAAOP,QAAQH,WAAW;AAC5B"}
|
|
@@ -14,11 +14,11 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
14
14
|
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
15
15
|
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
16
16
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
17
|
-
const
|
|
18
|
-
const matcher = createMatcher(
|
|
17
|
+
const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);
|
|
18
|
+
const matcher = createMatcher(tsconfig);
|
|
19
19
|
options = {
|
|
20
20
|
...options,
|
|
21
|
-
|
|
21
|
+
tsconfig
|
|
22
22
|
};
|
|
23
23
|
const iterator = new Iterator(src);
|
|
24
24
|
iterator.forEach((entry, cb)=>{
|
|
@@ -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\n// @ts-ignore\nimport createMatcher from './createMatcher.ts';\n// @ts-ignore\nimport transformFile from './transformFile.ts';\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
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\n// @ts-ignore\nimport createMatcher from './createMatcher.ts';\n// @ts-ignore\nimport transformFile from './transformFile.ts';\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,aAAa;AACb,OAAOC,mBAAmB,qBAAqB;AAC/C,aAAa;AACb,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"}
|
|
@@ -64,23 +64,23 @@ function transformFileCallback(src, dest, type, options, callback) {
|
|
|
64
64
|
if (err) return callback(err);
|
|
65
65
|
callback = once(callback);
|
|
66
66
|
try {
|
|
67
|
-
let
|
|
67
|
+
let tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);
|
|
68
68
|
// overrides for cjs
|
|
69
69
|
if (type === 'cjs') {
|
|
70
|
-
|
|
71
|
-
...
|
|
70
|
+
tsconfig = {
|
|
71
|
+
...tsconfig
|
|
72
72
|
};
|
|
73
|
-
|
|
74
|
-
...
|
|
73
|
+
tsconfig.tsconfig = {
|
|
74
|
+
...tsconfig.config || {}
|
|
75
75
|
};
|
|
76
|
-
|
|
77
|
-
...
|
|
76
|
+
tsconfig.config.compilerOptions = {
|
|
77
|
+
...tsconfig.config.compilerOptions || {}
|
|
78
78
|
};
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
tsconfig.config.compilerOptions.module = 'CommonJS';
|
|
80
|
+
tsconfig.config.compilerOptions.target = 'ES5';
|
|
81
81
|
}
|
|
82
82
|
const basename = path.basename(src);
|
|
83
|
-
const output = transformSync(contents, basename,
|
|
83
|
+
const output = transformSync(contents, basename, tsconfig);
|
|
84
84
|
// infer extension and patch .mjs imports
|
|
85
85
|
let ext = path.extname(basename);
|
|
86
86
|
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\n// @ts-ignore\nimport transformSync from './transformSync.ts';\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
|
|
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\n// @ts-ignore\nimport transformSync from './transformSync.ts';\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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AEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACtE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,sBAAsBC,KAAKC,MAAMC,MAAMC,SAASC;IAC3F,OAAO,IAAI0B,QAAQ,CAACC,SAASC;QAC3BjC,sBAAsBC,KAAKC,MAAMC,MAAMC,SAAS,SAAS8B,gBAAgB1B,GAAG,EAAE2B,MAAM;YAClF3B,MAAMyB,OAAOzB,OAAOwB,QAAQG;QAC9B;IACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import url from 'url';
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
import lazy from './lazy.cjs';
|
|
4
|
+
import lazy from './lib/lazy.cjs';
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import process from './process.cjs';
|
|
6
|
+
import process from './lib/process.cjs';
|
|
7
7
|
const major = +process.versions.node.split('.')[0];
|
|
8
8
|
const version = major >= 14 ? 'local' : 'lts';
|
|
9
9
|
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// @ts-ignore\nimport lazy from './lazy.
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// @ts-ignore\nimport lazy from './lib/lazy.cjs';\n// @ts-ignore\nimport process from './lib/process.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","lazy","process","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;AACtB,aAAa;AACb,OAAOC,UAAU,iBAAiB;AAClC,aAAa;AACb,OAAOC,aAAa,oBAAoB;AAExC,MAAMC,QAAQ,CAACD,QAAQE,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,OAAOd,KAAK;AAElB;;;;CAIC,GACD,eAAe,SAASe,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAOR,SAASI,QAAQM,UAAUC,UAAUC;AACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["export interface Context {\n parentURL?: string;\n parentPath?: string;\n}\n"],"names":[],"mappings":"AAAA,WAGC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { tmpdir } = require('os');
|
|
4
|
+
const tempSuffix = require('temp-suffix');
|
|
5
|
+
const mkdirp = require('mkdirp');
|
|
6
|
+
const Queue = require('queue-cb');
|
|
7
|
+
const spawn = require('cross-spawn-cb');
|
|
8
|
+
const once = require('call-once-fn');
|
|
9
|
+
module.exports = function installBindings(name, version, callback) {
|
|
10
|
+
callback = once(callback);
|
|
11
|
+
try {
|
|
12
|
+
const tmp = path.join(tmpdir(), 'ts-swc-transform', tempSuffix());
|
|
13
|
+
const source = path.join.apply(null, [
|
|
14
|
+
tmp,
|
|
15
|
+
'node_modules',
|
|
16
|
+
...name.split('/')
|
|
17
|
+
]);
|
|
18
|
+
const dest = path.join.apply(null, [
|
|
19
|
+
path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json')))),
|
|
20
|
+
...name.split('/')
|
|
21
|
+
]);
|
|
22
|
+
const queue = new Queue(1);
|
|
23
|
+
queue.defer(mkdirp.bind(null, tmp));
|
|
24
|
+
queue.defer(fs.writeFile.bind(null, path.join(tmp, 'package.json'), '{}', 'utf8'));
|
|
25
|
+
queue.defer((cb)=>{
|
|
26
|
+
// remove NODE_OPTIONS from ts-dev-stack
|
|
27
|
+
// biome-ignore lint/performance/noDelete: <explanation>
|
|
28
|
+
delete process.env.NODE_OPTIONS;
|
|
29
|
+
spawn('npm', [
|
|
30
|
+
'install',
|
|
31
|
+
`${name}@${version}`
|
|
32
|
+
], {
|
|
33
|
+
cwd: tmp
|
|
34
|
+
}, cb);
|
|
35
|
+
});
|
|
36
|
+
queue.defer(fs.rename.bind(null, source, dest));
|
|
37
|
+
queue.await((err)=>{
|
|
38
|
+
fs.rm(tmp, {
|
|
39
|
+
recursive: true,
|
|
40
|
+
force: true
|
|
41
|
+
}, ()=>callback(err));
|
|
42
|
+
});
|
|
43
|
+
} catch (err) {
|
|
44
|
+
return callback(err);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["installBinding.cts"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst { tmpdir } = require('os');\nconst tempSuffix = require('temp-suffix');\nconst mkdirp = require('mkdirp');\n\nconst Queue = require('queue-cb');\nconst spawn = require('cross-spawn-cb');\nconst once = require('call-once-fn');\n\nmodule.exports = function installBindings(name, version, callback) {\n callback = once(callback);\n try {\n const tmp = path.join(tmpdir(), 'ts-swc-transform', tempSuffix());\n const source = path.join.apply(null, [tmp, 'node_modules', ...name.split('/')]);\n const dest = path.join.apply(null, [path.dirname(path.dirname(path.dirname(require.resolve('@swc/core/package.json')))), ...name.split('/')]);\n\n const queue = new Queue(1);\n queue.defer(mkdirp.bind(null, tmp));\n queue.defer(fs.writeFile.bind(null, path.join(tmp, 'package.json'), '{}', 'utf8'));\n queue.defer((cb) => {\n // remove NODE_OPTIONS from ts-dev-stack\n // biome-ignore lint/performance/noDelete: <explanation>\n delete process.env.NODE_OPTIONS;\n spawn('npm', ['install', `${name}@${version}`], { cwd: tmp }, cb);\n });\n queue.defer(fs.rename.bind(null, source, dest));\n queue.await((err) => {\n fs.rm(tmp, { recursive: true, force: true }, () => callback(err));\n });\n } catch (err) {\n return callback(err);\n }\n};\n"],"names":["path","require","fs","tmpdir","tempSuffix","mkdirp","Queue","spawn","once","module","exports","installBindings","name","version","callback","tmp","join","source","apply","split","dest","dirname","resolve","queue","defer","bind","writeFile","cb","process","env","NODE_OPTIONS","cwd","rename","await","err","rm","recursive","force"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,MAAMC,KAAKD,QAAQ;AACnB,MAAM,EAAEE,MAAM,EAAE,GAAGF,QAAQ;AAC3B,MAAMG,aAAaH,QAAQ;AAC3B,MAAMI,SAASJ,QAAQ;AAEvB,MAAMK,QAAQL,QAAQ;AACtB,MAAMM,QAAQN,QAAQ;AACtB,MAAMO,OAAOP,QAAQ;AAErBQ,OAAOC,OAAO,GAAG,SAASC,gBAAgBC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC/DA,WAAWN,KAAKM;IAChB,IAAI;QACF,MAAMC,MAAMf,KAAKgB,IAAI,CAACb,UAAU,oBAAoBC;QACpD,MAAMa,SAASjB,KAAKgB,IAAI,CAACE,KAAK,CAAC,MAAM;YAACH;YAAK;eAAmBH,KAAKO,KAAK,CAAC;SAAK;QAC9E,MAAMC,OAAOpB,KAAKgB,IAAI,CAACE,KAAK,CAAC,MAAM;YAAClB,KAAKqB,OAAO,CAACrB,KAAKqB,OAAO,CAACrB,KAAKqB,OAAO,CAACpB,QAAQqB,OAAO,CAAC;eAAiCV,KAAKO,KAAK,CAAC;SAAK;QAE5I,MAAMI,QAAQ,IAAIjB,MAAM;QACxBiB,MAAMC,KAAK,CAACnB,OAAOoB,IAAI,CAAC,MAAMV;QAC9BQ,MAAMC,KAAK,CAACtB,GAAGwB,SAAS,CAACD,IAAI,CAAC,MAAMzB,KAAKgB,IAAI,CAACD,KAAK,iBAAiB,MAAM;QAC1EQ,MAAMC,KAAK,CAAC,CAACG;YACX,wCAAwC;YACxC,wDAAwD;YACxD,OAAOC,QAAQC,GAAG,CAACC,YAAY;YAC/BvB,MAAM,OAAO;gBAAC;gBAAW,GAAGK,KAAK,CAAC,EAAEC,SAAS;aAAC,EAAE;gBAAEkB,KAAKhB;YAAI,GAAGY;QAChE;QACAJ,MAAMC,KAAK,CAACtB,GAAG8B,MAAM,CAACP,IAAI,CAAC,MAAMR,QAAQG;QACzCG,MAAMU,KAAK,CAAC,CAACC;YACXhC,GAAGiC,EAAE,CAACpB,KAAK;gBAAEqB,WAAW;gBAAMC,OAAO;YAAK,GAAG,IAAMvB,SAASoB;QAC9D;IACF,EAAE,OAAOA,KAAK;QACZ,OAAOpB,SAASoB;IAClB;AACF"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
|
|
2
|
+
let swc;
|
|
3
|
+
try {
|
|
4
|
+
swc = require('@swc/core');
|
|
5
|
+
} catch (_) {
|
|
6
|
+
require('../lib/installBindings.cjs');
|
|
7
|
+
swc = require('@swc/core');
|
|
8
|
+
}
|
|
3
9
|
const ts = require('typescript');
|
|
4
10
|
const swcTranspiler = require('ts-node/transpilers/swc');
|
|
5
11
|
module.exports = function transformSync(contents, fileName, config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.cts"],"sourcesContent":["const path = require('path');\
|
|
1
|
+
{"version":3,"sources":["transformSync.cts"],"sourcesContent":["const path = require('path');\nlet swc: string;\ntry {\n swc = require('@swc/core');\n} catch (_) {\n require('../lib/installBindings.cjs');\n swc = require('@swc/core');\n}\nconst ts = require('typescript');\nconst swcTranspiler = require('ts-node/transpilers/swc');\n\nmodule.exports = function transformSync(contents, fileName, config) {\n const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(config.path));\n const transpile = swcTranspiler.create({ swc: swc, service: { config: { options: parsed.options } } });\n const res = transpile.transpile(contents, { fileName: fileName });\n return { code: res.outputText, map: res.sourceMapText };\n};\n"],"names":["path","require","swc","_","ts","swcTranspiler","module","exports","transformSync","contents","fileName","config","parsed","parseJsonConfigFileContent","sys","dirname","transpile","create","service","options","res","code","outputText","map","sourceMapText"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,IAAIC;AACJ,IAAI;IACFA,MAAMD,QAAQ;AAChB,EAAE,OAAOE,GAAG;IACVF,QAAQ;IACRC,MAAMD,QAAQ;AAChB;AACA,MAAMG,KAAKH,QAAQ;AACnB,MAAMI,gBAAgBJ,QAAQ;AAE9BK,OAAOC,OAAO,GAAG,SAASC,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAChE,MAAMC,SAASR,GAAGS,0BAA0B,CAACF,OAAOA,MAAM,EAAEP,GAAGU,GAAG,EAAEd,KAAKe,OAAO,CAACJ,OAAOX,IAAI;IAC5F,MAAMgB,YAAYX,cAAcY,MAAM,CAAC;QAAEf,KAAKA;QAAKgB,SAAS;YAAEP,QAAQ;gBAAEQ,SAASP,OAAOO,OAAO;YAAC;QAAE;IAAE;IACpG,MAAMC,MAAMJ,UAAUA,SAAS,CAACP,UAAU;QAAEC,UAAUA;IAAS;IAC/D,OAAO;QAAEW,MAAMD,IAAIE,UAAU;QAAEC,KAAKH,IAAII,aAAa;IAAC;AACxD"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export * from './types.js';
|
|
1
2
|
export { default as createMatcher } from './createMatcher.js';
|
|
3
|
+
export { default as extensions } from './extensions.js';
|
|
4
|
+
export { default as resolveFileSync } from './resolveFileSync.js';
|
|
2
5
|
export { default as transformFile } from './transformFile.js';
|
|
3
6
|
export { default as transformDirectory } from './transformDirectory.js';
|
|
4
7
|
export { default as transformSync } from './transformSync.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -43,22 +43,27 @@
|
|
|
43
43
|
"depcheck": "depcheck",
|
|
44
44
|
"deploy": "tsds deploy",
|
|
45
45
|
"format": "biome check --write --unsafe src/ test/",
|
|
46
|
-
"test": "tsds test:node --
|
|
46
|
+
"test": "tsds test:node --no-timeouts",
|
|
47
47
|
"test:engines": "nvu engines npm test",
|
|
48
48
|
"version": "tsds version"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@swc/core": "*",
|
|
52
52
|
"call-once-fn": "^1.0.1",
|
|
53
|
+
"cross-spawn-cb": "^1.1.2",
|
|
53
54
|
"exit": "^0.1.2",
|
|
55
|
+
"fs-access-sync-compat": "^1.0.2",
|
|
54
56
|
"fs-iterator": "^5.1.1",
|
|
55
|
-
"get-tsconfig-compat": "^1.1.
|
|
57
|
+
"get-tsconfig-compat": "^1.1.1",
|
|
58
|
+
"is-absolute": "^1.0.0",
|
|
56
59
|
"lazy-cache": "^2.0.2",
|
|
57
60
|
"minimatch": "^3.1.2",
|
|
58
61
|
"mkdirp": "^0.5.6",
|
|
59
|
-
"node-version-call": "^1.1.
|
|
62
|
+
"node-version-call": "^1.1.1",
|
|
60
63
|
"path-posix": "^1.0.0",
|
|
61
|
-
"queue-cb": "^1.2
|
|
64
|
+
"queue-cb": "^1.4.2",
|
|
65
|
+
"resolve": "^1.22.9",
|
|
66
|
+
"temp-suffix": "^0.1.1",
|
|
62
67
|
"ts-node": "*",
|
|
63
68
|
"typescript": "*",
|
|
64
69
|
"unixify": "^1.0.0"
|
|
@@ -67,11 +72,10 @@
|
|
|
67
72
|
"@biomejs/biome": "^1.9.4",
|
|
68
73
|
"@swc/core": "^1.9.3",
|
|
69
74
|
"@types/mocha": "^10.0.10",
|
|
70
|
-
"@types/node": "^22.10.
|
|
75
|
+
"@types/node": "^22.10.2",
|
|
71
76
|
"core-js": "^3.39.0",
|
|
72
77
|
"cr": "^0.1.0",
|
|
73
|
-
"
|
|
74
|
-
"react": "^19.0.0",
|
|
78
|
+
"react": "^18.3.1",
|
|
75
79
|
"rimraf2": "^2.8.2",
|
|
76
80
|
"ts-dev-stack": "^1.2.1",
|
|
77
81
|
"ts-node": "^10.8.2",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|