parent
c9b689545f
commit
82afdb9e7d
3 changed files with 50 additions and 6 deletions
|
@ -11,7 +11,7 @@ import * as minimatch from 'minimatch';
|
|||
import * as denodeify from 'denodeify';
|
||||
import * as mime from 'mime';
|
||||
import * as urljoin from 'url-join';
|
||||
import { validatePublisher, validateExtensionName, validateVersion } from './validation';
|
||||
import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility } from './validation';
|
||||
import { getDependencies } from './npm';
|
||||
|
||||
interface IReadFile {
|
||||
|
@ -418,12 +418,13 @@ class IconProcessor extends BaseProcessor {
|
|||
export function validateManifest(manifest: Manifest): Manifest {
|
||||
validatePublisher(manifest.publisher);
|
||||
validateExtensionName(manifest.name);
|
||||
validateVersion(manifest.version);
|
||||
|
||||
if (!manifest.version) {
|
||||
throw new Error('Manifest missing field: version');
|
||||
}
|
||||
|
||||
validateVersion(manifest.version);
|
||||
|
||||
if (!manifest.engines) {
|
||||
throw new Error('Manifest missing field: engines');
|
||||
}
|
||||
|
@ -432,6 +433,8 @@ export function validateManifest(manifest: Manifest): Manifest {
|
|||
throw new Error('Manifest missing field: engines.vscode');
|
||||
}
|
||||
|
||||
validateEngineCompatibility(manifest.engines['vscode']);
|
||||
|
||||
if (manifest.enableProposedApi) {
|
||||
throw new Error('Extensions using proposed API (enableProposedApi: true) cannot be published');
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as assert from 'assert';
|
||||
import { validatePublisher, validateExtensionName, validateVersion } from '../validation';
|
||||
import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility } from '../validation';
|
||||
|
||||
describe('validatePublisher', () => {
|
||||
it('should throw with empty', () => {
|
||||
|
@ -67,4 +67,35 @@ describe('validateVersion', () => {
|
|||
assert.throws(() => validateVersion('0.1.'));
|
||||
assert.throws(() => validateVersion('0.0.0.1'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateEngineCompatibility', () => {
|
||||
it('should throw with empty', () => {
|
||||
assert.throws(() => validateEngineCompatibility(null));
|
||||
assert.throws(() => validateEngineCompatibility(void 0));
|
||||
assert.throws(() => validateEngineCompatibility(''));
|
||||
});
|
||||
|
||||
it('should validate', () => {
|
||||
validateEngineCompatibility('*');
|
||||
|
||||
validateEngineCompatibility('1.0.0');
|
||||
validateEngineCompatibility('1.0.x');
|
||||
validateEngineCompatibility('1.x.x');
|
||||
|
||||
validateEngineCompatibility('^1.0.0');
|
||||
validateEngineCompatibility('^1.0.x');
|
||||
validateEngineCompatibility('^1.x.x');
|
||||
|
||||
validateEngineCompatibility('>=1.0.0');
|
||||
validateEngineCompatibility('>=1.0.x');
|
||||
validateEngineCompatibility('>=1.x.x');
|
||||
|
||||
assert.throws(() => validateVersion('0.0.0.1'));
|
||||
assert.throws(() => validateVersion('^0.0.0.1'));
|
||||
assert.throws(() => validateVersion('^1'));
|
||||
assert.throws(() => validateVersion('^1.0'));
|
||||
assert.throws(() => validateVersion('>=1'));
|
||||
assert.throws(() => validateVersion('>=1.0'));
|
||||
});
|
||||
});
|
|
@ -8,7 +8,7 @@ export function validatePublisher(publisher: string): void {
|
|||
}
|
||||
|
||||
if (!nameRegex.test(publisher)) {
|
||||
throw new Error(`Invalid publisher '${ publisher }'`);
|
||||
throw new Error(`Invalid publisher '${publisher}'`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ export function validateExtensionName(name: string): void {
|
|||
}
|
||||
|
||||
if (!nameRegex.test(name)) {
|
||||
throw new Error(`Invalid extension name '${ name }'`);
|
||||
throw new Error(`Invalid extension name '${name}'`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,16 @@ export function validateVersion(version: string): void {
|
|||
}
|
||||
|
||||
if (!semver.valid(version)) {
|
||||
throw new Error(`Invalid extension version '${ version }'`);
|
||||
throw new Error(`Invalid extension version '${version}'`);
|
||||
}
|
||||
}
|
||||
|
||||
export function validateEngineCompatibility(version: string): void {
|
||||
if (!version) {
|
||||
throw new Error(`Missing vscode engine compatibility version`);
|
||||
}
|
||||
|
||||
if (!/^\*$|^(\^|>=)?((\d+)|x)\.((\d+)|x)\.((\d+)|x)(\-.*)?$/.test(version)) {
|
||||
throw new Error(`Invalid vscode engine compatibility version '${version}'`);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue