Skip to content

Commit 77d4bd8

Browse files
committed
[change] Compile using Babel 7
Fix necolas#1170 Close necolas#1205 Close necolas#1191
1 parent 4040151 commit 77d4bd8

File tree

17 files changed

+2377
-2138
lines changed

17 files changed

+2377
-2138
lines changed

.babelrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22

33
node_js:
4-
- "8"
4+
- "10"
55

66
before_install:
77
# Install Yarn

babel.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
4+
return {
5+
presets: ['./scripts/babel/preset']
6+
};
7+
};

docs/guides/advanced.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@ If you're using `skpm`, you can rely on an [undocumented
109109
feature](https://github.com/sketch-pm/skpm/blob/master/lib/utils/webpackConfig.js)
110110
which will merge your `webpack.config.js`, `.babelrc`, or `package.json` Babel
111111
config into its internal webpack config. The simplest option may be to use the
112-
[babel-plugin-module-alias](https://www.npmjs.com/package/babel-plugin-module-alias)
112+
[babel-plugin-module-resolver](https://www.npmjs.com/package/babel-plugin-module-resolver)
113113
and configure it in your `package.json`.

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"scripts": {
66
"clean": "del ./packages/*/dist",
77
"compile": "npm-run-all clean -p \"compile:* -- {@}\" --",
8-
"compile:commonjs": "cd packages/react-native-web && BABEL_ENV=commonjs babel src --out-dir dist/cjs --ignore \"**/__tests__\"",
9-
"compile:es": "cd packages/react-native-web && babel src --out-dir dist --ignore \"**/__tests__\"",
8+
"compile:commonjs": "cd packages/react-native-web && BABEL_ENV=commonjs babel --root-mode upward src --out-dir dist/cjs --ignore \"**/__tests__\"",
9+
"compile:es": "cd packages/react-native-web && babel --root-mode upward src --out-dir dist --ignore \"**/__tests__\"",
1010
"benchmarks": "cd packages/benchmarks && yarn build",
1111
"benchmarks:release": "cd packages/benchmarks && yarn release",
1212
"examples": "cd packages/examples && yarn build",
@@ -15,7 +15,7 @@
1515
"website:release": "cd packages/website && yarn release",
1616
"flow": "flow",
1717
"fmt": "prettier --write \"**/*.js\"",
18-
"jest": "BABEL_ENV=commonjs jest --config ./scripts/jest/config.js",
18+
"jest": "jest --config ./scripts/jest/config.js",
1919
"lint": "yarn lint:check --fix",
2020
"lint:check": "eslint packages scripts",
2121
"precommit": "lint-staged",
@@ -25,18 +25,18 @@
2525
"test": "yarn flow && yarn lint:check && yarn jest --runInBand"
2626
},
2727
"devDependencies": {
28-
"babel-cli": "^6.26.0",
29-
"babel-core": "^6.26.0",
30-
"babel-eslint": "^8.2.3",
31-
"babel-loader": "^7.1.2",
32-
"babel-plugin-add-module-exports": "^0.2.1",
33-
"babel-plugin-transform-class-properties": "^6.24.1",
34-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
35-
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
36-
"babel-preset-env": "^1.6.1",
37-
"babel-preset-flow": "^6.23.0",
38-
"babel-preset-react": "^6.24.1",
39-
"babel-preset-react-native": "^4.0.0",
28+
"@babel/cli": "^7.2.3",
29+
"@babel/core": "^7.2.2",
30+
"@babel/plugin-proposal-class-properties": "^7.2.3",
31+
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
32+
"@babel/preset-env": "^7.2.3",
33+
"@babel/preset-flow": "^7.0.0",
34+
"@babel/preset-react": "^7.0.0",
35+
"babel-eslint": "^10.0.0",
36+
"babel-jest": "24.0.0-alpha.9",
37+
"babel-loader": "^8.0.0",
38+
"babel-plugin-add-module-exports": "^1.0.0",
39+
"babel-plugin-transform-react-remove-prop-types": "^0.4.21",
4040
"caniuse-api": "^2.0.0",
4141
"del-cli": "^1.1.0",
4242
"enzyme": "^3.6.0",
@@ -50,9 +50,10 @@
5050
"glob": "^7.1.2",
5151
"husky": "^0.14.3",
5252
"inline-style-prefixer": "^5.0.3",
53-
"jest": "^22.4.3",
53+
"jest": "24.0.0-alpha.9",
5454
"jest-canvas-mock": "^1.0.2",
5555
"lint-staged": "^7.1.0",
56+
"metro-react-native-babel-preset": "^0.51.0",
5657
"npm-run-all": "^4.1.3",
5758
"prettier": "^1.12.1",
5859
"react": "^16.7.0",

packages/benchmarks/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
loader: 'babel-loader',
3535
options: {
3636
cacheDirectory: false,
37-
presets: babelPreset,
37+
presets: [babelPreset],
3838
plugins: ['styled-jsx/babel']
3939
}
4040
}

packages/examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"release": "yarn build && git checkout gh-pages && rm -rf ../../examples && mv dist ../../examples && git add -A && git commit -m \"Examples deploy\" && git push origin gh-pages && git checkout -"
88
},
99
"dependencies": {
10-
"babel-runtime": "^6.26.0",
10+
"@babel/runtime": "^7.2.0",
1111
"react": "^16.5.1",
1212
"react-dom": "^16.5.1",
1313
"react-native-web": "0.9.13"
1414
},
1515
"devDependencies": {
16+
"@babel/plugin-transform-runtime": "^7.2.0",
1617
"babel-plugin-react-native-web": "0.9.13",
1718
"babel-plugin-transform-runtime": "^6.23.0",
1819
"file-loader": "^1.1.11",

packages/examples/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ module.exports = {
3434
loader: 'babel-loader',
3535
options: {
3636
cacheDirectory: false,
37-
presets: ['react-native'],
37+
presets: ['module:metro-react-native-babel-preset'],
3838
plugins: [
3939
// needed to support async/await
40-
'transform-runtime'
40+
'@babel/plugin-transform-runtime'
4141
]
4242
}
4343
}

packages/react-native-web/src/exports/AppRegistry/__tests__/__snapshots__/index-test.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ input::-webkit-inner-spin-button,input::-webkit-outer-spin-button,input::-webkit
5151

5252
exports[`AppRegistry getApplication returns "element" and "getStyleElement" 1`] = `
5353
<AppContainer
54-
WrapperComponent={undefined}
5554
rootTag={Object {}}
5655
>
5756
<RootComponent />

packages/react-native-web/src/exports/Text/__tests__/index-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('components/Text', () => {
3434
expect(component.contains(children)).toEqual(true);
3535
});
3636

37-
test('prop "numberOfLines"');
37+
test('prop "numberOfLines"', () => {});
3838

3939
test('prop "onPress"', () => {
4040
const onPress = e => {};

packages/react-native-web/src/exports/TextInput/__tests__/index-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const testIfDocumentIsFocused = (message, fn) => {
1212
if (document.hasFocus && document.hasFocus()) {
1313
test(message, fn);
1414
} else {
15-
test.skip(`${message} – document is not focused`);
15+
test.skip(`${message} – document is not focused`, () => {});
1616
}
1717
};
1818

packages/react-native-web/src/exports/TextInput/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ class TextInput extends Component<*> {
150150

151151
static State = TextInputState;
152152

153-
blur: Function;
154-
155153
clear() {
156154
this._node.value = '';
157155
}
@@ -401,6 +399,7 @@ class TextInput extends Component<*> {
401399
onSubmitEditing(e);
402400
}
403401
if (shouldBlurOnSubmit) {
402+
// $FlowFixMe
404403
this.blur();
405404
}
406405
}

packages/website/storybook/.storybook/.babelrc

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['module:metro-react-native-babel-preset'],
5+
plugins: ['react-native-web']
6+
};
7+
};

scripts/babel/preset.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const createConfig = ({ modules }) => ({
22
presets: [
33
[
4-
'babel-preset-env',
4+
'@babel/preset-env',
55
{
66
loose: true,
77
modules,
8-
exclude: ['transform-es2015-typeof-symbol'],
8+
exclude: ['transform-typeof-symbol'],
99
targets: {
1010
browsers: [
1111
'chrome 38',
@@ -24,17 +24,19 @@ const createConfig = ({ modules }) => ({
2424
}
2525
}
2626
],
27-
'babel-preset-react',
28-
'babel-preset-flow'
27+
'@babel/preset-react',
28+
'@babel/preset-flow'
2929
],
3030
plugins: [
31-
['babel-plugin-transform-class-properties', { loose: true }],
32-
['babel-plugin-transform-object-rest-spread', { useBuiltIns: true }],
33-
['babel-plugin-transform-react-remove-prop-types', { mode: 'wrap' }]
31+
'@babel/plugin-transform-flow-strip-types',
32+
['babel-plugin-transform-react-remove-prop-types', { mode: 'wrap' }],
33+
['@babel/plugin-proposal-class-properties', { loose: true }],
34+
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
3435
].concat(modules ? ['babel-plugin-add-module-exports'] : [])
3536
});
3637

37-
module.exports =
38-
process.env.BABEL_ENV === 'commonjs'
38+
module.exports = function() {
39+
return process.env.BABEL_ENV === 'commonjs' || process.env.NODE_ENV === 'test'
3940
? createConfig({ modules: 'commonjs' })
4041
: createConfig({ modules: false });
42+
};

scripts/jest/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
rootDir: process.cwd(),
1212
roots: ['<rootDir>/packages'],
1313
setupFiles: ['jest-canvas-mock'],
14-
setupTestFrameworkScriptFile: require.resolve('./setupFramework.js'),
14+
setupFilesAfterEnv: [require.resolve('./setupFramework.js')],
1515
snapshotSerializers: ['enzyme-to-json/serializer'],
1616
testEnvironment: 'jsdom',
1717
timers: 'fake'

0 commit comments

Comments
 (0)