Reject promise when there is a parse error in a package.json file.

This commit is contained in:
Erich Gamma 2017-10-27 15:59:50 +02:00
parent b4a0ebc5e8
commit 117e621595
3 changed files with 16 additions and 9 deletions

View file

@ -1,4 +1,5 @@
{
"config.npm.autoDetect": "Controls whether auto detection of npm scripts is on or off. Default is on.",
"config.npm.runSilent": "Run npm commands with the `--silent` option"
"config.npm.runSilent": "Run npm commands with the `--silent` option",
"npm.parseError": "Npm task detection could not parse the {0}"
}

View file

@ -8,6 +8,8 @@
import * as path from 'path';
import * as fs from 'fs';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
let localize = nls.loadMessageBundle();
type AutoDetect = 'on' | 'off';
let taskProvider: vscode.Disposable | undefined;
@ -89,14 +91,17 @@ async function provideNpmScripts(): Promise<vscode.Task[]> {
if (!folders) {
return emptyTasks;
}
for (let i = 0; i < folders.length; i++) {
if (isEnabled(folders[i])) {
let tasks = await provideNpmScriptsForFolder(folders[i]);
allTasks.push(...tasks);
try {
for (let i = 0; i < folders.length; i++) {
if (isEnabled(folders[i])) {
let tasks = await provideNpmScriptsForFolder(folders[i]);
allTasks.push(...tasks);
}
}
return allTasks;
} catch (error) {
return Promise.reject(error);
}
return allTasks;
}
function isEnabled(folder: vscode.WorkspaceFolder): boolean {
@ -138,7 +143,8 @@ async function provideNpmScriptsForFolder(folder: vscode.WorkspaceFolder): Promi
// result.push(createTask('install', 'install', rootPath, folder, []));
return result;
} catch (e) {
return emptyTasks;
let localizedParseError = localize('npm.parseerror', 'Npm task detection: failed to parse the file {0}', packageJson);
throw new Error(localizedParseError);
}
}

View file

@ -6,7 +6,7 @@
"no-string-throw": true,
"no-unused-expression": true,
"no-duplicate-variable": true,
"no-unused-variable": true,
//"no-unused-variable": true,
"curly": true,
"class-name": true,
"semicolon": [