Skip to content

Commit

Permalink
chore(NA): upgrades uuid to v9.0.0 (#149135)
Browse files Browse the repository at this point in the history
This PR upgrades uuid into its latest version `9.0.0`.
The previous default used version `v4` was kept where it was previously
used and places using `v1` or `v5` are still using it.

In this latest version they removed the deep import feature and as we
are not using tree shaking it increased our bundles by a significant
size. As such, I've moved this dependency into the `ui-shared-deps-npm`
bundle.

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
mistic and kibanamachine authored Jan 19, 2023
1 parent 195c8b0 commit e38350f
Show file tree
Hide file tree
Showing 361 changed files with 1,111 additions and 1,123 deletions.
4 changes: 2 additions & 2 deletions examples/controls_example/public/search_example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React, { useEffect, useState } from 'react';
import uuid from 'uuid/v4';
import { v4 as uuidv4 } from 'uuid';
import { lastValueFrom } from 'rxjs';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const SearchExample = ({ data, dataView, navigation }: Props) => {
const { rawResponse: resp } = await lastValueFrom(
searchSource.fetch$({
abortSignal: abortController.signal,
sessionId: uuid(),
sessionId: uuidv4(),
legacyHitsTotal: false,
})
);
Expand Down
4 changes: 2 additions & 2 deletions examples/search_examples/server/fibonacci_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { ISearchStrategy } from '@kbn/data-plugin/server';
import { FibonacciRequest, FibonacciResponse } from '../common/types';

Expand All @@ -17,7 +17,7 @@ export const fibonacciStrategyProvider = (): ISearchStrategy<
const responseMap = new Map<string, [number[], number, number]>();
return {
search: (request: FibonacciRequest) => {
const id = request.id ?? uuid();
const id = request.id ?? uuidv4();
const [sequence, total, started] = responseMap.get(id) ?? [
[],
request.params?.n ?? 0,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
"use-resize-observer": "^6.0.0",
"usng.js": "^0.4.5",
"utility-types": "^3.10.0",
"uuid": "3.3.2",
"uuid": "9.0.0",
"vega": "^5.22.1",
"vega-interpreter": "^1.0.4",
"vega-lite": "^5.5.0",
Expand Down Expand Up @@ -992,7 +992,7 @@
"@types/tough-cookie": "^4.0.2",
"@types/type-detect": "^4.0.1",
"@types/use-resize-observer": "^6.0.0",
"@types/uuid": "^3.4.4",
"@types/uuid": "^9.0.0",
"@types/vinyl": "^2.0.4",
"@types/vinyl-fs": "^2.4.11",
"@types/watchpack": "^1.1.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { join } from 'path';
import { PathConfigType } from '@kbn/utils';
import type { Logger } from '@kbn/logging';
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function resolveInstanceUuid({
}
}
if (uuidFromFile === undefined) {
const newUuid = uuid.v4();
const newUuid = uuidv4();
// no uuid either in config or file, we need to generate and write it.
logger.debug(`Setting new Kibana instance UUID: ${newUuid}`);
await writeUuidToFile(uuidFilePath, newUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { URL } from 'url';
import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import type { Request, RouteOptions } from '@hapi/hapi';
import { fromEvent, NEVER } from 'rxjs';
import { shareReplay, first, filter } from 'rxjs/operators';
Expand Down Expand Up @@ -131,8 +131,8 @@ export class CoreKibanaRequest<
// KibanaRequest in conjunction with scoped Elasticsearch and SavedObjectsClient in order to pass credentials.
// In these cases, the ids default to a newly generated UUID.
const appState = request.app as KibanaRequestState | undefined;
this.id = appState?.requestId ?? uuid.v4();
this.uuid = appState?.requestUuid ?? uuid.v4();
this.id = appState?.requestId ?? uuidv4();
this.uuid = appState?.requestUuid ?? uuidv4();
this.rewrittenUrl = appState?.rewrittenUrl;

this.url = request.url ?? new URL('https://fake-request/url');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { config, HttpConfig } from './http_config';
import { cspConfig } from './csp';
import { ExternalUrlConfig } from './external_url';
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('publicBaseUrl', () => {

test('accepts only valid uuids for server.uuid', () => {
const httpSchema = config.schema;
expect(() => httpSchema.validate({ uuid: uuid.v4() })).not.toThrow();
expect(() => httpSchema.validate({ uuid: uuidv4() })).not.toThrow();
expect(() => httpSchema.validate({ uuid: 'not an uuid' })).toThrowErrorMatchingInlineSnapshot(
`"[uuid]: must be a valid uuid"`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Server, Request } from '@hapi/hapi';
import HapiStaticFiles from '@hapi/inert';
import url from 'url';
import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import {
createServer,
getListenerOptions,
Expand Down Expand Up @@ -365,7 +365,7 @@ export class HttpServer {
request.app = {
...(request.app ?? {}),
requestId,
requestUuid: uuid.v4(),
requestUuid: uuidv4(),
// Kibana stores trace.id until https://github.com/elastic/apm-agent-nodejs/issues/2353 is resolved
// The current implementation of the APM agent ends a request transaction before "response" log is emitted.
traceId: apm.currentTraceIds['trace.id'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/

import Boom from '@hapi/boom';
import uuidv5 from 'uuid/v5';
import { v5 as uuidv5 } from 'uuid';
import { set } from '@kbn/safer-lodash-set';
import _ from 'lodash';
import Semver from 'semver';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
*/

const mockUuidv1 = jest.fn().mockReturnValue('uuidv1');
jest.mock('uuid/v1', () => mockUuidv1);

const mockUuidv5 = jest.fn().mockReturnValue('uuidv5');
Object.defineProperty(mockUuidv5, 'DNS', { value: 'DNSUUID', writable: false });
jest.mock('uuid/v5', () => mockUuidv5);

jest.mock('uuid', () => ({
v1: mockUuidv1,
v5: mockUuidv5,
}));

export { mockUuidv1, mockUuidv5 };
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* Side Public License, v 1.
*/

import uuidv1 from 'uuid/v1';
import uuidv5 from 'uuid/v5';
import { v1 as uuidv1, v5 as uuidv5 } from 'uuid';
import type {
SavedObjectsFindOptions,
SavedObjectsFindResponse,
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ pageLoadAssetSize:
visTypeTimeseries: 55203
visTypeVega: 153573
visTypeVislib: 242838
visTypeXy: 31800
visTypeXy: 46868
visualizations: 90000
watcher: 43598
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

import * as t from 'io-ts';
import { Either } from 'fp-ts/lib/Either';
import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { NonEmptyString } from '@kbn/securitysolution-io-ts-types';

/**
* Types the DefaultUuid as:
* - If null or undefined, then a default string uuid.v4() will be
* - If null or undefined, then a default string uuidv4() will be
* created otherwise it will be checked just against an empty string
*/
export const DefaultUuid = new t.Type<string, string | undefined, unknown>(
'DefaultUuid',
t.string.is,
(input, context): Either<t.Errors, string> =>
input == null ? t.success(uuid.v4()) : NonEmptyString.validate(input, context),
input == null ? t.success(uuidv4()) : NonEmptyString.validate(input, context),
t.identity
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

import * as t from 'io-ts';
import { Either } from 'fp-ts/lib/Either';
import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { NonEmptyString } from '../non_empty_string';

/**
* Types the DefaultUuid as:
* - If null or undefined, then a default string uuid.v4() will be
* - If null or undefined, then a default string uuidv4() will be
* created otherwise it will be checked just against an empty string
*/
export const DefaultUuid = new t.Type<string, string | undefined, unknown>(
'DefaultUuid',
t.string.is,
(input, context): Either<t.Errors, string> =>
input == null ? t.success(uuid.v4()) : NonEmptyString.validate(input, context),
input == null ? t.success(uuidv4()) : NonEmptyString.validate(input, context),
t.identity
);
8 changes: 4 additions & 4 deletions packages/kbn-securitysolution-list-utils/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { addIdToItem, removeIdFromItem } from '@kbn/securitysolution-utils';
import { validate } from '@kbn/securitysolution-io-ts-utils';
import {
Expand Down Expand Up @@ -159,7 +159,7 @@ export const getNewExceptionItem = ({
item_id: undefined,
list_id: listId,
meta: {
temporaryUuid: uuid.v4(),
temporaryUuid: uuidv4(),
},
name,
namespace_type: namespaceType,
Expand Down Expand Up @@ -897,7 +897,7 @@ export const getFormattedBuilderEntries = (

export const getDefaultEmptyEntry = (): EmptyEntry => ({
field: '',
id: uuid.v4(),
id: uuidv4(),
operator: OperatorEnum.INCLUDED,
type: OperatorTypeEnum.MATCH,
value: '',
Expand All @@ -906,7 +906,7 @@ export const getDefaultEmptyEntry = (): EmptyEntry => ({
export const getDefaultNestedEmptyEntry = (): EmptyNestedEntry => ({
entries: [],
field: '',
id: uuid.v4(),
id: uuidv4(),
type: OperatorTypeEnum.NESTED,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';

/**
* This is useful for when you have arrays without an ID and need to add one for
Expand All @@ -23,7 +23,7 @@ export const addIdToItem = <T>(item: NotArray<T>): T => {
if (maybeId.id != null) {
return item;
} else {
return { ...item, id: uuid.v4() };
return { ...item, id: uuidv4() };
}
};

Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-server-http-tools/src/get_request_id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Request } from '@hapi/hapi';
import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';

export function getRequestId(
request: Request,
Expand All @@ -17,6 +17,6 @@ export function getRequestId(
return allowFromAnyIp ||
// socket may be undefined in integration tests that connect via the http listener directly
(remoteAddress && ipAllowlist.includes(remoteAddress))
? request.headers['x-opaque-id'] ?? uuid.v4()
: uuid.v4();
? request.headers['x-opaque-id'] ?? uuidv4()
: uuidv4();
}
4 changes: 2 additions & 2 deletions packages/kbn-test/src/es/test_es_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Path from 'path';
import { format } from 'url';
import del from 'del';
import Uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import globby from 'globby';
import createArchiver from 'archiver';
import Fs from 'fs';
Expand Down Expand Up @@ -307,7 +307,7 @@ export function createTestEsCluster<
return;
}

const uuid = Uuid.v4();
const uuid = uuidv4();
const debugPath = Path.resolve(REPO_ROOT, `data/es_debug_${uuid}.tar.gz`);
log.error(`[es] debug files found, archiving install to ${debugPath}`);
const archiver = createArchiver('tar', { gzip: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Path from 'path';
import Os from 'os';

import Uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import type { ProcRunner } from '@kbn/dev-proc-runner';
import { REPO_ROOT } from '@kbn/repo-info';

Expand Down Expand Up @@ -98,7 +98,7 @@ export async function runKibanaServer(options: {
? []
: [
'--node.roles=["ui"]',
`--path.data=${Path.resolve(Os.tmpdir(), `ftr-ui-${Uuid.v4()}`)}`,
`--path.data=${Path.resolve(Os.tmpdir(), `ftr-ui-${uuidv4()}`)}`,
]),
]),
],
Expand All @@ -121,7 +121,7 @@ export async function runKibanaServer(options: {
...kbnFlags,
`--server.port=${DedicatedTaskRunner.getPort(config.get('servers.kibana.port'))}`,
'--node.roles=["background_tasks"]',
`--path.data=${Path.resolve(Os.tmpdir(), `ftr-task-runner-${Uuid.v4()}`)}`,
`--path.data=${Path.resolve(Os.tmpdir(), `ftr-task-runner-${uuidv4()}`)}`,
...(typeof mainUuid === 'string' && mainUuid
? [`--server.uuid=${DedicatedTaskRunner.getUuid(mainUuid)}`]
: []),
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps-npm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ RUNTIME_DEPS = [
"@npm//rxjs",
"@npm//styled-components",
"@npm//tslib",
"@npm//uuid",
]

webpack_cli(
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps-npm/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module.exports = (_, argv) => {
'rxjs/operators',
'styled-components',
'tslib',
'uuid',
],
'kbn-ui-shared-deps-npm.v8.dark': ['@elastic/eui/dist/eui_theme_dark.css'],
'kbn-ui-shared-deps-npm.v8.light': ['@elastic/eui/dist/eui_theme_light.css'],
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps-src/src/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const externals = {
* runtime deps which don't need to be copied across all bundles
*/
tslib: '__kbnSharedDeps__.TsLib',
uuid: '__kbnSharedDeps__.Uuid',
'@kbn/analytics': '__kbnSharedDeps__.KbnAnalytics',
'@kbn/es-query': '__kbnSharedDeps__.KbnEsQuery',
'@kbn/std': '__kbnSharedDeps__.KbnStd',
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps-src/src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const Fflate = { unzlibSync, strFromU8 };

// runtime deps which don't need to be copied across all bundles
export const TsLib = require('tslib');
export const Uuid = require('uuid');
export const KbnAnalytics = require('@kbn/analytics');
export const KbnEsQuery = require('@kbn/es-query');
export const KbnStd = require('@kbn/std');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ describe(`POST ${URL}`, () => {
const mockUuid = jest.requireMock('uuid');
mockUuid.v4 = jest
.fn()
.mockReturnValueOnce('foo') // a uuid.v4() is generated for the request.id
.mockReturnValueOnce('foo') // another uuid.v4() is used for the request.uuid
.mockReturnValueOnce('foo') // a uuidv4() is generated for the request.id
.mockReturnValueOnce('foo') // another uuidv4() is used for the request.uuid
.mockReturnValueOnce('new-id-1')
.mockReturnValueOnce('new-id-2');
savedObjectsClient.bulkGet.mockResolvedValueOnce({ saved_objects: [mockIndexPattern] });
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/console/common/constants/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';

export const DEFAULT_VARIABLES = [
{ id: uuid.v4(), name: 'exampleVariable1', value: '_search' },
{ id: uuid.v4(), name: 'exampleVariable2', value: 'match_all' },
{ id: uuidv4(), name: 'exampleVariable1', value: '_search' },
{ id: uuidv4(), name: 'exampleVariable2', value: 'match_all' },
];
Loading

0 comments on commit e38350f

Please sign in to comment.