Skip to content

Commit d0a5d3a

Browse files
authored
feat: detect and prevent hd update command in npm installation (#514)
1 parent b69b658 commit d0a5d3a

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/hooks/prerun/prerun.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
import * as path from 'node:path';
12
import type { Hook } from '@oclif/core';
23
import debug from 'debug';
34

4-
const hook: Hook<'prerun'> = async (opts) => {
5-
// If JSON flag is enabled, silence debug logging
6-
if (opts.Command.prototype.jsonEnabled()) {
5+
const hook: Hook<'prerun'> = async function (this: Hook.Context, { Command }) {
6+
if (Command.prototype.jsonEnabled()) {
77
debug.disable();
88
}
9+
10+
if (Command.id === 'update') {
11+
const isNpm = this.config.root.split(path.sep).includes('node_modules');
12+
13+
if (isNpm) {
14+
this.warn('The update command is not supported for npm installations.');
15+
this.log('\nTo update to the latest, run:\n');
16+
this.log(' npm install -g @herodevs/cli@latest\n');
17+
this.log('\nTo update to a specific version, run:\n');
18+
this.log(' npm install -g @herodevs/cli@<version>\n');
19+
20+
process.exit(0);
21+
}
22+
}
923
};
1024

1125
export default hook;

0 commit comments

Comments
 (0)