bin-home 1.0.1 → 1.1.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/bin/cli.js +3 -1
- package/lib/versionUpdate.js +36 -2
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
formatVersionOutput,
|
|
11
11
|
chooseTargetVersion,
|
|
12
12
|
runGlobalUpdate,
|
|
13
|
+
isVoltaManagedCommand,
|
|
13
14
|
isInteractiveSession,
|
|
14
15
|
formatVersionDiffHint,
|
|
15
16
|
promptToRunCli
|
|
@@ -126,8 +127,9 @@ async function run() {
|
|
|
126
127
|
return;
|
|
127
128
|
}
|
|
128
129
|
try {
|
|
130
|
+
const useVolta = await isVoltaManagedCommand(commandName);
|
|
129
131
|
console.log(t("updating"));
|
|
130
|
-
await runGlobalUpdate(packageName, targetVersion);
|
|
132
|
+
await runGlobalUpdate(packageName, targetVersion, { useVolta });
|
|
131
133
|
console.log(t("updateCompleted"));
|
|
132
134
|
|
|
133
135
|
const shouldRunCli = await promptToRunCli();
|
package/lib/versionUpdate.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const { exec, spawn } = require("child_process");
|
|
2
2
|
const readline = require("readline");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const which = require("which");
|
|
3
5
|
const { t } = require("./i18n");
|
|
4
6
|
|
|
5
7
|
const colors = {
|
|
@@ -16,6 +18,28 @@ function getNpmCommand() {
|
|
|
16
18
|
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
function getVoltaCommand() {
|
|
22
|
+
return process.platform === "win32" ? "volta.cmd" : "volta";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function isVoltaManagedCommand(commandName, options = {}) {
|
|
26
|
+
if (!commandName) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const whichFn = options.whichFn || which;
|
|
31
|
+
let resolvedPath;
|
|
32
|
+
try {
|
|
33
|
+
resolvedPath = await whichFn(commandName);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const normalizedPath = path.normalize(resolvedPath).toLowerCase();
|
|
39
|
+
const voltaBinSegment = path.join("volta", "bin", "").toLowerCase();
|
|
40
|
+
return normalizedPath.includes(voltaBinSegment);
|
|
41
|
+
}
|
|
42
|
+
|
|
19
43
|
function normalizeVersions(raw) {
|
|
20
44
|
if (!raw) {
|
|
21
45
|
return [];
|
|
@@ -273,9 +297,14 @@ function spawnCommand(command, args, options = {}) {
|
|
|
273
297
|
|
|
274
298
|
async function runGlobalUpdate(packageName, version, options = {}) {
|
|
275
299
|
const npmCommand = getNpmCommand();
|
|
300
|
+
const voltaCommand = getVoltaCommand();
|
|
301
|
+
const useVolta = options.useVolta === true;
|
|
302
|
+
const targetPackage = `${packageName}@${version}`;
|
|
276
303
|
|
|
277
304
|
if (options.execFn) {
|
|
278
|
-
const command =
|
|
305
|
+
const command = useVolta
|
|
306
|
+
? `${voltaCommand} install ${targetPackage}`
|
|
307
|
+
: `${npmCommand} i -g ${targetPackage}`;
|
|
279
308
|
return execCommand(
|
|
280
309
|
command,
|
|
281
310
|
options.execFn,
|
|
@@ -285,7 +314,11 @@ async function runGlobalUpdate(packageName, version, options = {}) {
|
|
|
285
314
|
}
|
|
286
315
|
|
|
287
316
|
try {
|
|
288
|
-
|
|
317
|
+
if (useVolta) {
|
|
318
|
+
await spawnCommand(voltaCommand, ["install", targetPackage]);
|
|
319
|
+
} else {
|
|
320
|
+
await spawnCommand(npmCommand, ["i", "-g", targetPackage]);
|
|
321
|
+
}
|
|
289
322
|
} catch (error) {
|
|
290
323
|
const err = new Error(`Failed to update ${packageName}: ${error.message}`);
|
|
291
324
|
err.exitCode = NPM_UPDATE_EXIT_CODE;
|
|
@@ -299,6 +332,7 @@ module.exports = {
|
|
|
299
332
|
chooseTargetVersion,
|
|
300
333
|
promptForVersion,
|
|
301
334
|
runGlobalUpdate,
|
|
335
|
+
isVoltaManagedCommand,
|
|
302
336
|
isInteractiveSession,
|
|
303
337
|
parseVersion,
|
|
304
338
|
compareVersions,
|