Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting npm version through CLI #99

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading