Skip to content

Commit 963330e

Browse files
committed
fix(cli): simplify global installation detection
Use inverted logic: assume global unless installed in local node_modules. This is package-manager agnostic (works with npm, yarn, pnpm, bun, etc).
1 parent 9ddb666 commit 963330e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/shared/src/functions/upgrade.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
import path from 'node:path'
2+
import { fileURLToPath } from 'node:url'
13
import { log } from '@clack/prompts'
2-
import isGlobal from 'is-installed-globally'
34
import { addDependency } from 'nypm'
45
import { i18n } from '../i18n'
56

7+
function isInstalledLocally (): boolean {
8+
// Check if CLI is inside a local node_modules (relative to cwd)
9+
// If so, it's a local installation and shouldn't be upgraded globally
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
11+
const cwd = process.cwd()
12+
const localNodeModules = path.join(cwd, 'node_modules')
13+
14+
return __dirname.startsWith(localNodeModules)
15+
}
16+
617
export async function upgradeSelf (pkgName: string) {
7-
if (!isGlobal) {
18+
if (isInstalledLocally()) {
819
log.warning(i18n.t('commands.upgrade.not_global', { pkg: pkgName }))
920
return
1021
}

0 commit comments

Comments
 (0)