diff --git a/extensions/npm/README.md b/extensions/npm/README.md index 33d85a1f547..1946e16a958 100644 --- a/extensions/npm/README.md +++ b/extensions/npm/README.md @@ -14,4 +14,4 @@ For more information about auto detection of Tasks pls see the [documentation](h - `npm.runSilent` run npm script with the `--silent` option, the default is `false`. - `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 when the workspace contains a 'package.json' file. +- `npm.enableScriptExplorer` enable an explorer view for npm scripts. diff --git a/extensions/npm/package.json b/extensions/npm/package.json index 5affb9009f4..7df53cb226a 100644 --- a/extensions/npm/package.json +++ b/extensions/npm/package.json @@ -30,8 +30,7 @@ "activationEvents": [ "onCommand:workbench.action.tasks.runTask", "onLanguage:json", - "onView:npm", - "workspaceContains:**/package.json" + "onView:npm" ], "contributes": { "views": { @@ -39,7 +38,7 @@ { "id": "npm", "name": "%view.name%", - "when": "hasNpmScripts" + "when": "showExplorer" } ] }, diff --git a/extensions/npm/package.nls.json b/extensions/npm/package.nls.json index 9caaff63fc3..a3b43f64c0b 100644 --- a/extensions/npm/package.nls.json +++ b/extensions/npm/package.nls.json @@ -5,7 +5,7 @@ "config.npm.runSilent": "Run npm commands with the `--silent` option.", "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, when the workspace contains a 'package.json' file.", + "config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts.", "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 ommitted.", diff --git a/extensions/npm/src/main.ts b/extensions/npm/src/main.ts index d3ebc055c7d..ef0c87d7467 100644 --- a/extensions/npm/src/main.ts +++ b/extensions/npm/src/main.ts @@ -9,7 +9,7 @@ import * as vscode from 'vscode'; import { addJSONProviders } from './features/jsonContributions'; import { NpmScriptsTreeDataProvider } from './npmView'; -import { provideNpmScripts, hasNpmScripts, explorerIsEnabled } from './tasks'; +import { provideNpmScripts, explorerIsEnabled } from './tasks'; let taskProvider: vscode.Disposable | undefined; @@ -17,7 +17,12 @@ export async function activate(context: vscode.ExtensionContext): Promise taskProvider = registerTaskProvider(); registerExplorer(context); configureHttpRequest(); - vscode.workspace.onDidChangeConfiguration(() => configureHttpRequest()); + vscode.workspace.onDidChangeConfiguration((e) => { + configureHttpRequest(); + if (e.affectsConfiguration('npm.enableScriptExplorer')) { + updateExplorerVisibility(); + } + }); context.subscriptions.push(addJSONProviders(httpRequest.xhr)); } @@ -36,14 +41,16 @@ function registerTaskProvider(): vscode.Disposable | undefined { return undefined; } +function updateExplorerVisibility() { + vscode.commands.executeCommand('setContext', 'showExplorer', explorerIsEnabled()); +} + async function registerExplorer(context: vscode.ExtensionContext) { - if (explorerIsEnabled() && vscode.workspace.workspaceFolders) { + if (vscode.workspace.workspaceFolders) { let treeDataProvider = vscode.window.registerTreeDataProvider('npm', new NpmScriptsTreeDataProvider(context)); context.subscriptions.push(treeDataProvider); - if (await hasNpmScripts()) { - vscode.commands.executeCommand('setContext', 'hasNpmScripts', true); - } } + updateExplorerVisibility(); } function configureHttpRequest() {