[7.x] upgrade elastic/numeral and complete migration away from numeral (#68035) (#68140)

Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Spencer 2020-06-03 12:31:54 -07:00 committed by GitHub
parent e4b9ef0983
commit da1e5596ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 31 additions and 69 deletions

View file

@ -126,7 +126,7 @@
"@elastic/eui": "23.3.1",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "2.4.0",
"@elastic/numeral": "^2.5.0",
"@elastic/request-crypto": "1.1.4",
"@elastic/ui-ace": "0.2.3",
"@hapi/good-squeeze": "5.2.1",
@ -359,7 +359,6 @@
"@types/node": ">=10.17.17 <10.20.0",
"@types/node-forge": "^0.9.0",
"@types/normalize-path": "^3.0.0",
"@types/numeral": "^0.0.26",
"@types/opn": "^5.1.0",
"@types/pegjs": "^0.10.1",
"@types/pngjs": "^3.3.2",

View file

@ -39,6 +39,10 @@ module.exports = {
to: false,
disallowedMessage: `Don't use 'mkdirp', use the new { recursive: true } option of Fs.mkdir instead`
},
{
from: 'numeral',
to: '@elastic/numeral',
},
{
from: '@kbn/elastic-idx',
to: false,

View file

@ -44,6 +44,7 @@ Moment.tz.load(require('moment-timezone/data/packed/latest.json'));
// big deps which are locked to a single version
export const Rxjs = require('rxjs');
export const RxjsOperators = require('rxjs/operators');
export const ElasticNumeral = require('@elastic/numeral');
export const ElasticCharts = require('@elastic/charts');
export const ElasticEui = require('@elastic/eui');
export const ElasticEuiLibServices = require('@elastic/eui/lib/services');

View file

@ -51,6 +51,8 @@ exports.externals = {
*/
rxjs: '__kbnSharedDeps__.Rxjs',
'rxjs/operators': '__kbnSharedDeps__.RxjsOperators',
numeral: '__kbnSharedDeps__.ElasticNumeral',
'@elastic/numeral': '__kbnSharedDeps__.ElasticNumeral',
'@elastic/charts': '__kbnSharedDeps__.ElasticCharts',
'@elastic/eui': '__kbnSharedDeps__.ElasticEui',
'@elastic/eui/lib/services': '__kbnSharedDeps__.ElasticEuiLibServices',

View file

@ -11,6 +11,7 @@
"dependencies": {
"@elastic/charts": "19.2.0",
"@elastic/eui": "23.3.1",
"@elastic/numeral": "^2.5.0",
"@kbn/i18n": "1.0.0",
"abortcontroller-polyfill": "^1.4.0",
"angular": "^1.7.9",

View file

@ -4,7 +4,7 @@ exports[`byte metric 1`] = `
<EuiCard
description="Heap Total"
layout="horizontal"
title="1.50 GB"
title="1.40 GB"
/>
`;

View file

@ -47,20 +47,20 @@ const MS_METRIC = {
test('general metric', () => {
const component = shallow(<MetricTile metric={GENERAL_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});
test('byte metric', () => {
const component = shallow(<MetricTile metric={BYTE_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});
test('float metric', () => {
const component = shallow(<MetricTile metric={FLOAT_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});
test('millisecond metric', () => {
const component = shallow(<MetricTile metric={MS_METRIC} />);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(component).toMatchSnapshot();
});

View file

@ -17,7 +17,7 @@
* under the License.
*/
import numeral from 'numeral';
import numeral from '@elastic/numeral';
export default function formatNumber(num, which) {
let format = '0.00';

View file

@ -21,42 +21,42 @@ import formatNumber from './format_number';
describe('format byte', () => {
test('zero', () => {
expect(formatNumber(0, 'byte')).toEqual('0.00 B');
expect(formatNumber(0, 'byte')).toMatchInlineSnapshot(`"0.00 B"`);
});
test('mb', () => {
expect(formatNumber(181142512, 'byte')).toEqual('181.14 MB');
expect(formatNumber(181142512, 'byte')).toMatchInlineSnapshot(`"172.75 MB"`);
});
test('gb', () => {
expect(formatNumber(273727485000, 'byte')).toEqual('273.73 GB');
expect(formatNumber(273727485000, 'byte')).toMatchInlineSnapshot(`"254.93 GB"`);
});
});
describe('format ms', () => {
test('zero', () => {
expect(formatNumber(0, 'ms')).toEqual('0.00 ms');
expect(formatNumber(0, 'ms')).toMatchInlineSnapshot(`"0.00 ms"`);
});
test('sub ms', () => {
expect(formatNumber(0.128, 'ms')).toEqual('0.13 ms');
expect(formatNumber(0.128, 'ms')).toMatchInlineSnapshot(`"0.13 ms"`);
});
test('many ms', () => {
expect(formatNumber(3030.284, 'ms')).toEqual('3030.28 ms');
expect(formatNumber(3030.284, 'ms')).toMatchInlineSnapshot(`"3030.28 ms"`);
});
});
describe('format integer', () => {
test('zero', () => {
expect(formatNumber(0, 'integer')).toEqual('0');
expect(formatNumber(0, 'integer')).toMatchInlineSnapshot(`"0"`);
});
test('sub integer', () => {
expect(formatNumber(0.728, 'integer')).toEqual('1');
expect(formatNumber(0.728, 'integer')).toMatchInlineSnapshot(`"1"`);
});
test('many integer', () => {
expect(formatNumber(3030.284, 'integer')).toEqual('3030');
expect(formatNumber(3030.284, 'integer')).toMatchInlineSnapshot(`"3030"`);
});
});

View file

@ -19,7 +19,7 @@
import React from 'react';
import _ from 'lodash';
import numeral from 'numeral';
import numeral from '@elastic/numeral';
import { renderToStaticMarkup } from 'react-dom/server';
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react';

View file

@ -20,7 +20,7 @@
import d3 from 'd3';
import _ from 'lodash';
import $ from 'jquery';
import numeral from 'numeral';
import numeral from '@elastic/numeral';
import { PieContainsAllZeros, ContainerTooSmall } from '../errors';
import { Chart } from './_chart';
import { truncateLabel } from '../components/labels/truncate_labels';

View file

@ -1,20 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
module.exports = require('@elastic/numeral');

View file

@ -195,7 +195,7 @@
"@elastic/filesaver": "1.1.2",
"@elastic/maki": "6.3.0",
"@elastic/node-crypto": "1.1.1",
"@elastic/numeral": "2.4.0",
"@elastic/numeral": "^2.5.0",
"@kbn/babel-preset": "1.0.0",
"@kbn/config-schema": "1.0.0",
"@kbn/i18n": "1.0.0",

View file

@ -1,20 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
interface Numeral {
(value?: unknown): Numeral;
format: (pattern: string) => string;
unformat: (pattern: string) => number;
language: (key?: any, values?: any) => Numeral;
set: (value?: any) => Numeral;
}
// eslint-disable-next-line no-var
declare var numeral: Numeral;
declare module '@elastic/numeral' {
export = numeral;
}

View file

@ -1379,10 +1379,10 @@
resolved "https://registry.yarnpkg.com/@elastic/node-crypto/-/node-crypto-1.1.1.tgz#619b70322c9cce4a7ee5fbf8f678b1baa7f06095"
integrity sha512-F6tIk8Txdqjg8Siv60iAvXzO9ZdQI87K3sS/fh5xd2XaWK+T5ZfqeTvsT7srwG6fr6uCBfuQEJV1KBBl+JpLZA==
"@elastic/numeral@2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@elastic/numeral/-/numeral-2.4.0.tgz#883197b7f4bf3c2dd994f53b274769ddfa2bf79a"
integrity sha512-uGBKGCNghTgUZPHClji/00v+AKt5nidPTGOIbcT+lbTPVxNB6QPpPLGWtXyrg3QZAxobPM/LAZB1mAqtJeq44Q==
"@elastic/numeral@^2.5.0":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@elastic/numeral/-/numeral-2.5.0.tgz#8da714827fc278f17546601fdfe55f5c920e2bc5"
integrity sha512-NVTuy9Wzblp6nOH86CXjWXTajHgJGn5Tk2l59/Z5cWFU14KlE+8/zqPTgZdxYABzBJFE3L7S07kJDMN8sDvTmA==
"@elastic/request-crypto@1.1.4":
version "1.1.4"
@ -4497,11 +4497,6 @@
resolved "https://registry.yarnpkg.com/@types/numeral/-/numeral-0.0.25.tgz#b6f55062827a4787fe4ab151cf3412a468e65271"
integrity sha512-ShHzHkYD+Ldw3eyttptCpUhF1/mkInWwasQkCNXZHOsJMJ/UMa8wXrxSrTJaVk0r4pLK/VnESVM0wFsfQzNEKQ==
"@types/numeral@^0.0.26":
version "0.0.26"
resolved "https://registry.yarnpkg.com/@types/numeral/-/numeral-0.0.26.tgz#cfab9842ef9349ce714b06722940ca7ebf8a6298"
integrity sha512-DwCsRqeOWopdEsm5KLTxKVKDSDoj+pzZD1vlwu1GQJ6IF3RhjuleYlRwyRH6MJLGaf3v8wFTnC6wo3yYfz0bnA==
"@types/object-hash@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@types/object-hash/-/object-hash-1.3.0.tgz#b20db2074129f71829d61ff404e618c4ac3d73cf"