Skip to content

Commit 213bb52

Browse files
author
John Schulz
committed
Change "from 'semver'" imports to reduce client bundle size
1 parent 206b825 commit 213bb52

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@
297297
"rison-node": "1.0.2",
298298
"rxjs": "^6.5.5",
299299
"seedrandom": "^3.0.5",
300-
"semver": "^7",
300+
"semver": "^7.3.2",
301301
"set-value": "^3.0.2",
302302
"source-map-support": "^0.5.19",
303303
"squel": "^5.13.0",

src/plugins/dashboard/common/migrate_to_730_panels.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919
import { i18n } from '@kbn/i18n';
20-
import semver from 'semver';
20+
import semverSatisfies from 'semver/functions/satisfies';
2121
import uuid from 'uuid';
2222
import {
2323
GridData,
@@ -60,23 +60,23 @@ function isPre61Panel(
6060
}
6161

6262
function is61Panel(panel: unknown | RawSavedDashboardPanel610): panel is RawSavedDashboardPanel610 {
63-
return semver.satisfies((panel as RawSavedDashboardPanel610).version, '6.1.x');
63+
return semverSatisfies((panel as RawSavedDashboardPanel610).version, '6.1.x');
6464
}
6565

6666
function is62Panel(panel: unknown | RawSavedDashboardPanel620): panel is RawSavedDashboardPanel620 {
67-
return semver.satisfies((panel as RawSavedDashboardPanel620).version, '6.2.x');
67+
return semverSatisfies((panel as RawSavedDashboardPanel620).version, '6.2.x');
6868
}
6969

7070
function is63Panel(panel: unknown | RawSavedDashboardPanel630): panel is RawSavedDashboardPanel630 {
71-
return semver.satisfies((panel as RawSavedDashboardPanel630).version, '6.3.x');
71+
return semverSatisfies((panel as RawSavedDashboardPanel630).version, '6.3.x');
7272
}
7373

7474
function is640To720Panel(
7575
panel: unknown | RawSavedDashboardPanel640To720
7676
): panel is RawSavedDashboardPanel640To720 {
7777
return (
78-
semver.satisfies((panel as RawSavedDashboardPanel630).version, '>6.3') &&
79-
semver.satisfies((panel as RawSavedDashboardPanel630).version, '<7.3')
78+
semverSatisfies((panel as RawSavedDashboardPanel630).version, '>6.3') &&
79+
semverSatisfies((panel as RawSavedDashboardPanel630).version, '<7.3')
8080
);
8181
}
8282

src/plugins/dashboard/public/application/lib/migrate_app_state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import semver from 'semver';
20+
import semverSatisfies from 'semver/functions/satisfies';
2121
import { i18n } from '@kbn/i18n';
2222
import { METRIC_TYPE } from '@kbn/analytics';
2323

@@ -68,7 +68,7 @@ export function migrateAppState(
6868
usageCollection.reportUiStats('DashboardPanelVersionInUrl', METRIC_TYPE.LOADED, `${version}`);
6969
}
7070

71-
return semver.satisfies(version, '<7.3');
71+
return semverSatisfies(version, '<7.3');
7272
});
7373

7474
if (panelNeedsMigration) {

src/plugins/telemetry/common/telemetry_config/get_telemetry_opt_in.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
import semver from 'semver';
20+
import SemVer from 'semver/classes/semver';
21+
import semverParse from 'semver/functions/parse';
2122
import { TelemetrySavedObject } from './types';
2223

2324
interface GetTelemetryOptInConfig {
@@ -80,10 +81,10 @@ export const getTelemetryOptIn: GetTelemetryOptIn = ({
8081
return savedOptIn;
8182
};
8283

83-
function parseSemver(version: string): semver.SemVer | null {
84+
function parseSemver(version: string): SemVer | null {
8485
// semver functions both return nulls AND throw exceptions: "it depends!"
8586
try {
86-
return semver.parse(version);
87+
return semverParse(version);
8788
} catch (err) {
8889
return null;
8990
}

x-pack/plugins/enterprise_search/common/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { SemVer } from 'semver';
7+
import SemVer from 'semver/classes/semver';
88
import pkg from '../../../../package.json';
99

1010
export const CURRENT_VERSION = new SemVer(pkg.version as string);

x-pack/plugins/ml/common/util/job_utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66

77
import { isEmpty, isEqual, each, pick } from 'lodash';
8-
9-
import semver from 'semver';
8+
import semverGte from 'semver/functions/gte';
109
import moment, { Duration } from 'moment';
1110
// @ts-ignore
1211
import numeral from '@elastic/numeral';
@@ -205,7 +204,7 @@ export function isModelPlotEnabled(
205204
// created with) is greater than or equal to the supplied version (e.g. '6.1.0').
206205
export function isJobVersionGte(job: CombinedJob, version: string): boolean {
207206
const jobVersion = job.job_version ?? '0.0.0';
208-
return semver.gte(jobVersion, version);
207+
return semverGte(jobVersion, version);
209208
}
210209

211210
// Takes an ML detector 'function' and returns the corresponding ES aggregation name

x-pack/plugins/monitoring/public/lib/logstash/pipelines.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import semver from 'semver';
7+
import semverMajor from 'semver/functions/major';
88
import { LOGSTASH } from '../../../common/constants';
99

1010
export function isPipelineMonitoringSupportedInVersion(logstashVersion) {
11-
const major = semver.major(logstashVersion);
11+
const major = semverMajor(logstashVersion);
1212
return major >= LOGSTASH.MAJOR_VER_REQD_FOR_PIPELINES;
1313
}

x-pack/plugins/upgrade_assistant/common/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { SemVer } from 'semver';
7+
import SemVer from 'semver/classes/semver';
88
import pkg from '../../../../package.json';
99

1010
export const CURRENT_VERSION = new SemVer(pkg.version as string);

x-pack/tasks/helpers/pkg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import Fs from 'fs';
8-
import semver from 'semver';
8+
import semverValid from 'semver/functions/valid';
99

1010
interface PackageJson {
1111
name: string;
@@ -28,6 +28,6 @@ if (!PKG_NAME) {
2828
throw new Error('No "name" found in package.json');
2929
}
3030

31-
if (!semver.valid(PKG_VERSION)) {
31+
if (!semverValid(PKG_VERSION)) {
3232
throw new Error(`Version is not valid semver: ${PKG_VERSION}`);
3333
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25129,7 +25129,7 @@ semver@7.0.0:
2512925129
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
2513025130
integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==
2513125131

25132-
semver@7.3.2, semver@^7, semver@^7.1.3, semver@^7.3.2:
25132+
semver@7.3.2, semver@^7.1.3, semver@^7.3.2:
2513325133
version "7.3.2"
2513425134
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
2513525135
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==

0 commit comments

Comments
 (0)