Skip to content

Commit 83cb1d7

Browse files
committed
Support to run npm install from a package node
1 parent a50384a commit 83cb1d7

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

extensions/npm/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
"command": "npm.openScript",
6464
"title": "%command.openScript%"
6565
},
66+
{
67+
"command": "npm.runInstall",
68+
"title": "%command.runInstall%"
69+
},
6670
{
6771
"command": "npm.refresh",
6872
"title": "%command.refresh%",
@@ -84,9 +88,13 @@
8488
{
8589
"command": "npm.openScript",
8690
"when": "view == npm && viewItem == packageJSON",
87-
"group": "navigation"
91+
"group": "navigation@1"
8892
},
8993
{
94+
"command": "npm.runInstall",
95+
"when": "view == npm && viewItem == packageJSON",
96+
"group": "navigation@2"
97+
}, {
9098
"command": "npm.openScript",
9199
"when": "view == npm && viewItem == script",
92100
"group": "navigation@1"

extensions/npm/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"command.refresh": "Refresh",
1515
"command.run": "Run",
1616
"command.debug": "Debug",
17-
"command.openScript": "Open"
17+
"command.openScript": "Open",
18+
"command.runInstall": "Run Install"
1819
}

extensions/npm/src/npmView.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
WorkspaceFolder, commands, debug, window, workspace, Selection, TaskGroup
1212
} from 'vscode';
1313
import { visit, JSONVisitor } from 'jsonc-parser';
14-
import { NpmTaskDefinition, getPackageJsonUriFromTask, getScripts, isWorkspaceFolder, getPackageManager, getTaskName } from './tasks';
14+
import {
15+
NpmTaskDefinition, getPackageJsonUriFromTask, getScripts,
16+
isWorkspaceFolder, getPackageManager, getTaskName, createTask
17+
} from './tasks';
1518
import * as nls from 'vscode-nls';
1619

1720
const localize = nls.loadMessageBundle();
@@ -133,6 +136,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
133136
subscriptions.push(commands.registerCommand('npm.debugScript', this.debugScript, this));
134137
subscriptions.push(commands.registerCommand('npm.openScript', this.openScript, this));
135138
subscriptions.push(commands.registerCommand('npm.refresh', this.refresh, this));
139+
subscriptions.push(commands.registerCommand('npm.runInstall', this.runInstall, this));
136140
}
137141

138142
private scriptIsValid(scripts: any, task: Task): boolean {
@@ -258,6 +262,19 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
258262
return scriptOffset;
259263

260264
}
265+
266+
private async runInstall(selection: PackageJSON) {
267+
let uri: Uri | undefined = undefined;
268+
if (selection instanceof PackageJSON) {
269+
uri = selection.resourceUri;
270+
}
271+
if (!uri) {
272+
return;
273+
}
274+
let task = createTask('install', 'install', selection.folder.workspaceFolder, uri, []);
275+
workspace.executeTask(task);
276+
}
277+
261278
private async openScript(selection: PackageJSON | NpmScript) {
262279
let uri: Uri | undefined = undefined;
263280
if (selection instanceof PackageJSON) {

extensions/npm/src/tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export function getTaskName(script: string, relativePath: string | undefined) {
205205
return script;
206206
}
207207

208-
function createTask(script: string, cmd: string, folder: WorkspaceFolder, packageJsonUri: Uri, matcher?: any): Task {
208+
export function createTask(script: string, cmd: string, folder: WorkspaceFolder, packageJsonUri: Uri, matcher?: any): Task {
209209

210210
function getCommandLine(folder: WorkspaceFolder, cmd: string): string {
211211
let packageManager = getPackageManager(folder);

0 commit comments

Comments
 (0)