mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
use --json
This commit is contained in:
parent
8cbd7355ee
commit
4284a8ff20
|
@ -231,8 +231,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
const currentKey = location.path[location.path.length - 1];
|
||||
if (typeof currentKey === 'string') {
|
||||
return this.npmView(currentKey).then(info => {
|
||||
try {
|
||||
const latest = info && info['dist-tags.latest'];
|
||||
const latest = info.distTagsLatest;
|
||||
if (latest) {
|
||||
let name = JSON.stringify(latest);
|
||||
let proposal = new CompletionItem(name);
|
||||
|
@ -255,9 +254,6 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)');
|
||||
result.add(proposal);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return 0;
|
||||
}, () => {
|
||||
return 0;
|
||||
|
@ -284,42 +280,30 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
}
|
||||
|
||||
private getInfo(pack: string): Thenable<string[]> {
|
||||
return new Promise((resolve) => {
|
||||
return this.npmView(pack).then(info => {
|
||||
const result: string[] = [];
|
||||
result.push(info.description || '');
|
||||
result.push(info['dist-tags.latest'] ? localize('json.npm.version.hover', 'Latest version: {0}', info['dist-tags.latest']) : '');
|
||||
result.push(info.distTagsLatest ? localize('json.npm.version.hover', 'Latest version: {0}', info.distTagsLatest) : '');
|
||||
result.push(info.homepage || '');
|
||||
return resolve(result);
|
||||
}).catch(() => {
|
||||
return resolve([]);
|
||||
});
|
||||
return result;
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
private npmView(pack: string): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
const command = 'npm view ' + pack + ' description dist-tags.latest homepage';
|
||||
private npmView(pack: string): Promise<PackageInfo> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const command = 'npm view --json ' + pack + ' description dist-tags.latest homepage';
|
||||
cp.exec(command, (error, stdout) => {
|
||||
if (error) {
|
||||
return resolve();
|
||||
}
|
||||
const lines = stdout.split('\n');
|
||||
if (lines.length) {
|
||||
const info: any = {};
|
||||
lines.forEach((line) => {
|
||||
const nameval = line.split(' = ');
|
||||
if (nameval.length === 2) {
|
||||
/* tslint:disable:no-unexternalized-strings */
|
||||
const fq = nameval[1].indexOf("'");
|
||||
const lq = nameval[1].lastIndexOf("'");
|
||||
const val = nameval[1].slice(fq + 1, lq).replace("\'", "'");
|
||||
/* tslint:enable:no-unexternalized-strings */
|
||||
info[nameval[0]] = val;
|
||||
return reject();
|
||||
}
|
||||
const content = JSON.parse(stdout);
|
||||
resolve({
|
||||
description: content['description'],
|
||||
distTagsLatest: content['dist-tags.latest'],
|
||||
homepage: content['homepage']
|
||||
});
|
||||
return resolve(info);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -339,3 +323,9 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
interface PackageInfo {
|
||||
description: string;
|
||||
distTagsLatest?: string;
|
||||
homepage?: string;
|
||||
}
|
Loading…
Reference in a new issue