From b5501e6127c4a922206059d9be4acf0cb7245be2 Mon Sep 17 00:00:00 2001 From: SrTobi Date: Mon, 29 Feb 2016 11:32:04 +0100 Subject: [PATCH 1/3] renamed npm list cmd string --- src/npm.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/npm.ts b/src/npm.ts index d9301d9f..abe14e9f 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -1,11 +1,11 @@ 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 { return new Promise((c, e) => { - cp.exec(cmd, { cwd }, (err, stdout, stderr) => { + cp.exec(listCmd, { cwd }, (err, stdout, stderr) => { if (err) return e(err); c(stdout.toString('utf8') From f39481ab9868e43067fd564368aeaaf319cfc3c6 Mon Sep 17 00:00:00 2001 From: SrTobi Date: Mon, 29 Feb 2016 11:32:20 +0100 Subject: [PATCH 2/3] added function to determine bad npm versions --- src/npm.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/npm.ts b/src/npm.ts index abe14e9f..f38770f6 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -14,4 +14,21 @@ export function getDependencies(cwd: string): Promise { } ); }); +} + +const versionCmd = 'npm -v'; + +const badNpmVersions = [ + /3.7.[0123]/ +]; + +export function isBadNpmVersion(): Promise { + return new Promise((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))); + }); + }); } \ No newline at end of file From 682f7a6daad836ebd14e69d21fc71ce90ce4130e Mon Sep 17 00:00:00 2001 From: SrTobi Date: Mon, 29 Feb 2016 13:17:33 +0100 Subject: [PATCH 3/3] Output warning when using npm list with bad npm version --- src/npm.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/npm.ts b/src/npm.ts index f38770f6..bcd7af09 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -4,16 +4,23 @@ import * as cp from 'child_process'; const listCmd = 'npm list --production --parseable'; export function getDependencies(cwd: string): Promise { - return new Promise((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))); + 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((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';