Skip to content

Commit

Permalink
feat(react): remove warning dependency in favor of internal module (#…
Browse files Browse the repository at this point in the history
…8114)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
joshblack and kodiakhq[bot] authored Mar 17, 2021
1 parent 8d39b78 commit 7f498bb
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 74 deletions.
2 changes: 1 addition & 1 deletion docs/developer-handbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ pattern that we tend to use:
```jsx
// SomeComponent.js
// React imports
import warning from 'warning';
import { warning } from '../../internal/warning';

let didWarnAboutDeprecation = false;

Expand Down
1 change: 1 addition & 0 deletions packages/components/src/components/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import warning from 'warning';
import settings from '../../globals/js/settings';
import mixin from '../../globals/js/misc/mixin';
Expand Down
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"lodash.throttle": "^4.1.1",
"react-is": "^16.8.6",
"use-resize-observer": "^6.0.0",
"warning": "^3.0.0",
"window-or-global": "^1.0.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import { settings } from 'carbon-components';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import warning from 'warning';
import { settings } from 'carbon-components';
import { match, keys } from '../../internal/keyboard';
import { warning } from '../../internal/warning';
import deprecate from '../../prop-types/deprecate.js';

const { prefix } = settings;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/RadioButton/RadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import { settings } from 'carbon-components';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import warning from 'warning';
import { settings } from 'carbon-components';
import { warning } from '../../internal/warning';
import uid from '../../tools/uniqueId';

const { prefix } = settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import RadioButton from '../RadioButton';
import warning from 'warning';
import { warning } from '../../internal/warning';
import { settings } from 'carbon-components';

const { prefix } = settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ describe('[Deprecated] SearchFilterButton', () => {
let wrapper;

beforeEach(() => {
jest.mock('warning', () => {
return jest.fn();
});
jest.mock('../../internal/warning');
SearchFilterButton = require('../SearchFilterButton').default;
wrapper = mount(<SearchFilterButton labelText="testlabel" />);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import PropTypes from 'prop-types';
import warning from 'warning';
import { settings } from 'carbon-components';
import { Filter16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import PropTypes from 'prop-types';
import React from 'react';
import { warning } from '../../internal/warning';

const { prefix } = settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ describe('[Deprecated] SearchLayoutButton', () => {
let wrapper;

beforeEach(() => {
jest.mock('warning', () => {
return jest.fn();
});
jest.mock('../../internal/warning');
SearchLayoutButton = require('../SearchLayoutButton').default;
wrapper = mount(<SearchLayoutButton labelText="testlabel" />);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import warning from 'warning';
import { settings } from 'carbon-components';
import { ListBulleted16, Grid16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { warning } from '../../internal/warning';

const { prefix } = settings;

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/TileGroup/TileGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import { settings } from 'carbon-components';
import PropTypes from 'prop-types';
import React from 'react';
import RadioTile from '../RadioTile';
import warning from 'warning';
import { settings } from 'carbon-components';
import { warning } from '../../internal/warning';

const { prefix } = settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ describe('ToggleSmall', () => {
let ToggleSmall;

beforeEach(() => {
jest.mock('warning', () => {
return jest.fn();
});
jest.mock('../../internal/warning');

ToggleSmall = require('../ToggleSmall').default;
});
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/ToggleSmall/ToggleSmall.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import { settings } from 'carbon-components';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import { keys, match } from '../../internal/keyboard';
import warning from 'warning';
import { warning } from '../../internal/warning';

const { prefix } = settings;

Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/components/Toolbar/Toolbar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ describe('[Deprecated] Toolbar', () => {

beforeEach(() => {
// Toolbar is deprecated
jest.mock('warning', () => {
return jest.fn();
});
jest.mock('../../internal/warning');

Toolbar = require('../Toolbar').default;
ToolbarItem = require('../Toolbar').ToolbarItem;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Toolbar/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
import ToolbarSearch from '../ToolbarSearch';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import warning from 'warning';
import { warning } from '../../internal/warning';

const { prefix } = settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import classNames from 'classnames';
import { Search16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import ClickListener from '../../internal/ClickListener';
import warning from 'warning';
import { warning } from '../../internal/warning';

const { prefix } = settings;

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/internal/FloatingMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

import warning from 'warning';
import PropTypes from 'prop-types';
import React from 'react';
import ReactDOM from 'react-dom';
import window from 'window-or-global';
import { settings } from 'carbon-components';
import OptimizedResize from './OptimizedResize';
import { selectorFocusable, selectorTabbable } from './keyboard/navigation';
import { warning } from './warning';
import wrapFocus from './wrapFocus';

const { prefix } = settings;
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/internal/__mocks__/warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = {
warning: jest.fn(),
};
6 changes: 3 additions & 3 deletions packages/react/src/internal/useControllableState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useEffect, useRef, useState } from 'react';
import { warn } from './warn';
import { warning } from './warning';

export function useControllableState(
controlledState,
Expand Down Expand Up @@ -47,7 +47,7 @@ export function useControllableState(
// Uncontrolled -> Controlled
// If the component prop is uncontrolled, the prop value should be undefined
if (controlled.current === false && controlledState !== undefined) {
warn(
warning(
false,
'A component is changing an uncontrolled component to be controlled. ' +
'This is likely caused by the value changing to a defined value ' +
Expand All @@ -60,7 +60,7 @@ export function useControllableState(
// Controlled -> Uncontrolled
// If the component prop is controlled, the prop value should be defined
if (controlled.current === true && controlledState === undefined) {
warn(
warning(
false,
'A component is changing a controlled component to be uncontrolled. ' +
'This is likely caused by the value changing to an undefined value ' +
Expand Down
30 changes: 0 additions & 30 deletions packages/react/src/internal/warn.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/react/src/prop-types/__tests__/deprecate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('deprecate', () => {

beforeEach(() => {
jest.resetModules();
jest.mock('warning');
warning = require('warning');
jest.mock('../../internal/warning');
warning = require('../../internal/warning').warning;
deprecate = require('../deprecate').default;
mockPropType = jest.fn();
mockArgs = [{ propName: true }, 'propName', 'ComponentName'];
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/prop-types/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import warning from 'warning';
import { warning } from '../internal/warning';

const didWarnAboutDeprecation = {};

Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9259,7 +9259,6 @@ __metadata:
string-replace-loader: ^2.1.0
terser-webpack-plugin: ^2.3.2
use-resize-observer: ^6.0.0
warning: ^3.0.0
webpack: ^4.41.5
whatwg-fetch: ^2.0.3
window-or-global: ^1.0.1
Expand Down

0 comments on commit 7f498bb

Please sign in to comment.