提交 117e6215 编写于 作者: E Erich Gamma

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

上级 b4a0ebc5
{
"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}"
}
\ No newline at end of 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);
}
}
......
......@@ -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": [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册