File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3131 "activationEvents" : [
3232 " onCommand:workbench.action.tasks.runTask" ,
3333 " onLanguage:json" ,
34+ " workspaceContains:package.json" ,
3435 " onView:npm"
3536 ],
3637 "contributes" : {
4748 {
4849 "id" : " npm" ,
4950 "name" : " %view.name%" ,
50- "when" : " config.npm.enableScriptExplorer"
51+ "when" : " npm:showScriptExplorer || config.npm.enableScriptExplorer"
5152 }
5253 ]
5354 },
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import * as httpRequest from 'request-light';
77import * as vscode from 'vscode' ;
88import { addJSONProviders } from './features/jsonContributions' ;
99import { NpmScriptsTreeDataProvider } from './npmView' ;
10- import { invalidateTasksCache , NpmTaskProvider } from './tasks' ;
10+ import { invalidateTasksCache , NpmTaskProvider , hasPackageJson } from './tasks' ;
1111import { invalidateHoverScriptsCache , NpmScriptHoverProvider } from './scriptHover' ;
1212import { runSelectedScript } from './commands' ;
1313
@@ -41,6 +41,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
4141 context . subscriptions . push ( d ) ;
4242 context . subscriptions . push ( vscode . commands . registerCommand ( 'npm.runSelectedScript' , runSelectedScript ) ) ;
4343 context . subscriptions . push ( addJSONProviders ( httpRequest . xhr ) ) ;
44+
45+ if ( await hasPackageJson ( ) ) {
46+ vscode . commands . executeCommand ( 'setContext' , 'npm:showScriptExplorer' , true ) ;
47+ }
4448}
4549
4650function registerTaskProvider ( context : vscode . ExtensionContext ) : vscode . Disposable | undefined {
Original file line number Diff line number Diff line change @@ -262,6 +262,22 @@ export function getPackageJsonUriFromTask(task: Task): Uri | null {
262262 return null ;
263263}
264264
265+ export async function hasPackageJson ( ) : Promise < boolean > {
266+ let folders = workspace . workspaceFolders ;
267+ if ( ! folders ) {
268+ return false ;
269+ }
270+ for ( const folder of folders ) {
271+ if ( folder . uri . scheme === 'file' ) {
272+ let packageJson = path . join ( folder . uri . fsPath , 'package.json' ) ;
273+ if ( await exists ( packageJson ) ) {
274+ return true ;
275+ }
276+ }
277+ }
278+ return false ;
279+ }
280+
265281async function exists ( file : string ) : Promise < boolean > {
266282 return new Promise < boolean > ( ( resolve , _reject ) => {
267283 fs . exists ( file , ( value ) => {
You can’t perform that action at this time.
0 commit comments