Skip to content

Commit

Permalink
Merge pull request #732 from microsoft/sandy081/sponsorExtension
Browse files Browse the repository at this point in the history
feat: support sponsoring extension
  • Loading branch information
sandy081 committed May 30, 2022
2 parents 3826665 + 9e7825d commit 2ec05b1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface Manifest {
enabledApiProposals?: readonly string[];
qna?: 'marketplace' | string | false;
extensionKind?: ExtensionKind | ExtensionKind[];
sponsor?: string;

// optional (npm)
author?: string | Person;
Expand Down
9 changes: 9 additions & 0 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export interface VSIX {
extensionKind: string;
localizedLanguages: string;
preRelease: boolean;
sponsorLink: string;
}

export class BaseProcessor implements IProcessor {
Expand Down Expand Up @@ -453,6 +454,7 @@ export class ManifestProcessor extends BaseProcessor {
.join(',')
: '',
preRelease: !!this.options.preRelease,
sponsorLink: manifest.sponsor || '',
};

if (isGitHub) {
Expand Down Expand Up @@ -603,6 +605,7 @@ export class TagsProcessor extends BaseProcessor {
);

const webExensionTags = isWebKind(this.manifest) ? ['__web_extension'] : [];
const sponsorTags = this.manifest.sponsor ? ['__sponsor_extension'] : [];

const tags = new Set([
...keywords,
Expand All @@ -620,6 +623,7 @@ export class TagsProcessor extends BaseProcessor {
...grammars,
...descriptionKeywords,
...webExensionTags,
...sponsorTags,
]);

this.tags = [...tags].filter(tag => !!tag);
Expand Down Expand Up @@ -1299,6 +1303,11 @@ export async function toVsixManifest(vsix: VSIX): Promise<string> {
<Property Id="Microsoft.VisualStudio.Code.ExtensionKind" Value="${escape(vsix.extensionKind)}" />
<Property Id="Microsoft.VisualStudio.Code.LocalizedLanguages" Value="${escape(vsix.localizedLanguages)}" />
${vsix.preRelease ? `<Property Id="Microsoft.VisualStudio.Code.PreRelease" Value="${escape(vsix.preRelease)}" />` : ''}
${
vsix.sponsorLink
? `<Property Id="Microsoft.VisualStudio.Code.SponsorLink" Value="${escape(vsix.sponsorLink)}" />`
: ''
}
${
!vsix.links.repository
? ''
Expand Down
28 changes: 28 additions & 0 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,34 @@ describe('toVsixManifest', () => {
assertProperty(xmlManifest, 'Microsoft.VisualStudio.Code.PreRelease', 'true');
});

it('should add sponsor link property', () => {
const sponsor = 'https://foo.bar';
const manifest: Manifest = {
name: 'test',
publisher: 'mocha',
version: '0.0.1',
description: 'test extension',
engines: Object.create(null),
sponsor,
};

return _toVsixManifest(manifest, [])
.then(parseXmlManifest)
.then(result => {
const properties = result.PackageManifest.Metadata[0].Properties[0].Property;
const sponsorLinkProp = properties.find(p => p.$.Id === 'Microsoft.VisualStudio.Code.SponsorLink');
assert.strictEqual(sponsorLinkProp?.$.Value, sponsor);
});
});

it('should automatically add sponsor tag for extension with sponsor link', async () => {
const manifest = createManifest({ sponsor: 'https://foo.bar' });
const vsixManifest = await _toVsixManifest(manifest, []);
const result = await parseXmlManifest(vsixManifest);

assert.ok(result.PackageManifest.Metadata[0].Tags[0].split(',').includes('__sponsor_extension'));
});

it('should add prerelease property when --pre-release flag is passed when engine property is for insiders', async () => {
const manifest = createManifest({ engines: { vscode: '>=1.64.0-insider' } });

Expand Down

0 comments on commit 2ec05b1

Please sign in to comment.