From e38022fc41c086362a48b88b51b12d1252656bfc Mon Sep 17 00:00:00 2001 From: Mohankumar Ramachandran Date: Sat, 9 Nov 2024 11:41:00 +0530 Subject: [PATCH 1/3] Updated the semver comparison --- src/package.ts | 9 ++++----- src/typings/parse-semver.d.ts | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/package.ts b/src/package.ts index d27b71ca..206b1563 100644 --- a/src/package.ts +++ b/src/package.ts @@ -493,17 +493,16 @@ export class ManifestProcessor extends BaseProcessor { const preRelease = options.preRelease; if (target || preRelease) { - let engineVersion: string; + let engineSemver: ReturnType; 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'); } if (target) { - if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.61', { includePrerelease: true })) { + if (engineSemver.version !== 'latest' && !semver.satisfies(engineSemver.range, '>=1.61', { includePrerelease: true })) { throw new Error( `Platform specific extension is supported by VS Code >=1.61. Current 'engines.vscode' is '${manifest.engines.vscode}'.` ); @@ -514,7 +513,7 @@ export class ManifestProcessor extends BaseProcessor { } if (preRelease) { - if (engineVersion !== 'latest' && !semver.satisfies(engineVersion, '>=1.63', { includePrerelease: true })) { + if (engineSemver.version !== 'latest' && !semver.satisfies(engineSemver.range, '>=1.63', { includePrerelease: true })) { throw new Error( `Pre-release versions are supported by VS Code >=1.63. Current 'engines.vscode' is '${manifest.engines.vscode}'.` ); diff --git a/src/typings/parse-semver.d.ts b/src/typings/parse-semver.d.ts index 648b8b70..95b65ad5 100644 --- a/src/typings/parse-semver.d.ts +++ b/src/typings/parse-semver.d.ts @@ -1,6 +1,7 @@ declare module 'parse-semver' { interface Result { readonly name: string; + readonly range: string; readonly version: string; } module parseSemver {} From 6d0a71c308e8800e08436065b959bdefe2a16a7c Mon Sep 17 00:00:00 2001 From: Mohankumar Ramachandran Date: Sat, 9 Nov 2024 14:45:33 +0530 Subject: [PATCH 2/3] Updated comparison login --- src/package.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/package.ts b/src/package.ts index 206b1563..f2b6015e 100644 --- a/src/package.ts +++ b/src/package.ts @@ -501,8 +501,13 @@ export class ManifestProcessor extends BaseProcessor { 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 (engineSemver.version !== 'latest' && !semver.satisfies(engineSemver.range, '>=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}'.` ); @@ -513,7 +518,7 @@ export class ManifestProcessor extends BaseProcessor { } if (preRelease) { - if (engineSemver.version !== 'latest' && !semver.satisfies(engineSemver.range, '>=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}'.` ); From a1cdb4e5f60e00d9ad8a814cfd90703c6e590db9 Mon Sep 17 00:00:00 2001 From: Mohankumar Ramachandran Date: Tue, 26 Nov 2024 12:13:39 +0000 Subject: [PATCH 3/3] Added Tests --- src/test/package.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/package.test.ts b/src/test/package.test.ts index a6689471..467850a7 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -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', () => {