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