From 1492bca530c122adef852f0590a26b98b4442672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Tue, 21 Feb 2023 21:02:23 +0100 Subject: [PATCH] Language contributions shouldn't force an entrypoint (#839) * remove pre-commit hooks * language contributions shouldn't force an entrypoint fixes #826 --- src/package.ts | 157 ++++++++++++++++++--------------------- src/test/package.test.ts | 13 ++++ 2 files changed, 87 insertions(+), 83 deletions(-) diff --git a/src/package.ts b/src/package.ts index b404c1d8..677be0e6 100644 --- a/src/package.ts +++ b/src/package.ts @@ -180,7 +180,7 @@ export interface VSIX { } export class BaseProcessor implements IProcessor { - constructor(protected manifest: Manifest) {} + constructor(protected manifest: Manifest) { } assets: IAsset[] = []; tags: string[] = []; vsix: VSIX = Object.create(null); @@ -499,8 +499,8 @@ export class ManifestProcessor extends BaseProcessor { localizedLanguages: manifest.contributes && manifest.contributes.localizations ? manifest.contributes.localizations - .map(loc => loc.localizedLanguageName ?? loc.languageName ?? loc.languageId) - .join(',') + .map(loc => loc.localizedLanguageName ?? loc.languageName ?? loc.languageId) + .join(',') : '', preRelease: !!this.options.preRelease, sponsorLink: manifest.sponsor?.url || '', @@ -801,10 +801,9 @@ export class MarkdownProcessor extends BaseProcessor { // Issue in own repository result = prefix + - `[#${issueNumber}](${ - this.isGitHub - ? urljoin(this.repositoryUrl, 'issues', issueNumber) - : urljoin(this.repositoryUrl, '-', 'issues', issueNumber) + `[#${issueNumber}](${this.isGitHub + ? urljoin(this.repositoryUrl, 'issues', issueNumber) + : urljoin(this.repositoryUrl, '-', 'issues', issueNumber) })`; } @@ -1061,8 +1060,8 @@ function getExtensionKind(manifest: Manifest): ExtensionKind[] { const result: ExtensionKind[] = Array.isArray(manifest.extensionKind) ? manifest.extensionKind : manifest.extensionKind === 'ui' - ? ['ui', 'workspace'] - : [manifest.extensionKind]; + ? ['ui', 'workspace'] + : [manifest.extensionKind]; // Add web kind if the extension can run as web extension if (deduced.includes('web') && !result.includes('web')) { @@ -1215,12 +1214,14 @@ export function validateManifest(manifest: Manifest): Manifest { validateEngineCompatibility(engineVersion); const hasActivationEvents = !!manifest.activationEvents; - const hasImplicitActivationEvents = + const hasImplicitLanguageActivationEvents = manifest.contributes?.languages; + const hasOtherImplicitActivationEvents = manifest.contributes?.commands || manifest.contributes?.authentication || - manifest.contributes?.languages || manifest.contributes?.customEditors || manifest.contributes?.views; + const hasImplicitActivationEvents = hasImplicitLanguageActivationEvents || hasOtherImplicitActivationEvents; + const hasMain = !!manifest.main; const hasBrowser = !!manifest.browser; @@ -1237,7 +1238,7 @@ export function validateManifest(manifest: Manifest): Manifest { ((engineVersion === '*' || semver.satisfies(parsedEngineVersion, '>=1.74', { includePrerelease: true })) && hasImplicitActivationEvents) ) { - if (!hasMain && !hasBrowser) { + if (!hasMain && !hasBrowser && (hasActivationEvents || !hasImplicitLanguageActivationEvents)) { throw new Error( "Manifest needs either a 'main' or 'browser' property, given it has a 'activationEvents' property." ); @@ -1371,18 +1372,17 @@ export async function toVsixManifest(vsix: VSIX): Promise { ${escape(vsix.tags)} ${escape(vsix.categories)} ${escape(vsix.flags)} - ${ - !vsix.badges - ? '' - : `${vsix.badges - .map( - badge => - `` - ) - .join('\n')}` - } + ${!vsix.badges + ? '' + : `${vsix.badges + .map( + badge => + `` + ) + .join('\n')}` + } @@ -1390,65 +1390,56 @@ export async function toVsixManifest(vsix: VSIX): Promise { ${vsix.preRelease ? `` : ''} - ${ - vsix.sponsorLink - ? `` - : '' - } - ${ - !vsix.links.repository - ? '' - : ` + ${vsix.sponsorLink + ? `` + : '' + } + ${!vsix.links.repository + ? '' + : ` - ${ - vsix.links.github - ? `` - : `` - }` - } - ${ - vsix.links.bugs - ? `` - : '' - } - ${ - vsix.links.homepage - ? `` - : '' - } - ${ - vsix.galleryBanner.color - ? `` - : '' - } - ${ - vsix.galleryBanner.theme - ? `` - : '' - } + ${vsix.links.github + ? `` + : `` + }` + } + ${vsix.links.bugs + ? `` + : '' + } + ${vsix.links.homepage + ? `` + : '' + } + ${vsix.galleryBanner.color + ? `` + : '' + } + ${vsix.galleryBanner.theme + ? `` + : '' + } - ${ - vsix.enableMarketplaceQnA !== undefined - ? `` - : '' - } - ${ - vsix.customerQnALink !== undefined - ? `` - : '' - } + ${vsix.enableMarketplaceQnA !== undefined + ? `` + : '' + } + ${vsix.customerQnALink !== undefined + ? `` + : '' + } ${vsix.license ? `${escape(vsix.license)}` : ''} ${vsix.icon ? `${escape(vsix.icon)}` : ''} @@ -1460,8 +1451,8 @@ export async function toVsixManifest(vsix: VSIX): Promise { ${vsix.assets - .map(asset => ``) - .join('\n')} + .map(asset => ``) + .join('\n')} `; } @@ -1680,8 +1671,8 @@ function writeVsix(files: IFile[], packagePath: string): Promise { files.forEach(f => isInMemoryFile(f) ? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path, { - mode: f.mode, - }) + mode: f.mode, + }) : zip.addFile(f.localPath, f.path, { mode: f.mode }) ); zip.end(); diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 4933fc42..dcf94e1b 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -435,6 +435,19 @@ describe('validateManifest', () => { }) ); + validateManifest( + createManifest({ + engines: { vscode: '>=1.74.0' }, + contributes: { + languages: [ + { + id: 'typescript', + } + ] + } + }) + ); + assert.throws(() => validateManifest( createManifest({