Skip to content

Commit

Permalink
Merge pull request #1078 from mohankumarelec/issues-1077
Browse files Browse the repository at this point in the history
Updated the semver comparison
  • Loading branch information
benibenj authored Dec 10, 2024
2 parents b694572 + 0d2281c commit 0a22db7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,21 @@ export class ManifestProcessor extends BaseProcessor {
const preRelease = options.preRelease;

if (target || preRelease) {
let engineVersion: string;
let engineSemver: ReturnType<typeof parseSemver>;

try {
const engineSemver = parseSemver(`vscode@${manifest.engines.vscode}`);
engineVersion = engineSemver.version;
engineSemver = parseSemver(`vscode@${manifest.engines.vscode}`);
} catch (err) {
throw new Error('Failed to parse semver of engines.vscode');
}

const minEngineVersion = semver.minVersion(engineSemver.range);
if (!minEngineVersion) {
throw new Error('Failed to get minVersion of engines.vscode')
}

if (target) {
if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.61', { includePrerelease: true })) {
if (engineSemver.version !== 'latest' && !semver.satisfies(minEngineVersion, '>=1.61', { includePrerelease: true })) {
throw new Error(
`Platform specific extension is supported by VS Code >=1.61. Current 'engines.vscode' is '${manifest.engines.vscode}'.`
);
Expand All @@ -514,7 +518,7 @@ export class ManifestProcessor extends BaseProcessor {
}

if (preRelease) {
if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.63', { includePrerelease: true })) {
if (engineSemver.version !== 'latest' && !semver.satisfies(minEngineVersion, '>=1.63', { includePrerelease: true })) {
throw new Error(
`Pre-release versions are supported by VS Code >=1.63. Current 'engines.vscode' is '${manifest.engines.vscode}'.`
);
Expand Down
9 changes: 9 additions & 0 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,15 @@ describe('ManifestProcessor', () => {
manifest = JSON.parse(await fs.promises.readFile(path.join(root, 'package.json'), 'utf8'));
assert.deepStrictEqual(manifest.version, '1.0.0');
});

it('should not throw error for engine version with x (e.g. 1.95.x)', async () => {
const root = fixture('uuid');
const manifest = JSON.parse(await fs.promises.readFile(path.join(root, 'package.json'), 'utf8'));
manifest.engines.vscode = '1.95.x'; // Non-strict semver, but acceptable

assert.doesNotThrow(() => new ManifestProcessor(manifest, { target: 'web' }));
assert.doesNotThrow(() => new ManifestProcessor(manifest, { preRelease: true }));
});
});

describe('MarkdownProcessor', () => {
Expand Down
1 change: 1 addition & 0 deletions src/typings/parse-semver.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module 'parse-semver' {
interface Result {
readonly name: string;
readonly range: string;
readonly version: string;
}
module parseSemver {}
Expand Down

0 comments on commit 0a22db7

Please sign in to comment.