Skip to content

Commit

Permalink
Merge pull request #99 from ericcornelissen/patch-1
Browse files Browse the repository at this point in the history
Fix getting npm version through CLI
  • Loading branch information
jeemok authored Sep 2, 2024
2 parents 84b1eb9 + 8820f03 commit f1f7ab1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 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();
}
6 changes: 5 additions & 1 deletion test/handlers/flags.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sinon from 'sinon';
import { expect } from 'chai';
import * as semver from 'semver';
import { CommandOptions } from '../../src/types';
import handleInput from '../../src/handlers/handleInput';
import { getNpmVersion } from '../../src/utils/npm';

describe('Flags', () => {
describe('default', () => {
Expand Down Expand Up @@ -92,7 +94,9 @@ describe('Flags', () => {
it('should be able to set production mode from the command flag correctly', () => {
const callbackStub = sinon.stub();
const options = { production: true };
const auditCommand = 'npm audit --omit=dev';
const npmVersion = getNpmVersion();
const flag = semver.satisfies(npmVersion, '<=8.13.2') ? '--production' : '--omit=dev';
const auditCommand = `npm audit ${flag}`;
const auditLevel = 'info';
const exceptionIds: string[] = [];

Expand Down

0 comments on commit f1f7ab1

Please sign in to comment.