Skip to content

Commit 285d5f7

Browse files
author
Charlike Mike Reagent
committed
fix: update deps
Signed-off-by: Charlike Mike Reagent <[email protected]>
1 parent 92ba73f commit 285d5f7

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"@tunnckocore/execa": "^2.1.1",
1515
"esm": "^3.0.84",
16-
"is-installed-globally": "^0.1.0",
16+
"global-dirs": "^0.1.1",
1717
"update-notifier": "^2.5.0"
1818
},
1919
"devDependencies": {

src/index.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// import proc from 'process';
1+
import fs from 'fs';
2+
import path from 'path';
23
import unpdateNotifier from 'update-notifier';
3-
import isInstalledGlobally from 'is-installed-globally';
44
import { exec } from '@tunnckocore/execa';
5+
import globalDirs from 'global-dirs';
56

67
export default function updater(options) {
78
const opts = Object.assign({}, options);
@@ -14,33 +15,44 @@ export default function updater(options) {
1415
if (err) {
1516
throw err;
1617
}
17-
if (info.type !== 'latest') {
18+
if (isInstalledGlobally(opts.pkg) && info.type !== 'latest') {
1819
autoupdate(opts.pkg, opts.manager);
1920
}
2021
};
2122

2223
return unpdateNotifier(opts);
2324
}
2425

26+
function isInstalledGlobally({ name }) {
27+
/* eslint-disable no-restricted-syntax */
28+
29+
let exists = false;
30+
for (const [, dirs] of Object.entries(globalDirs)) {
31+
for (const [, globalPath] of Object.entries(dirs)) {
32+
const fp = path.join(globalPath, name);
33+
if (fs.existsSync(fp)) {
34+
exists = true;
35+
break;
36+
}
37+
}
38+
}
39+
return exists;
40+
}
41+
2542
async function autoupdate(pkg, manager) {
2643
const isNpm = manager === 'npm';
2744

2845
if (isNpm || manager === 'pnpm') {
29-
await exec(
30-
`${isNpm ? 'npm' : 'pnpm'} install ${
31-
isInstalledGlobally ? '--global' : ''
32-
} ${pkg.name}`,
33-
);
46+
await exec(`${isNpm ? 'npm' : 'pnpm'} install --global ${pkg.name}`);
3447
}
3548

3649
if (manager === 'yarn') {
37-
const g = isInstalledGlobally ? 'global' : '';
3850
await exec([
3951
// ensure it is cleanest one
40-
`yarn ${g} remove ${pkg.name}`,
52+
`yarn global remove ${pkg.name}`,
4153

4254
// install it after that ensurance
43-
`yarn ${g} add ${pkg.name}`,
55+
`yarn global add ${pkg.name}`,
4456
]);
4557
}
4658
}

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ glob@^7.0.3, glob@^7.0.5, glob@^7.1.2, glob@^7.1.3:
16041604
once "^1.3.0"
16051605
path-is-absolute "^1.0.0"
16061606

1607-
global-dirs@^0.1.0:
1607+
global-dirs@^0.1.0, global-dirs@^0.1.1:
16081608
version "0.1.1"
16091609
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
16101610
integrity sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU=

0 commit comments

Comments
 (0)