Fix for #31274 Support for yarn when running detected tasks

This commit is contained in:
Erich Gamma 2017-10-27 10:51:50 +02:00
parent 10ba78f6f3
commit 1420d41bf8
2 changed files with 21 additions and 8 deletions

View file

@ -41,17 +41,29 @@
"description": "%config.npm.autoDetect%"
},
"npm.runSilent": {
"type": "boolean",
"type": "boolean",
"default": false,
"scope": "resource",
"description": "%config.npm.runSilent%"
"description": "%config.npm.runSilent%"
},
"npm.packageManager": {
"scope": "resource",
"type": "string",
"enum": [
"npm",
"yarn"
],
"default": "npm",
"description": "The package manager used to run scripts"
}
}
},
"taskDefinitions": [
{
"type": "npm",
"required": ["script"],
"required": [
"script"
],
"properties": {
"script": {
"type": "string",

View file

@ -135,7 +135,7 @@ async function provideNpmScriptsForFolder(folder: vscode.WorkspaceFolder): Promi
result.push(task);
});
// always add npm install (without a problem matcher)
result.push(createTask('install', 'install', rootPath, folder, []));
// result.push(createTask('install', 'install', rootPath, folder, []));
return result;
} catch (e) {
return emptyTasks;
@ -148,11 +148,12 @@ function createTask(script: string, cmd: string, rootPath: string, folder: vscod
return script;
}
function getNpmCommandLine(folder: vscode.WorkspaceFolder, cmd: string): string {
function getCommandLine(folder: vscode.WorkspaceFolder, cmd: string): string {
let packageManager = vscode.workspace.getConfiguration('npm', folder.uri).get<string>('packageManager', 'npm');
if (vscode.workspace.getConfiguration('npm', folder.uri).get<boolean>('runSilent')) {
return `npm --silent ${cmd}`;
return `${packageManager} --silent ${cmd}`;
}
return `npm ${cmd}`;
return `${packageManager} ${cmd}`;
}
let kind: NpmTaskDefinition = {
@ -160,5 +161,5 @@ function createTask(script: string, cmd: string, rootPath: string, folder: vscod
script: script
};
let taskName = getTaskName(script);
return new vscode.Task(kind, folder, taskName, 'npm', new vscode.ShellExecution(getNpmCommandLine(folder, cmd), { cwd: rootPath }), matcher);
return new vscode.Task(kind, folder, taskName, 'npm', new vscode.ShellExecution(getCommandLine(folder, cmd), { cwd: rootPath }), matcher);
}