Skip to content

Commit

Permalink
Add setting to exclude scripts from NPM scripts view
Browse files Browse the repository at this point in the history
Fixes #71635
  • Loading branch information
alexr00 committed Nov 12, 2021
1 parent ca90423 commit 231fe61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@
"scope": "window",
"default": "open"
},
"npm.scriptExplorerExclude": {
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "%config.npm.scriptExplorerExclude%",
"scope": "resource",
"default": []
},
"npm.fetchOnlinePackageInfo": {
"type": "boolean",
"description": "%config.npm.fetchOnlinePackageInfo%",
Expand Down
1 change: 1 addition & 0 deletions extensions/npm/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"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 when there is no top-level 'package.json' file.",
"config.npm.scriptExplorerAction": "The default click action used in the npm scripts explorer: `open` or `run`, the default is `open`.",
"config.npm.scriptExplorerExclude": "An array of regular expressions that indicate which scripts should be excluded from the NPM Scripts view.",
"config.npm.enableRunFromFolder": "Enable running npm scripts contained in a folder from the Explorer context menu.",
"config.npm.fetchOnlinePackageInfo": "Fetch data from https://registry.npmjs.org and https://registry.bower.io to provide auto-completion and information on hover features on npm dependencies.",
"npm.parseError": "Npm task detection: failed to parse the file {0}",
Expand Down
2 changes: 1 addition & 1 deletion extensions/npm/src/npmMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
treeDataProvider = registerExplorer(context);

context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('npm.exclude') || e.affectsConfiguration('npm.autoDetect')) {
if (e.affectsConfiguration('npm.exclude') || e.affectsConfiguration('npm.autoDetect') || e.affectsConfiguration('npm.scriptExplorerExclude')) {
invalidateTasksCache();
if (treeDataProvider) {
treeDataProvider.refresh();
Expand Down
7 changes: 7 additions & 0 deletions extensions/npm/src/npmView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
let folder = null;
let packageJson = null;

const regularExpressionsSetting = workspace.getConfiguration('npm').get<string[]>('scriptExplorerExclude', []);
const regularExpressions = regularExpressionsSetting?.map(value => RegExp(value));

tasks.forEach(each => {
if (regularExpressions.some((regularExpression) => (<NpmTaskDefinition>each.task.definition).script.match(regularExpression))) {
return;
}

if (isWorkspaceFolder(each.task.scope) && !this.isInstallTask(each.task)) {
folder = folders.get(each.task.scope.name);
if (!folder) {
Expand Down

0 comments on commit 231fe61

Please sign in to comment.