in src/package.ts [1138:1219]
export function validateManifest(manifest: Manifest): Manifest {
validateExtensionName(manifest.name);
if (!manifest.version) {
throw new Error('Manifest missing field: version');
}
validateVersion(manifest.version);
if (!manifest.engines) {
throw new Error('Manifest missing field: engines');
}
if (!manifest.engines['vscode']) {
throw new Error('Manifest missing field: engines.vscode');
}
validateEngineCompatibility(manifest.engines['vscode']);
const hasActivationEvents = !!manifest.activationEvents;
const hasMain = !!manifest.main;
const hasBrowser = !!manifest.browser;
if (hasActivationEvents) {
if (!hasMain && !hasBrowser) {
throw new Error(
"Manifest needs either a 'main' or 'browser' property, given it has a 'activationEvents' property."
);
}
} else if (hasMain) {
throw new Error("Manifest needs the 'activationEvents' property, given it has a 'main' property.");
} else if (hasBrowser) {
throw new Error("Manifest needs the 'activationEvents' property, given it has a 'browser' property.");
}
if (manifest.devDependencies && manifest.devDependencies['@types/vscode']) {
validateVSCodeTypesCompatibility(manifest.engines['vscode'], manifest.devDependencies['@types/vscode']);
}
if (/\.svg$/i.test(manifest.icon || '')) {
throw new Error(`SVGs can't be used as icons: ${manifest.icon}`);
}
(manifest.badges ?? []).forEach(badge => {
const decodedUrl = decodeURI(badge.url);
const srcUrl = new url.URL(decodedUrl);
if (!/^https:$/i.test(srcUrl.protocol)) {
throw new Error(`Badge URLs must come from an HTTPS source: ${badge.url}`);
}
if (/\.svg$/i.test(srcUrl.pathname) && !isHostTrusted(srcUrl)) {
throw new Error(`Badge SVGs are restricted. Please use other file image formats, such as PNG: ${badge.url}`);
}
});
Object.keys(manifest.dependencies || {}).forEach(dep => {
if (dep === 'vscode') {
throw new Error(
`You should not depend on 'vscode' in your 'dependencies'. Did you mean to add it to 'devDependencies'?`
);
}
});
if (manifest.extensionKind) {
const extensionKinds = Array.isArray(manifest.extensionKind) ? manifest.extensionKind : [manifest.extensionKind];
for (const kind of extensionKinds) {
if (!ValidExtensionKinds.has(kind)) {
throw new Error(
`Manifest contains invalid value '${kind}' in the 'extensionKind' property. Allowed values are ${[
...ValidExtensionKinds,
]
.map(k => `'${k}'`)
.join(', ')}.`
);
}
}
}
return manifest;
}