Check @types/vscode against engine for microsoft/vscode#71048
This commit is contained in:
parent
cd6d8a6e2e
commit
e52ca9fb30
3 changed files with 62 additions and 2 deletions
|
@ -14,7 +14,7 @@ import * as cheerio from 'cheerio';
|
|||
import * as url from 'url';
|
||||
import { lookup } from 'mime';
|
||||
import * as urljoin from 'url-join';
|
||||
import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility } from './validation';
|
||||
import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility, validateVSCodeTypesCompatibility } from './validation';
|
||||
import { getDependencies } from './npm';
|
||||
|
||||
interface IReadFile {
|
||||
|
@ -605,6 +605,10 @@ export function validateManifest(manifest: Manifest): Manifest {
|
|||
|
||||
validateEngineCompatibility(manifest.engines['vscode']);
|
||||
|
||||
if (manifest.devDependencies && manifest.devDependencies['@types/vscode']) {
|
||||
validateVSCodeTypesCompatibility(manifest.engines['vscode'], manifest.devDependencies['@types/vscode']);
|
||||
}
|
||||
|
||||
if (/\.svg$/i.test(manifest.icon || '')) {
|
||||
throw new Error(`SVGs can't be used as icons: ${manifest.icon}`);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as assert from 'assert';
|
||||
import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility } from '../validation';
|
||||
import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility, validateVSCodeTypesCompatibility } from '../validation';
|
||||
|
||||
describe('validatePublisher', () => {
|
||||
it('should throw with empty', () => {
|
||||
|
@ -99,3 +99,26 @@ describe('validateEngineCompatibility', () => {
|
|||
assert.throws(() => validateVersion('>=1.0'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateVSCodeTypesCompatibility', () => {
|
||||
|
||||
it('should validate', () => {
|
||||
validateVSCodeTypesCompatibility('*', '1.30.0')
|
||||
validateVSCodeTypesCompatibility('*', '^1.30.0')
|
||||
validateVSCodeTypesCompatibility('*', '~1.30.0')
|
||||
|
||||
validateVSCodeTypesCompatibility('1.30.0', '1.30.0')
|
||||
validateVSCodeTypesCompatibility('1.30.0', '1.20.0')
|
||||
|
||||
assert.throws(() => validateVSCodeTypesCompatibility('1.x.x', '1.30.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'))
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import * as semver from 'semver';
|
||||
import * as parseSemver from 'parse-semver';
|
||||
|
||||
const nameRegex = /^[a-z0-9][a-z0-9\-]*$/i;
|
||||
|
||||
|
@ -41,3 +42,35 @@ export function validateEngineCompatibility(version: string): void {
|
|||
throw new Error(`Invalid vscode engine compatibility version '${version}'`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User shouldn't use a newer version of @types/vscode than the one specified in engines.vscode
|
||||
*/
|
||||
export function validateVSCodeTypesCompatibility(engineVersion: string, typeVersion: string): void {
|
||||
if (engineVersion === '*') {
|
||||
return
|
||||
}
|
||||
|
||||
if (!typeVersion) {
|
||||
throw new Error(`Missing @types/vscode version`);
|
||||
}
|
||||
|
||||
let plainEngineVersion: string, plainTypeVersion: string;
|
||||
|
||||
try {
|
||||
const engineSemver = parseSemver(`vscode@${engineVersion}`);
|
||||
const typeSemver = parseSemver(`@types/vscode@${typeVersion}`);
|
||||
|
||||
plainEngineVersion = engineSemver.version;
|
||||
plainTypeVersion = typeSemver.version;
|
||||
} catch (err) {
|
||||
throw new Error('Failed to parse semver of engines.vscode and @types/vscode');
|
||||
}
|
||||
|
||||
// For all `x`, use smallest version for comparison
|
||||
plainEngineVersion = plainEngineVersion.replace(/x/g, '0')
|
||||
|
||||
if(plainTypeVersion > plainEngineVersion) {
|
||||
throw new Error(`@types/vscode ${typeVersion} greater than engines.vscode ${engineVersion}. Consider upgrade engines.vscode or use an older @types/vscode version`)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue