Skip to content

Commit 1492bca

Browse files
authored
Language contributions shouldn't force an entrypoint (#839)
* remove pre-commit hooks * language contributions shouldn't force an entrypoint fixes #826
1 parent 2285266 commit 1492bca

File tree

2 files changed

+87
-83
lines changed

2 files changed

+87
-83
lines changed

src/package.ts

Lines changed: 74 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export interface VSIX {
180180
}
181181

182182
export class BaseProcessor implements IProcessor {
183-
constructor(protected manifest: Manifest) {}
183+
constructor(protected manifest: Manifest) { }
184184
assets: IAsset[] = [];
185185
tags: string[] = [];
186186
vsix: VSIX = Object.create(null);
@@ -499,8 +499,8 @@ export class ManifestProcessor extends BaseProcessor {
499499
localizedLanguages:
500500
manifest.contributes && manifest.contributes.localizations
501501
? manifest.contributes.localizations
502-
.map(loc => loc.localizedLanguageName ?? loc.languageName ?? loc.languageId)
503-
.join(',')
502+
.map(loc => loc.localizedLanguageName ?? loc.languageName ?? loc.languageId)
503+
.join(',')
504504
: '',
505505
preRelease: !!this.options.preRelease,
506506
sponsorLink: manifest.sponsor?.url || '',
@@ -801,10 +801,9 @@ export class MarkdownProcessor extends BaseProcessor {
801801
// Issue in own repository
802802
result =
803803
prefix +
804-
`[#${issueNumber}](${
805-
this.isGitHub
806-
? urljoin(this.repositoryUrl, 'issues', issueNumber)
807-
: urljoin(this.repositoryUrl, '-', 'issues', issueNumber)
804+
`[#${issueNumber}](${this.isGitHub
805+
? urljoin(this.repositoryUrl, 'issues', issueNumber)
806+
: urljoin(this.repositoryUrl, '-', 'issues', issueNumber)
808807
})`;
809808
}
810809

@@ -1061,8 +1060,8 @@ function getExtensionKind(manifest: Manifest): ExtensionKind[] {
10611060
const result: ExtensionKind[] = Array.isArray(manifest.extensionKind)
10621061
? manifest.extensionKind
10631062
: manifest.extensionKind === 'ui'
1064-
? ['ui', 'workspace']
1065-
: [manifest.extensionKind];
1063+
? ['ui', 'workspace']
1064+
: [manifest.extensionKind];
10661065

10671066
// Add web kind if the extension can run as web extension
10681067
if (deduced.includes('web') && !result.includes('web')) {
@@ -1215,12 +1214,14 @@ export function validateManifest(manifest: Manifest): Manifest {
12151214
validateEngineCompatibility(engineVersion);
12161215

12171216
const hasActivationEvents = !!manifest.activationEvents;
1218-
const hasImplicitActivationEvents =
1217+
const hasImplicitLanguageActivationEvents = manifest.contributes?.languages;
1218+
const hasOtherImplicitActivationEvents =
12191219
manifest.contributes?.commands ||
12201220
manifest.contributes?.authentication ||
1221-
manifest.contributes?.languages ||
12221221
manifest.contributes?.customEditors ||
12231222
manifest.contributes?.views;
1223+
const hasImplicitActivationEvents = hasImplicitLanguageActivationEvents || hasOtherImplicitActivationEvents;
1224+
12241225
const hasMain = !!manifest.main;
12251226
const hasBrowser = !!manifest.browser;
12261227

@@ -1237,7 +1238,7 @@ export function validateManifest(manifest: Manifest): Manifest {
12371238
((engineVersion === '*' || semver.satisfies(parsedEngineVersion, '>=1.74', { includePrerelease: true })) &&
12381239
hasImplicitActivationEvents)
12391240
) {
1240-
if (!hasMain && !hasBrowser) {
1241+
if (!hasMain && !hasBrowser && (hasActivationEvents || !hasImplicitLanguageActivationEvents)) {
12411242
throw new Error(
12421243
"Manifest needs either a 'main' or 'browser' property, given it has a 'activationEvents' property."
12431244
);
@@ -1371,84 +1372,74 @@ export async function toVsixManifest(vsix: VSIX): Promise<string> {
13711372
<Tags>${escape(vsix.tags)}</Tags>
13721373
<Categories>${escape(vsix.categories)}</Categories>
13731374
<GalleryFlags>${escape(vsix.flags)}</GalleryFlags>
1374-
${
1375-
!vsix.badges
1376-
? ''
1377-
: `<Badges>${vsix.badges
1378-
.map(
1379-
badge =>
1380-
`<Badge Link="${escape(badge.href)}" ImgUri="${escape(badge.url)}" Description="${escape(
1381-
badge.description
1382-
)}" />`
1383-
)
1384-
.join('\n')}</Badges>`
1385-
}
1375+
${!vsix.badges
1376+
? ''
1377+
: `<Badges>${vsix.badges
1378+
.map(
1379+
badge =>
1380+
`<Badge Link="${escape(badge.href)}" ImgUri="${escape(badge.url)}" Description="${escape(
1381+
badge.description
1382+
)}" />`
1383+
)
1384+
.join('\n')}</Badges>`
1385+
}
13861386
<Properties>
13871387
<Property Id="Microsoft.VisualStudio.Code.Engine" Value="${escape(vsix.engine)}" />
13881388
<Property Id="Microsoft.VisualStudio.Code.ExtensionDependencies" Value="${escape(vsix.extensionDependencies)}" />
13891389
<Property Id="Microsoft.VisualStudio.Code.ExtensionPack" Value="${escape(vsix.extensionPack)}" />
13901390
<Property Id="Microsoft.VisualStudio.Code.ExtensionKind" Value="${escape(vsix.extensionKind)}" />
13911391
<Property Id="Microsoft.VisualStudio.Code.LocalizedLanguages" Value="${escape(vsix.localizedLanguages)}" />
13921392
${vsix.preRelease ? `<Property Id="Microsoft.VisualStudio.Code.PreRelease" Value="${escape(vsix.preRelease)}" />` : ''}
1393-
${
1394-
vsix.sponsorLink
1395-
? `<Property Id="Microsoft.VisualStudio.Code.SponsorLink" Value="${escape(vsix.sponsorLink)}" />`
1396-
: ''
1397-
}
1398-
${
1399-
!vsix.links.repository
1400-
? ''
1401-
: `<Property Id="Microsoft.VisualStudio.Services.Links.Source" Value="${escape(vsix.links.repository)}" />
1393+
${vsix.sponsorLink
1394+
? `<Property Id="Microsoft.VisualStudio.Code.SponsorLink" Value="${escape(vsix.sponsorLink)}" />`
1395+
: ''
1396+
}
1397+
${!vsix.links.repository
1398+
? ''
1399+
: `<Property Id="Microsoft.VisualStudio.Services.Links.Source" Value="${escape(vsix.links.repository)}" />
14021400
<Property Id="Microsoft.VisualStudio.Services.Links.Getstarted" Value="${escape(vsix.links.repository)}" />
1403-
${
1404-
vsix.links.github
1405-
? `<Property Id="Microsoft.VisualStudio.Services.Links.GitHub" Value="${escape(vsix.links.github)}" />`
1406-
: `<Property Id="Microsoft.VisualStudio.Services.Links.Repository" Value="${escape(
1407-
vsix.links.repository
1408-
)}" />`
1409-
}`
1410-
}
1411-
${
1412-
vsix.links.bugs
1413-
? `<Property Id="Microsoft.VisualStudio.Services.Links.Support" Value="${escape(vsix.links.bugs)}" />`
1414-
: ''
1415-
}
1416-
${
1417-
vsix.links.homepage
1418-
? `<Property Id="Microsoft.VisualStudio.Services.Links.Learn" Value="${escape(vsix.links.homepage)}" />`
1419-
: ''
1420-
}
1421-
${
1422-
vsix.galleryBanner.color
1423-
? `<Property Id="Microsoft.VisualStudio.Services.Branding.Color" Value="${escape(
1424-
vsix.galleryBanner.color
1425-
)}" />`
1426-
: ''
1427-
}
1428-
${
1429-
vsix.galleryBanner.theme
1430-
? `<Property Id="Microsoft.VisualStudio.Services.Branding.Theme" Value="${escape(
1431-
vsix.galleryBanner.theme
1432-
)}" />`
1433-
: ''
1434-
}
1401+
${vsix.links.github
1402+
? `<Property Id="Microsoft.VisualStudio.Services.Links.GitHub" Value="${escape(vsix.links.github)}" />`
1403+
: `<Property Id="Microsoft.VisualStudio.Services.Links.Repository" Value="${escape(
1404+
vsix.links.repository
1405+
)}" />`
1406+
}`
1407+
}
1408+
${vsix.links.bugs
1409+
? `<Property Id="Microsoft.VisualStudio.Services.Links.Support" Value="${escape(vsix.links.bugs)}" />`
1410+
: ''
1411+
}
1412+
${vsix.links.homepage
1413+
? `<Property Id="Microsoft.VisualStudio.Services.Links.Learn" Value="${escape(vsix.links.homepage)}" />`
1414+
: ''
1415+
}
1416+
${vsix.galleryBanner.color
1417+
? `<Property Id="Microsoft.VisualStudio.Services.Branding.Color" Value="${escape(
1418+
vsix.galleryBanner.color
1419+
)}" />`
1420+
: ''
1421+
}
1422+
${vsix.galleryBanner.theme
1423+
? `<Property Id="Microsoft.VisualStudio.Services.Branding.Theme" Value="${escape(
1424+
vsix.galleryBanner.theme
1425+
)}" />`
1426+
: ''
1427+
}
14351428
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="${escape(vsix.githubMarkdown)}" />
14361429
<Property Id="Microsoft.VisualStudio.Services.Content.Pricing" Value="${escape(vsix.pricing)}"/>
14371430
1438-
${
1439-
vsix.enableMarketplaceQnA !== undefined
1440-
? `<Property Id="Microsoft.VisualStudio.Services.EnableMarketplaceQnA" Value="${escape(
1441-
vsix.enableMarketplaceQnA
1442-
)}" />`
1443-
: ''
1444-
}
1445-
${
1446-
vsix.customerQnALink !== undefined
1447-
? `<Property Id="Microsoft.VisualStudio.Services.CustomerQnALink" Value="${escape(
1448-
vsix.customerQnALink
1449-
)}" />`
1450-
: ''
1451-
}
1431+
${vsix.enableMarketplaceQnA !== undefined
1432+
? `<Property Id="Microsoft.VisualStudio.Services.EnableMarketplaceQnA" Value="${escape(
1433+
vsix.enableMarketplaceQnA
1434+
)}" />`
1435+
: ''
1436+
}
1437+
${vsix.customerQnALink !== undefined
1438+
? `<Property Id="Microsoft.VisualStudio.Services.CustomerQnALink" Value="${escape(
1439+
vsix.customerQnALink
1440+
)}" />`
1441+
: ''
1442+
}
14521443
</Properties>
14531444
${vsix.license ? `<License>${escape(vsix.license)}</License>` : ''}
14541445
${vsix.icon ? `<Icon>${escape(vsix.icon)}</Icon>` : ''}
@@ -1460,8 +1451,8 @@ export async function toVsixManifest(vsix: VSIX): Promise<string> {
14601451
<Assets>
14611452
<Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" />
14621453
${vsix.assets
1463-
.map(asset => `<Asset Type="${escape(asset.type)}" Path="${escape(asset.path)}" Addressable="true" />`)
1464-
.join('\n')}
1454+
.map(asset => `<Asset Type="${escape(asset.type)}" Path="${escape(asset.path)}" Addressable="true" />`)
1455+
.join('\n')}
14651456
</Assets>
14661457
</PackageManifest>`;
14671458
}
@@ -1680,8 +1671,8 @@ function writeVsix(files: IFile[], packagePath: string): Promise<void> {
16801671
files.forEach(f =>
16811672
isInMemoryFile(f)
16821673
? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path, {
1683-
mode: f.mode,
1684-
})
1674+
mode: f.mode,
1675+
})
16851676
: zip.addFile(f.localPath, f.path, { mode: f.mode })
16861677
);
16871678
zip.end();

src/test/package.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,19 @@ describe('validateManifest', () => {
435435
})
436436
);
437437

438+
validateManifest(
439+
createManifest({
440+
engines: { vscode: '>=1.74.0' },
441+
contributes: {
442+
languages: [
443+
{
444+
id: 'typescript',
445+
}
446+
]
447+
}
448+
})
449+
);
450+
438451
assert.throws(() =>
439452
validateManifest(
440453
createManifest({

0 commit comments

Comments
 (0)