mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +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": [
|
"activationEvents": [
|
||||||
"onCommand:workbench.action.tasks.runTask",
|
"onCommand:workbench.action.tasks.runTask",
|
||||||
"onLanguage:json",
|
"onLanguage:json",
|
||||||
|
"workspaceContains:package.json",
|
||||||
"onView:npm"
|
"onView:npm"
|
||||||
],
|
],
|
||||||
"contributes": {
|
"contributes": {
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
{
|
{
|
||||||
"id": "npm",
|
"id": "npm",
|
||||||
"name": "%view.name%",
|
"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 * as vscode from 'vscode';
|
||||||
import { addJSONProviders } from './features/jsonContributions';
|
import { addJSONProviders } from './features/jsonContributions';
|
||||||
import { NpmScriptsTreeDataProvider } from './npmView';
|
import { NpmScriptsTreeDataProvider } from './npmView';
|
||||||
import { invalidateTasksCache, NpmTaskProvider } from './tasks';
|
import { invalidateTasksCache, NpmTaskProvider, hasPackageJson } from './tasks';
|
||||||
import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHover';
|
import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHover';
|
||||||
import { runSelectedScript } from './commands';
|
import { runSelectedScript } from './commands';
|
||||||
|
|
||||||
|
@ -41,6 +41,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||||
context.subscriptions.push(d);
|
context.subscriptions.push(d);
|
||||||
context.subscriptions.push(vscode.commands.registerCommand('npm.runSelectedScript', runSelectedScript));
|
context.subscriptions.push(vscode.commands.registerCommand('npm.runSelectedScript', runSelectedScript));
|
||||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
||||||
|
|
||||||
|
if (await hasPackageJson()) {
|
||||||
|
vscode.commands.executeCommand('setContext', 'npm:showScriptExplorer', true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined {
|
function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined {
|
||||||
|
|
|
@ -262,6 +262,22 @@ export function getPackageJsonUriFromTask(task: Task): Uri | null {
|
||||||
return 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> {
|
async function exists(file: string): Promise<boolean> {
|
||||||
return new Promise<boolean>((resolve, _reject) => {
|
return new Promise<boolean>((resolve, _reject) => {
|
||||||
fs.exists(file, (value) => {
|
fs.exists(file, (value) => {
|
||||||
|
|
Loading…
Reference in a new issue