Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/extensionManagement/node/extensionManagementUtil.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { buffer, ExtractError } from '../../../base/node/zip.js';
7
import { localize } from '../../../nls.js';
8
import { toExtensionManagementError } from '../common/abstractExtensionManagementService.js';
9
import { ExtensionManagementError, ExtensionManagementErrorCode } from '../common/extensionManagement.js';
10
import { IExtensionManifest } from '../../extensions/common/extensions.js';
11
12
export function fromExtractError(e: Error): ExtensionManagementError {
13
let errorCode = ExtensionManagementErrorCode.Extract;
14
if (e instanceof ExtractError) {
15
if (e.type === 'CorruptZip') {
16
errorCode = ExtensionManagementErrorCode.CorruptZip;
17
} else if (e.type === 'Incomplete') {
18
errorCode = ExtensionManagementErrorCode.IncompleteZip;
19
}
20
}
21
return toExtensionManagementError(e, errorCode);
22
}
23
24
export async function getManifest(vsixPath: string): Promise<IExtensionManifest> {
25
let data;
26
try {
27
data = await buffer(vsixPath, 'extension/package.json');
28
} catch (e) {
29
throw fromExtractError(e);
30
}
31
32
try {
33
return JSON.parse(data.toString('utf8'));
34
} catch (err) {
35
throw new ExtensionManagementError(localize('invalidManifest', "VSIX invalid: package.json is not a JSON file."), ExtensionManagementErrorCode.Invalid);
36
}
37
}
38
39