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

Output warning when using bad npm version #73

Merged
merged 3 commits into from
Feb 29, 2016
Merged
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
42 changes: 33 additions & 9 deletions src/npm.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
import * as path from 'path';
import * as cp from 'child_process';

const cmd = 'npm list --production --parseable';
const listCmd = 'npm list --production --parseable';

export function getDependencies(cwd: string): Promise<string[]> {
return new Promise<string[]>((c, e) => {
cp.exec(cmd, { cwd }, (err, stdout, stderr) => {
if (err) return e(err);

c(stdout.toString('utf8')
.split(/[\r\n]/)
.filter(dir => path.isAbsolute(dir)));
return isBadNpmVersion()
.then((isBadVersion) => {
if(isBadVersion) {
console.warn('You are using a npm version, that does not work well with vsce! Consider to update with "npm install -g npm".')
}
);
}).then(() => {
return new Promise<string[]>((c, e) => {
cp.exec(listCmd, { cwd }, (err, stdout, stderr) => {
if (err) return e(err);

c(stdout.toString('utf8')
.split(/[\r\n]/)
.filter(dir => path.isAbsolute(dir)));
}
);
});
});
}

const versionCmd = 'npm -v';

const badNpmVersions = [
/3.7.[0123]/
];

export function isBadNpmVersion(): Promise<boolean> {
return new Promise<boolean>((c, e) => {
cp.exec(versionCmd, (err, stdout, stderr) => {
if (err) return e(err);

let version = stdout.toString('utf8').trim();
c(badNpmVersions.some((regex) => regex.test(version)));
});
});
}