Skip to content

Commit 1dcedef

Browse files
authored
feat: support pricing model in the manifest file (#749)
* feat: support pricing model in the manifest file * feat: make pricing value case insensitive * Revert "feat: make pricing value case insensitive" This reverts commit 29d1fb4.
1 parent 2589114 commit 1dcedef

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/manifest.ts

+1
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

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export interface VSIX {
172172
localizedLanguages: string;
173173
preRelease: boolean;
174174
sponsorLink: string;
175+
pricing: string;
175176
}
176177

177178
export class BaseProcessor implements IProcessor {
@@ -475,6 +476,7 @@ export class ManifestProcessor extends BaseProcessor {
475476
target,
476477
engine: manifest.engines['vscode'],
477478
description: manifest.description ?? '',
479+
pricing: manifest.pricing ?? 'Free',
478480
categories: (manifest.categories ?? []).join(','),
479481
flags: flags.join(' '),
480482
links: {
@@ -1191,6 +1193,10 @@ export function validateManifest(manifest: Manifest): Manifest {
11911193
throw new Error('Manifest missing field: version');
11921194
}
11931195

1196+
if (manifest.pricing && !['Free', 'Trial'].includes(manifest.pricing)) {
1197+
throw new Error('Pricing should be Free or Trial');
1198+
}
1199+
11941200
validateVersion(manifest.version);
11951201

11961202
if (!manifest.engines) {
@@ -1404,6 +1410,8 @@ export async function toVsixManifest(vsix: VSIX): Promise<string> {
14041410
: ''
14051411
}
14061412
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="${escape(vsix.githubMarkdown)}" />
1413+
<Property Id="Microsoft.VisualStudio.Services.Content.Pricing" Value="${escape(vsix.pricing)}"/>
1414+
14071415
${
14081416
vsix.enableMarketplaceQnA !== undefined
14091417
? `<Property Id="Microsoft.VisualStudio.Services.EnableMarketplaceQnA" Value="${escape(

src/test/package.test.ts

+14
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)