Skip to content

Commit 11e68aa

Browse files
committed
feat: support pricing model in the manifest file
1 parent 955c760 commit 11e68aa

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface Manifest {
7979
dependencies?: { [name: string]: string };
8080
devDependencies?: { [name: string]: string };
8181
private?: boolean;
82+
pricing?: string;
8283

8384
// vsce
8485
vsce?: any;

src/package.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export interface VSIX {
129129
localizedLanguages: string;
130130
preRelease: boolean;
131131
sponsorLink: string;
132+
pricing: string;
132133
}
133134

134135
export class BaseProcessor implements IProcessor {
@@ -432,6 +433,7 @@ export class ManifestProcessor extends BaseProcessor {
432433
target,
433434
engine: manifest.engines['vscode'],
434435
description: manifest.description ?? '',
436+
pricing: manifest.pricing ?? 'Free',
435437
categories: (manifest.categories ?? []).join(','),
436438
flags: flags.join(' '),
437439
links: {
@@ -1148,6 +1150,10 @@ export function validateManifest(manifest: Manifest): Manifest {
11481150
throw new Error('Manifest missing field: version');
11491151
}
11501152

1153+
if (manifest.pricing && !['Free', 'Trial'].includes(manifest.pricing)) {
1154+
throw new Error('Pricing should be Free or Trial');
1155+
}
1156+
11511157
validateVersion(manifest.version);
11521158

11531159
if (!manifest.engines) {
@@ -1361,6 +1367,8 @@ export async function toVsixManifest(vsix: VSIX): Promise<string> {
13611367
: ''
13621368
}
13631369
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="${escape(vsix.githubMarkdown)}" />
1370+
<Property Id="Microsoft.VisualStudio.Services.Content.Pricing" Value="${escape(vsix.pricing)}"/>
1371+
13641372
${
13651373
vsix.enableMarketplaceQnA !== undefined
13661374
? `<Property Id="Microsoft.VisualStudio.Services.EnableMarketplaceQnA" Value="${escape(

src/test/package.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,13 @@ describe('validateManifest', () => {
390390
validateManifest(createManifest({ sponsor: { url: 'https://foo.bar' } }));
391391
validateManifest(createManifest({ sponsor: { url: 'http://www.foo.com' } }));
392392
});
393+
394+
it('should validate pricing', () => {
395+
assert.throws(() => validateManifest(createManifest({ pricing: 'Paid' })));
396+
validateManifest(createManifest({ pricing: 'Trial' }));
397+
validateManifest(createManifest({ pricing: 'Free' }));
398+
validateManifest(createManifest());
399+
});
393400
});
394401

395402
describe('toVsixManifest', () => {
@@ -1724,6 +1731,13 @@ describe('toVsixManifest', () => {
17241731

17251732
throw new Error('Should not reach here');
17261733
});
1734+
1735+
it('should identify trial version of an extension', async () => {
1736+
const manifest = createManifest({ pricing: 'Trial' });
1737+
var raw = await _toVsixManifest(manifest, []);
1738+
const xmlManifest = await parseXmlManifest(raw);
1739+
assertProperty(xmlManifest, 'Microsoft.VisualStudio.Services.Content.Pricing', 'Trial');
1740+
});
17271741
});
17281742

17291743
describe('qna', () => {

0 commit comments

Comments
 (0)