Skip to content

Commit

Permalink
fix: change sponsor to object with url property
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed May 31, 2022
1 parent ded4841 commit 75456f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface Manifest {
enabledApiProposals?: readonly string[];
qna?: 'marketplace' | string | false;
extensionKind?: ExtensionKind | ExtensionKind[];
sponsor?: string;
sponsor?: { url: string };

// optional (npm)
author?: string | Person;
Expand Down
8 changes: 4 additions & 4 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export class ManifestProcessor extends BaseProcessor {
.join(',')
: '',
preRelease: !!this.options.preRelease,
sponsorLink: manifest.sponsor || '',
sponsorLink: manifest.sponsor?.url || '',
};

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

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

const tags = new Set([
...keywords,
Expand Down Expand Up @@ -1224,14 +1224,14 @@ export function validateManifest(manifest: Manifest): Manifest {
if (manifest.sponsor) {
let isValidSponsorUrl = true;
try {
const sponsorUrl = new url.URL(manifest.sponsor);
const sponsorUrl = new url.URL(manifest.sponsor.url);
isValidSponsorUrl = /^(https|http):$/i.test(sponsorUrl.protocol);
} catch (error) {
isValidSponsorUrl = false;
}
if (!isValidSponsorUrl) {
throw new Error(
`Manifest contains invalid value '${manifest.sponsor}' in the 'sponsor' property. It must be a valid URL with a HTTP or HTTPS protocol.`
`Manifest contains invalid value '${manifest.sponsor.url}' in the 'sponsor' property. It must be a valid URL with a HTTP or HTTPS protocol.`
);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ describe('validateManifest', () => {
});

it('should validate sponsor', () => {
assert.throws(() => validateManifest(createManifest({ sponsor: 'hello' })));
assert.throws(() => validateManifest(createManifest({ sponsor: 'www.foo.com' })));
validateManifest(createManifest({ sponsor: 'https://foo.bar' }));
validateManifest(createManifest({ sponsor: 'http://www.foo.com' }));
assert.throws(() => validateManifest(createManifest({ sponsor: { url: 'hello' } })));
assert.throws(() => validateManifest(createManifest({ sponsor: { url: 'www.foo.com' } })));
validateManifest(createManifest({ sponsor: { url: 'https://foo.bar' } }));
validateManifest(createManifest({ sponsor: { url: 'http://www.foo.com' } }));
});
});

Expand Down Expand Up @@ -1668,7 +1668,7 @@ describe('toVsixManifest', () => {
});

it('should add sponsor link property', () => {
const sponsor = 'https://foo.bar';
const sponsor = { url: 'https://foo.bar' };
const manifest: Manifest = {
name: 'test',
publisher: 'mocha',
Expand All @@ -1683,12 +1683,12 @@ describe('toVsixManifest', () => {
.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);
assert.strictEqual(sponsorLinkProp?.$.Value, sponsor.url);
});
});

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

Expand Down

0 comments on commit 75456f2

Please sign in to comment.