ts-swc-transform 1.4.1 → 1.4.3
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/lib/installBindings.js +57 -48
- package/dist/cjs/lib/installBindings.js.map +1 -1
- package/dist/cjs/lib/loadSWC.js +15 -3
- package/dist/cjs/lib/loadSWC.js.map +1 -1
- package/dist/cjs/lib/packageRoot.js +7 -4
- package/dist/cjs/lib/packageRoot.js.map +1 -1
- package/dist/cjs/lib/transformVersion.js +20 -0
- package/dist/cjs/lib/transformVersion.js.map +1 -0
- package/dist/cjs/transformDirectory.js +19 -77
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformFile.js +22 -132
- package/dist/cjs/transformFile.js.map +1 -1
- package/dist/cjs/transformSync.js +4 -5
- package/dist/cjs/transformSync.js.map +1 -1
- package/dist/cjs/workers/transformDirectory.js +89 -0
- package/dist/cjs/workers/transformDirectory.js.map +1 -0
- package/dist/cjs/workers/transformFile.js +143 -0
- package/dist/cjs/workers/transformFile.js.map +1 -0
- package/dist/cjs/workers/transformSync.js +2 -2
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/esm/lib/installBindings.mjs +43 -35
- package/dist/esm/lib/installBindings.mjs.map +1 -1
- package/dist/esm/lib/loadSWC.mjs +15 -3
- package/dist/esm/lib/loadSWC.mjs.map +1 -1
- package/dist/esm/lib/packageRoot.mjs +7 -4
- package/dist/esm/lib/packageRoot.mjs.map +1 -1
- package/dist/esm/lib/transformVersion.mjs +4 -0
- package/dist/esm/lib/transformVersion.mjs.map +1 -0
- package/dist/esm/transformDirectory.mjs +20 -26
- package/dist/esm/transformDirectory.mjs.map +1 -1
- package/dist/esm/transformFile.mjs +23 -105
- package/dist/esm/transformFile.mjs.map +1 -1
- package/dist/esm/transformSync.mjs +3 -5
- package/dist/esm/transformSync.mjs.map +1 -1
- package/dist/esm/workers/transformDirectory.mjs +22 -0
- package/dist/esm/workers/transformDirectory.mjs.map +1 -0
- package/dist/esm/workers/transformFile.mjs +100 -0
- package/dist/esm/workers/transformFile.mjs.map +1 -0
- package/dist/esm/workers/transformSync.mjs +1 -1
- package/dist/esm/workers/transformSync.mjs.map +1 -1
- package/dist/types/lib/loadSWC.d.ts +1 -1
- package/dist/types/lib/packageRoot.d.ts +1 -1
- package/dist/types/lib/transformVersion.d.ts +2 -0
- package/dist/types/transformDirectory.d.ts +1 -1
- package/dist/types/transformFile.d.ts +4 -4
- package/dist/types/transformSync.d.ts +3 -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 +6 -5
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
var _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
13
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
-
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
15
14
|
var _crossspawncb = /*#__PURE__*/ _interop_require_default(require("cross-spawn-cb"));
|
|
16
15
|
var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
|
|
17
16
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
@@ -77,59 +76,69 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
77
76
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
78
77
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
79
78
|
}
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
var
|
|
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
|
+
}
|
|
83
113
|
function installBindings(callback) {
|
|
114
|
+
var swcPackagePath = _resolve.default.sync('@swc/core/package.json');
|
|
115
|
+
var swcDir = _path.default.dirname(_path.default.dirname(swcPackagePath));
|
|
116
|
+
var optionalDependencies = JSON.parse(_fs.default.readFileSync(swcPackagePath, 'utf8')).optionalDependencies;
|
|
117
|
+
var installDir = _path.default.dirname(swcDir);
|
|
84
118
|
var depKey = "".concat(_processcjs.default.platform, "-").concat(_processcjs.default.arch);
|
|
85
119
|
var queue = new _queuecb.default();
|
|
86
|
-
Object.keys(optionalDependencies).filter(function(
|
|
87
|
-
return
|
|
88
|
-
}).filter(function(
|
|
89
|
-
return !(0, _existsSync.default)(_path.default.join(installDir,
|
|
120
|
+
Object.keys(optionalDependencies).filter(function(name) {
|
|
121
|
+
return name.indexOf(depKey) >= 0;
|
|
122
|
+
}).filter(function(name) {
|
|
123
|
+
return !(0, _existsSync.default)(_path.default.join(installDir, name));
|
|
90
124
|
}).map(function(name) {
|
|
91
125
|
queue.defer(function(callback) {
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
tmp,
|
|
107
|
-
'node_modules'
|
|
108
|
-
].concat(_to_consumable_array(installParts)));
|
|
109
|
-
var dest = (_path2 = _path.default).join.apply(_path2, [
|
|
110
|
-
_path.default.dirname(_path.default.dirname(_path.default.dirname(require.resolve('@swc/core/package.json'))))
|
|
111
|
-
].concat(_to_consumable_array(installParts)));
|
|
112
|
-
var queue = new _queuecb.default(1);
|
|
113
|
-
queue.defer(_mkdirpclassic.default.bind(null, tmp));
|
|
114
|
-
queue.defer(_fs.default.writeFile.bind(null, _path.default.join(tmp, 'package.json'), '{}', 'utf8'));
|
|
115
|
-
queue.defer(_crossspawncb.default.bind(null, 'npm', [
|
|
116
|
-
'install',
|
|
117
|
-
installString
|
|
118
|
-
], {
|
|
119
|
-
cwd: tmp,
|
|
120
|
-
env: env
|
|
121
|
-
}));
|
|
122
|
-
queue.defer(_fs.default.rename.bind(null, source, dest));
|
|
123
|
-
queue.await(function(err) {
|
|
124
|
-
(0, _rimraf2.default)(tmp, {
|
|
125
|
-
disableGlob: true
|
|
126
|
-
}, function() {
|
|
127
|
-
return callback(err);
|
|
128
|
-
});
|
|
126
|
+
var _path1;
|
|
127
|
+
var version = optionalDependencies[name];
|
|
128
|
+
var installString = "".concat(name).concat(version ? "@".concat(version) : '');
|
|
129
|
+
var installedAt = (_path1 = _path.default).join.apply(_path1, [
|
|
130
|
+
_path.default.dirname(swcDir)
|
|
131
|
+
].concat(_to_consumable_array(name.split('/'))));
|
|
132
|
+
var cachedAt = _path.default.join(cache, installString);
|
|
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();
|
|
129
140
|
});
|
|
130
|
-
}
|
|
131
|
-
return callback(err);
|
|
132
|
-
}
|
|
141
|
+
});
|
|
133
142
|
});
|
|
134
143
|
});
|
|
135
144
|
queue.await(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport
|
|
1
|
+
{"version":3,"sources":["installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport spawn from 'cross-spawn-cb';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\nimport resolve from 'resolve';\nimport rimraf2 from 'rimraf2';\nimport tempSuffix from 'temp-suffix';\nimport existsSync from './existsSync.js';\n// @ts-ignore\nimport process from './process.cjs';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst symlinkType = isWindows ? 'junction' : 'dir';\nconst cache = path.join(os.tmpdir(), 'ts-swc-transform', 'cache');\n\nfunction ensureCached(name, installString, cachedAt, callback) {\n if (existsSync(cachedAt)) return callback();\n\n const tmp = `${cachedAt}.${tempSuffix()}`;\n const installedAt = path.join(tmp, 'node_modules', ...name.split('/'));\n const { NODE_OPTIONS, ...env } = process.env;\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(spawn.bind(null, 'npm', ['install', installString], { cwd: tmp, env }));\n queue.defer((cb) => fs.rename(installedAt, cachedAt, cb.bind(null, null)));\n queue.await(() => {\n // clean up whether installed or not\n rimraf2(tmp, { disableGlob: true }, callback);\n });\n}\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 .filter((name) => !existsSync(path.join(installDir, name)))\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 const cachedAt = path.join(cache, installString);\n\n ensureCached(name, installString, cachedAt, () => {\n if (!existsSync(cachedAt)) {\n console.log(`Unsupported version: ${installString}`);\n return callback();\n }\n\n fs.symlink(cachedAt, installedAt, symlinkType, (err) => {\n err && !existsSync(installedAt) ? callback(err) : callback();\n });\n });\n });\n });\n queue.await(callback);\n}\n"],"names":["installBindings","isWindows","process","platform","test","env","OSTYPE","symlinkType","cache","path","join","os","tmpdir","ensureCached","name","installString","cachedAt","callback","existsSync","tmp","tempSuffix","installedAt","split","NODE_OPTIONS","queue","Queue","defer","mkdirp","bind","fs","writeFile","spawn","cwd","cb","rename","await","rimraf2","disableGlob","swcPackagePath","resolve","sync","swcDir","dirname","optionalDependencies","JSON","parse","readFileSync","installDir","depKey","arch","Object","keys","filter","indexOf","map","version","console","log","symlink","err"],"mappings":"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"}
|
package/dist/cjs/lib/loadSWC.js
CHANGED
|
@@ -15,10 +15,22 @@ function _interop_require_default(obj) {
|
|
|
15
15
|
default: obj
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
var
|
|
18
|
+
var lazySWC = (0, _lazycjs.default)('@swc/core');
|
|
19
|
+
var swc = null;
|
|
20
|
+
var err = null;
|
|
19
21
|
function loadSWC(callback) {
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
+
if (swc) return callback(null, swc);
|
|
23
|
+
if (err) return callback(err);
|
|
24
|
+
(0, _installBindings.default)(function(err_) {
|
|
25
|
+
err = err || err_;
|
|
26
|
+
if (err) return callback(err);
|
|
27
|
+
try {
|
|
28
|
+
swc = swc || lazySWC();
|
|
29
|
+
return callback(null, swc);
|
|
30
|
+
} catch (err_) {
|
|
31
|
+
err = err || err_;
|
|
32
|
+
return callback(err);
|
|
33
|
+
}
|
|
22
34
|
});
|
|
23
35
|
}
|
|
24
36
|
/* 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
|
|
1
|
+
{"version":3,"sources":["loadSWC.ts"],"sourcesContent":["import installBindings from './installBindings.js';\n// @ts-ignore\nimport lazy from './lazy.cjs';\nconst lazySWC = lazy('@swc/core');\n\nlet swc = null;\nlet err: Error = null;\nexport default function loadSWC(callback) {\n if (swc) return callback(null, swc);\n if (err) return callback(err);\n\n installBindings((err_) => {\n err = err || err_;\n if (err) return callback(err);\n try {\n swc = swc || lazySWC();\n return callback(null, swc);\n } catch (err_) {\n err = err || err_;\n return callback(err);\n }\n });\n}\n"],"names":["loadSWC","lazySWC","lazy","swc","err","callback","installBindings","err_"],"mappings":";;;;+BAOA;;;eAAwBA;;;sEAPI;8DAEX;;;;;;AACjB,IAAMC,UAAUC,IAAAA,gBAAI,EAAC;AAErB,IAAIC,MAAM;AACV,IAAIC,MAAa;AACF,SAASJ,QAAQK,QAAQ;IACtC,IAAIF,KAAK,OAAOE,SAAS,MAAMF;IAC/B,IAAIC,KAAK,OAAOC,SAASD;IAEzBE,IAAAA,wBAAe,EAAC,SAACC;QACfH,MAAMA,OAAOG;QACb,IAAIH,KAAK,OAAOC,SAASD;QACzB,IAAI;YACFD,MAAMA,OAAOF;YACb,OAAOI,SAAS,MAAMF;QACxB,EAAE,OAAOI,MAAM;YACbH,MAAMA,OAAOG;YACb,OAAOF,SAASD;QAClB;IACF;AACF"}
|
|
@@ -8,16 +8,19 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return packageRoot;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
11
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
var _existsSync = /*#__PURE__*/ _interop_require_default(require("./existsSync.js"));
|
|
12
14
|
function _interop_require_default(obj) {
|
|
13
15
|
return obj && obj.__esModule ? obj : {
|
|
14
16
|
default: obj
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
|
-
function packageRoot(dir
|
|
18
|
-
|
|
19
|
+
function packageRoot(dir) {
|
|
20
|
+
var packagePath = _path.default.join(dir, 'package.json');
|
|
21
|
+
if ((0, _existsSync.default)(packagePath) && JSON.parse(_fs.default.readFileSync(packagePath, 'utf8')).name) return dir;
|
|
19
22
|
var nextDir = _path.default.dirname(dir);
|
|
20
|
-
if (nextDir === dir) throw new Error(
|
|
21
|
-
return packageRoot(nextDir
|
|
23
|
+
if (nextDir === dir) throw new Error('Package root not found');
|
|
24
|
+
return packageRoot(nextDir);
|
|
22
25
|
}
|
|
23
26
|
/* 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":["packageRoot.ts"],"sourcesContent":["import path from 'path';\n\nexport default function packageRoot(dir
|
|
1
|
+
{"version":3,"sources":["packageRoot.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport existsSync from './existsSync.js';\n\nexport default function packageRoot(dir) {\n const packagePath = path.join(dir, 'package.json');\n if (existsSync(packagePath) && JSON.parse(fs.readFileSync(packagePath, 'utf8')).name) return dir;\n const nextDir = path.dirname(dir);\n if (nextDir === dir) throw new Error('Package root not found');\n return packageRoot(nextDir);\n}\n"],"names":["packageRoot","dir","packagePath","path","join","existsSync","JSON","parse","fs","readFileSync","name","nextDir","dirname","Error"],"mappings":";;;;+BAIA;;;eAAwBA;;;yDAJT;2DACE;iEACM;;;;;;AAER,SAASA,YAAYC,GAAG;IACrC,IAAMC,cAAcC,aAAI,CAACC,IAAI,CAACH,KAAK;IACnC,IAAII,IAAAA,mBAAU,EAACH,gBAAgBI,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACP,aAAa,SAASQ,IAAI,EAAE,OAAOT;IAC7F,IAAMU,UAAUR,aAAI,CAACS,OAAO,CAACX;IAC7B,IAAIU,YAAYV,KAAK,MAAM,IAAIY,MAAM;IACrC,OAAOb,YAAYW;AACrB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return _default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _processcjs = /*#__PURE__*/ _interop_require_default(require("./process.js"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var major = +_processcjs.default.versions.node.split('.')[0];
|
|
19
|
+
var _default = major < 14 ? '14' : 'local';
|
|
20
|
+
/* 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":["transformVersion.ts"],"sourcesContent":["// @ts-ignore\nimport process from './process.cjs';\n\nconst major = +process.versions.node.split('.')[0];\nexport default major < 14 ? '14' : 'local';\n"],"names":["major","process","versions","node","split"],"mappings":"AAAA,aAAa;;;;;+BAIb;;;eAAA;;;iEAHoB;;;;;;AAEpB,IAAMA,QAAQ,CAACC,mBAAO,CAACC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;IAClD,WAAeJ,QAAQ,KAAK,OAAO"}
|
|
@@ -16,90 +16,29 @@ Object.defineProperty(exports, /**
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
function _define_property(obj, key, value) {
|
|
24
|
-
if (key in obj) {
|
|
25
|
-
Object.defineProperty(obj, key, {
|
|
26
|
-
value: value,
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
obj[key] = value;
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
|
-
}
|
|
19
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
20
|
+
var _lazycjs = /*#__PURE__*/ _interop_require_default(require("./lib/lazy.js"));
|
|
21
|
+
var _packageRoot = /*#__PURE__*/ _interop_require_default(require("./lib/packageRoot.js"));
|
|
22
|
+
var _transformVersion = /*#__PURE__*/ _interop_require_default(require("./lib/transformVersion.js"));
|
|
36
23
|
function _interop_require_default(obj) {
|
|
37
24
|
return obj && obj.__esModule ? obj : {
|
|
38
25
|
default: obj
|
|
39
26
|
};
|
|
40
27
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
46
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
47
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
ownKeys.forEach(function(key) {
|
|
51
|
-
_define_property(target, key, source[key]);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return target;
|
|
55
|
-
}
|
|
56
|
-
function ownKeys(object, enumerableOnly) {
|
|
57
|
-
var keys = Object.keys(object);
|
|
58
|
-
if (Object.getOwnPropertySymbols) {
|
|
59
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
60
|
-
if (enumerableOnly) {
|
|
61
|
-
symbols = symbols.filter(function(sym) {
|
|
62
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
keys.push.apply(keys, symbols);
|
|
66
|
-
}
|
|
67
|
-
return keys;
|
|
68
|
-
}
|
|
69
|
-
function _object_spread_props(target, source) {
|
|
70
|
-
source = source != null ? source : {};
|
|
71
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
72
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
73
|
-
} else {
|
|
74
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
75
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return target;
|
|
79
|
-
}
|
|
28
|
+
var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
|
|
29
|
+
var root = (0, _packageRoot.default)(__dirname);
|
|
30
|
+
var worker = _path.default.resolve(root, 'dist', 'cjs', 'workers', 'transformDirectory.js');
|
|
31
|
+
var call = (0, _lazycjs.default)('node-version-call');
|
|
80
32
|
function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
33
|
+
try {
|
|
34
|
+
var res = call()({
|
|
35
|
+
version: _transformVersion.default,
|
|
36
|
+
callbacks: true
|
|
37
|
+
}, worker, src, dest, type, options);
|
|
38
|
+
return callback(null, res);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
return callback(err);
|
|
84
41
|
}
|
|
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');
|
|
89
|
-
var tsconfig = options.tsconfig ? options.tsconfig : _gettsconfigcompat.default.getTsconfig(src);
|
|
90
|
-
var matcher = (0, _createMatcher.default)(tsconfig);
|
|
91
|
-
options = _object_spread_props(_object_spread({}, options), {
|
|
92
|
-
tsconfig: tsconfig
|
|
93
|
-
});
|
|
94
|
-
var iterator = new _fsiterator.default(src);
|
|
95
|
-
iterator.forEach(function(entry, cb) {
|
|
96
|
-
if (!entry.stats.isFile()) return cb();
|
|
97
|
-
if (!matcher(entry.fullPath)) return cb();
|
|
98
|
-
(0, _transformFile.default)(entry.fullPath, _path.default.dirname(_path.default.join(dest, entry.path)), type, options, cb);
|
|
99
|
-
}, {
|
|
100
|
-
callbacks: true,
|
|
101
|
-
concurrency: options.concurrency || 1024
|
|
102
|
-
}, callback);
|
|
103
42
|
}
|
|
104
43
|
function transformDirectory(src, dest, type, options, callback) {
|
|
105
44
|
if (typeof options === 'function') {
|
|
@@ -107,6 +46,9 @@ function transformDirectory(src, dest, type, options, callback) {
|
|
|
107
46
|
options = null;
|
|
108
47
|
}
|
|
109
48
|
options = options || {};
|
|
49
|
+
if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');
|
|
50
|
+
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
51
|
+
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
110
52
|
if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);
|
|
111
53
|
return new Promise(function(resolve, reject) {
|
|
112
54
|
transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport
|
|
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';\nimport version from './lib/transformVersion.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 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":["transformDirectory","__dirname","path","dirname","__filename","url","fileURLToPath","root","packageRoot","worker","resolve","call","lazy","transformDirectoryCallback","src","dest","type","options","callback","res","version","callbacks","err","Error","Promise","reject","compileCallback","result"],"mappings":";;;;+BAsBA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DA9BP;0DACD;8DAGC;kEACO;uEACJ;;;;;;AAEpB,IAAMC,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAClG,IAAMC,OAAOC,IAAAA,oBAAW,EAACP;AACzB,IAAMQ,SAASP,aAAI,CAACQ,OAAO,CAACH,MAAM,QAAQ,OAAO,WAAW;AAC5D,IAAMI,OAAOC,IAAAA,gBAAI,EAAC;AAElB,SAASC,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI;QACF,IAAMC,MAAMR,OAAO;YAAES,SAAAA,yBAAO;YAAEC,WAAW;QAAK,GAAGZ,QAAQK,KAAKC,MAAMC,MAAMC;QAC1E,OAAOC,SAAS,MAAMC;IACxB,EAAE,OAAOG,KAAK;QACZ,OAAOJ,SAASI;IAClB;AACF;AAUe,SAAStB,mBAAmBc,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,SAACd,SAASe;QAC3BZ,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASS,gBAAgBJ,GAAG,EAAEK,MAAM;YACvFL,MAAMG,OAAOH,OAAOZ,QAAQiB;QAC9B;IACF;AACF"}
|
|
@@ -4,154 +4,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, /**
|
|
6
6
|
* @param {string} src The source directory to traverse.
|
|
7
|
-
* @param {string} dest The output directory to write
|
|
7
|
+
* @param {string} dest The output directory to write files to.
|
|
8
8
|
* @param {string} type The type of transform ('esm' or 'cjs').
|
|
9
9
|
* @param {{sourceMaps: boolean}} options Options to pass to swc.
|
|
10
|
-
* @param {(err
|
|
11
|
-
* @returns {void | Promise<
|
|
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
12
|
*/ "default", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function() {
|
|
15
15
|
return transformFile;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
19
18
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var _transformSync = /*#__PURE__*/ _interop_require_default(require("./transformSync.js"));
|
|
25
|
-
function _define_property(obj, key, value) {
|
|
26
|
-
if (key in obj) {
|
|
27
|
-
Object.defineProperty(obj, key, {
|
|
28
|
-
value: value,
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
obj[key] = value;
|
|
35
|
-
}
|
|
36
|
-
return obj;
|
|
37
|
-
}
|
|
19
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
20
|
+
var _lazycjs = /*#__PURE__*/ _interop_require_default(require("./lib/lazy.js"));
|
|
21
|
+
var _packageRoot = /*#__PURE__*/ _interop_require_default(require("./lib/packageRoot.js"));
|
|
22
|
+
var _transformVersion = /*#__PURE__*/ _interop_require_default(require("./lib/transformVersion.js"));
|
|
38
23
|
function _interop_require_default(obj) {
|
|
39
24
|
return obj && obj.__esModule ? obj : {
|
|
40
25
|
default: obj
|
|
41
26
|
};
|
|
42
27
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
ownKeys.forEach(function(key) {
|
|
53
|
-
_define_property(target, key, source[key]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return target;
|
|
57
|
-
}
|
|
58
|
-
var matchingDeps = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
59
|
-
var matchingName = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
60
|
-
var regexCJS = new RegExp("(?:(?:var|const|let)".concat(matchingName, "=\\s*)?require\\(").concat(matchingDeps, "\\);?"), 'g');
|
|
61
|
-
var regexESM = new RegExp("".concat(regexCJS, "|import(?:").concat(matchingName, "from\\s*)?").concat(matchingDeps, ";?|export(?:").concat(matchingName, "from\\s*)?").concat(matchingDeps, ";?"), 'g');
|
|
62
|
-
var importReplaceMJS = [
|
|
63
|
-
'.js',
|
|
64
|
-
'.ts',
|
|
65
|
-
'.tsx',
|
|
66
|
-
'.mts',
|
|
67
|
-
'.mjs'
|
|
68
|
-
];
|
|
69
|
-
var importReplaceCJS = [
|
|
70
|
-
'.cts'
|
|
71
|
-
];
|
|
72
|
-
var requireReplaceJS = [
|
|
73
|
-
'.mjs',
|
|
74
|
-
'.cjs',
|
|
75
|
-
'.ts',
|
|
76
|
-
'.tsx',
|
|
77
|
-
'.mts',
|
|
78
|
-
'.cts'
|
|
79
|
-
];
|
|
80
|
-
function makeReplacements(code, regex, extensions, extension) {
|
|
81
|
-
var _loop = function() {
|
|
82
|
-
var dependency = match[1] || match[2] || match[3] || match[4];
|
|
83
|
-
var ext = extensions.find(function(x) {
|
|
84
|
-
return dependency.slice(-x.length) === x;
|
|
85
|
-
});
|
|
86
|
-
if (ext) matches.push({
|
|
87
|
-
ext: ext,
|
|
88
|
-
match: match,
|
|
89
|
-
dependency: dependency
|
|
90
|
-
});
|
|
91
|
-
match = regex.exec(code);
|
|
92
|
-
};
|
|
93
|
-
var matches = [];
|
|
94
|
-
var match = regex.exec(code);
|
|
95
|
-
while(match)_loop();
|
|
96
|
-
matches = matches.reverse();
|
|
97
|
-
for(var index in matches){
|
|
98
|
-
var match1 = matches[index];
|
|
99
|
-
var start = match1.match.index + match1.match[0].indexOf(match1.dependency) + match1.dependency.indexOf(match1.ext);
|
|
100
|
-
code = code.substring(0, start) + extension + code.substring(start + match1.ext.length);
|
|
101
|
-
}
|
|
102
|
-
return code;
|
|
103
|
-
}
|
|
104
|
-
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
105
|
-
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; }";
|
|
28
|
+
var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
|
|
29
|
+
var root = (0, _packageRoot.default)(__dirname);
|
|
30
|
+
var worker = _path.default.resolve(root, 'dist', 'cjs', 'workers', 'transformFile.js');
|
|
31
|
+
var call = (0, _lazycjs.default)('node-version-call');
|
|
106
32
|
function transformFileCallback(src, dest, type, options, callback) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
33
|
+
try {
|
|
34
|
+
var res = call()({
|
|
35
|
+
version: _transformVersion.default,
|
|
36
|
+
callbacks: true
|
|
37
|
+
}, worker, src, dest, type, options);
|
|
38
|
+
return callback(null, res);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
return callback(err);
|
|
110
41
|
}
|
|
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');
|
|
115
|
-
_fs.default.readFile(src, 'utf8', function(err, contents) {
|
|
116
|
-
if (err) return callback(err);
|
|
117
|
-
callback = (0, _calloncefn.default)(callback);
|
|
118
|
-
try {
|
|
119
|
-
var tsconfig = options.tsconfig ? options.tsconfig : _gettsconfigcompat.default.getTsconfig(src);
|
|
120
|
-
// overrides for cjs
|
|
121
|
-
if (type === 'cjs') {
|
|
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
|
-
}
|
|
128
|
-
var basename = _path.default.basename(src);
|
|
129
|
-
var output = (0, _transformSync.default)(contents, basename, tsconfig);
|
|
130
|
-
// infer extension and patch .mjs imports
|
|
131
|
-
var ext = _path.default.extname(basename);
|
|
132
|
-
if (type === 'esm') {
|
|
133
|
-
ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;
|
|
134
|
-
output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');
|
|
135
|
-
ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;
|
|
136
|
-
output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');
|
|
137
|
-
} else {
|
|
138
|
-
ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;
|
|
139
|
-
output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');
|
|
140
|
-
output.code += interopClientDefaultExport;
|
|
141
|
-
}
|
|
142
|
-
var destFilePath = _path.default.join(dest, basename.replace(/\.[^/.]+$/, '') + ext);
|
|
143
|
-
(0, _mkdirpclassic.default)(_path.default.dirname(destFilePath), function() {
|
|
144
|
-
var queue = new _queuecb.default();
|
|
145
|
-
queue.defer(_fs.default.writeFile.bind(null, destFilePath, output.code, 'utf8'));
|
|
146
|
-
!options.sourceMaps || queue.defer(_fs.default.writeFile.bind(null, "".concat(destFilePath, ".map"), output.map, 'utf8'));
|
|
147
|
-
queue.await(function() {
|
|
148
|
-
return err ? callback(err) : callback(null, destFilePath);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
} catch (err) {
|
|
152
|
-
callback(err);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
42
|
}
|
|
156
43
|
function transformFile(src, dest, type, options, callback) {
|
|
157
44
|
if (typeof options === 'function') {
|
|
@@ -159,6 +46,9 @@ function transformFile(src, dest, type, options, callback) {
|
|
|
159
46
|
options = null;
|
|
160
47
|
}
|
|
161
48
|
options = options || {};
|
|
49
|
+
if (typeof src !== 'string') throw new Error('transformFile: unexpected source');
|
|
50
|
+
if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');
|
|
51
|
+
if (typeof type !== 'string') throw new Error('transformFile: unexpected type');
|
|
162
52
|
if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);
|
|
163
53
|
return new Promise(function(resolve, reject) {
|
|
164
54
|
transformFileCallback(src, dest, type, options, function compileCallback(err, result) {
|