Skip to content

Commit f710e83

Browse files
authored
Merge pull request #660 from microsoft/sandy081/prerelease-validate-engine
fix: validate engine for prereleases
2 parents 2c60208 + e675eca commit f710e83

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/package.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,9 @@ export class ManifestProcessor extends BaseProcessor {
388388

389389
const extensionKind = getExtensionKind(manifest);
390390
const target = options.target;
391+
const preRelease = options.preRelease;
391392

392-
if (target) {
393+
if (target || preRelease) {
393394
let engineVersion: string;
394395

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

402-
if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.61')) {
403-
throw new Error(
404-
`Platform specific extension is supported by VS Code >=1.61. Current 'engines.vscode' is '${manifest.engines['vscode']}'.`
405-
);
403+
if (target) {
404+
if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.61')) {
405+
throw new Error(
406+
`Platform specific extension is supported by VS Code >=1.61. Current 'engines.vscode' is '${manifest.engines['vscode']}'.`
407+
);
408+
}
409+
if (!Targets.has(target)) {
410+
throw new Error(`'${target}' is not a valid VS Code target. Valid targets: ${[...Targets].join(', ')}`);
411+
}
406412
}
407413

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

src/test/package.test.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ describe('toVsixManifest', () => {
16411641
});
16421642

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

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

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

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

16581658
assertMissingProperty(xmlManifest, 'Microsoft.VisualStudio.Code.PreRelease');
16591659
});
1660+
1661+
it('should throw when targeting an old VS Code version with --pre-release', async () => {
1662+
const manifest = createManifest({ engines: { vscode: '>=1.62.0' } });
1663+
1664+
try {
1665+
await _toVsixManifest(manifest, [], { preRelease: true });
1666+
} catch (err: any) {
1667+
return assert.ok(/>=1.63/.test(err.message));
1668+
}
1669+
1670+
throw new Error('Should not reach here');
1671+
});
16601672
});
16611673

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

0 commit comments

Comments
 (0)