Skip to content

Commit f163b2e

Browse files
committed
Merge pull request #3 from ndelangen/ndelangen/dev
FIX babel-core including react-display-name & UPGRADE babel & other packages
2 parents d514923 + cf2c8dd commit f163b2e

File tree

12 files changed

+68
-77
lines changed

12 files changed

+68
-77
lines changed

.babelrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"stage": 0
2+
"env": {
3+
"development": {
4+
"presets": [
5+
"react-hmre"
6+
]
7+
}
8+
},
9+
"presets": ["es2015", "react", "stage-0"]
310
}

example/lib/components/Button/Button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ export default class Button extends Component {
1313
children: PropTypes.string.isRequired,
1414
color: PropTypes.string,
1515
size: PropTypes.oneOf(['small', 'normal', 'large']),
16-
}
16+
};
1717
static defaultProps = {
1818
color: '#333',
1919
size: 'normal'
20-
}
20+
};
2121
static sizes = {
2222
small: '10px',
2323
normal: '14px',
2424
large: '18px'
25-
}
25+
};
2626

2727
render() {
2828
let styles = {

example/lib/components/Placeholder/Placeholder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export default class Placeholder extends Component {
1010
type: PropTypes.oneOf(['animal', 'bacon', 'beard', 'bear', 'cat', 'food', 'city', 'nature', 'people']),
1111
width: PropTypes.number,
1212
height: PropTypes.number
13-
}
13+
};
1414

1515
static defaultProps = {
1616
type: 'animal',
1717
width: 150,
1818
height: 150
19-
}
19+
};
2020

2121
getImageUrl() {
2222
let { type, width, height } = this.props;

loaders/examples.loader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var marked = require('marked');
33

44
var evalPlaceholder = '<%{#eval#}%>';
55

6-
var requireAnythingRegex = /require\s*\(([^)]+)\)/g;
6+
var requireAnythingTest = 'require\\s*\\(([^)]+)\\)';
7+
var requireAnythingRegex = new RegExp(requireAnythingTest, 'g');
78
var simpleStringRegex = /^"([^"]+)"$|^'([^']+)'$/;
89

910
function readExamples(markdown) {
@@ -74,6 +75,7 @@ function examplesLoader(source, map) {
7475
}
7576

7677
_.assign(examplesLoader, {
78+
requireAnythingTest: requireAnythingTest,
7779
requireAnythingRegex: requireAnythingRegex,
7880
simpleStringRegex: simpleStringRegex,
7981
readExamples: readExamples,

package.json

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,60 @@
2525
"node": ">=0.12.0"
2626
},
2727
"dependencies": {
28-
"babel-core": "5.8.30",
29-
"babel-loader": "5.3.2",
30-
"babel-plugin-react-display-name": "2.0.0",
31-
"babel-plugin-react-transform": "1.1.1",
32-
"chalk": "1.1.1",
28+
"babel-core": "~6.9.0",
29+
"babel-loader": "6.2.4",
30+
"babel-preset-react-hmre": "^1.1.1",
31+
"babel-plugin-react-transform": "2.0.2",
32+
"babel-preset-es2015": "^6.9.0",
33+
"babel-preset-react": "^6.5.0",
34+
"babel-preset-stage-0": "^6.5.0",
35+
"chalk": "1.1.3",
3336
"codemirror": "5.8.0",
34-
"css-loader": "0.21.0",
37+
"cross-env": "^1.0.7",
38+
"css-loader": "0.23.1",
3539
"express": "4.13.3",
36-
"extract-text-webpack-plugin": "0.8.2",
40+
"extract-text-webpack-plugin": "1.0.1",
3741
"findup": "0.1.5",
38-
"glob": "5.0.15",
39-
"lodash": "3.10.1",
42+
"glob": "7.0.3",
43+
"lodash": "4.12.0",
4044
"marked": "0.3.5",
4145
"minimist": "1.2.0",
4246
"postcss-advanced-variables": "1.2.2",
43-
"postcss-loader": "0.7.0",
47+
"postcss-loader": "0.9.1",
4448
"prettyjson": "1.1.3",
45-
"react-codemirror": "0.1.7",
46-
"react-transform-catch-errors": "1.0.0",
47-
"react-transform-hmr": "1.0.1",
49+
"react": "^0.14.8",
50+
"react-codemirror": "0.2.6",
51+
"react-dom": "^0.14.8",
52+
"react-transform-catch-errors": "1.0.2",
53+
"react-transform-hmr": "1.0.4",
4854
"redbox-react": "1.1.1",
4955
"sanitize.css": "3.0.0",
5056
"style-loader": "0.13.0",
51-
"webpack": "1.12.2",
52-
"webpack-dev-middleware": "1.2.0",
53-
"webpack-hot-middleware": "2.4.1",
54-
"webpack-merge": "0.2.0"
57+
"webpack": "1.13.1",
58+
"webpack-dev-middleware": "1.6.1",
59+
"webpack-hot-middleware": "2.10.0",
60+
"webpack-merge": "0.12.0"
5561
},
5662
"peerDependencies": {
5763
"react": ">=0.14.0",
5864
"react-dom": "~0.14.2"
5965
},
6066
"devDependencies": {
61-
"babel-core": "~5.8.30",
62-
"babel-eslint": "4.1.3",
63-
"chai": "~3.4.1",
67+
"babel-core": "~6.9.0",
68+
"babel-eslint": "6.0.4",
69+
"babel-preset-react-hmre": "^1.1.1",
70+
"babel-standalone": "^6.7.7",
71+
"chai": "~3.5.0",
6472
"css-modules-require-hook": "~2.0.2",
65-
"eslint": "1.7.3",
66-
"eslint-plugin-react": "3.6.3",
73+
"eslint": "2.10.2",
74+
"eslint-plugin-react": "5.1.1",
6775
"expect-react-shallow": "~1.0.0",
68-
"gulp": "3.9.0",
76+
"gulp": "3.9.1",
6977
"gulp-gh-pages": "0.5.4",
70-
"mocha": "~2.3.3",
78+
"mocha": "~2.4.5",
7179
"postcss-modules-extract-imports": "~1.0.0",
7280
"postcss-modules-scope": "~1.0.0",
73-
"react": "~0.14.2"
81+
"react": "^0.14.8"
7482
},
7583
"scripts": {
7684
"test": "npm run lint && npm run mocha && npm run build",

src/components/Editor/Editor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'codemirror/lib/codemirror.css';
44

55
import _ from 'lodash';
66
import { Component, PropTypes } from 'react';
7-
import debounce from 'lodash/function/debounce';
87
import Codemirror from 'react-codemirror';
98

109
import s from './Editor.css';
@@ -30,7 +29,7 @@ export default class Editor extends Component {
3029

3130
constructor() {
3231
super();
33-
this._handleChange = debounce(this.handleChange.bind(this), UPDATE_DELAY);
32+
this._handleChange = _.debounce(this.handleChange.bind(this), UPDATE_DELAY);
3433
}
3534

3635
componentWillMount() {

src/components/Preview/Preview.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React, { Component, PropTypes } from 'react';
44
import ReactDOM from 'react-dom';
5-
import babel from 'babel-core/browser';
5+
import { transform } from 'babel-standalone';
66
import Wrapper from 'components/Wrapper';
77

88
import s from './Preview.css';
@@ -31,7 +31,10 @@ export default class Preview extends Component {
3131
}
3232

3333
compileCode(code) {
34-
return babel.transform(code, {stage: 0}).code;
34+
return transform(code, {
35+
presets: ['es2015', 'react', 'stage-0'],
36+
ignore: [/node_modules/]
37+
}).code;
3538
}
3639

3740
executeCode() {

src/make-webpack-config.js

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ module.exports = function(env) {
1515
codeMirrorPath = path.join(__dirname, '../node_modules/codemirror'); // npm 2 or react-styleguidist develop
1616
}
1717

18-
var reactTransformPath = path.join(__dirname, '../../babel-plugin-react-transform'); // npm 3
19-
var reactDisplayNamePath = path.join(__dirname, '../../babel-plugin-react-display-name'); // npm 3
20-
if (!fs.existsSync(reactTransformPath)) {
21-
reactTransformPath = path.resolve(__dirname, '../node_modules/babel-plugin-react-transform'); // npm 2 or react-styleguidist develop
22-
reactDisplayNamePath = path.resolve(__dirname, '../node_modules/babel-plugin-react-display-name'); // npm 2 or react-styleguidist develop
23-
}
24-
2518
var includes = [
2619
__dirname,
2720
config.rootDir
@@ -61,7 +54,7 @@ module.exports = function(env) {
6154
loaders: [
6255
],
6356
noParse: [
64-
/babel-core\/browser.js/
57+
/babel-standalone/
6558
]
6659
},
6760
postcss: function() {
@@ -101,10 +94,7 @@ module.exports = function(env) {
10194
{
10295
test: /\.jsx?$/,
10396
include: includes,
104-
loader: 'babel',
105-
query: {
106-
stage: 0
107-
}
97+
loader: 'babel'
10898
},
10999
{
110100
test: /\.css$/,
@@ -143,29 +133,7 @@ module.exports = function(env) {
143133
{
144134
test: /\.jsx?$/,
145135
include: includes,
146-
loader: 'babel',
147-
query: {
148-
stage: 0,
149-
plugins: [
150-
reactDisplayNamePath,
151-
reactTransformPath
152-
],
153-
extra: {
154-
'react-transform': {
155-
transforms: [
156-
{
157-
transform: 'react-transform-hmr',
158-
imports: ['react'],
159-
locals: ['module']
160-
},
161-
{
162-
transform: 'react-transform-catch-errors',
163-
imports: ['react', 'redbox-react']
164-
}
165-
]
166-
}
167-
}
168-
}
136+
loader: 'babel'
169137
},
170138
{
171139
test: /\.css$/,

src/utils/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function readConfig() {
5656
customConfig = require(configFilepath);
5757
options = _.merge({}, options, customConfig);
5858
options.rootDir = path.resolve(path.dirname(configFilepath), options.rootDir);
59-
} else {
59+
}
60+
else {
6061
options.rootDir = path.join(pathToSourceJSUser, options.rootDir);
6162

6263
options._styleguideDir = config.styleguideDir;

src/utils/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ export function setComponentsNames(components) {
22
Object.keys(components).forEach(key => {
33
var component = components[key];
44

5-
let module = component.module;
6-
component.name = module.displayName || module.name;
5+
let {module} = component;
6+
component.name = module.displayName || module.name || module.default.name;
7+
78
if (!component.name) {
89
throw Error(`Cannot detect component name for ${component.filepath}`);
910
}
@@ -16,6 +17,6 @@ export function globalizeComponents(components) {
1617
Object.keys(components).forEach(key => {
1718
var component = components[key];
1819

19-
global[component.name] = component.module;
20+
global[component.name] = component.module.default || component.module;
2021
});
2122
}

test/examples.loader.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('examples loader', () => {
1212
beforeEach(() => {
1313
expect(examplesLoader.requireAnythingRegex).to.be.an.instanceof(RegExp);
1414
// we make a version without the /g flag
15-
regex = new RegExp(examplesLoader.requireAnythingRegex, '');
15+
regex = new RegExp(examplesLoader.requireAnythingTest);
1616
});
1717

1818
it('should match require invocations', () => {
@@ -32,6 +32,8 @@ describe('examples loader', () => {
3232
});
3333

3434
it('should match many requires in the same line correctly', () => {
35+
// Revert to the /g flagged version used by examplesLoader
36+
regex = new RegExp(examplesLoader.requireAnythingRegex);
3537
var replaced = `require('foo');require('bar')`.replace(examplesLoader.requireAnythingRegex, 'x');
3638
expect(replaced).to.equal('x;x');
3739
});

test/utils.utils.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('utils', () => {
1515
module: {name: 'Bar'}
1616
}
1717
]);
18-
expect(_.pluck(result, 'name')).to.eql(['Foo', 'Bar']);
18+
expect(_.map(result, 'name')).to.eql(['Foo', 'Bar']);
1919
});
2020
});
2121

0 commit comments

Comments
 (0)