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

Use named "polyfill" export and support ES module target #11

Merged
merged 7 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Next, update your component and replace any of the deprecated lifecycles with ne
Lastly, use the polyfill to make the new lifecycles work with older versions of React:
```js
import React from 'react';
import polyfill from 'react-lifecycles-compat';
import {polyfill} from 'react-lifecycles-compat';

class ExampleComponent extends React.Component {
// ...
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ componentWillMount.__suppressDeprecationWarning = true;
componentWillReceiveProps.__suppressDeprecationWarning = true;
componentWillUpdate.__suppressDeprecationWarning = true;

export default function polyfill(Component) {
export function polyfill(Component) {
if (!Component.prototype || !Component.prototype.isReactComponent) {
throw new Error('Can only polyfill class components');
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "react-lifecycles-compat",
"version": "1.1.3",
"version": "2.0.0",
"description": "Backwards compatibility polyfill for React class components",
"main": "react-lifecycles-compat.cjs.js",
"module": "react-lifecycles-compat.es.js",
"license": "MIT",
"repository": "reactjs/react-lifecycles-compat",
"scripts": {
Expand All @@ -16,6 +17,7 @@
},
"files": [
"react-lifecycles-compat.cjs.js",
"react-lifecycles-compat.es.js",
"react-lifecycles-compat.js",
"react-lifecycles-compat.min.js"
],
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default [
createConfig({
output: [
{ file: pkg.main, format: 'cjs' },
// Re-enable for 2.0 { file: pkg.module, format: 'es' },
{ file: pkg.module, format: 'es' },
],
}),
createConfig({
Expand Down
6 changes: 4 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ const POLYFILLS = {
'umd: prod': require('./react-lifecycles-compat.min'),
};

Object.entries(POLYFILLS).forEach(([name, polyfill]) => {
Object.entries(POLYFILLS).forEach(([name, module]) => {
describe(`react-lifecycles-compat (${name})`, () => {
readdirSync(join(__dirname, 'react')).forEach(version => {
const basePath = `./react/${version}/node_modules/`;

let createReactClass;
let polyfill;
let React;
let ReactDOM;

beforeEach(() => {
beforeAll(() => {
createReactClass = require(basePath + 'create-react-class');
polyfill = module.polyfill;
React = require(basePath + 'react');
ReactDOM = require(basePath + 'react-dom');
});
Expand Down