Skip to content

Commit

Permalink
Merge pull request #660 from microsoft/sandy081/prerelease-validate-e…
Browse files Browse the repository at this point in the history
…ngine

fix: validate engine for prereleases
  • Loading branch information
sandy081 committed Nov 29, 2021
2 parents 2c60208 + e675eca commit f710e83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ export class ManifestProcessor extends BaseProcessor {

const extensionKind = getExtensionKind(manifest);
const target = options.target;
const preRelease = options.preRelease;

if (target) {
if (target || preRelease) {
let engineVersion: string;

try {
Expand All @@ -399,14 +400,23 @@ export class ManifestProcessor extends BaseProcessor {
throw new Error('Failed to parse semver of engines.vscode');
}

if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.61')) {
throw new Error(
`Platform specific extension is supported by VS Code >=1.61. Current 'engines.vscode' is '${manifest.engines['vscode']}'.`
);
if (target) {
if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.61')) {
throw new Error(
`Platform specific extension is supported by VS Code >=1.61. Current 'engines.vscode' is '${manifest.engines['vscode']}'.`
);
}
if (!Targets.has(target)) {
throw new Error(`'${target}' is not a valid VS Code target. Valid targets: ${[...Targets].join(', ')}`);
}
}

if (!Targets.has(target)) {
throw new Error(`'${target}' is not a valid VS Code target. Valid targets: ${[...Targets].join(', ')}`);
if (preRelease) {
if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.63')) {
throw new Error(
`Pre-release versions are supported by VS Code >=1.63. Current 'engines.vscode' is '${manifest.engines['vscode']}'.`
);
}
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ describe('toVsixManifest', () => {
});

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

const raw = await _toVsixManifest(manifest, [], { preRelease: true });
const xmlManifest = await parseXmlManifest(raw);
Expand All @@ -1650,13 +1650,25 @@ describe('toVsixManifest', () => {
});

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

const raw = await _toVsixManifest(manifest, []);
const xmlManifest = await parseXmlManifest(raw);

assertMissingProperty(xmlManifest, 'Microsoft.VisualStudio.Code.PreRelease');
});

it('should throw when targeting an old VS Code version with --pre-release', async () => {
const manifest = createManifest({ engines: { vscode: '>=1.62.0' } });

try {
await _toVsixManifest(manifest, [], { preRelease: true });
} catch (err: any) {
return assert.ok(/>=1.63/.test(err.message));
}

throw new Error('Should not reach here');
});
});

describe('qna', () => {
Expand Down

0 comments on commit f710e83

Please sign in to comment.