diff --git a/package.json b/package.json index 29090e87e0a05..be9ad31700326 100644 --- a/package.json +++ b/package.json @@ -297,7 +297,7 @@ "rison-node": "1.0.2", "rxjs": "^6.5.5", "seedrandom": "^3.0.5", - "semver": "^7", + "semver": "^7.3.2", "set-value": "^3.0.2", "source-map-support": "^0.5.19", "squel": "^5.13.0", diff --git a/src/plugins/dashboard/common/migrate_to_730_panels.ts b/src/plugins/dashboard/common/migrate_to_730_panels.ts index d870e3c87d6ab..163f4242d12e6 100644 --- a/src/plugins/dashboard/common/migrate_to_730_panels.ts +++ b/src/plugins/dashboard/common/migrate_to_730_panels.ts @@ -17,7 +17,7 @@ * under the License. */ import { i18n } from '@kbn/i18n'; -import semver from 'semver'; +import semverSatisfies from 'semver/functions/satisfies'; import uuid from 'uuid'; import { GridData, @@ -60,23 +60,23 @@ function isPre61Panel( } function is61Panel(panel: unknown | RawSavedDashboardPanel610): panel is RawSavedDashboardPanel610 { - return semver.satisfies((panel as RawSavedDashboardPanel610).version, '6.1.x'); + return semverSatisfies((panel as RawSavedDashboardPanel610).version, '6.1.x'); } function is62Panel(panel: unknown | RawSavedDashboardPanel620): panel is RawSavedDashboardPanel620 { - return semver.satisfies((panel as RawSavedDashboardPanel620).version, '6.2.x'); + return semverSatisfies((panel as RawSavedDashboardPanel620).version, '6.2.x'); } function is63Panel(panel: unknown | RawSavedDashboardPanel630): panel is RawSavedDashboardPanel630 { - return semver.satisfies((panel as RawSavedDashboardPanel630).version, '6.3.x'); + return semverSatisfies((panel as RawSavedDashboardPanel630).version, '6.3.x'); } function is640To720Panel( panel: unknown | RawSavedDashboardPanel640To720 ): panel is RawSavedDashboardPanel640To720 { return ( - semver.satisfies((panel as RawSavedDashboardPanel630).version, '>6.3') && - semver.satisfies((panel as RawSavedDashboardPanel630).version, '<7.3') + semverSatisfies((panel as RawSavedDashboardPanel630).version, '>6.3') && + semverSatisfies((panel as RawSavedDashboardPanel630).version, '<7.3') ); } diff --git a/src/plugins/dashboard/public/application/lib/migrate_app_state.ts b/src/plugins/dashboard/public/application/lib/migrate_app_state.ts index e2b32b1dbdad0..b5b96e4ced678 100644 --- a/src/plugins/dashboard/public/application/lib/migrate_app_state.ts +++ b/src/plugins/dashboard/public/application/lib/migrate_app_state.ts @@ -17,7 +17,7 @@ * under the License. */ -import semver from 'semver'; +import semverSatisfies from 'semver/functions/satisfies'; import { i18n } from '@kbn/i18n'; import { METRIC_TYPE } from '@kbn/analytics'; @@ -68,7 +68,7 @@ export function migrateAppState( usageCollection.reportUiStats('DashboardPanelVersionInUrl', METRIC_TYPE.LOADED, `${version}`); } - return semver.satisfies(version, '<7.3'); + return semverSatisfies(version, '<7.3'); }); if (panelNeedsMigration) { diff --git a/src/plugins/telemetry/common/telemetry_config/get_telemetry_opt_in.ts b/src/plugins/telemetry/common/telemetry_config/get_telemetry_opt_in.ts index 7beb5415ad7b1..14b28a1a5013e 100644 --- a/src/plugins/telemetry/common/telemetry_config/get_telemetry_opt_in.ts +++ b/src/plugins/telemetry/common/telemetry_config/get_telemetry_opt_in.ts @@ -17,7 +17,8 @@ * under the License. */ -import semver from 'semver'; +import SemVer from 'semver/classes/semver'; +import semverParse from 'semver/functions/parse'; import { TelemetrySavedObject } from './types'; interface GetTelemetryOptInConfig { @@ -80,10 +81,10 @@ export const getTelemetryOptIn: GetTelemetryOptIn = ({ return savedOptIn; }; -function parseSemver(version: string): semver.SemVer | null { +function parseSemver(version: string): SemVer | null { // semver functions both return nulls AND throw exceptions: "it depends!" try { - return semver.parse(version); + return semverParse(version); } catch (err) { return null; } diff --git a/x-pack/plugins/enterprise_search/common/version.ts b/x-pack/plugins/enterprise_search/common/version.ts index e29ad8a9f866b..8c3edb0558835 100644 --- a/x-pack/plugins/enterprise_search/common/version.ts +++ b/x-pack/plugins/enterprise_search/common/version.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SemVer } from 'semver'; +import SemVer from 'semver/classes/semver'; import pkg from '../../../../package.json'; export const CURRENT_VERSION = new SemVer(pkg.version as string); diff --git a/x-pack/plugins/ml/common/util/job_utils.ts b/x-pack/plugins/ml/common/util/job_utils.ts index 878f5a2c71cb9..a5b854a8d59a7 100644 --- a/x-pack/plugins/ml/common/util/job_utils.ts +++ b/x-pack/plugins/ml/common/util/job_utils.ts @@ -5,8 +5,7 @@ */ import { isEmpty, isEqual, each, pick } from 'lodash'; - -import semver from 'semver'; +import semverGte from 'semver/functions/gte'; import moment, { Duration } from 'moment'; // @ts-ignore import numeral from '@elastic/numeral'; @@ -205,7 +204,7 @@ export function isModelPlotEnabled( // created with) is greater than or equal to the supplied version (e.g. '6.1.0'). export function isJobVersionGte(job: CombinedJob, version: string): boolean { const jobVersion = job.job_version ?? '0.0.0'; - return semver.gte(jobVersion, version); + return semverGte(jobVersion, version); } // Takes an ML detector 'function' and returns the corresponding ES aggregation name diff --git a/x-pack/plugins/monitoring/public/lib/logstash/pipelines.js b/x-pack/plugins/monitoring/public/lib/logstash/pipelines.js index a93cb28e07745..8f0175386526a 100644 --- a/x-pack/plugins/monitoring/public/lib/logstash/pipelines.js +++ b/x-pack/plugins/monitoring/public/lib/logstash/pipelines.js @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import semver from 'semver'; +import semverMajor from 'semver/functions/major'; import { LOGSTASH } from '../../../common/constants'; export function isPipelineMonitoringSupportedInVersion(logstashVersion) { - const major = semver.major(logstashVersion); + const major = semverMajor(logstashVersion); return major >= LOGSTASH.MAJOR_VER_REQD_FOR_PIPELINES; } diff --git a/x-pack/plugins/upgrade_assistant/common/version.ts b/x-pack/plugins/upgrade_assistant/common/version.ts index 744ec4e87a49b..231614dc38c6d 100644 --- a/x-pack/plugins/upgrade_assistant/common/version.ts +++ b/x-pack/plugins/upgrade_assistant/common/version.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SemVer } from 'semver'; +import SemVer from 'semver/classes/semver'; import pkg from '../../../../package.json'; export const CURRENT_VERSION = new SemVer(pkg.version as string); diff --git a/x-pack/tasks/helpers/pkg.ts b/x-pack/tasks/helpers/pkg.ts index 8411ebcf7186a..c7d55f6e458c1 100644 --- a/x-pack/tasks/helpers/pkg.ts +++ b/x-pack/tasks/helpers/pkg.ts @@ -5,7 +5,7 @@ */ import Fs from 'fs'; -import semver from 'semver'; +import semverValid from 'semver/functions/valid'; interface PackageJson { name: string; @@ -28,6 +28,6 @@ if (!PKG_NAME) { throw new Error('No "name" found in package.json'); } -if (!semver.valid(PKG_VERSION)) { +if (!semverValid(PKG_VERSION)) { throw new Error(`Version is not valid semver: ${PKG_VERSION}`); } diff --git a/yarn.lock b/yarn.lock index 05a6d993e4a9f..58732d4909b77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -25129,7 +25129,7 @@ semver@7.0.0: resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e" integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A== -semver@7.3.2, semver@^7, semver@^7.1.3, semver@^7.3.2: +semver@7.3.2, semver@^7.1.3, semver@^7.3.2: version "7.3.2" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==