mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Show the npm script explorer when there is a top level package.json
This commit is contained in:
parent
6aa6b3e2ed
commit
af4bfe6ef4
|
@ -31,6 +31,7 @@
|
|||
"activationEvents": [
|
||||
"onCommand:workbench.action.tasks.runTask",
|
||||
"onLanguage:json",
|
||||
"workspaceContains:package.json",
|
||||
"onView:npm"
|
||||
],
|
||||
"contributes": {
|
||||
|
@ -47,7 +48,7 @@
|
|||
{
|
||||
"id": "npm",
|
||||
"name": "%view.name%",
|
||||
"when": "config.npm.enableScriptExplorer"
|
||||
"when": "npm:showScriptExplorer || config.npm.enableScriptExplorer"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ import * as httpRequest from 'request-light';
|
|||
import * as vscode from 'vscode';
|
||||
import { addJSONProviders } from './features/jsonContributions';
|
||||
import { NpmScriptsTreeDataProvider } from './npmView';
|
||||
import { invalidateTasksCache, NpmTaskProvider } from './tasks';
|
||||
import { invalidateTasksCache, NpmTaskProvider, hasPackageJson } from './tasks';
|
||||
import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHover';
|
||||
import { runSelectedScript } from './commands';
|
||||
|
||||
|
@ -41,6 +41,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
|||
context.subscriptions.push(d);
|
||||
context.subscriptions.push(vscode.commands.registerCommand('npm.runSelectedScript', runSelectedScript));
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
||||
|
||||
if (await hasPackageJson()) {
|
||||
vscode.commands.executeCommand('setContext', 'npm:showScriptExplorer', true);
|
||||
}
|
||||
}
|
||||
|
||||
function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined {
|
||||
|
|
|
@ -262,6 +262,22 @@ export function getPackageJsonUriFromTask(task: Task): Uri | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
export async function hasPackageJson(): Promise<boolean> {
|
||||
let folders = workspace.workspaceFolders;
|
||||
if (!folders) {
|
||||
return false;
|
||||
}
|
||||
for (const folder of folders) {
|
||||
if (folder.uri.scheme === 'file') {
|
||||
let packageJson = path.join(folder.uri.fsPath, 'package.json');
|
||||
if (await exists(packageJson)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function exists(file: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, _reject) => {
|
||||
fs.exists(file, (value) => {
|
||||
|
|
Loading…
Reference in a new issue