Skip to content

Commit ff5fead

Browse files
author
Henri Beck
committed
- Upgraded build step to babel 7 and rollup
- Updated eslint and packages
1 parent 27cd281 commit ff5fead

15 files changed

+3620
-1541
lines changed

.babelrc

-29
This file was deleted.

.babelrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/env', { loose: true }],
4+
'@babel/react',
5+
'@babel/flow'
6+
],
7+
plugins: ['@babel/proposal-class-properties'],
8+
};

.eslintrc

-26
This file was deleted.

.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
parser: 'babel-eslint',
3+
extends: 'airbnb',
4+
rules: {
5+
'react/jsx-filename-extension': ['error', { extensions: ['.js'] }],
6+
},
7+
};

.size-snapshot.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"dist/theming.js": {
3+
"bundled": 55338,
4+
"minified": 19038,
5+
"gzipped": 6048
6+
},
7+
"dist/theming.min.js": {
8+
"bundled": 25525,
9+
"minified": 9722,
10+
"gzipped": 3528
11+
},
12+
"dist/theming.cjs.js": {
13+
"bundled": 4141,
14+
"minified": 2612,
15+
"gzipped": 973
16+
},
17+
"dist/theming.esm.js": {
18+
"bundled": 3766,
19+
"minified": 2311,
20+
"gzipped": 908,
21+
"treeshaked": {
22+
"rollup": {
23+
"code": 1394,
24+
"import_statements": 179
25+
},
26+
"webpack": {
27+
"code": 2904
28+
}
29+
}
30+
}
31+
}

ava.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
files: [
3+
'src/*.test.js',
4+
],
5+
require: [
6+
'@babel/register',
7+
'./.browser-env',
8+
],
9+
};

package.json

+28-38
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,22 @@
22
"name": "theming",
33
"version": "1.3.0",
44
"description": "Unified CSSinJS theming solution for React",
5-
"main": "dist/cjs",
6-
"module": "dist/esm",
5+
"main": "dist/theming.cjs.js",
6+
"module": "dist/theming.esm.js",
77
"files": [
88
"src",
99
"dist"
1010
],
1111
"scripts": {
1212
"lint": "eslint .",
1313
"flow": "flow check --max-warnings 0",
14-
"test": "cross-env BABEL_ENV=cjs ava",
15-
"tdd": "npm run test -- --watch",
14+
"test": "ava",
15+
"tdd": "yarn test --watch",
1616
"coverage": "nyc yarn test",
17-
"coveralls": "run-s coveralls:*",
18-
"coveralls:gather": "npm run coverage",
19-
"coveralls:upload": "coveralls < coverage/lcov.info",
20-
"clean": "rimraf dist",
21-
"build": "run-s clean babel:*",
22-
"babel:cjs": "cross-env BABEL_ENV=cjs babel src -d dist/cjs --ignore '*test*'",
23-
"babel:esm": "cross-env BABEL_ENV=esm babel src -d dist/esm --ignore '*test*'",
24-
"watch": "npm-run-all clean -p babel:watch:*",
25-
"babel:watch:cjs": "npm run babel:cjs -- --watch",
26-
"babel:watch:esm": "npm run babel:esm -- --watch",
27-
"postversion": "npm run build"
28-
},
29-
"ava": {
30-
"files": [
31-
"src/**/*test.js"
32-
],
33-
"require": [
34-
"babel-register",
35-
"./.browser-env"
36-
],
37-
"babel": "inherit"
17+
"coveralls": "yarn coverage && coveralls < coverage/lcov.info",
18+
"prebuild": "rimraf dist",
19+
"build": "rollup -c",
20+
"postversion": "yarn build"
3821
},
3922
"nyc": {
4023
"include": [
@@ -70,31 +53,38 @@
7053
},
7154
"homepage": "https://github.com/cssinjs/theming#readme",
7255
"devDependencies": {
73-
"ava": "^0.22.0",
74-
"babel-cli": "^6.24.1",
75-
"babel-eslint": "^8.0.1",
76-
"babel-preset-env": "^1.4.0",
77-
"babel-preset-es2017": "^6.24.1",
78-
"babel-preset-react": "^6.24.1",
79-
"babel-preset-stage-0": "^6.24.1",
80-
"babel-register": "^6.24.1",
56+
"@babel/cli": "^7.1.0",
57+
"@babel/core": "^7.1.0",
58+
"@babel/plugin-proposal-class-properties": "^7.1.0",
59+
"@babel/preset-env": "^7.1.0",
60+
"@babel/preset-flow": "^7.0.0",
61+
"@babel/preset-react": "^7.0.0",
62+
"@babel/register": "^7.0.0",
63+
"ava": "^1.0.0-beta.8",
64+
"babel-eslint": "^9.0.0",
8165
"browser-env": "^3.2.1",
8266
"coveralls": "3.0.0",
83-
"cross-env": "^5.0.1",
8467
"enzyme": "^3.1.0",
8568
"enzyme-adapter-react-16": "^1.0.2",
8669
"eslint": "^4.1.0",
87-
"eslint-config-pedant": "^0.10.0",
88-
"eslint-config-prettier": "^2.1.0",
70+
"eslint-config-airbnb": "^17.1.0",
71+
"eslint-plugin-import": "^2.14.0",
72+
"eslint-plugin-jsx-a11y": "^6.1.1",
8973
"eslint-plugin-react": "^7.0.1",
90-
"eslint-plugin-require-path-exists": "^1.1.7",
9174
"flow-bin": "^0.81.0",
92-
"npm-run-all": "^4.0.2",
9375
"nyc": "^11.0.2",
9476
"react": "^16.0.0",
9577
"react-dom": "^16.0.0",
9678
"react-test-renderer": "^16.0.0",
9779
"rimraf": "^2.6.1",
80+
"rollup": "^0.66.2",
81+
"rollup-plugin-babel": "^4.0.3",
82+
"rollup-plugin-commonjs": "^9.1.8",
83+
"rollup-plugin-node-globals": "^1.4.0",
84+
"rollup-plugin-node-resolve": "^3.4.0",
85+
"rollup-plugin-replace": "^2.0.0",
86+
"rollup-plugin-size-snapshot": "^0.7.0",
87+
"rollup-plugin-uglify": "^6.0.0",
9888
"sinon": "^6.3.3"
9989
},
10090
"dependencies": {

rollup.config.js

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import fs from 'fs';
2+
import nodeResolve from 'rollup-plugin-node-resolve';
3+
import nodeGlobals from 'rollup-plugin-node-globals';
4+
import commonjs from 'rollup-plugin-commonjs';
5+
import babel from 'rollup-plugin-babel';
6+
import replace from 'rollup-plugin-replace';
7+
import { uglify } from 'rollup-plugin-uglify';
8+
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
9+
10+
const pkg = require('./package');
11+
12+
function toCamelCase(name) {
13+
return name.replace(/-(\w)/g, (match, letter) => letter.toUpperCase());
14+
}
15+
16+
const matchSnapshot = process.env.SNAPSHOT === 'match';
17+
const input = './src/index.js';
18+
19+
const globals = Object.keys(pkg.peerDependencies || {}).reduce(
20+
(acc, key) => Object.assign({}, acc, { [key]: toCamelCase(key) }),
21+
{},
22+
);
23+
24+
const external = id => !id.startsWith('.') && !id.startsWith('/');
25+
26+
const babelOptions = {
27+
exclude: '**/node_modules/**',
28+
runtimeHelpers: true,
29+
};
30+
31+
const commonjsOptions = {
32+
ignoreGlobal: true,
33+
};
34+
35+
const snapshotOptions = {
36+
matchSnapshot,
37+
snapshotPath: './.size-snapshot.json',
38+
};
39+
40+
const createFlowBundlePlugin = {
41+
transformBundle(code, outputOptions) {
42+
const file = `${outputOptions.file}.flow`;
43+
const content = "// @flow\n\nexport * from '../src';";
44+
fs.writeFileSync(file, content);
45+
},
46+
};
47+
48+
export default [
49+
{
50+
input,
51+
output: {
52+
file: `dist/${pkg.name}.js`,
53+
format: 'umd',
54+
sourcemap: true,
55+
exports: 'named',
56+
name: pkg.name,
57+
globals,
58+
},
59+
external: Object.keys(globals),
60+
plugins: [
61+
nodeResolve(),
62+
babel(babelOptions),
63+
commonjs(commonjsOptions),
64+
nodeGlobals({ process: false }),
65+
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
66+
sizeSnapshot(snapshotOptions),
67+
],
68+
},
69+
70+
{
71+
input,
72+
output: {
73+
file: `dist/${pkg.name}.min.js`,
74+
format: 'umd',
75+
exports: 'named',
76+
name: pkg.name,
77+
globals,
78+
},
79+
external: Object.keys(globals),
80+
plugins: [
81+
nodeResolve(),
82+
babel(babelOptions),
83+
commonjs(commonjsOptions),
84+
nodeGlobals({ process: false }),
85+
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
86+
sizeSnapshot(snapshotOptions),
87+
uglify(),
88+
],
89+
},
90+
91+
{
92+
input,
93+
output: { file: pkg.main, format: 'cjs', exports: 'named' },
94+
external,
95+
plugins: [
96+
createFlowBundlePlugin,
97+
babel(babelOptions),
98+
nodeGlobals({ process: false }),
99+
sizeSnapshot(snapshotOptions),
100+
],
101+
},
102+
103+
{
104+
input,
105+
output: { file: pkg.module, format: 'esm' },
106+
external,
107+
plugins: [
108+
babel(babelOptions),
109+
nodeGlobals({ process: false }),
110+
sizeSnapshot(snapshotOptions),
111+
],
112+
},
113+
];

src/create-theme-provider.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function createThemeProvider(context: Context<{}>) {
2222

2323
// Get the theme from the props, supporting both (outerTheme) => {} as well as object notation
2424
getTheme(outerTheme: Object) {
25-
const theme = this.props.theme;
25+
const { theme } = this.props;
2626

2727
if (typeof theme === 'function') {
2828
const mergedTheme = theme(outerTheme);
@@ -44,15 +44,17 @@ export default function createThemeProvider(context: Context<{}>) {
4444
}
4545

4646
render() {
47-
if (!this.props.children) {
47+
const { children } = this.props;
48+
49+
if (!children) {
4850
return null;
4951
}
5052

5153
return (
5254
<context.Consumer>
5355
{outerTheme => (
5456
<context.Provider value={this.getTheme(outerTheme)}>
55-
{this.props.children}
57+
{children}
5658
</context.Provider>
5759
)}
5860
</context.Consumer>

0 commit comments

Comments
 (0)