Skip to content

Commit baf3b60

Browse files
committed
Merge NPM Scripts: Added configuration option to change default click action microsoft#49282
1 parent c6d1072 commit baf3b60

5 files changed

Lines changed: 44 additions & 13 deletions

File tree

extensions/npm/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Node npm
22

3-
**Notice** This is a an extension that is bundled with Visual Studio Code.
3+
**Notice** This is a an extension that is bundled with Visual Studio Code.
44

55
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'
66
are treated as build tasks.
@@ -15,3 +15,4 @@ For more information about auto detection of Tasks pls see the [documentation](h
1515
- `npm.packageManager` the package manager used to run the scripts: `npm` or `yarn`, the default is `npm`.
1616
- `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/**'.
1717
- `npm.enableScriptExplorer` enable an explorer view for npm scripts.
18+
- `npm.scriptExplorerAction` the default click action: `open` or `run`, the default is `open`.

extensions/npm/package.json

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,20 @@
9898
},
9999
{
100100
"command": "npm.runScript",
101-
"when": "view == npm && viewItem == script",
102-
"group": "inline"
101+
"when": "view == npm && viewItem == script",
102+
"group": "inline"
103103
},
104104
{
105105
"command": "npm.runScript",
106-
"when": "view == npm && viewItem == debugScript",
107-
"group": "inline"
106+
"when": "view == npm && viewItem == debugScript",
107+
"group": "inline"
108108
},
109109
{
110110
"command": "npm.debugScript",
111-
"when": "view == npm && viewItem == debugScript",
112-
"group": "inline"
113-
}, {
111+
"when": "view == npm && viewItem == debugScript",
112+
"group": "inline"
113+
},
114+
{
114115
"command": "npm.debugScript",
115116
"when": "view == npm && viewItem == script",
116117
"group": "navigation@3"
@@ -164,6 +165,16 @@
164165
"default": false,
165166
"scope": "resource",
166167
"description": "%config.npm.enableScriptExplorer%"
168+
},
169+
"npm.scriptExplorerAction": {
170+
"type": "string",
171+
"enum": [
172+
"open",
173+
"run"
174+
],
175+
"description": "%config.npm.scriptExplorerAction%",
176+
"scope": "window",
177+
"default": "open"
167178
}
168179
}
169180
},

extensions/npm/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"config.npm.packageManager": "The package manager used to run scripts.",
77
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
88
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts.",
9+
"config.npm.scriptExplorerAction": "The default click action used in the scripts explorer: 'open' or 'run', the default is 'open'.",
910
"npm.parseError": "Npm task detection: failed to parse the file {0}",
1011
"taskdef.script": "The npm script to customize.",
1112
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",

extensions/npm/src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
2525
treeDataProvider.refresh();
2626
}
2727
}
28+
if (e.affectsConfiguration('npm.scriptExplorerAction')) {
29+
if (treeDataProvider) {
30+
treeDataProvider.refresh();
31+
}
32+
}
2833
});
2934
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
3035
}

extensions/npm/src/npmView.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,36 @@ class PackageJSON extends TreeItem {
6565
}
6666
}
6767

68+
type ExplorerCommands = 'open' | 'run';
69+
6870
class NpmScript extends TreeItem {
6971
task: Task;
7072
package: PackageJSON;
7173

7274
constructor(context: ExtensionContext, packageJson: PackageJSON, task: Task) {
7375
super(task.name, TreeItemCollapsibleState.None);
76+
const command: ExplorerCommands = workspace.getConfiguration('npm').get<ExplorerCommands>('scriptExplorerAction') || 'open';
77+
78+
const commandList = {
79+
'open': {
80+
title: 'Edit Script',
81+
command: 'npm.openScript',
82+
arguments: [this]
83+
},
84+
'run': {
85+
title: 'Run Script',
86+
command: 'npm.runScript',
87+
arguments: [this]
88+
}
89+
};
7490
this.contextValue = 'script';
7591
if (task.group && task.group === TaskGroup.Rebuild) {
7692
this.contextValue = 'debugScript';
7793
}
7894
this.package = packageJson;
7995
this.task = task;
80-
this.command = {
81-
title: 'Run Script',
82-
command: 'npm.openScript',
83-
arguments: [this]
84-
};
96+
this.command = commandList[command];
97+
8598
if (task.group && task.group === TaskGroup.Clean) {
8699
this.iconPath = {
87100
light: context.asAbsolutePath(path.join('resources', 'light', 'prepostscript.svg')),

0 commit comments

Comments
 (0)