Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kibanaUtils] Don't import full semver client side #114986

Merged
merged 7 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 90 additions & 75 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,78 @@ const DEV_PATTERNS = [
'x-pack/plugins/*/server/scripts/**/*',
];

/** Restricted imports with suggested alternatives */
const RESTRICTED_IMPORTS = [
{
name: 'lodash',
importNames: ['set', 'setWith'],
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.setwith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp',
importNames: ['set', 'setWith', 'assoc', 'assocPath'],
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/assoc',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash',
importNames: ['template'],
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash.template',
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/template',
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp',
importNames: ['template'],
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp/template',
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'react-use',
message: 'Please use react-use/lib/{method} instead.',
},
];

module.exports = {
root: true,

Expand Down Expand Up @@ -667,81 +739,7 @@ module.exports = {
'no-restricted-imports': [
2,
{
paths: [
{
name: 'lodash',
importNames: ['set', 'setWith'],
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.setwith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp',
importNames: ['set', 'setWith', 'assoc', 'assocPath'],
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/assoc',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash',
importNames: ['template'],
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash.template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp',
importNames: ['template'],
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp/template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'react-use',
message: 'Please use react-use/lib/{method} instead.',
},
],
paths: RESTRICTED_IMPORTS,
},
],
'no-restricted-modules': [
Expand Down Expand Up @@ -834,6 +832,23 @@ module.exports = {
],
},
},
{
files: ['**/common/**/*.{js,mjs,ts,tsx}', '**/public/**/*.{js,mjs,ts,tsx}'],
rules: {
'no-restricted-imports': [
2,
{
paths: [
...RESTRICTED_IMPORTS,
{
name: 'semver',
message: 'Please use "semver/*/{function}" instead',
},
],
},
],
},
},

/**
* APM and Observability overrides
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pageLoadAssetSize:
console: 46091
core: 435325
crossClusterReplication: 65408
dashboard: 374194
dashboard: 186763
dashboardEnhanced: 65646
devTools: 38637
discover: 99999
Expand Down Expand Up @@ -99,7 +99,7 @@ pageLoadAssetSize:
expressionMetricVis: 23121
visTypeMetric: 23332
bfetch: 22837
kibanaUtils: 97808
kibanaUtils: 79713
data: 491273
dataViews: 41532
expressions: 140958
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dashboard/common/saved_dashboard_references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import Semver from 'semver';
import semverGt from 'semver/functions/gt';
import { SavedObjectAttributes, SavedObjectReference } from '../../../core/types';
import { DashboardContainerStateWithType, DashboardPanelState } from './types';
import { EmbeddablePersistableStateService } from '../../embeddable/common/types';
Expand All @@ -23,7 +23,7 @@ export interface SavedObjectAttributesAndReferences {
}

const isPre730Panel = (panel: Record<string, string>): boolean => {
return 'version' in panel ? Semver.gt('7.3.0', panel.version) : true;
return 'version' in panel ? semverGt('7.3.0', panel.version) : true;
};

function dashboardAttributesToState(attributes: SavedObjectAttributes): {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { compare } from 'semver';
import compare from 'semver/functions/compare';
import { SerializableRecord } from '@kbn/utility-types';
import { VersionedState, MigrateFunctionsObject } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import React, { useCallback, useMemo } from 'react';
import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import semver from 'semver';
import semverMajor from 'semver/functions/major';
import semverMinor from 'semver/functions/minor';
import semverPatch from 'semver/functions/patch';

import type { AgentPolicy } from '../../types';
import { useKibanaVersion } from '../../hooks';
Expand All @@ -21,9 +23,7 @@ export const DownloadStep = () => {
const kibanaVersion = useKibanaVersion();
const kibanaVersionURLString = useMemo(
() =>
`${semver.major(kibanaVersion)}-${semver.minor(kibanaVersion)}-${semver.patch(
kibanaVersion
)}`,
`${semverMajor(kibanaVersion)}-${semverMinor(kibanaVersion)}-${semverPatch(kibanaVersion)}`,
[kibanaVersion]
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import { merge } from 'lodash';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import {
notificationServiceMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { createContext, useContext } from 'react';
import { ScopedHistory } from 'kibana/public';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';
import { ManagementAppMountParams } from 'src/plugins/management/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

/* eslint-disable-next-line @kbn/eslint/no-restricted-paths */
import '../../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor/jest_mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
EuiSpacer,
EuiCallOut,
} from '@elastic/eui';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { documentationService } from '../../../../../../services/documentation';
import { Form, FormHook, FormDataProvider } from '../../../../shared_imports';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { i18n } from '@kbn/i18n';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';
import { i18n } from '@kbn/i18n';

import { NormalizedField, Field as FieldType } from '../../../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { NormalizedField, Field as FieldType } from '../../../../types';
import { UseField, Field } from '../../../../shared_imports';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ComponentType } from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { MainType, SubType, DataType, NormalizedField, NormalizedFields } from '../../../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { NormalizedField, Field as FieldType } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';
import { i18n } from '@kbn/i18n';

import { documentationService } from '../../../../../../services/documentation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { NormalizedField, Field as FieldType, ComboBoxOption } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import {
NormalizedField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { EuiSpacer, EuiDualRange, EuiFormRow, EuiCallOut } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { documentationService } from '../../../../../../services/documentation';
import { NormalizedField, Field as FieldType } from '../../../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';
import { i18n } from '@kbn/i18n';

import { documentationService } from '../../../../../../services/documentation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { Provider } from 'react-redux';
import { render, unmountComponentAtNode } from 'react-dom';
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { CoreStart, CoreSetup } from '../../../../../src/core/public';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';

import { MAJOR_VERSION } from '../../../common';
import { Index } from '../../../common';
Expand Down
Loading