Various cleanup and fix edge cases
This commit is contained in:
parent
e52ca9fb30
commit
7722c8191b
2 changed files with 48 additions and 21 deletions
|
@ -103,22 +103,26 @@ describe('validateEngineCompatibility', () => {
|
||||||
describe('validateVSCodeTypesCompatibility', () => {
|
describe('validateVSCodeTypesCompatibility', () => {
|
||||||
|
|
||||||
it('should validate', () => {
|
it('should validate', () => {
|
||||||
validateVSCodeTypesCompatibility('*', '1.30.0')
|
validateVSCodeTypesCompatibility('*', '1.30.0');
|
||||||
validateVSCodeTypesCompatibility('*', '^1.30.0')
|
validateVSCodeTypesCompatibility('*', '^1.30.0');
|
||||||
validateVSCodeTypesCompatibility('*', '~1.30.0')
|
validateVSCodeTypesCompatibility('*', '~1.30.0');
|
||||||
|
|
||||||
validateVSCodeTypesCompatibility('1.30.0', '1.30.0')
|
validateVSCodeTypesCompatibility('1.30.0', '1.30.0');
|
||||||
validateVSCodeTypesCompatibility('1.30.0', '1.20.0')
|
validateVSCodeTypesCompatibility('1.30.0', '1.20.0');
|
||||||
|
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('1.x.x', '1.30.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '1.40.0'));
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('1.x.0', '1.30.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '^1.40.0'));
|
||||||
|
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '~1.40.0'));
|
||||||
|
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '1.40.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '1.40.0'));
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '^1.40.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('^1.30.0', '1.40.0'));
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '~1.40.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('~1.30.0', '1.40.0'));
|
||||||
|
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('1.30.0', '1.40.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('1.x.x', '1.30.0'));
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('^1.30.0', '1.40.0'))
|
assert.throws(() => validateVSCodeTypesCompatibility('1.x.0', '1.30.0'));
|
||||||
assert.throws(() => validateVSCodeTypesCompatibility('~1.30.0', '1.40.0'))
|
|
||||||
|
assert.throws(() => validateVSCodeTypesCompatibility('1.5.0', '1.30.0'));
|
||||||
|
assert.throws(() => validateVSCodeTypesCompatibility('1.5', '1.30.0'));
|
||||||
|
assert.throws(() => validateVSCodeTypesCompatibility('1.5', '1.30'));
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -48,29 +48,52 @@ export function validateEngineCompatibility(version: string): void {
|
||||||
*/
|
*/
|
||||||
export function validateVSCodeTypesCompatibility(engineVersion: string, typeVersion: string): void {
|
export function validateVSCodeTypesCompatibility(engineVersion: string, typeVersion: string): void {
|
||||||
if (engineVersion === '*') {
|
if (engineVersion === '*') {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!typeVersion) {
|
if (!typeVersion) {
|
||||||
throw new Error(`Missing @types/vscode version`);
|
throw new Error(`Missing @types/vscode version`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let plainEngineVersion: string, plainTypeVersion: string;
|
let plainEngineVersion: string, plainTypeVersion: string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const engineSemver = parseSemver(`vscode@${engineVersion}`);
|
const engineSemver = parseSemver(`vscode@${engineVersion}`);
|
||||||
const typeSemver = parseSemver(`@types/vscode@${typeVersion}`);
|
const typeSemver = parseSemver(`@types/vscode@${typeVersion}`);
|
||||||
|
|
||||||
plainEngineVersion = engineSemver.version;
|
plainEngineVersion = engineSemver.version;
|
||||||
plainTypeVersion = typeSemver.version;
|
plainTypeVersion = typeSemver.version;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error('Failed to parse semver of engines.vscode and @types/vscode');
|
throw new Error('Failed to parse semver of engines.vscode and @types/vscode');
|
||||||
}
|
}
|
||||||
|
|
||||||
// For all `x`, use smallest version for comparison
|
// For all `x`, use smallest version for comparison
|
||||||
plainEngineVersion = plainEngineVersion.replace(/x/g, '0')
|
plainEngineVersion = plainEngineVersion.replace(/x/g, '0');
|
||||||
|
|
||||||
if(plainTypeVersion > plainEngineVersion) {
|
const [typeMajor, typeMinor, typePatch] = plainTypeVersion.split('.').map(x => {
|
||||||
throw new Error(`@types/vscode ${typeVersion} greater than engines.vscode ${engineVersion}. Consider upgrade engines.vscode or use an older @types/vscode version`)
|
try {
|
||||||
|
return parseInt(x);
|
||||||
|
} catch (err) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const [engineMajor, engineMinor, enginePatch] = plainEngineVersion.split('.').map(x => {
|
||||||
|
try {
|
||||||
|
return parseInt(x);
|
||||||
|
} catch (err) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const error = new Error(`@types/vscode ${typeVersion} greater than engines.vscode ${engineVersion}. Consider upgrade engines.vscode or use an older @types/vscode version`);
|
||||||
|
|
||||||
|
if (typeof typeMajor === 'number' && typeof engineMajor === 'number' && typeMajor > engineMajor) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (typeof typeMinor === 'number' && typeof engineMinor === 'number' && typeMinor > engineMinor) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (typeof typePatch === 'number' && typeof enginePatch === 'number' && typePatch > enginePatch) {
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue