mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-07 17:23:56 -05:00
Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)
This commit is contained in:
@@ -24,10 +24,12 @@ export interface INormalizedVersion {
|
||||
minorMustEqual: boolean;
|
||||
patchBase: number;
|
||||
patchMustEqual: boolean;
|
||||
notBefore: number; /* milliseconds timestamp, or 0 */
|
||||
isMinimum: boolean;
|
||||
}
|
||||
|
||||
const VERSION_REGEXP = /^(\^|>=)?((\d+)|x)\.((\d+)|x)\.((\d+)|x)(\-.*)?$/;
|
||||
const NOT_BEFORE_REGEXP = /^-(\d{4})(\d{2})(\d{2})$/;
|
||||
|
||||
export function isValidVersionStr(version: string): boolean {
|
||||
version = version.trim();
|
||||
@@ -93,6 +95,15 @@ export function normalizeVersion(version: IParsedVersion | null): INormalizedVer
|
||||
}
|
||||
}
|
||||
|
||||
let notBefore = 0;
|
||||
if (version.preRelease) {
|
||||
const match = NOT_BEFORE_REGEXP.exec(version.preRelease);
|
||||
if (match) {
|
||||
const [, year, month, day] = match;
|
||||
notBefore = Date.UTC(Number(year), Number(month) - 1, Number(day));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
majorBase: majorBase,
|
||||
majorMustEqual: majorMustEqual,
|
||||
@@ -100,16 +111,24 @@ export function normalizeVersion(version: IParsedVersion | null): INormalizedVer
|
||||
minorMustEqual: minorMustEqual,
|
||||
patchBase: patchBase,
|
||||
patchMustEqual: patchMustEqual,
|
||||
isMinimum: version.hasGreaterEquals
|
||||
isMinimum: version.hasGreaterEquals,
|
||||
notBefore,
|
||||
};
|
||||
}
|
||||
|
||||
export function isValidVersion(_version: string | INormalizedVersion, _desiredVersion: string | INormalizedVersion): boolean {
|
||||
export function isValidVersion(_inputVersion: string | INormalizedVersion, _inputDate: ProductDate, _desiredVersion: string | INormalizedVersion): boolean {
|
||||
let version: INormalizedVersion | null;
|
||||
if (typeof _version === 'string') {
|
||||
version = normalizeVersion(parseVersion(_version));
|
||||
if (typeof _inputVersion === 'string') {
|
||||
version = normalizeVersion(parseVersion(_inputVersion));
|
||||
} else {
|
||||
version = _version;
|
||||
version = _inputVersion;
|
||||
}
|
||||
|
||||
let productTs: number | undefined;
|
||||
if (_inputDate instanceof Date) {
|
||||
productTs = _inputDate.getTime();
|
||||
} else if (typeof _inputDate === 'string') {
|
||||
productTs = new Date(_inputDate).getTime();
|
||||
}
|
||||
|
||||
let desiredVersion: INormalizedVersion | null;
|
||||
@@ -130,6 +149,7 @@ export function isValidVersion(_version: string | INormalizedVersion, _desiredVe
|
||||
let desiredMajorBase = desiredVersion.majorBase;
|
||||
let desiredMinorBase = desiredVersion.minorBase;
|
||||
let desiredPatchBase = desiredVersion.patchBase;
|
||||
let desiredNotBefore = desiredVersion.notBefore;
|
||||
|
||||
let majorMustEqual = desiredVersion.majorMustEqual;
|
||||
let minorMustEqual = desiredVersion.minorMustEqual;
|
||||
@@ -152,6 +172,10 @@ export function isValidVersion(_version: string | INormalizedVersion, _desiredVe
|
||||
return false;
|
||||
}
|
||||
|
||||
if (productTs && productTs < desiredNotBefore) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return patchBase >= desiredPatchBase;
|
||||
}
|
||||
|
||||
@@ -200,6 +224,11 @@ export function isValidVersion(_version: string | INormalizedVersion, _desiredVe
|
||||
}
|
||||
|
||||
// at this point, patchBase are equal
|
||||
|
||||
if (productTs && productTs < desiredNotBefore) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -213,7 +242,9 @@ export interface IReducedExtensionDescription {
|
||||
main?: string;
|
||||
}
|
||||
|
||||
export function isValidExtensionVersion(version: string, extensionDesc: IReducedExtensionDescription, notices: string[]): boolean {
|
||||
type ProductDate = string | Date | undefined;
|
||||
|
||||
export function isValidExtensionVersion(version: string, date: ProductDate, extensionDesc: IReducedExtensionDescription, notices: string[]): boolean {
|
||||
|
||||
if (extensionDesc.isBuiltin || typeof extensionDesc.main === 'undefined') {
|
||||
// No version check for builtin or declarative extensions
|
||||
@@ -221,16 +252,16 @@ export function isValidExtensionVersion(version: string, extensionDesc: IReduced
|
||||
}
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
return extensionDesc.engines.azdata ? extensionDesc.engines.azdata === '*' || isVersionValid(version, extensionDesc.engines.azdata, notices) : true;
|
||||
return extensionDesc.engines.azdata ? extensionDesc.engines.azdata === '*' || isVersionValid(version, date, extensionDesc.engines.azdata, notices) : true;
|
||||
}
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
export function isEngineValid(engine: string, version: string): boolean {
|
||||
export function isEngineValid(engine: string, version: string, date: ProductDate): boolean {
|
||||
// TODO@joao: discuss with alex '*' doesn't seem to be a valid engine version
|
||||
return engine === '*' || isVersionValid(version, engine);
|
||||
return engine === '*' || isVersionValid(version, date, engine);
|
||||
}
|
||||
|
||||
export function isVersionValid(currentVersion: string, requestedVersion: string, notices: string[] = []): boolean {
|
||||
function isVersionValid(currentVersion: string, date: ProductDate, requestedVersion: string, notices: string[] = []): boolean {
|
||||
|
||||
let desiredVersion = normalizeVersion(parseVersion(requestedVersion));
|
||||
if (!desiredVersion) {
|
||||
@@ -255,7 +286,7 @@ export function isVersionValid(currentVersion: string, requestedVersion: string,
|
||||
}
|
||||
}
|
||||
|
||||
if (!isValidVersion(currentVersion, desiredVersion)) {
|
||||
if (!isValidVersion(currentVersion, date, desiredVersion)) {
|
||||
notices.push(nls.localize('versionMismatch', "Extension is not compatible with Code {0}. Extension requires: {1}.", currentVersion, requestedVersion));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -123,10 +123,12 @@ export interface IAuthenticationContribution {
|
||||
export interface IWalkthroughStep {
|
||||
readonly id: string;
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly description: string | undefined;
|
||||
readonly media:
|
||||
| { path: string | { dark: string, light: string, hc: string }, altText: string }
|
||||
| { path: string, },
|
||||
| { image: string | { dark: string, light: string, hc: string }, altText: string, markdown?: never }
|
||||
| { markdown: string, image?: never }
|
||||
readonly completionEvents?: string[];
|
||||
/** @deprecated use `completionEvents: 'onCommand:...'` */
|
||||
readonly doneOn?: { command: string };
|
||||
readonly when?: string;
|
||||
}
|
||||
@@ -136,7 +138,6 @@ export interface IWalkthrough {
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly steps: IWalkthroughStep[];
|
||||
readonly primary?: boolean;
|
||||
readonly when?: string;
|
||||
}
|
||||
|
||||
@@ -173,13 +174,30 @@ export interface IExtensionContributions {
|
||||
}
|
||||
|
||||
export interface IExtensionCapabilities {
|
||||
readonly virtualWorkspaces?: boolean;
|
||||
readonly virtualWorkspaces?: ExtensionVirtualWorkpaceSupport;
|
||||
readonly untrustedWorkspaces?: ExtensionUntrustedWorkspaceSupport;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export type ExtensionKind = 'ui' | 'workspace' | 'web';
|
||||
export type ExtensionUntrustedWorkpaceSupportType = boolean | 'limited';
|
||||
export type ExtensionUntrustedWorkspaceSupport = { supported: true; } | { supported: false, description: string } | { supported: 'limited', description: string, restrictedConfigurations?: string[] };
|
||||
|
||||
export type LimitedWorkpaceSupportType = 'limited';
|
||||
export type ExtensionUntrustedWorkpaceSupportType = boolean | LimitedWorkpaceSupportType;
|
||||
export type ExtensionUntrustedWorkspaceSupport = { supported: true; } | { supported: false, description: string } | { supported: LimitedWorkpaceSupportType, description: string, restrictedConfigurations?: string[] };
|
||||
|
||||
export type ExtensionVirtualWorkpaceSupportType = boolean | LimitedWorkpaceSupportType;
|
||||
export type ExtensionVirtualWorkpaceSupport = boolean | { supported: true; } | { supported: false | LimitedWorkpaceSupportType, description: string };
|
||||
|
||||
export function getWorkpaceSupportTypeMessage(supportType: ExtensionUntrustedWorkspaceSupport | ExtensionVirtualWorkpaceSupport | undefined): string | undefined {
|
||||
if (typeof supportType === 'object' && supportType !== null) {
|
||||
if (supportType.supported !== true) {
|
||||
return supportType.description;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
export function isIExtensionIdentifier(thing: any): thing is IExtensionIdentifier {
|
||||
return thing
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as assert from 'assert';
|
||||
import { INormalizedVersion, IParsedVersion, IReducedExtensionDescription, isValidExtensionVersion, isValidVersion, isValidVersionStr, normalizeVersion, parseVersion } from 'vs/platform/extensions/common/extensionValidator';
|
||||
|
||||
suite('Extension Version Validator', () => {
|
||||
const productVersion = '2021-05-11T21:54:30.577Z';
|
||||
|
||||
test('isValidVersionStr', () => {
|
||||
assert.strictEqual(isValidVersionStr('0.10.0-dev'), true);
|
||||
@@ -53,13 +54,16 @@ suite('Extension Version Validator', () => {
|
||||
});
|
||||
|
||||
test('normalizeVersion', () => {
|
||||
function assertNormalizeVersion(version: string, majorBase: number, majorMustEqual: boolean, minorBase: number, minorMustEqual: boolean, patchBase: number, patchMustEqual: boolean, isMinimum: boolean): void {
|
||||
function assertNormalizeVersion(version: string, majorBase: number, majorMustEqual: boolean, minorBase: number, minorMustEqual: boolean, patchBase: number, patchMustEqual: boolean, isMinimum: boolean, notBefore = 0): void {
|
||||
const actual = normalizeVersion(parseVersion(version));
|
||||
const expected: INormalizedVersion = { majorBase, majorMustEqual, minorBase, minorMustEqual, patchBase, patchMustEqual, isMinimum };
|
||||
const expected: INormalizedVersion = { majorBase, majorMustEqual, minorBase, minorMustEqual, patchBase, patchMustEqual, isMinimum, notBefore };
|
||||
assert.deepStrictEqual(actual, expected, 'parseVersion for ' + version);
|
||||
}
|
||||
|
||||
assertNormalizeVersion('0.10.0-dev', 0, true, 10, true, 0, true, false);
|
||||
assertNormalizeVersion('0.10.0-dev', 0, true, 10, true, 0, true, false, 0);
|
||||
assertNormalizeVersion('0.10.0-222222222', 0, true, 10, true, 0, true, false, 0);
|
||||
assertNormalizeVersion('0.10.0-20210511', 0, true, 10, true, 0, true, false, new Date('2021-05-11T00:00:00Z').getTime());
|
||||
|
||||
assertNormalizeVersion('0.10.0', 0, true, 10, true, 0, true, false);
|
||||
assertNormalizeVersion('0.10.1', 0, true, 10, true, 1, true, false);
|
||||
assertNormalizeVersion('0.10.100', 0, true, 10, true, 100, true, false);
|
||||
@@ -75,11 +79,12 @@ suite('Extension Version Validator', () => {
|
||||
|
||||
assertNormalizeVersion('>=0.0.1', 0, true, 0, true, 1, true, true);
|
||||
assertNormalizeVersion('>=2.4.3', 2, true, 4, true, 3, true, true);
|
||||
assertNormalizeVersion('>=2.4.3', 2, true, 4, true, 3, true, true);
|
||||
});
|
||||
|
||||
test('isValidVersion', () => {
|
||||
function testIsValidVersion(version: string, desiredVersion: string, expectedResult: boolean): void {
|
||||
let actual = isValidVersion(version, desiredVersion);
|
||||
let actual = isValidVersion(version, productVersion, desiredVersion);
|
||||
assert.strictEqual(actual, expectedResult, 'extension - vscode: ' + version + ', desiredVersion: ' + desiredVersion + ' should be ' + expectedResult);
|
||||
}
|
||||
|
||||
@@ -211,7 +216,7 @@ suite('Extension Version Validator', () => {
|
||||
main: hasMain ? 'something' : undefined
|
||||
};
|
||||
let reasons: string[] = [];
|
||||
let actual = isValidExtensionVersion(version, desc, reasons);
|
||||
let actual = isValidExtensionVersion(version, productVersion, desc, reasons);
|
||||
|
||||
assert.strictEqual(actual, expectedResult, 'version: ' + version + ', desiredVersion: ' + desiredVersion + ', desc: ' + JSON.stringify(desc) + ', reasons: ' + JSON.stringify(reasons));
|
||||
}
|
||||
@@ -390,5 +395,12 @@ suite('Extension Version Validator', () => {
|
||||
testIsValidVersion('2.0.0', '^1.100.0', false);
|
||||
testIsValidVersion('2.0.0', '^2.0.0', true);
|
||||
testIsValidVersion('2.0.0', '*', false); // fails due to lack of specificity
|
||||
|
||||
// date tags
|
||||
testIsValidVersion('1.10.0', '^1.10.0-20210511', true); // current date
|
||||
testIsValidVersion('1.10.0', '^1.10.0-20210510', true); // before date
|
||||
testIsValidVersion('1.10.0', '^1.10.0-20210512', false); // future date
|
||||
testIsValidVersion('1.10.1', '^1.10.0-20200101', true); // before date, but ahead version
|
||||
testIsValidVersion('1.11.0', '^1.10.0-20200101', true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user