Add setting to exclude scripts from NPM scripts view

Fixes #71635
This commit is contained in:
Alex Ross 2021-11-12 17:14:05 +01:00
parent ca9042324f
commit 231fe61ab5
No known key found for this signature in database
GPG key ID: 89DDDBA66CBA7840
4 changed files with 18 additions and 1 deletions

View file

@ -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%",

View file

@ -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}",

View file

@ -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();

View file

@ -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) {