Skip to content

Commit

Permalink
Fix getting npm version through CLI
Browse files Browse the repository at this point in the history
Update the logic to get the npm version from the npm CLI to use the
synchronous version of `exec`, `execSync`, to ensure the output can be
read correctly. In the previous implementation the output would not be
read correctly, leading to the comparison at `handleInput.ts:14` always
evaluating to false and `'--omit=dev'` always being used.
  • Loading branch information
ericcornelissen committed Aug 25, 2024
1 parent adf6857 commit ee5ea05
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/utils/npm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { exec } from 'child_process';
import { Readable } from 'stream';
import { execSync } from 'child_process';

/**
* Get the current npm version
* @return {String} The npm version
*/
export function getNpmVersion(): string {
const version = exec('npm --version');
return (version.stdout as Readable).toString();
const version = execSync('npm --version');
return version.toString();
}

0 comments on commit ee5ea05

Please sign in to comment.