Skip to content

Commit f1f7ab1

Browse files
authored
Merge pull request #99 from ericcornelissen/patch-1
Fix getting npm version through CLI
2 parents 84b1eb9 + 8820f03 commit f1f7ab1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/utils/npm.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { exec } from 'child_process';
2-
import { Readable } from 'stream';
1+
import { execSync } from 'child_process';
32

43
/**
54
* Get the current npm version
65
* @return {String} The npm version
76
*/
87
export function getNpmVersion(): string {
9-
const version = exec('npm --version');
10-
return (version.stdout as Readable).toString();
8+
const version = execSync('npm --version');
9+
return version.toString();
1110
}

test/handlers/flags.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import sinon from 'sinon';
22
import { expect } from 'chai';
3+
import * as semver from 'semver';
34
import { CommandOptions } from '../../src/types';
45
import handleInput from '../../src/handlers/handleInput';
6+
import { getNpmVersion } from '../../src/utils/npm';
57

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

0 commit comments

Comments
 (0)