From 49e0825c45a22052c6a960f55f062282d7cbab0c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 8 Apr 2017 18:14:39 -0700 Subject: [PATCH] Add prop-types as a regular dependency --- README.md | 1 - package.json | 3 ++- src/ReactWrapperComponent.jsx | 3 ++- src/react-compat.js | 5 ----- test/ReactWrapper-spec.jsx | 27 +++++++++++++------------ test/ShallowWrapper-spec.jsx | 37 ++++++++++++++++++----------------- test/staticRender-spec.jsx | 7 ++++--- 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index a3b8ce821..43a3f134f 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,6 @@ the following npm modules installed if they were not already: ```bash npm i --save-dev react-dom -npm i --save-dev prop-types ``` diff --git a/package.json b/package.json index 2c93e9aa4..7f77372fc 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", "react:13": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@0.13 && npm install", "react:14": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14 && npm install", - "react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 prop-types@15 create-react-class@15 react-test-renderer@15 && npm install", + "react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 create-react-class@15 react-test-renderer@15 && npm install", "docs:clean": "rimraf _book", "docs:prepare": "gitbook install", "docs:build": "npm run docs:prepare && gitbook build", @@ -60,6 +60,7 @@ "object.assign": "^4.0.4", "object.entries": "^1.0.3", "object.values": "^1.0.3", + "prop-types": "^15.5.4", "uuid": "^2.0.3" }, "devDependencies": { diff --git a/src/ReactWrapperComponent.jsx b/src/ReactWrapperComponent.jsx index 049a4c182..4cbeb00b9 100644 --- a/src/ReactWrapperComponent.jsx +++ b/src/ReactWrapperComponent.jsx @@ -1,6 +1,7 @@ import React from 'react'; +import PropTypes from 'prop-types'; import objectAssign from 'object.assign'; -import { PropTypes, createClass } from './react-compat'; +import { createClass } from './react-compat'; /* eslint react/forbid-prop-types: 0 */ diff --git a/src/react-compat.js b/src/react-compat.js index afde69bff..6ca2e7c57 100644 --- a/src/react-compat.js +++ b/src/react-compat.js @@ -18,7 +18,6 @@ let childrenToArray; let renderWithOptions; let unmountComponentAtNode; let batchedUpdates; -let PropTypes; let createClass; let shallowRendererFactory; @@ -179,12 +178,9 @@ if (REACT013) { } if (REACT155) { - // eslint-disable-next-line import/no-extraneous-dependencies - PropTypes = require('prop-types'); // eslint-disable-next-line import/no-extraneous-dependencies createClass = require('create-react-class'); } else { - PropTypes = React.PropTypes; createClass = React.createClass; } @@ -223,6 +219,5 @@ export { renderWithOptions, unmountComponentAtNode, batchedUpdates, - PropTypes, createClass, }; diff --git a/test/ReactWrapper-spec.jsx b/test/ReactWrapper-spec.jsx index d80529b6a..ab9370e40 100644 --- a/test/ReactWrapper-spec.jsx +++ b/test/ReactWrapper-spec.jsx @@ -1,6 +1,7 @@ /* globals document */ import React from 'react'; +import PropTypes from 'prop-types'; import { expect } from 'chai'; import sinon from 'sinon'; import { batchedUpdates } from '../src/react-compat'; @@ -25,7 +26,7 @@ describeWithDOM('mount', () => { it('can pass in context', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -40,7 +41,7 @@ describeWithDOM('mount', () => { it('can pass context to the child of mounted component', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -53,7 +54,7 @@ describeWithDOM('mount', () => { }); const childContextTypes = { - name: React.PropTypes.string.isRequired, + name: PropTypes.string.isRequired, }; const context = { name: 'foo' }; const wrapper = mount(, { context, childContextTypes }); @@ -74,7 +75,7 @@ describeWithDOM('mount', () => { it('is instrospectable through context API', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -93,7 +94,7 @@ describeWithDOM('mount', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const context = { name: 'foo' }; const wrapper = mount(, { context }); @@ -104,14 +105,14 @@ describeWithDOM('mount', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const ComplexComponent = () => (
); const childContextTypes = { - name: React.PropTypes.string.isRequired, + name: PropTypes.string.isRequired, }; const context = { name: 'foo' }; @@ -132,7 +133,7 @@ describeWithDOM('mount', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const context = { name: 'foo' }; const wrapper = mount(, { context }); @@ -150,7 +151,7 @@ describeWithDOM('mount', () => { ); Foo.contextTypes = { - _: React.PropTypes.string, + _: PropTypes.string, }; const wrapper = mount(, { @@ -1098,7 +1099,7 @@ describeWithDOM('mount', () => { it('should set context for a component multiple times', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -1117,7 +1118,7 @@ describeWithDOM('mount', () => { it('should throw if it is called when shallow didn’t include context', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -1136,7 +1137,7 @@ describeWithDOM('mount', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const context = { name: 'foo' }; const wrapper = mount(, { context }); @@ -1151,7 +1152,7 @@ describeWithDOM('mount', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const wrapper = mount(); expect(() => wrapper.setContext({ name: 'bar' })).to.throw( diff --git a/test/ShallowWrapper-spec.jsx b/test/ShallowWrapper-spec.jsx index bf82dc7e6..3afeb3b1b 100644 --- a/test/ShallowWrapper-spec.jsx +++ b/test/ShallowWrapper-spec.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { expect } from 'chai'; import sinon from 'sinon'; @@ -12,7 +13,7 @@ describe('shallow', () => { it('can pass in context', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -38,7 +39,7 @@ describe('shallow', () => { it('is instrospectable through context API', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -57,7 +58,7 @@ describe('shallow', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const context = { name: 'foo' }; const wrapper = shallow(, { context }); @@ -77,7 +78,7 @@ describe('shallow', () => { const SimpleComponent = (props, context) => (
{context.name}
); - SimpleComponent.contextTypes = { name: React.PropTypes.string }; + SimpleComponent.contextTypes = { name: PropTypes.string }; const wrapper = shallow(, { context }); @@ -892,7 +893,7 @@ describe('shallow', () => { } } - Foo.contextTypes = { x: React.PropTypes.string }; + Foo.contextTypes = { x: PropTypes.string }; const context = { x: 'yolo' }; const wrapper = shallow(, { context }); @@ -938,7 +939,7 @@ describe('shallow', () => { const Foo = (props, context) => (
{context.x}
); - Foo.contextTypes = { x: React.PropTypes.string }; + Foo.contextTypes = { x: PropTypes.string }; const context = { x: 'yolo' }; const wrapper = shallow(, { context }); @@ -953,7 +954,7 @@ describe('shallow', () => { describe('.setContext(newContext)', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -982,7 +983,7 @@ describe('shallow', () => { const SFC = (props, context) => (
{context.name}
); - SFC.contextTypes = { name: React.PropTypes.string }; + SFC.contextTypes = { name: PropTypes.string }; it('should set context for a component multiple times', () => { const context = { name: 'foo' }; @@ -2309,7 +2310,7 @@ describe('shallow', () => { } } Bar.contextTypes = { - name: React.PropTypes.string, + name: PropTypes.string, }; class Foo extends React.Component { render() { @@ -2355,7 +2356,7 @@ describe('shallow', () => { } } Bar.contextTypes = { - name: React.PropTypes.string, + name: PropTypes.string, }; class Foo extends React.Component { render() { @@ -2399,7 +2400,7 @@ describe('shallow', () => { const Bar = (props, context) => (
{context.name}
); - Bar.contextTypes = { name: React.PropTypes.string }; + Bar.contextTypes = { name: PropTypes.string }; const Foo = () => (
@@ -2430,7 +2431,7 @@ describe('shallow', () => { const Bar = (props, context) => (
{context.name}
); - Bar.contextTypes = { name: React.PropTypes.string }; + Bar.contextTypes = { name: PropTypes.string }; const Foo = () => (
@@ -2921,7 +2922,7 @@ describe('shallow', () => { } } Foo.contextTypes = { - foo: React.PropTypes.string, + foo: PropTypes.string, }; const wrapper = shallow( @@ -3145,7 +3146,7 @@ describe('shallow', () => { } } Foo.contextTypes = { - foo: React.PropTypes.string, + foo: PropTypes.string, }; const wrapper = shallow( @@ -3304,7 +3305,7 @@ describe('shallow', () => { } } Foo.contextTypes = { - foo: React.PropTypes.string, + foo: PropTypes.string, }; const wrapper = shallow( , @@ -3363,7 +3364,7 @@ describe('shallow', () => { } } Foo.contextTypes = { - foo: React.PropTypes.string, + foo: PropTypes.string, }; const wrapper = shallow( , @@ -4005,7 +4006,7 @@ describe('shallow', () => { return ; } } - WrapsRendersDOM.contextTypes = { foo: React.PropTypes.string }; + WrapsRendersDOM.contextTypes = { foo: PropTypes.string }; class DoubleWrapsRendersDOM extends React.Component { render() { return ; @@ -4016,7 +4017,7 @@ describe('shallow', () => { return ; } } - ContextWrapsRendersDOM.contextTypes = { foo: React.PropTypes.string }; + ContextWrapsRendersDOM.contextTypes = { foo: PropTypes.string }; it('throws on a DOM node', () => { const wrapper = shallow(); diff --git a/test/staticRender-spec.jsx b/test/staticRender-spec.jsx index 39a1c663d..4fa4f4a64 100644 --- a/test/staticRender-spec.jsx +++ b/test/staticRender-spec.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { expect } from 'chai'; import { describeWithDOM, describeIf } from './_helpers'; import { render } from '../src/'; @@ -9,7 +10,7 @@ describeWithDOM('render', () => { it('can pass in context', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -23,7 +24,7 @@ describeWithDOM('render', () => { it('can pass context to the child of mounted component', () => { const SimpleComponent = React.createClass({ contextTypes: { - name: React.PropTypes.string, + name: PropTypes.string, }, render() { return
{this.context.name}
; @@ -36,7 +37,7 @@ describeWithDOM('render', () => { }); const childContextTypes = { - name: React.PropTypes.string.isRequired, + name: PropTypes.string.isRequired, }; const context = { name: 'foo' }; const wrapper = render(, { context, childContextTypes });