[chore] Reuse bundled lodash and lodash/fp dependency (#217467)

## Summary

After #217202 and #217034 this the another attempt with `lodash` and
`lodash/fp`.

In short:
`lodash` and `lodash/fp` have a special webpack treatment as they are
imported within the shared bundle.
Now webpack is not smart enough to understand that `import camelCase
from 'lodash/camelCase';` is still pointing to `lodash` and it thinks
that `lodash/camelCase` is a different package, de-optimizing the
bundling caching system.
So I’ve tweaked the import to make it point to the shared bundle and
save few kbs here and there
This commit is contained in:
Marco Liberati 2025-04-17 14:54:25 +02:00 committed by GitHub
parent ea3dead452
commit e21bec3f31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 57 additions and 68 deletions

View file

@ -8,7 +8,7 @@
*/
import { TSESTree } from '@typescript-eslint/typescript-estree';
import camelCase from 'lodash/camelCase';
import { camelCase } from 'lodash';
/*
Attempts to get a string representation of the intent

View file

@ -8,7 +8,7 @@
*/
import { unlinkSync as unlink } from 'fs';
import once from 'lodash/once';
import { once } from 'lodash';
import type { Logger } from '@kbn/logging';
import { writeFile, exists } from './fs';
import { PidConfigType } from './pid_config';

View file

@ -9,7 +9,7 @@
import pMap from 'p-map';
import type { estypes } from '@elastic/elasticsearch';
import intersection from 'lodash/intersection';
import { intersection } from 'lodash';
import type { Logger } from '@kbn/logging';
import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';

View file

@ -9,7 +9,7 @@
import { transformWithTs } from '@formatjs/ts-transformer';
import difference from 'lodash/difference';
import { difference } from 'lodash';
import * as icuParser from '@formatjs/icu-messageformat-parser';
import type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';

View file

@ -19,7 +19,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { isEqual } from 'lodash';
import { isEqual, memoize } from 'lodash';
import { CodeEditor, CodeEditorProps } from '@kbn/code-editor';
import { KBN_FIELD_TYPES } from '@kbn/field-types';
import type { CoreStart } from '@kbn/core/public';
@ -29,7 +29,6 @@ import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { ILicense } from '@kbn/licensing-plugin/public';
import { ESQLLang, ESQL_LANG_ID, monaco, type ESQLCallbacks } from '@kbn/monaco';
import memoize from 'lodash/memoize';
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { fixESQLQueryWithVariables } from '@kbn/esql-utils';
import { createPortal } from 'react-dom';

View file

@ -8,7 +8,7 @@
*/
import execa from 'execa';
import memoize from 'lodash/memoize';
import { memoize } from 'lodash';
export const extractImageInfo = memoize(async (image: string) => {
try {

View file

@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import words from 'lodash/words';
import { words } from 'lodash';
import { Query } from '@elastic/eui';
import { FieldDefinition, SettingType } from '@kbn/management-settings-types';

View file

@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import isEqual from 'lodash/isEqual';
import { isEqual } from 'lodash';
import type {
FieldDefinition,

View file

@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import isEqual from 'lodash/isEqual';
import { isEqual } from 'lodash';
import { FieldDefinition, SettingType, UnsavedFieldChange } from '@kbn/management-settings-types';
import { hasUnsavedChange } from './has_unsaved_change';

View file

@ -8,7 +8,7 @@
*/
import { UiSettingMetadata, Value } from '@kbn/management-settings-types';
import isEqual from 'lodash/isEqual';
import { isEqual } from 'lodash';
/**
* Utility function to compare a value to the default value of a {@link UiSettingMetadata}.

View file

@ -9,7 +9,7 @@
const { join } = require('path');
const { ESLint } = require('eslint');
const partition = require('lodash/partition');
const { partition } = require('lodash');
const { readdirSync, readFileSync, writeFileSync } = require('fs');
const ora = require('ora');
const log = ora('Updating ES|QL AST walker from antlr grammar').start();

View file

@ -22,7 +22,7 @@ import { BehaviorSubject } from 'rxjs';
import { castEsToKbnFieldTypeName } from '@kbn/field-types';
import { renderToString } from 'react-dom/server';
import React from 'react';
import debounce from 'lodash/debounce';
import { debounce } from 'lodash';
import { PreviewState, FetchDocError } from './types';
import { BehaviorObservable } from '../../state_utils';
import { EsDocument, ScriptErrorCodes, Params, FieldPreview } from './types';

View file

@ -13,8 +13,7 @@ import expect from '@kbn/expect';
import { MappingProperty } from '@elastic/elasticsearch/lib/api/types';
import { hasStartEndParams } from '@kbn/esql-utils';
import { REPO_ROOT } from '@kbn/repo-info';
import uniqBy from 'lodash/uniqBy';
import { groupBy, mapValues } from 'lodash';
import { groupBy, mapValues, uniqBy } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';
function getConfigPath() {

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import get from 'lodash/get';
import { get } from 'lodash';
import {
SavedObjectsType,
ISavedObjectTypeRegistry,

View file

@ -7,9 +7,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
// Prefer importing entire lodash library, e.g. import { get } from "lodash"
// eslint-disable-next-line no-restricted-imports
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'lodash';
import { EuiForm, EuiButton, EuiPage, EuiPageBody, EuiPageSection, EuiSpacer } from '@elastic/eui';
import { EventInput } from '../event_input';

View file

@ -7,7 +7,7 @@
import ipaddr from 'ipaddr.js';
import { parseAddressList } from 'email-addresses';
import isString from 'lodash/isString';
import { isString } from 'lodash';
import {
OBSERVABLE_TYPE_DOMAIN,

View file

@ -7,7 +7,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import pick from 'lodash/pick';
import { pick } from 'lodash';
import { FieldAttribute, FieldMetadataPlain, PartialFieldMetadataPlain } from '../types';
// Use class/interface merging to define instance properties from FieldMetadataPlain.

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import mapValues from 'lodash/mapValues';
import { mapValues } from 'lodash';
import { FieldAttribute, FieldMetadataPlain, PartialFieldMetadataPlain } from '../types';
import { FieldMetadata } from './field_metadata';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import mapValues from 'lodash/mapValues';
import { mapValues } from 'lodash';
import { FieldsMetadataDictionary } from '../../../../common/fields_metadata/models/fields_metadata_dictionary';
import { AnyFieldName, EcsFieldName, FieldMetadata, TEcsFields } from '../../../../common';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import mapValues from 'lodash/mapValues';
import { mapValues } from 'lodash';
import { MetadataFieldName } from '../../../../common/fields_metadata';
import { FieldsMetadataDictionary } from '../../../../common/fields_metadata/models/fields_metadata_dictionary';
import { AnyFieldName, FieldMetadata, TMetadataFields } from '../../../../common';

View file

@ -22,7 +22,7 @@ import {
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { getFlattenedObject } from '@kbn/std';
import omit from 'lodash/omit';
import { omit } from 'lodash';
import type { SearchHit } from '@kbn/es-types';
import styled from 'styled-components';
@ -109,7 +109,7 @@ const AgentDataPreview: React.FC<{ dataPreview: SearchHit[] }> = ({ dataPreview
{previewData.map((hit) => (
<div id={hit._id}>
<EuiFlexGroup gutterSize={'xs'}>
<EuiFlexItem style={{ minWidth: '220px' }}>
<EuiFlexItem css={{ minWidth: '220px' }}>
<HitTimestamp hit={hit} />
</EuiFlexItem>

View file

@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import partition from 'lodash/partition';
import { partition } from 'lodash';
import { FEATURED_INTEGRATIONS_BY_CATEGORY } from '@kbn/custom-integrations-plugin/common';

View file

@ -9,7 +9,7 @@ import path from 'path';
import { readdirSync, statSync, readFile } from 'fs';
import { promisify } from 'util';
import partition from 'lodash/partition';
import { partition } from 'lodash';
import type { Logger } from '@kbn/core/server';
import { ToolingLog } from '@kbn/tooling-log';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import { deserializeGeoipDatabase, type GeoipDatabaseFromES } from './serialization';
import { API_BASE_PATH } from '../../../../common/constants';
import { RouteDependencies } from '../../../types';

View file

@ -10,7 +10,7 @@ import { identity } from 'fp-ts/function';
import { pipe } from 'fp-ts/pipeable';
import * as rt from 'io-ts';
import { failure } from 'io-ts/lib/PathReporter';
import get from 'lodash/get';
import { get } from 'lodash';
type ErrorFactory = (message: string) => Error;

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import dateMath from '@elastic/datemath';
import type { estypes } from '@elastic/elasticsearch';
import type { RuleExecutorOptions } from '@kbn/alerting-plugin/server';

View file

@ -6,8 +6,7 @@
*/
import { from } from 'rxjs';
import isEmpty from 'lodash/isEmpty';
import get from 'lodash/get';
import { isEmpty, get } from 'lodash';
import deepmerge from 'deepmerge';
import { ElasticsearchClient, StartServicesAccessor } from '@kbn/core/server';
import {

View file

@ -9,7 +9,7 @@ import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import type { QueryClientConfig } from '@tanstack/react-query';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import merge from 'lodash/merge';
import { merge } from 'lodash';
import { EuiButtonIcon } from '@elastic/eui';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
@ -44,7 +44,7 @@ function HideableReactQueryDevTools() {
data-test-subj="infraHideableReactQueryDevToolsButton"
iconType="cross"
color="primary"
style={{ zIndex: 99999, position: 'fixed', bottom: '40px', left: '40px' }}
css={{ zIndex: 99999, position: 'fixed', bottom: '40px', left: '40px' }}
onClick={() => setIsHidden(!isHidden)}
aria-label={i18n.translate(
'xpack.infra.hideableReactQueryDevTools.euiButtonIcon.disableReactQueryDevLabel',

View file

@ -10,7 +10,7 @@ import type {
RouteValidationError,
} from '@kbn/core/server';
import { either, fold } from 'fp-ts/Either';
import get from 'lodash/get';
import { get } from 'lodash';
import { pipe } from 'fp-ts/pipeable';
import { formatErrors } from '@kbn/securitysolution-io-ts-utils';
import * as rt from 'io-ts';

View file

@ -6,7 +6,7 @@
*/
import pMap from 'p-map';
import times from 'lodash/times';
import { times } from 'lodash';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { intersection } from 'lodash';
import { AlertStatusMetaData } from '../../../../common/runtime_types/alert_rules/common';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import throttle from 'lodash/throttle';
import { throttle } from 'lodash';
import { useEffect, useState } from 'react';
export const useCurrentWindowWidth = () => {

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import sortBy from 'lodash/fp/sortBy';
import { sortBy } from 'lodash/fp';
import { DataQualityCheckResult, ErrorSummary, PatternRollup } from '../../../types';
export const getErrorSummary = ({

View file

@ -8,7 +8,7 @@
import { defaultConfig, StorybookConfig } from '@kbn/storybook';
import type { Configuration } from 'webpack';
import { merge as webpackMerge } from 'webpack-merge';
import merge from 'lodash/merge';
import { merge } from 'lodash';
// eslint-disable-next-line import/no-nodejs-modules
import { resolve } from 'path';

View file

@ -18,7 +18,7 @@ import {
EuiButtonIcon,
EuiIcon,
} from '@elastic/eui';
import partition from 'lodash/fp/partition';
import { partition } from 'lodash/fp';
import classNames from 'classnames';
import { METRIC_TYPE } from '@kbn/analytics';
import { i18n } from '@kbn/i18n';

View file

@ -14,7 +14,7 @@ import type {
} from '@kbn/fleet-plugin/common';
import { SetupTechnology } from '@kbn/fleet-plugin/public';
import { CSPM_POLICY_TEMPLATE, KSPM_POLICY_TEMPLATE } from '@kbn/cloud-security-posture-common';
import merge from 'lodash/merge';
import { merge } from 'lodash';
import semverValid from 'semver/functions/valid';
import semverCoerce from 'semver/functions/coerce';
import semverLt from 'semver/functions/lt';

View file

@ -5,8 +5,7 @@
* 2.0.
*/
import get from 'lodash/get';
import isArray from 'lodash/isArray';
import { get, isArray } from 'lodash';
import type { Capabilities } from '@kbn/core/public';
/**

View file

@ -7,7 +7,7 @@
import type { DataView, DataViewLazy, DataViewsServicePublic } from '@kbn/data-views-plugin/public';
import type { AnyAction, Dispatch, ListenerEffectAPI } from '@reduxjs/toolkit';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'lodash';
import type { RootState } from '../reducer';
import { scopes } from '../reducer';
import { selectDataViewAsync } from '../actions';

View file

@ -7,7 +7,7 @@
import type { FC } from 'react';
import React, { useMemo, memo } from 'react';
import { EuiSwitch, EuiToolTip } from '@elastic/eui';
import noop from 'lodash/noop';
import { noop } from 'lodash';
import type { MlSummaryJob } from '@kbn/ml-plugin/public';

View file

@ -10,7 +10,7 @@
import { has, isEmpty, get } from 'lodash/fp';
import type { Unit } from '@kbn/datemath';
import deepmerge from 'deepmerge';
import omit from 'lodash/omit';
import { omit } from 'lodash';
import type {
ExceptionListType,

View file

@ -7,7 +7,7 @@
import { v4 as uuidv4 } from 'uuid';
import type { LensAttributes } from '@kbn/lens-embeddable-utils';
import capitalize from 'lodash/capitalize';
import { capitalize } from 'lodash';
import { SEVERITY_UI_SORT_ORDER, RISK_SCORE_RANGES, RISK_SEVERITY_COLOUR } from '../common/utils';
import type { EntityType } from '../../../common/entity_analytics/types';

View file

@ -7,8 +7,7 @@
import React, { memo } from 'react';
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
import isEmpty from 'lodash/isEmpty';
import { groupBy } from 'lodash';
import { groupBy, isEmpty } from 'lodash';
import { EnrichmentSection } from './threat_details_view_enrichment_section';
import { ENRICHMENT_TYPES } from '../../../../../common/cti/constants';
import { EnrichmentRangePicker } from './threat_intelligence_view_enrichment_range_picker';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { performance } from 'perf_hooks';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'lodash';
import type { ShardFailure } from '@elastic/elasticsearch/lib/api/types';
import { buildEqlSearchRequest } from './build_eql_search_request';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import get from 'lodash/fp/get';
import { get } from 'lodash/fp';
import type { Filter } from '@kbn/es-query';
import type {
ThreatMapping,

View file

@ -6,7 +6,7 @@
*/
import objectHash from 'object-hash';
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import type { SuppressionFieldsLatest } from '@kbn/rule-registry-plugin/common/schemas';
import {

View file

@ -5,9 +5,7 @@
* 2.0.
*/
import pick from 'lodash/pick';
import get from 'lodash/get';
import partition from 'lodash/partition';
import { pick, get, partition } from 'lodash';
import type { SignalSourceHit } from '../types';

View file

@ -5,8 +5,7 @@
* 2.0.
*/
import get from 'lodash/get';
import sortBy from 'lodash/sortBy';
import { get, sortBy } from 'lodash';
import {
ALERT_SUPPRESSION_DOCS_COUNT,

View file

@ -7,7 +7,7 @@
import type { IKibanaResponse, Logger } from '@kbn/core/server';
import { buildRouteValidationWithZod } from '@kbn/zod-helpers';
import partition from 'lodash/partition';
import { partition } from 'lodash';
import { SIEM_RULE_MIGRATION_RESOURCES_PATH } from '../../../../../../common/siem_migrations/constants';
import {
UpsertRuleMigrationResourcesRequestBody,

View file

@ -7,7 +7,7 @@
import { either } from 'fp-ts/Either';
import * as rt from 'io-ts';
import get from 'lodash/get';
import { get } from 'lodash';
export type GenericIntersectionC =
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -6,7 +6,7 @@
*/
import { EuiBadge } from '@elastic/eui';
import capitalize from 'lodash/capitalize';
import { capitalize } from 'lodash';
import React, { useMemo, VFC } from 'react';
import { EMPTY_VALUE } from '../../../../constants/common';

View file

@ -7,7 +7,7 @@
import { EuiDataGridColumn, EuiDataGridSorting } from '@elastic/eui';
import { useCallback, useEffect, useMemo, useState } from 'react';
import negate from 'lodash/negate';
import { negate } from 'lodash';
import { RawIndicatorFieldId } from '../../../../common/types/indicator';
import { useKibana } from '../../../hooks/use_kibana';
import { translateFieldLabel } from '../components/common/field_label';

View file

@ -7,8 +7,7 @@
import expect from 'expect';
import { v4 as uuidv4 } from 'uuid';
import sortBy from 'lodash/sortBy';
import partition from 'lodash/partition';
import { sortBy, partition } from 'lodash';
import {
DetectionAlert,

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import expect from 'expect';
import { v4 as uuidv4 } from 'uuid';

View file

@ -7,7 +7,7 @@
import { v4 as uuidv4 } from 'uuid';
import expect from 'expect';
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import {
ALERT_SUPPRESSION_START,

View file

@ -7,7 +7,7 @@
import { v4 as uuidv4 } from 'uuid';
import expect from 'expect';
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import {
ALERT_SUPPRESSION_START,

View file

@ -7,7 +7,7 @@
import { v4 as uuidv4 } from 'uuid';
import expect from 'expect';
import sortBy from 'lodash/sortBy';
import { sortBy } from 'lodash';
import {
ALERT_SUPPRESSION_START,
ALERT_SUPPRESSION_END,