phewsh 0.15.44 → 0.15.45
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/commands/update.js +18 -3
- package/package.json +1 -1
package/commands/update.js
CHANGED
|
@@ -112,9 +112,24 @@ async function main() {
|
|
|
112
112
|
if (code === 0) {
|
|
113
113
|
console.log(` ${green('✓')} Updated to v${latest}. New shells pick it up immediately.`);
|
|
114
114
|
} else {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
// NEVER suggest `sudo npm i -g` — that root-owns the package dir and
|
|
116
|
+
// poisons every future non-sudo update (the exact trap users hit). The
|
|
117
|
+
// correct fix is to OWN the package, once, then update normally.
|
|
118
|
+
let prefix = '';
|
|
119
|
+
try {
|
|
120
|
+
prefix = require('child_process').execFileSync('npm', ['config', 'get', 'prefix'],
|
|
121
|
+
{ encoding: 'utf-8', timeout: 3000 }).trim();
|
|
122
|
+
} catch { /* unknown prefix */ }
|
|
123
|
+
const pkgDir = prefix ? `${prefix}/lib/node_modules/${pkg.name}` : `$(npm prefix -g)/lib/node_modules/${pkg.name}`;
|
|
124
|
+
const binLink = prefix ? `${prefix}/bin/${pkg.name}` : `$(npm prefix -g)/bin/${pkg.name}`;
|
|
125
|
+
console.log(` ${yellow('Update failed')} (npm exited ${code}) — almost certainly a permissions issue.`);
|
|
126
|
+
console.log(` ${g('The phewsh package is probably root-owned from a past `sudo` install.')}`);
|
|
127
|
+
console.log(` ${b('Own it once, then updates never need sudo again:')}`);
|
|
128
|
+
console.log(` ${w(`sudo chown -R $(whoami) "${pkgDir}"`)}`);
|
|
129
|
+
console.log(` ${w(`sudo chown -h $(whoami) "${binLink}"`)}`);
|
|
130
|
+
console.log(` ${w(`phewsh update`)}`);
|
|
131
|
+
console.log(` ${g('Or reinstall with the installer (handles this for you):')} ${w('curl -fsSL phewsh.com/install.sh | sh')}`);
|
|
132
|
+
console.log(` ${g('Do NOT run `sudo npm i -g` — that is what caused this.')}`);
|
|
118
133
|
}
|
|
119
134
|
console.log('');
|
|
120
135
|
process.exit(code ?? 0);
|