chore(vscode): update to 1.56.0
This commit is contained in:
@ -18,6 +18,7 @@ module.exports = withBrowserDefaults({
|
||||
filename: 'npmBrowserMain.js'
|
||||
},
|
||||
node: {
|
||||
'child_process': 'empty'
|
||||
'child_process': 'empty',
|
||||
'which': 'empty'
|
||||
}
|
||||
});
|
||||
|
@ -24,11 +24,13 @@
|
||||
"minimatch": "^3.0.4",
|
||||
"request-light": "^0.4.0",
|
||||
"vscode-nls": "^4.1.1",
|
||||
"which": "^2.0.2",
|
||||
"which-pm": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/minimatch": "^3.0.3",
|
||||
"@types/node": "^12.19.9"
|
||||
"@types/node": "^12.19.9",
|
||||
"@types/which": "^2.0.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"which-pm/load-yaml-file/**/argparse": "1.0.9"
|
||||
@ -42,6 +44,13 @@
|
||||
"workspaceContains:package.json",
|
||||
"onView:npm"
|
||||
],
|
||||
"capabilities": {
|
||||
"virtualWorkspaces": false,
|
||||
"untrustedWorkspaces": {
|
||||
"supported": "limited",
|
||||
"description": "%workspaceTrust%"
|
||||
}
|
||||
},
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"description": "Extension to add task support for npm scripts.",
|
||||
"displayName": "NPM support for VS Code",
|
||||
"workspaceTrust": "This extension calls the `tasks.executeTask()` API, which requires trust to run.",
|
||||
"config.npm.autoDetect": "Controls whether npm scripts should be automatically detected.",
|
||||
"config.npm.runSilent": "Run npm commands with the `--silent` option.",
|
||||
"config.npm.packageManager": "The package manager used to run scripts.",
|
||||
|
@ -29,8 +29,8 @@ export interface IJSONContribution {
|
||||
resolveSuggestion?(resourceUri: Uri | undefined, item: CompletionItem): Thenable<CompletionItem | null> | null;
|
||||
}
|
||||
|
||||
export function addJSONProviders(xhr: XHRRequest, canRunNPM: boolean): Disposable {
|
||||
const contributions = [new PackageJSONContribution(xhr, canRunNPM), new BowerJSONContribution(xhr)];
|
||||
export function addJSONProviders(xhr: XHRRequest, npmCommandPath: string | undefined): Disposable {
|
||||
const contributions = [new PackageJSONContribution(xhr, npmCommandPath), new BowerJSONContribution(xhr)];
|
||||
const subscriptions: Disposable[] = [];
|
||||
contributions.forEach(contribution => {
|
||||
const selector = contribution.getDocumentSelector();
|
||||
@ -136,7 +136,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
}
|
||||
if (collectPromise) {
|
||||
return collectPromise.then(() => {
|
||||
if (items.length > 0) {
|
||||
if (items.length > 0 || isIncomplete) {
|
||||
return new CompletionList(items, isIncomplete);
|
||||
}
|
||||
return null;
|
||||
|
@ -14,7 +14,6 @@ import { dirname } from 'path';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
const LIMIT = 40;
|
||||
const SCOPED_LIMIT = 250;
|
||||
|
||||
const USER_AGENT = 'Visual Studio Code';
|
||||
|
||||
@ -33,7 +32,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
return [{ language: 'json', scheme: '*', pattern: '**/package.json' }];
|
||||
}
|
||||
|
||||
public constructor(private xhr: XHRRequest, private canRunNPM: boolean) {
|
||||
public constructor(private xhr: XHRRequest, private npmCommandPath: string | undefined) {
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(_resource: Uri, result: ISuggestionsCollector): Thenable<any> {
|
||||
@ -53,7 +52,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
private isEnabled() {
|
||||
return this.canRunNPM || this.onlineEnabled();
|
||||
return this.npmCommandPath || this.onlineEnabled();
|
||||
}
|
||||
|
||||
private onlineEnabled() {
|
||||
@ -94,7 +93,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
|
||||
queryUrl = `https://api.npms.io/v2/search/suggestions?size=${LIMIT}&q=${encodeURIComponent(currentWord)}`;
|
||||
queryUrl = `https://registry.npmjs.org/-/v1/search?size=${LIMIT}&text=${encodeURIComponent(currentWord)}`;
|
||||
return this.xhr({
|
||||
url: queryUrl,
|
||||
agent: USER_AGENT
|
||||
@ -102,18 +101,17 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj && Array.isArray(obj)) {
|
||||
const results = <{ package: SearchPackageInfo; }[]>obj;
|
||||
if (obj && obj.objects && Array.isArray(obj.objects)) {
|
||||
const results = <{ package: SearchPackageInfo; }[]>obj.objects;
|
||||
for (const result of results) {
|
||||
this.processPackage(result.package, addValue, isLast, collector);
|
||||
}
|
||||
if (results.length === LIMIT) {
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
collector.setAsIncomplete();
|
||||
} else {
|
||||
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
|
||||
return 0;
|
||||
@ -155,7 +153,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
if (name.length < 4) {
|
||||
name = '';
|
||||
}
|
||||
let queryUrl = `https://api.npms.io/v2/search?q=scope:${scope}%20${name}&size=250`;
|
||||
let queryUrl = `https://registry.npmjs.com/-/v1/search?text=scope:${scope}%20${name}&size=250`;
|
||||
return this.xhr({
|
||||
url: queryUrl,
|
||||
agent: USER_AGENT
|
||||
@ -163,18 +161,16 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj && Array.isArray(obj.results)) {
|
||||
const objects = <{ package: SearchPackageInfo }[]>obj.results;
|
||||
if (obj && Array.isArray(obj.objects)) {
|
||||
const objects = <{ package: SearchPackageInfo; }[]>obj.objects;
|
||||
for (let object of objects) {
|
||||
this.processPackage(object.package, addValue, isLast, collector);
|
||||
}
|
||||
if (objects.length === SCOPED_LIMIT) {
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
collector.setAsIncomplete();
|
||||
} else {
|
||||
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
|
||||
}
|
||||
@ -272,8 +268,8 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
return undefined; // avoid unnecessary lookups
|
||||
}
|
||||
let info: ViewPackageInfo | undefined;
|
||||
if (this.canRunNPM) {
|
||||
info = await this.npmView(pack, resource);
|
||||
if (this.npmCommandPath) {
|
||||
info = await this.npmView(this.npmCommandPath, pack, resource);
|
||||
}
|
||||
if (!info && this.onlineEnabled()) {
|
||||
info = await this.npmjsView(pack);
|
||||
@ -281,11 +277,11 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
return info;
|
||||
}
|
||||
|
||||
private npmView(pack: string, resource: Uri | undefined): Promise<ViewPackageInfo | undefined> {
|
||||
private npmView(npmCommandPath: string, pack: string, resource: Uri | undefined): Promise<ViewPackageInfo | undefined> {
|
||||
return new Promise((resolve, _reject) => {
|
||||
const args = ['view', '--json', pack, 'description', 'dist-tags.latest', 'homepage', 'version'];
|
||||
let cwd = resource && resource.scheme === 'file' ? dirname(resource.fsPath) : undefined;
|
||||
cp.execFile(process.platform === 'win32' ? 'npm.cmd' : 'npm', args, { cwd }, (error, stdout) => {
|
||||
cp.execFile(npmCommandPath, args, { cwd }, (error, stdout) => {
|
||||
if (!error) {
|
||||
try {
|
||||
const content = JSON.parse(stdout);
|
||||
@ -305,21 +301,18 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
private async npmjsView(pack: string): Promise<ViewPackageInfo | undefined> {
|
||||
const queryUrl = 'https://api.npms.io/v2/package/' + encodeURIComponent(pack);
|
||||
const queryUrl = 'https://registry.npmjs.org/' + encodeURIComponent(pack);
|
||||
try {
|
||||
const success = await this.xhr({
|
||||
url: queryUrl,
|
||||
agent: USER_AGENT
|
||||
});
|
||||
const obj = JSON.parse(success.responseText);
|
||||
const metadata = obj?.collected?.metadata;
|
||||
if (metadata) {
|
||||
return {
|
||||
description: metadata.description || '',
|
||||
version: metadata.version,
|
||||
homepage: metadata.links?.homepage || ''
|
||||
};
|
||||
}
|
||||
return {
|
||||
description: obj.description || '',
|
||||
version: Object.keys(obj.versions).pop(),
|
||||
homepage: obj.homepage || ''
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
//ignore
|
||||
|
@ -8,7 +8,7 @@ import * as vscode from 'vscode';
|
||||
import { addJSONProviders } from './features/jsonContributions';
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, false));
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, undefined));
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
|
@ -11,6 +11,7 @@ import { NpmScriptsTreeDataProvider } from './npmView';
|
||||
import { getPackageManager, invalidateTasksCache, NpmTaskProvider, hasPackageJson } from './tasks';
|
||||
import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHover';
|
||||
import { NpmScriptLensProvider } from './npmScriptLens';
|
||||
import * as which from 'which';
|
||||
|
||||
let treeDataProvider: NpmScriptsTreeDataProvider | undefined;
|
||||
|
||||
@ -30,8 +31,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
}
|
||||
}));
|
||||
|
||||
const canRunNPM = canRunNpmInCurrentWorkspace();
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, canRunNPM));
|
||||
const npmCommandPath = await getNPMCommandPath();
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, npmCommandPath));
|
||||
registerTaskProvider(context);
|
||||
|
||||
treeDataProvider = registerExplorer(context);
|
||||
@ -71,6 +72,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
context.subscriptions.push(new NpmScriptLensProvider());
|
||||
}
|
||||
|
||||
async function getNPMCommandPath(): Promise<string | undefined> {
|
||||
if (canRunNpmInCurrentWorkspace()) {
|
||||
try {
|
||||
return await which(process.platform === 'win32' ? 'npm.cmd' : 'npm');
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function canRunNpmInCurrentWorkspace() {
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
return vscode.workspace.workspaceFolders.some(f => f.uri.scheme === 'file');
|
||||
|
@ -370,7 +370,23 @@ export async function hasPackageJson(): Promise<boolean> {
|
||||
const timeout = setTimeout(() => token.cancel(), 1000);
|
||||
const files = await workspace.findFiles('**/package.json', undefined, 1, token.token);
|
||||
clearTimeout(timeout);
|
||||
return files.length > 0;
|
||||
return files.length > 0 || await hasRootPackageJson();
|
||||
}
|
||||
|
||||
async function hasRootPackageJson(): 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> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../shared.tsconfig.json",
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out"
|
||||
},
|
||||
|
@ -12,6 +12,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.9.tgz#990ad687ad8b26ef6dcc34a4f69c33d40c95b679"
|
||||
integrity sha512-yj0DOaQeUrk3nJ0bd3Y5PeDRJ6W0r+kilosLA+dzF3dola/o9hxhMSg2sFvVcA2UHS5JSOsZp4S0c1OEXc4m1Q==
|
||||
|
||||
"@types/which@^2.0.0":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/which/-/which-2.0.0.tgz#446d35586611dee657120de8e0457382a658fc25"
|
||||
integrity sha512-JHTNOEpZnACQdsTojWggn+SQ8IucfqEhtz7g8Z0G67WdSj4x3F0X5I2c/CVcl8z/QukGrIHeQ/N49v1au74XFQ==
|
||||
|
||||
agent-base@4:
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.0.tgz#9838b5c3392b962bad031e6a4c5e1024abec45ce"
|
||||
@ -130,6 +135,11 @@ is-number@^7.0.0:
|
||||
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
|
||||
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
|
||||
|
||||
isexe@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
|
||||
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
|
||||
|
||||
js-yaml@^3.13.0:
|
||||
version "3.14.0"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
|
||||
@ -257,3 +267,10 @@ which-pm@^2.0.0:
|
||||
dependencies:
|
||||
load-yaml-file "^0.2.0"
|
||||
path-exists "^4.0.0"
|
||||
|
||||
which@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
|
||||
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
|
||||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
Reference in New Issue
Block a user