Skip to content

Commit 55a4d80

Browse files
authored
feat(utils): Add deprecation helpers (#443)
* feat(utils): add deprecation helper * feat(utils): add deprecated prop type * feat(configs): remove deprecation warnings in production * fix(components): use tiny-warning * refactor(utils): move copyright notice above imports
1 parent 065b5ec commit 55a4d80

File tree

8 files changed

+72
-8
lines changed

8 files changed

+72
-8
lines changed

.babelrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"plugins": [
1717
"@babel/plugin-proposal-class-properties",
1818
"lodash",
19-
"inline-react-svg"
19+
"inline-react-svg",
20+
"dev-expression"
2021
],
2122
"presets": [
2223
["@babel/preset-env", { "loose": true }],
@@ -34,7 +35,8 @@
3435
"plugins": [
3536
"@babel/plugin-proposal-class-properties",
3637
"lodash",
37-
"inline-react-svg"
38+
"inline-react-svg",
39+
"dev-expression"
3840
],
3941
"presets": [
4042
["@babel/preset-env", { "loose": true, "modules": false }],

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"babel-eslint": "^10.0.1",
8383
"babel-jest": "^24.5.0",
8484
"babel-loader": "^8.0.5",
85+
"babel-plugin-dev-expression": "^0.2.2",
8586
"babel-plugin-dynamic-import-node": "^2.2.0",
8687
"babel-plugin-lodash": "^3.3.2",
8788
"babel-plugin-module-resolver": "^3.2.0",
@@ -123,8 +124,8 @@
123124
"@emotion/styled": "^10.0.10",
124125
"@svgr/webpack": "^4.1.0",
125126
"babel-plugin-inline-react-svg": "^1.1.0",
126-
"css-loader": "^2.1.1",
127127
"commitizen": "^3.0.5",
128+
"css-loader": "^2.1.1",
128129
"cz-customizable": "^5.3.0",
129130
"cz-customizable-ghooks": "^1.5.0",
130131
"dom-helpers": "^3.4.0",
@@ -153,7 +154,7 @@
153154
"react-with-styles": "^3.2.1",
154155
"recompose": "^0.30.0",
155156
"text-mask-addons": "^3.8.0",
156-
"warning": "^4.0.3"
157+
"tiny-warning": "^1.0.3"
157158
},
158159
"husky": {
159160
"hooks": {

src/components/SideNav/components/Modal/Modal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import React from 'react';
1919
import ReactDOM from 'react-dom';
2020
import styled from '@emotion/styled';
2121
import PropTypes from 'prop-types';
22-
import warning from 'warning';
22+
import warning from 'tiny-warning';
2323
import keycode from 'keycode';
2424
import ownerDocument from '../../../../util/ownerDocument';
2525
import RootRef from '../RootRef';

src/components/SideNav/transitions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/* eslint-disable no-param-reassign */
1717
/* eslint-disable no-restricted-globals */
1818

19-
import warning from 'warning';
19+
import warning from 'tiny-warning';
2020

2121
// Follow https://material.google.com/motion/duration-easing.html#duration-easing-natural-easing-curves
2222
// to learn the context in which each easing should be used.

src/util/deprecate.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2019, SumUp Ltd.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import warning from 'tiny-warning';
17+
18+
const warned = {};
19+
20+
export default function deprecate(explanation = '') {
21+
if (__DEV__) {
22+
const { stack } = new Error();
23+
const message = `DEPRECATION: ${explanation}\n ${stack}`;
24+
25+
if (!warned[message]) {
26+
warning(false, message);
27+
warned[message] = true;
28+
}
29+
}
30+
}

src/util/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import warning from 'warning';
16+
import warning from 'tiny-warning';
1717

1818
/**
1919
* Safe chained function

src/util/shared-prop-types.js

+21
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,33 @@
1414
*/
1515

1616
import PropTypes from 'prop-types';
17+
import deprecate from './deprecate';
1718
import { TOP, BOTTOM, LEFT, RIGHT, START, END, CENTER } from './constants';
1819

1920
// TODO: figure out if we can still get these props in react-docgen
2021
// when they are imported and merged into a component's
2122
// propTypes.
2223

24+
export const deprecatedPropType = (propType, explanation = '') => (
25+
props,
26+
propName,
27+
componentName
28+
) => {
29+
if (props[propName] !== null) {
30+
deprecate(
31+
// eslint-disable-next-line max-len
32+
`"${propName}" prop of "${componentName}" has been deprecated.\n${explanation}`
33+
);
34+
}
35+
36+
return PropTypes.checkPropTypes(
37+
{ propName: propType },
38+
props,
39+
propName,
40+
componentName
41+
);
42+
};
43+
2344
export const eitherOrPropType = (
2445
firstProp,
2546
secondProp,

yarn.lock

+11-1
Original file line numberDiff line numberDiff line change
@@ -3278,6 +3278,11 @@ babel-plugin-add-react-displayname@^0.0.5:
32783278
resolved "https://registry.yarnpkg.com/babel-plugin-add-react-displayname/-/babel-plugin-add-react-displayname-0.0.5.tgz#339d4cddb7b65fd62d1df9db9fe04de134122bd5"
32793279
integrity sha1-M51M3be2X9YtHfnbn+BN4TQSK9U=
32803280

3281+
babel-plugin-dev-expression@^0.2.2:
3282+
version "0.2.2"
3283+
resolved "https://registry.yarnpkg.com/babel-plugin-dev-expression/-/babel-plugin-dev-expression-0.2.2.tgz#c18de18a06150f9480edd151acbb01d2e65e999b"
3284+
integrity sha512-y32lfBif+c2FIh5dwGfcc/IfX5aw/Bru7Du7W2n17sJE/GJGAsmIk5DPW/8JOoeKpXW5evJfJOvRq5xkiS6vng==
3285+
32813286
32823287
version "2.2.0"
32833288
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.2.0.tgz#c0adfb07d95f4a4495e9aaac6ec386c4d7c2524e"
@@ -17148,6 +17153,11 @@ tiny-relative-date@^1.3.0:
1714817153
resolved "https://registry.yarnpkg.com/tiny-relative-date/-/tiny-relative-date-1.3.0.tgz#fa08aad501ed730f31cc043181d995c39a935e07"
1714917154
integrity sha512-MOQHpzllWxDCHHaDno30hhLfbouoYlOI8YlMNtvKe1zXbjEVhbcEovQxvZrPvtiYW630GQDoMMarCnjfyfHA+A==
1715017155

17156+
tiny-warning@^1.0.3:
17157+
version "1.0.3"
17158+
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
17159+
integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==
17160+
1715117161
tinycolor2@^1.4.1:
1715217162
version "1.4.1"
1715317163
resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.1.tgz#f4fad333447bc0b07d4dc8e9209d8f39a8ac77e8"
@@ -18007,7 +18017,7 @@ warning@^3.0.0:
1800718017
dependencies:
1800818018
loose-envify "^1.0.0"
1800918019

18010-
warning@^4.0.1, warning@^4.0.2, warning@^4.0.3:
18020+
warning@^4.0.1, warning@^4.0.2:
1801118021
version "4.0.3"
1801218022
resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3"
1801318023
integrity sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==

0 commit comments

Comments
 (0)