diff --git a/extensions/npm/README.md b/extensions/npm/README.md index 1946e16a958..625002ee7ee 100644 --- a/extensions/npm/README.md +++ b/extensions/npm/README.md @@ -1,6 +1,6 @@ # Node npm -**Notice** This is a an extension that is bundled with Visual Studio Code. +**Notice** This is a an extension that is bundled with Visual Studio Code. This extension supports running npm scripts defined in the `package.json` as [tasks](https://code.visualstudio.com/docs/editor/tasks). Scripts with the name 'build', 'compile', or 'watch' are treated as build tasks. @@ -15,3 +15,4 @@ For more information about auto detection of Tasks pls see the [documentation](h - `npm.packageManager` the package manager used to run the scripts: `npm` or `yarn`, the default is `npm`. - `npm.exclude` glob patterns for folders that should be excluded from automatic script detection. The pattern is matched against the **absolute path** of the package.json. For example, to exclude all test folders use '**/test/**'. - `npm.enableScriptExplorer` enable an explorer view for npm scripts. +- `npm.scriptExplorerAction` the default click action: `open` or `run`, the default is `open`. diff --git a/extensions/npm/package.json b/extensions/npm/package.json index 80d97e225af..a57db1747a0 100644 --- a/extensions/npm/package.json +++ b/extensions/npm/package.json @@ -98,19 +98,20 @@ }, { "command": "npm.runScript", - "when": "view == npm && viewItem == script", - "group": "inline" + "when": "view == npm && viewItem == script", + "group": "inline" }, { "command": "npm.runScript", - "when": "view == npm && viewItem == debugScript", - "group": "inline" + "when": "view == npm && viewItem == debugScript", + "group": "inline" }, { "command": "npm.debugScript", - "when": "view == npm && viewItem == debugScript", - "group": "inline" - }, { + "when": "view == npm && viewItem == debugScript", + "group": "inline" + }, + { "command": "npm.debugScript", "when": "view == npm && viewItem == script", "group": "navigation@3" @@ -164,6 +165,16 @@ "default": false, "scope": "resource", "description": "%config.npm.enableScriptExplorer%" + }, + "npm.scriptExplorerAction": { + "type": "string", + "enum": [ + "open", + "run" + ], + "description": "%config.npm.scriptExplorerAction%", + "scope": "window", + "default": "open" } } }, diff --git a/extensions/npm/package.nls.json b/extensions/npm/package.nls.json index 19acf55d865..dedd7af6161 100644 --- a/extensions/npm/package.nls.json +++ b/extensions/npm/package.nls.json @@ -6,6 +6,7 @@ "config.npm.packageManager": "The package manager used to run scripts.", "config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.", "config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts.", + "config.npm.scriptExplorerAction": "The default click action used in the scripts explorer: 'open' or 'run', the default is 'open'.", "npm.parseError": "Npm task detection: failed to parse the file {0}", "taskdef.script": "The npm script to customize.", "taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.", diff --git a/extensions/npm/src/main.ts b/extensions/npm/src/main.ts index 18db3890ef5..023fddbffb6 100644 --- a/extensions/npm/src/main.ts +++ b/extensions/npm/src/main.ts @@ -25,6 +25,11 @@ export async function activate(context: vscode.ExtensionContext): Promise treeDataProvider.refresh(); } } + if (e.affectsConfiguration('npm.scriptExplorerAction')) { + if (treeDataProvider) { + treeDataProvider.refresh(); + } + } }); context.subscriptions.push(addJSONProviders(httpRequest.xhr)); } diff --git a/extensions/npm/src/npmView.ts b/extensions/npm/src/npmView.ts index acdf930f907..db2e086d50a 100644 --- a/extensions/npm/src/npmView.ts +++ b/extensions/npm/src/npmView.ts @@ -65,23 +65,36 @@ class PackageJSON extends TreeItem { } } +type ExplorerCommands = 'open' | 'run'; + class NpmScript extends TreeItem { task: Task; package: PackageJSON; constructor(context: ExtensionContext, packageJson: PackageJSON, task: Task) { super(task.name, TreeItemCollapsibleState.None); + const command: ExplorerCommands = workspace.getConfiguration('npm').get('scriptExplorerAction') || 'open'; + + const commandList = { + 'open': { + title: 'Edit Script', + command: 'npm.openScript', + arguments: [this] + }, + 'run': { + title: 'Run Script', + command: 'npm.runScript', + arguments: [this] + } + }; this.contextValue = 'script'; if (task.group && task.group === TaskGroup.Rebuild) { this.contextValue = 'debugScript'; } this.package = packageJson; this.task = task; - this.command = { - title: 'Run Script', - command: 'npm.openScript', - arguments: [this] - }; + this.command = commandList[command]; + if (task.group && task.group === TaskGroup.Clean) { this.iconPath = { light: context.asAbsolutePath(path.join('resources', 'light', 'prepostscript.svg')),