ts-swc-transform 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cjs/transformDirectory.js +59 -0
- package/dist/cjs/cjs/transformDirectory.js.map +1 -0
- package/dist/cjs/cjs/transformFile.js +59 -0
- package/dist/cjs/cjs/transformFile.js.map +1 -0
- package/dist/cjs/{transformSync.js → cjs/transformSync.js} +6 -7
- package/dist/cjs/cjs/transformSync.js.map +1 -0
- package/dist/cjs/esm/transformDirectory.js +49 -0
- package/dist/cjs/esm/transformDirectory.js.map +1 -0
- package/dist/cjs/esm/transformFile.js +49 -0
- package/dist/cjs/esm/transformFile.js.map +1 -0
- package/dist/cjs/esm/transformSync.js +17 -0
- package/dist/cjs/esm/transformSync.js.map +1 -0
- package/dist/cjs/index.cjs.js +46 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/existsSync.js +5 -4
- package/dist/cjs/lib/existsSync.js.map +1 -1
- package/dist/cjs/lib/install-module/index.js +40 -0
- package/dist/cjs/lib/install-module/index.js.map +1 -0
- package/dist/cjs/lib/install-module/lib/ensureCached.js +114 -0
- package/dist/cjs/lib/install-module/lib/ensureCached.js.map +1 -0
- package/dist/cjs/lib/install-module/lib/parseInstallString.js +48 -0
- package/dist/cjs/lib/install-module/lib/parseInstallString.js.map +1 -0
- package/dist/cjs/lib/installBindings.js +3 -80
- package/dist/cjs/lib/installBindings.js.map +1 -1
- package/dist/cjs/lib/loadSWC.js +9 -2
- package/dist/cjs/lib/loadSWC.js.map +1 -1
- package/dist/cjs/{transformDirectory.js → workers/transformDirectory.js} +21 -41
- package/dist/cjs/workers/transformDirectory.js.map +1 -0
- package/dist/cjs/{transformFile.js → workers/transformFile.js} +25 -51
- package/dist/cjs/workers/transformFile.js.map +1 -0
- package/dist/cjs/workers/transformSync.js +6 -4
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/esm/{transformDirectory.mjs → cjs/transformDirectory.mjs} +20 -26
- package/dist/esm/cjs/transformDirectory.mjs.map +1 -0
- package/dist/esm/cjs/transformFile.mjs +44 -0
- package/dist/esm/cjs/transformFile.mjs.map +1 -0
- package/dist/esm/{transformSync.mjs → cjs/transformSync.mjs} +6 -8
- package/dist/esm/cjs/transformSync.mjs.map +1 -0
- package/dist/esm/esm/transformDirectory.mjs +34 -0
- package/dist/esm/esm/transformDirectory.mjs.map +1 -0
- package/dist/esm/esm/transformFile.mjs +34 -0
- package/dist/esm/esm/transformFile.mjs.map +1 -0
- package/dist/esm/esm/transformSync.mjs +1 -0
- package/dist/esm/esm/transformSync.mjs.map +1 -0
- package/dist/esm/index.cjs.mjs +7 -0
- package/dist/esm/index.cjs.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/existsSync.mjs +4 -3
- package/dist/esm/lib/existsSync.mjs.map +1 -1
- package/dist/esm/lib/install-module/index.mjs +24 -0
- package/dist/esm/lib/install-module/index.mjs.map +1 -0
- package/dist/esm/lib/install-module/lib/ensureCached.mjs +37 -0
- package/dist/esm/lib/install-module/lib/ensureCached.mjs.map +1 -0
- package/dist/esm/lib/install-module/lib/parseInstallString.mjs +13 -0
- package/dist/esm/lib/install-module/lib/parseInstallString.mjs.map +1 -0
- package/dist/esm/lib/installBindings.mjs +4 -44
- package/dist/esm/lib/installBindings.mjs.map +1 -1
- package/dist/esm/lib/loadSWC.mjs +9 -2
- package/dist/esm/lib/loadSWC.mjs.map +1 -1
- package/dist/esm/workers/transformDirectory.mjs +28 -0
- package/dist/esm/workers/transformDirectory.mjs.map +1 -0
- package/dist/esm/{transformFile.mjs → workers/transformFile.mjs} +22 -48
- package/dist/esm/workers/transformFile.mjs.map +1 -0
- package/dist/esm/workers/transformSync.mjs +6 -3
- package/dist/esm/workers/transformSync.mjs.map +1 -1
- package/dist/types/cjs/transformDirectory.d.ts +9 -0
- package/dist/types/cjs/transformFile.d.ts +9 -0
- package/dist/types/{transformSync.d.ts → cjs/transformSync.d.ts} +3 -1
- package/dist/types/esm/transformFile.d.ts +9 -0
- package/dist/types/esm/transformSync.d.ts +1 -0
- package/dist/types/index.cjs.d.ts +8 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/lib/existsSync.d.ts +3 -1
- package/dist/types/lib/install-module/index.d.ts +1 -0
- package/dist/types/lib/install-module/lib/ensureCached.d.ts +2 -0
- package/dist/types/lib/install-module/lib/parseInstallString.d.ts +4 -0
- package/dist/types/lib/loadSWC.d.ts +2 -1
- package/dist/types/workers/transformDirectory.d.ts +1 -0
- package/dist/types/workers/transformFile.d.ts +1 -0
- package/dist/types/workers/transformSync.d.ts +1 -1
- package/package.json +7 -6
- package/dist/cjs/transformDirectory.js.map +0 -1
- package/dist/cjs/transformFile.js.map +0 -1
- package/dist/cjs/transformSync.js.map +0 -1
- package/dist/esm/transformDirectory.mjs.map +0 -1
- package/dist/esm/transformFile.mjs.map +0 -1
- package/dist/esm/transformSync.mjs.map +0 -1
- package/dist/types/transformFile.d.ts +0 -9
- /package/dist/types/{transformDirectory.d.ts → esm/transformDirectory.d.ts} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
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 parseInstallString;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _array_like_to_array(arr, len) {
|
|
12
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
13
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
14
|
+
return arr2;
|
|
15
|
+
}
|
|
16
|
+
function _array_without_holes(arr) {
|
|
17
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
18
|
+
}
|
|
19
|
+
function _iterable_to_array(iter) {
|
|
20
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
21
|
+
}
|
|
22
|
+
function _non_iterable_spread() {
|
|
23
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
24
|
+
}
|
|
25
|
+
function _to_consumable_array(arr) {
|
|
26
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
27
|
+
}
|
|
28
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
29
|
+
if (!o) return;
|
|
30
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
31
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
32
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
33
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
34
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
35
|
+
}
|
|
36
|
+
function parseInstallString(installString) {
|
|
37
|
+
var installParts = installString.split('/');
|
|
38
|
+
var nameVersionParts = installParts.pop().split('@');
|
|
39
|
+
var version = nameVersionParts.length > 1 ? nameVersionParts.pop() : undefined;
|
|
40
|
+
var name = _to_consumable_array(installParts).concat([
|
|
41
|
+
nameVersionParts.join('@')
|
|
42
|
+
]).join('/');
|
|
43
|
+
return {
|
|
44
|
+
name: name,
|
|
45
|
+
version: version
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/* 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":["parseInstallString.ts"],"sourcesContent":["export default function parseInstallString(installString: string) {\n const installParts = installString.split('/');\n const nameVersionParts = installParts.pop().split('@');\n const version = nameVersionParts.length > 1 ? nameVersionParts.pop() : undefined;\n const name = [...installParts, nameVersionParts.join('@')].join('/');\n return {\n name,\n version,\n };\n}\n"],"names":["parseInstallString","installString","installParts","split","nameVersionParts","pop","version","length","undefined","name","join"],"mappings":";;;;+BAAA;;;eAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAASA,mBAAmBC,aAAqB;IAC9D,IAAMC,eAAeD,cAAcE,KAAK,CAAC;IACzC,IAAMC,mBAAmBF,aAAaG,GAAG,GAAGF,KAAK,CAAC;IAClD,IAAMG,UAAUF,iBAAiBG,MAAM,GAAG,IAAIH,iBAAiBC,GAAG,KAAKG;IACvE,IAAMC,OAAO,AAAC,qBAAGP,qBAAJ;QAAkBE,iBAAiBM,IAAI,CAAC;KAAK,EAACA,IAAI,CAAC;IAChE,OAAO;QACLD,MAAAA;QACAH,SAAAA;IACF;AACF"}
|
|
@@ -9,15 +9,10 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
-
var _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
13
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
-
var _crossspawncb = /*#__PURE__*/ _interop_require_default(require("cross-spawn-cb"));
|
|
15
|
-
var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
|
|
16
13
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
17
14
|
var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
|
|
18
|
-
var
|
|
19
|
-
var _tempsuffix = /*#__PURE__*/ _interop_require_default(require("temp-suffix"));
|
|
20
|
-
var _existsSync = /*#__PURE__*/ _interop_require_default(require("./existsSync.js"));
|
|
15
|
+
var _index = /*#__PURE__*/ _interop_require_default(require("./install-module/index.js"));
|
|
21
16
|
var _processcjs = /*#__PURE__*/ _interop_require_default(require("./process.js"));
|
|
22
17
|
function _array_like_to_array(arr, len) {
|
|
23
18
|
if (len == null || len > arr.length) len = arr.length;
|
|
@@ -38,33 +33,6 @@ function _iterable_to_array(iter) {
|
|
|
38
33
|
function _non_iterable_spread() {
|
|
39
34
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
40
35
|
}
|
|
41
|
-
function _object_without_properties(source, excluded) {
|
|
42
|
-
if (source == null) return {};
|
|
43
|
-
var target = _object_without_properties_loose(source, excluded);
|
|
44
|
-
var key, i;
|
|
45
|
-
if (Object.getOwnPropertySymbols) {
|
|
46
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
47
|
-
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
48
|
-
key = sourceSymbolKeys[i];
|
|
49
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
50
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
51
|
-
target[key] = source[key];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return target;
|
|
55
|
-
}
|
|
56
|
-
function _object_without_properties_loose(source, excluded) {
|
|
57
|
-
if (source == null) return {};
|
|
58
|
-
var target = {};
|
|
59
|
-
var sourceKeys = Object.keys(source);
|
|
60
|
-
var key, i;
|
|
61
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
62
|
-
key = sourceKeys[i];
|
|
63
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
64
|
-
target[key] = source[key];
|
|
65
|
-
}
|
|
66
|
-
return target;
|
|
67
|
-
}
|
|
68
36
|
function _to_consumable_array(arr) {
|
|
69
37
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
70
38
|
}
|
|
@@ -76,51 +44,15 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
76
44
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
77
45
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
78
46
|
}
|
|
79
|
-
var isWindows = _processcjs.default.platform === 'win32' || /^(msys|cygwin)$/.test(_processcjs.default.env.OSTYPE);
|
|
80
|
-
var symlinkType = isWindows ? 'junction' : 'dir';
|
|
81
|
-
var cache = _path.default.join(_os.default.tmpdir(), 'ts-swc-transform', 'cache');
|
|
82
|
-
function ensureCached(name, installString, cachedAt, callback) {
|
|
83
|
-
var _path1;
|
|
84
|
-
if ((0, _existsSync.default)(cachedAt)) return callback();
|
|
85
|
-
var tmp = "".concat(cachedAt, ".").concat((0, _tempsuffix.default)());
|
|
86
|
-
var installedAt = (_path1 = _path.default).join.apply(_path1, [
|
|
87
|
-
tmp,
|
|
88
|
-
'node_modules'
|
|
89
|
-
].concat(_to_consumable_array(name.split('/'))));
|
|
90
|
-
var _process_env = _processcjs.default.env, NODE_OPTIONS = _process_env.NODE_OPTIONS, env = _object_without_properties(_process_env, [
|
|
91
|
-
"NODE_OPTIONS"
|
|
92
|
-
]);
|
|
93
|
-
var queue = new _queuecb.default(1);
|
|
94
|
-
queue.defer(_mkdirpclassic.default.bind(null, tmp));
|
|
95
|
-
queue.defer(_fs.default.writeFile.bind(null, _path.default.join(tmp, 'package.json'), '{}', 'utf8'));
|
|
96
|
-
queue.defer(_crossspawncb.default.bind(null, 'npm', [
|
|
97
|
-
'install',
|
|
98
|
-
installString
|
|
99
|
-
], {
|
|
100
|
-
cwd: tmp,
|
|
101
|
-
env: env
|
|
102
|
-
}));
|
|
103
|
-
queue.defer(function(cb) {
|
|
104
|
-
return _fs.default.rename(installedAt, cachedAt, cb.bind(null, null));
|
|
105
|
-
});
|
|
106
|
-
queue.await(function() {
|
|
107
|
-
// clean up whether installed or not
|
|
108
|
-
(0, _rimraf2.default)(tmp, {
|
|
109
|
-
disableGlob: true
|
|
110
|
-
}, callback);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
47
|
function installBindings(callback) {
|
|
114
48
|
var swcPackagePath = _resolve.default.sync('@swc/core/package.json');
|
|
115
49
|
var swcDir = _path.default.dirname(_path.default.dirname(swcPackagePath));
|
|
116
50
|
var optionalDependencies = JSON.parse(_fs.default.readFileSync(swcPackagePath, 'utf8')).optionalDependencies;
|
|
117
|
-
var
|
|
51
|
+
var _installDir = _path.default.dirname(swcDir);
|
|
118
52
|
var depKey = "".concat(_processcjs.default.platform, "-").concat(_processcjs.default.arch);
|
|
119
53
|
var queue = new _queuecb.default();
|
|
120
54
|
Object.keys(optionalDependencies).filter(function(name) {
|
|
121
55
|
return name.indexOf(depKey) >= 0;
|
|
122
|
-
}).filter(function(name) {
|
|
123
|
-
return !(0, _existsSync.default)(_path.default.join(installDir, name));
|
|
124
56
|
}).map(function(name) {
|
|
125
57
|
queue.defer(function(callback) {
|
|
126
58
|
var _path1;
|
|
@@ -129,16 +61,7 @@ function installBindings(callback) {
|
|
|
129
61
|
var installedAt = (_path1 = _path.default).join.apply(_path1, [
|
|
130
62
|
_path.default.dirname(swcDir)
|
|
131
63
|
].concat(_to_consumable_array(name.split('/'))));
|
|
132
|
-
|
|
133
|
-
ensureCached(name, installString, cachedAt, function() {
|
|
134
|
-
if (!(0, _existsSync.default)(cachedAt)) {
|
|
135
|
-
console.log("Unsupported version: ".concat(installString));
|
|
136
|
-
return callback();
|
|
137
|
-
}
|
|
138
|
-
_fs.default.symlink(cachedAt, installedAt, symlinkType, function(err) {
|
|
139
|
-
err && !(0, _existsSync.default)(installedAt) ? callback(err) : callback();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
64
|
+
(0, _index.default)(installString, installedAt, callback);
|
|
142
65
|
});
|
|
143
66
|
});
|
|
144
67
|
queue.await(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport
|
|
1
|
+
{"version":3,"sources":["installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolve from 'resolve';\nimport installModule from './install-module/index.js';\n// @ts-ignore\nimport process from './process.cjs';\n\nexport default function installBindings(callback) {\n const swcPackagePath = resolve.sync('@swc/core/package.json');\n const swcDir = path.dirname(path.dirname(swcPackagePath));\n const { optionalDependencies } = JSON.parse(fs.readFileSync(swcPackagePath, 'utf8'));\n const _installDir = path.dirname(swcDir);\n const depKey = `${process.platform}-${process.arch}`;\n\n const queue = new Queue();\n Object.keys(optionalDependencies)\n .filter((name) => name.indexOf(depKey) >= 0)\n .map((name) => {\n queue.defer((callback) => {\n const version = optionalDependencies[name];\n const installString = `${name}${version ? `@${version}` : ''}`;\n const installedAt = path.join(path.dirname(swcDir), ...name.split('/'));\n installModule(installString, installedAt, callback);\n });\n });\n queue.await(callback);\n}\n"],"names":["installBindings","callback","swcPackagePath","resolve","sync","swcDir","path","dirname","optionalDependencies","JSON","parse","fs","readFileSync","_installDir","depKey","process","platform","arch","queue","Queue","Object","keys","filter","name","indexOf","map","defer","version","installString","installedAt","join","split","installModule","await"],"mappings":";;;;+BAQA;;;eAAwBA;;;yDART;2DACE;8DACC;8DACE;4DACM;iEAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEL,SAASA,gBAAgBC,QAAQ;IAC9C,IAAMC,iBAAiBC,gBAAO,CAACC,IAAI,CAAC;IACpC,IAAMC,SAASC,aAAI,CAACC,OAAO,CAACD,aAAI,CAACC,OAAO,CAACL;IACzC,IAAM,AAAEM,uBAAyBC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACV,gBAAgB,SAApEM;IACR,IAAMK,cAAcP,aAAI,CAACC,OAAO,CAACF;IACjC,IAAMS,SAAS,AAAC,GAAsBC,OAApBA,mBAAO,CAACC,QAAQ,EAAC,KAAgB,OAAbD,mBAAO,CAACE,IAAI;IAElD,IAAMC,QAAQ,IAAIC,gBAAK;IACvBC,OAAOC,IAAI,CAACb,sBACTc,MAAM,CAAC,SAACC;eAASA,KAAKC,OAAO,CAACV,WAAW;OACzCW,GAAG,CAAC,SAACF;QACJL,MAAMQ,KAAK,CAAC,SAACzB;gBAGSK;YAFpB,IAAMqB,UAAUnB,oBAAoB,CAACe,KAAK;YAC1C,IAAMK,gBAAgB,AAAC,GAASD,OAAPJ,MAAoC,OAA7BI,UAAU,AAAC,IAAW,OAARA,WAAY;YAC1D,IAAME,cAAcvB,CAAAA,SAAAA,aAAI,EAACwB,IAAI,OAATxB,QAAAA;gBAAUA,aAAI,CAACC,OAAO,CAACF;aAA4B,CAAnDC,OAAgC,qBAAGiB,KAAKQ,KAAK,CAAC;YAClEC,IAAAA,cAAa,EAACJ,eAAeC,aAAa5B;QAC5C;IACF;IACFiB,MAAMe,KAAK,CAAChC;AACd"}
|
package/dist/cjs/lib/loadSWC.js
CHANGED
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
Object.defineProperty(exports, "default", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _resolveoncecb = /*#__PURE__*/ _interop_require_default(require("resolve-once-cb"));
|
|
11
12
|
var _installBindings = /*#__PURE__*/ _interop_require_default(require("./installBindings.js"));
|
|
12
13
|
var _lazycjs = /*#__PURE__*/ _interop_require_default(require("./lazy.js"));
|
|
13
14
|
function _interop_require_default(obj) {
|
|
@@ -18,7 +19,13 @@ function _interop_require_default(obj) {
|
|
|
18
19
|
var swc = (0, _lazycjs.default)('@swc/core');
|
|
19
20
|
function loadSWC(callback) {
|
|
20
21
|
(0, _installBindings.default)(function(err) {
|
|
21
|
-
|
|
22
|
+
if (err) return callback(err);
|
|
23
|
+
try {
|
|
24
|
+
return callback(null, swc());
|
|
25
|
+
} catch (err) {
|
|
26
|
+
return callback(err);
|
|
27
|
+
}
|
|
22
28
|
});
|
|
23
29
|
}
|
|
30
|
+
var _default = (0, _resolveoncecb.default)(loadSWC);
|
|
24
31
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["loadSWC.ts"],"sourcesContent":["import installBindings from './installBindings.js';\n// @ts-ignore\nimport lazy from './lazy.cjs';\nconst swc = lazy('@swc/core');\n\
|
|
1
|
+
{"version":3,"sources":["loadSWC.ts"],"sourcesContent":["import resolveOnce from 'resolve-once-cb';\nimport installBindings from './installBindings.js';\n// @ts-ignore\nimport lazy from './lazy.cjs';\nconst swc = lazy('@swc/core');\n\nfunction loadSWC(callback) {\n installBindings((err) => {\n if (err) return callback(err);\n try {\n return callback(null, swc());\n } catch (err) {\n return callback(err);\n }\n });\n}\n\nexport default resolveOnce(loadSWC);\n"],"names":["swc","lazy","loadSWC","callback","installBindings","err","resolveOnce"],"mappings":";;;;+BAiBA;;;eAAA;;;oEAjBwB;sEACI;8DAEX;;;;;;AACjB,IAAMA,MAAMC,IAAAA,gBAAI,EAAC;AAEjB,SAASC,QAAQC,QAAQ;IACvBC,IAAAA,wBAAe,EAAC,SAACC;QACf,IAAIA,KAAK,OAAOF,SAASE;QACzB,IAAI;YACF,OAAOF,SAAS,MAAMH;QACxB,EAAE,OAAOK,KAAK;YACZ,OAAOF,SAASE;QAClB;IACF;AACF;IAEA,WAAeC,IAAAA,sBAAW,EAACJ"}
|
|
@@ -2,23 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports,
|
|
6
|
-
* @param {string} src The source directory to traverse.
|
|
7
|
-
* @param {string} dest The output directory to write files to.
|
|
8
|
-
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
9
|
-
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
10
|
-
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
11
|
-
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
12
|
-
*/ "default", {
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
13
6
|
enumerable: true,
|
|
14
7
|
get: function() {
|
|
15
|
-
return
|
|
8
|
+
return transformDirectoryWorker;
|
|
16
9
|
}
|
|
17
10
|
});
|
|
18
11
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
19
12
|
var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
|
|
20
13
|
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_default(require("get-tsconfig-compat"));
|
|
21
|
-
var
|
|
14
|
+
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
15
|
+
var _constants = require("../constants.js");
|
|
16
|
+
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("../createMatcher.js"));
|
|
22
17
|
var _transformFile = /*#__PURE__*/ _interop_require_default(require("./transformFile.js"));
|
|
23
18
|
function _define_property(obj, key, value) {
|
|
24
19
|
if (key in obj) {
|
|
@@ -77,41 +72,26 @@ function _object_spread_props(target, source) {
|
|
|
77
72
|
}
|
|
78
73
|
return target;
|
|
79
74
|
}
|
|
80
|
-
function
|
|
81
|
-
if (typeof options === 'function') {
|
|
82
|
-
callback = options;
|
|
83
|
-
options = {};
|
|
84
|
-
}
|
|
85
|
-
options = options || {};
|
|
86
|
-
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
87
|
-
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
88
|
-
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
75
|
+
function transformDirectoryWorker(src, dest, type, options, callback) {
|
|
89
76
|
var tsconfig = options.tsconfig ? options.tsconfig : _gettsconfigcompat.default.getTsconfig(src);
|
|
90
77
|
var matcher = (0, _createMatcher.default)(tsconfig);
|
|
91
|
-
|
|
92
|
-
tsconfig: tsconfig
|
|
93
|
-
});
|
|
78
|
+
var entries = [];
|
|
94
79
|
var iterator = new _fsiterator.default(src);
|
|
95
|
-
iterator.forEach(function(entry
|
|
96
|
-
if (!entry.stats.isFile()) return
|
|
97
|
-
if (!matcher(entry.fullPath)) return
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
options = options || {};
|
|
110
|
-
if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);
|
|
111
|
-
return new Promise(function(resolve, reject) {
|
|
112
|
-
transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {
|
|
113
|
-
err ? reject(err) : resolve(result);
|
|
80
|
+
iterator.forEach(function(entry) {
|
|
81
|
+
if (!entry.stats.isFile()) return;
|
|
82
|
+
if (!matcher(entry.fullPath)) return;
|
|
83
|
+
if (_constants.typeFileRegEx.test(entry.basename)) return;
|
|
84
|
+
entries.push(entry);
|
|
85
|
+
}, function(err) {
|
|
86
|
+
if (err) return callback(err);
|
|
87
|
+
options = _object_spread_props(_object_spread({}, options), {
|
|
88
|
+
tsconfig: tsconfig
|
|
89
|
+
});
|
|
90
|
+
var queue = new _queuecb.default();
|
|
91
|
+
entries.forEach(function(entry) {
|
|
92
|
+
return queue.defer(_transformFile.default.bind(null, entry.fullPath, _path.default.dirname(_path.default.join(dest, entry.path)), type, options));
|
|
114
93
|
});
|
|
94
|
+
queue.await(callback);
|
|
115
95
|
});
|
|
116
96
|
}
|
|
117
97
|
/* 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":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\nimport Queue from 'queue-cb';\n\nimport { typeFileRegEx } from '../constants.js';\nimport createMatcher from '../createMatcher.js';\nimport transformFile from './transformFile.js';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);\n const matcher = createMatcher(tsconfig);\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (!matcher(entry.fullPath)) return;\n if (typeFileRegEx.test(entry.basename)) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n\n options = { ...options, tsconfig };\n const queue = new Queue();\n entries.forEach((entry) => queue.defer(transformFile.bind(null, entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options)));\n queue.await(callback);\n }\n );\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","getTS","getTsconfig","matcher","createMatcher","entries","iterator","Iterator","forEach","entry","stats","isFile","fullPath","typeFileRegEx","test","basename","push","err","queue","Queue","defer","transformFile","bind","path","dirname","join","await"],"mappings":";;;;+BASA;;;eAAwBA;;;2DATP;iEACI;wEACH;8DACA;yBAEY;oEACJ;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEX,SAASA,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,IAAMC,WAAWF,QAAQE,QAAQ,GAAGF,QAAQE,QAAQ,GAAGC,0BAAK,CAACC,WAAW,CAACP;IACzE,IAAMQ,UAAUC,IAAAA,sBAAa,EAACJ;IAE9B,IAAMK,UAAU,EAAE;IAClB,IAAMC,WAAW,IAAIC,mBAAQ,CAACZ;IAC9BW,SAASE,OAAO,CACd,SAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;QAC3B,IAAI,CAACR,QAAQM,MAAMG,QAAQ,GAAG;QAC9B,IAAIC,wBAAa,CAACC,IAAI,CAACL,MAAMM,QAAQ,GAAG;QACxCV,QAAQW,IAAI,CAACP;IACf,GACA,SAACQ;QACC,IAAIA,KAAK,OAAOlB,SAASkB;QAEzBnB,UAAU,wCAAKA;YAASE,UAAAA;;QACxB,IAAMkB,QAAQ,IAAIC,gBAAK;QACvBd,QAAQG,OAAO,CAAC,SAACC;mBAAUS,MAAME,KAAK,CAACC,sBAAa,CAACC,IAAI,CAAC,MAAMb,MAAMG,QAAQ,EAAEW,aAAI,CAACC,OAAO,CAACD,aAAI,CAACE,IAAI,CAAC7B,MAAMa,MAAMc,IAAI,IAAI1B,MAAMC;;QACjIoB,MAAMQ,KAAK,CAAC3B;IACd;AAEJ"}
|
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports,
|
|
6
|
-
* @param {string} src The source directory to traverse.
|
|
7
|
-
* @param {string} dest The output directory to write the file to.
|
|
8
|
-
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
9
|
-
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
10
|
-
* @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.
|
|
11
|
-
* @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.
|
|
12
|
-
*/ "default", {
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
13
6
|
enumerable: true,
|
|
14
7
|
get: function() {
|
|
15
|
-
return
|
|
8
|
+
return transformFileWorker;
|
|
16
9
|
}
|
|
17
10
|
});
|
|
18
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
@@ -103,15 +96,7 @@ function makeReplacements(code, regex, extensions, extension) {
|
|
|
103
96
|
}
|
|
104
97
|
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
105
98
|
var 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; }";
|
|
106
|
-
function
|
|
107
|
-
if (typeof options === 'function') {
|
|
108
|
-
callback = options;
|
|
109
|
-
options = {};
|
|
110
|
-
}
|
|
111
|
-
options = options || {};
|
|
112
|
-
if (typeof src !== 'string') throw new Error('transformFile: unexpected source');
|
|
113
|
-
if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');
|
|
114
|
-
if (typeof type !== 'string') throw new Error('transformFile: unexpected type');
|
|
99
|
+
function transformFileWorker(src, dest, type, options, callback) {
|
|
115
100
|
_fs.default.readFile(src, 'utf8', function(err, contents) {
|
|
116
101
|
if (err) return callback(err);
|
|
117
102
|
callback = (0, _calloncefn.default)(callback);
|
|
@@ -126,26 +111,28 @@ function transformFileCallback(src, dest, type, options, callback) {
|
|
|
126
111
|
tsconfig.config.compilerOptions.target = 'ES5';
|
|
127
112
|
}
|
|
128
113
|
var basename = _path.default.basename(src);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
114
|
+
(0, _transformSync.default)(contents, basename, tsconfig, function(err, output) {
|
|
115
|
+
if (err) return callback(err);
|
|
116
|
+
// infer extension and patch .mjs imports
|
|
117
|
+
var ext = _path.default.extname(basename);
|
|
118
|
+
if (type === 'esm') {
|
|
119
|
+
ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;
|
|
120
|
+
output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');
|
|
121
|
+
ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;
|
|
122
|
+
output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');
|
|
123
|
+
} else {
|
|
124
|
+
ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;
|
|
125
|
+
output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');
|
|
126
|
+
output.code += interopClientDefaultExport;
|
|
127
|
+
}
|
|
128
|
+
var destFilePath = _path.default.join(dest, basename.replace(/\.[^/.]+$/, '') + ext);
|
|
129
|
+
(0, _mkdirpclassic.default)(_path.default.dirname(destFilePath), function() {
|
|
130
|
+
var queue = new _queuecb.default();
|
|
131
|
+
queue.defer(_fs.default.writeFile.bind(null, destFilePath, output.code, 'utf8'));
|
|
132
|
+
!options.sourceMaps || queue.defer(_fs.default.writeFile.bind(null, "".concat(destFilePath, ".map"), output.map, 'utf8'));
|
|
133
|
+
queue.await(function() {
|
|
134
|
+
return err ? callback(err) : callback(null, destFilePath);
|
|
135
|
+
});
|
|
149
136
|
});
|
|
150
137
|
});
|
|
151
138
|
} catch (err) {
|
|
@@ -153,17 +140,4 @@ function transformFileCallback(src, dest, type, options, callback) {
|
|
|
153
140
|
}
|
|
154
141
|
});
|
|
155
142
|
}
|
|
156
|
-
function transformFile(src, dest, type, options, callback) {
|
|
157
|
-
if (typeof options === 'function') {
|
|
158
|
-
callback = options;
|
|
159
|
-
options = null;
|
|
160
|
-
}
|
|
161
|
-
options = options || {};
|
|
162
|
-
if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);
|
|
163
|
-
return new Promise(function(resolve, reject) {
|
|
164
|
-
transformFileCallback(src, dest, type, options, function compileCallback(err, result) {
|
|
165
|
-
err ? reject(err) : resolve(result);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
143
|
/* 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":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport transformSync from './transformSync.js';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst interopClientDefaultExport = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nexport default function transformFileWorker(src, dest, type, options, callback) {\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 transformSync(contents, basename, tsconfig, (err, output) => {\n if (err) return callback(err);\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 });\n } catch (err) {\n callback(err);\n }\n });\n}\n"],"names":["transformFileWorker","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","src","dest","type","options","callback","fs","readFile","err","contents","once","tsconfig","getTS","getTsconfig","config","compilerOptions","module","target","basename","path","transformSync","output","extname","destFilePath","join","replace","mkdirp","dirname","queue","Queue","defer","writeFile","bind","sourceMaps","map","await"],"mappings":"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"}
|
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
Object.defineProperty(exports, "default", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return transformSyncWorker;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
12
|
var _swc = /*#__PURE__*/ _interop_require_wildcard(require("ts-node/transpilers/swc"));
|
|
13
|
-
var
|
|
13
|
+
var _lazycjs = /*#__PURE__*/ _interop_require_default(require("../lib/lazy.js"));
|
|
14
14
|
var _loadSWC = /*#__PURE__*/ _interop_require_default(require("../lib/loadSWC.js"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
@@ -58,10 +58,12 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
58
58
|
}
|
|
59
59
|
return newObj;
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
var lazyTS = (0, _lazycjs.default)('typescript');
|
|
62
|
+
function transformSyncWorker(contents, fileName, tsconfig, callback) {
|
|
62
63
|
(0, _loadSWC.default)(function(err, swc) {
|
|
63
64
|
if (err) return callback(err);
|
|
64
|
-
var
|
|
65
|
+
var ts = lazyTS();
|
|
66
|
+
var parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, _path.default.dirname(tsconfig.path));
|
|
65
67
|
var transpile = _swc.create({
|
|
66
68
|
swc: swc,
|
|
67
69
|
service: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nimport * as transpiler from 'ts-node/transpilers/swc';\nimport
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nimport * as transpiler from 'ts-node/transpilers/swc';\n// @ts-ignore\nimport lazy from '../lib/lazy.cjs';\n// @ts-ignore\nimport loadSWC from '../lib/loadSWC.js';\nconst lazyTS = lazy('typescript');\n\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult, callback) {\n loadSWC((err, swc) => {\n if (err) return callback(err);\n const ts = lazyTS();\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n const transpile = transpiler.create({ swc: swc, service: { config: { options: parsed.options } } });\n const res = transpile.transpile(contents, { fileName });\n callback(null, { code: res.outputText, map: res.sourceMapText });\n });\n}\n"],"names":["transformSyncWorker","lazyTS","lazy","contents","fileName","tsconfig","callback","loadSWC","err","swc","ts","parsed","parseJsonConfigFileContent","config","sys","path","dirname","transpile","transpiler","create","service","options","res","code","outputText","map","sourceMapText"],"mappings":";;;;+BASA;;;eAAwBA;;;2DATP;2DAEW;8DAEX;8DAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACpB,IAAMC,SAASC,IAAAA,gBAAI,EAAC;AAEL,SAASF,oBAAoBG,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB,EAAEC,QAAQ;IAChHC,IAAAA,gBAAO,EAAC,SAACC,KAAKC;QACZ,IAAID,KAAK,OAAOF,SAASE;QACzB,IAAME,KAAKT;QACX,IAAMU,SAASD,GAAGE,0BAA0B,CAACP,SAASQ,MAAM,EAAEH,GAAGI,GAAG,EAAEC,aAAI,CAACC,OAAO,CAACX,SAASU,IAAI;QAChG,IAAME,YAAYC,KAAWC,MAAM,CAAC;YAAEV,KAAKA;YAAKW,SAAS;gBAAEP,QAAQ;oBAAEQ,SAASV,OAAOU,OAAO;gBAAC;YAAE;QAAE;QACjG,IAAMC,MAAML,UAAUA,SAAS,CAACd,UAAU;YAAEC,UAAAA;QAAS;QACrDE,SAAS,MAAM;YAAEiB,MAAMD,IAAIE,UAAU;YAAEC,KAAKH,IAAII,aAAa;QAAC;IAChE;AACF"}
|
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import url from 'url';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import lazy from '../lib/lazy.cjs';
|
|
5
|
+
import packageRoot from '../lib/packageRoot.mjs';
|
|
6
|
+
const __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
|
|
7
|
+
const root = packageRoot(__dirname);
|
|
8
|
+
const worker = path.resolve(root, 'dist', 'cjs', 'workers', 'transformDirectory.js');
|
|
9
|
+
const version = 'lts';
|
|
10
|
+
const call = lazy('node-version-call');
|
|
6
11
|
function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
try {
|
|
13
|
+
const res = call()({
|
|
14
|
+
version,
|
|
15
|
+
callbacks: true
|
|
16
|
+
}, worker, src, dest, type, options);
|
|
17
|
+
return callback(null, res);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
return callback(err);
|
|
10
20
|
}
|
|
11
|
-
options = options || {};
|
|
12
|
-
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
13
|
-
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
14
|
-
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
15
|
-
const tsconfig = options.tsconfig ? options.tsconfig : getTS.getTsconfig(src);
|
|
16
|
-
const matcher = createMatcher(tsconfig);
|
|
17
|
-
options = {
|
|
18
|
-
...options,
|
|
19
|
-
tsconfig
|
|
20
|
-
};
|
|
21
|
-
const iterator = new Iterator(src);
|
|
22
|
-
iterator.forEach((entry, cb)=>{
|
|
23
|
-
if (!entry.stats.isFile()) return cb();
|
|
24
|
-
if (!matcher(entry.fullPath)) return cb();
|
|
25
|
-
transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);
|
|
26
|
-
}, {
|
|
27
|
-
callbacks: true,
|
|
28
|
-
concurrency: options.concurrency || 1024
|
|
29
|
-
}, callback);
|
|
30
21
|
}
|
|
31
22
|
/**
|
|
32
23
|
* @param {string} src The source directory to traverse.
|
|
@@ -41,6 +32,9 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
41
32
|
options = null;
|
|
42
33
|
}
|
|
43
34
|
options = options || {};
|
|
35
|
+
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
36
|
+
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
37
|
+
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
44
38
|
if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);
|
|
45
39
|
return new Promise((resolve, reject)=>{
|
|
46
40
|
transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n\n// @ts-ignore\nimport lazy from '../lib/lazy.cjs';\nimport packageRoot from '../lib/packageRoot.js';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\nconst root = packageRoot(__dirname);\nconst worker = path.resolve(root, 'dist', 'cjs', 'workers', 'transformDirectory.js');\nconst version = 'lts';\nconst call = lazy('node-version-call');\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n try {\n const res = call()({ version, callbacks: true }, worker, src, dest, type, options);\n return callback(null, res);\n } catch (err) {\n return callback(err);\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 if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n if (typeof 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","url","lazy","packageRoot","__dirname","dirname","__filename","fileURLToPath","root","worker","resolve","version","call","transformDirectoryCallback","src","dest","type","options","callback","res","callbacks","err","transformDirectory","Error","Promise","reject","compileCallback","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,aAAa;AACb,OAAOC,UAAU,kBAAkB;AACnC,OAAOC,iBAAiB,wBAAwB;AAEhD,MAAMC,YAAYJ,KAAKK,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaL,IAAIM,aAAa,CAAC,YAAYN,GAAG;AACjH,MAAMO,OAAOL,YAAYC;AACzB,MAAMK,SAAST,KAAKU,OAAO,CAACF,MAAM,QAAQ,OAAO,WAAW;AAC5D,MAAMG,UAAU;AAChB,MAAMC,OAAOV,KAAK;AAElB,SAASW,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI;QACF,MAAMC,MAAMP,OAAO;YAAED;YAASS,WAAW;QAAK,GAAGX,QAAQK,KAAKC,MAAMC,MAAMC;QAC1E,OAAOC,SAAS,MAAMC;IACxB,EAAE,OAAOE,KAAK;QACZ,OAAOH,SAASG;IAClB;AACF;AAEA;;;;;;;CAOC,GACD,eAAe,SAASC,mBAAmBR,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3E,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IACtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIS,MAAM;IAC7C,IAAI,OAAOR,SAAS,UAAU,MAAM,IAAIQ,MAAM;IAC9C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;IAE9C,IAAI,OAAOL,aAAa,YAAY,OAAOL,2BAA2BC,KAAKC,MAAMC,MAAMC,SAASC;IAChG,OAAO,IAAIM,QAAQ,CAACd,SAASe;QAC3BZ,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASS,gBAAgBL,GAAG,EAAEM,MAAM;YACvFN,MAAMI,OAAOJ,OAAOX,QAAQiB;QAC9B;IACF;AACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import url from 'url';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import lazy from '../lib/lazy.cjs';
|
|
5
|
+
import packageRoot from '../lib/packageRoot.mjs';
|
|
6
|
+
const __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
|
|
7
|
+
const root = packageRoot(__dirname);
|
|
8
|
+
const worker = path.resolve(root, 'dist', 'cjs', 'workers', 'transformFile.js');
|
|
9
|
+
const version = 'lts';
|
|
10
|
+
const call = lazy('node-version-call');
|
|
11
|
+
function transformFileCallback(src, dest, type, options, callback) {
|
|
12
|
+
try {
|
|
13
|
+
const res = call()({
|
|
14
|
+
version,
|
|
15
|
+
callbacks: true
|
|
16
|
+
}, worker, src, dest, type, options);
|
|
17
|
+
return callback(null, res);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
return callback(err);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} src The source directory to traverse.
|
|
24
|
+
* @param {string} dest The output directory to write files to.
|
|
25
|
+
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
26
|
+
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
27
|
+
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
28
|
+
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
29
|
+
*/ export default function transformFile(src, dest, type, options, callback) {
|
|
30
|
+
if (typeof options === 'function') {
|
|
31
|
+
callback = options;
|
|
32
|
+
options = null;
|
|
33
|
+
}
|
|
34
|
+
options = options || {};
|
|
35
|
+
if (typeof src !== 'string') throw new Error('transformFile: unexpected source');
|
|
36
|
+
if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');
|
|
37
|
+
if (typeof type !== 'string') throw new Error('transformFile: unexpected type');
|
|
38
|
+
if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);
|
|
39
|
+
return new Promise((resolve, reject)=>{
|
|
40
|
+
transformFileCallback(src, dest, type, options, function compileCallback(err, result) {
|
|
41
|
+
err ? reject(err) : resolve(result);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|