Skip to content

Commit

Permalink
feat: update babel 7 (geowarin#95)
Browse files Browse the repository at this point in the history
* chore: update jest

* feat: update babel 7
  • Loading branch information
christophehurpeau authored Jul 12, 2019
1 parent 4d66ccc commit aa98706
Show file tree
Hide file tree
Showing 15 changed files with 1,434 additions and 901 deletions.
4 changes: 4 additions & 0 deletions .babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
"only": ["test/"],
"plugins": ["@babel/plugin-transform-async-to-generator"]
}
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion _sandbox/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
loader: require.resolve('babel-loader-7'),
query: {
presets: ['react'],
},
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

const FriendlyErrorsWebpackPlugin = require('./src/friendly-errors-plugin');

module.exports = FriendlyErrorsWebpackPlugin;
module.exports = FriendlyErrorsWebpackPlugin;
module.exports.default = FriendlyErrorsWebpackPlugin;
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@
"url": "https://github.com/geowarin/friendly-errors-webpack-plugin/issues"
},
"license": "MIT",
"jest": {
"testEnvironment": "node",
"transformIgnorePatterns": ["node_modules", "src", "index.js"]
},
"peerDependencies": {
"webpack": "^4.0.0"
},
"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/plugin-transform-async-to-generator": "^7.5.0",
"autoprefixer": "^9.6.0",
"babel-core": "^6.23.1",
"babel-core": "6.26.3",
"babel-eslint": "^10.0.1",
"babel-loader": "^7.1.4",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-preset-react": "^6.23.0",
"babel-loader-8@npm:babel-loader": "^8.0.6",
"babel-loader-7@npm:babel-loader": "^7.1.4",
"css-loader": "^2.1.1",
"eslint": "^5.16.0",
"eslint-loader": "^2.1.2",
"eslint-plugin-node": "^9.0.1",
"expect": "^24.8.0",
"jest": "^18.1.0",
"jest": "^24.8.0",
"memory-fs": "^0.4.1",
"mini-css-extract-plugin": "^0.6.0",
"node-sass": "^4.12.0",
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/babelSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function cleanMessage(message) {
.replace(/^Module build failed.*:\s/, 'Syntax Error: ')
// remove mini-css-extract-plugin loader tracing errors
.replace(/^Syntax Error: ModuleBuildError:.*:\s/, '')
// remove babel extra wording
.replace('SyntaxError: ', '');
// remove babel extra wording and path
.replace(/^Syntax Error: SyntaxError: (([A-Z]:)?\/.*:\s)?/, 'Syntax Error: ');
}

function isBabelSyntaxError(e) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/babel-syntax-babel-6/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
loader: require.resolve('babel-loader-7'),
}
]
},
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/babel-syntax-babel-7/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions test/fixtures/babel-syntax-babel-7/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

class MyComponent extends React.Component {

render() {
return <div>
}
}
22 changes: 22 additions & 0 deletions test/fixtures/babel-syntax-babel-7/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const FriendlyErrorsWebpackPlugin = require('../../../index');

module.exports = {
mode: 'development',
entry: __dirname + "/index.js",
output: {
path: __dirname + "/dist",
filename: "bundle.js"
},
plugins: [
new FriendlyErrorsWebpackPlugin()
],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader-8'),
}
]
},
};
2 changes: 1 addition & 1 deletion test/fixtures/eslint-warnings/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
loader: require.resolve('babel-loader-7'),
}
]
},
Expand Down
30 changes: 25 additions & 5 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ it('integration : success', async() => {

const logs = await executeAndGetLogs('./fixtures/success/webpack.config')

expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/);
expect(logs.join('\n')).toMatch(/DONE {2}Compiled successfully in (.\d*)ms/);
});

it('integration : module-errors', async() => {
Expand Down Expand Up @@ -93,14 +93,34 @@ Use /* eslint-disable */ to ignore all warnings in a file.`
)
});

it('integration : babel syntax error', async() => {
it('integration : babel syntax error with babel-loader 7 (babel 6)', async() => {

const logs = await executeAndGetLogs('./fixtures/babel-syntax/webpack.config');
const logs = await executeAndGetLogs('./fixtures/babel-syntax-babel-6/webpack.config');

expect(logs).toEqual([
'ERROR Failed to compile with 1 errors',
'',
'error in ./test/fixtures/babel-syntax/index.js',
'error in ./test/fixtures/babel-syntax-babel-6/index.js',
'',
`Syntax Error: Unexpected token (5:11)
3 |${' '}
4 | render() {
> 5 | return <div>
| ^
6 | }
7 | }`,
''
]);
});
it('integration : babel syntax error with babel-loader 8 (babel 7)', async() => {

const logs = await executeAndGetLogs('./fixtures/babel-syntax-babel-7/webpack.config');

expect(logs).toEqual([
'ERROR Failed to compile with 1 errors',
'',
'error in ./test/fixtures/babel-syntax-babel-7/index.js',
'',
`Syntax Error: Unexpected token (5:11)
Expand Down Expand Up @@ -137,7 +157,7 @@ it('integration : webpack multi compiler : success', async() => {
let globalPlugins = [new FriendlyErrorsWebpackPlugin()];
const logs = await executeAndGetLogs('./fixtures/multi-compiler-success/webpack.config', globalPlugins);

expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/)
expect(logs.join('\n')).toMatch(/DONE {2}Compiled successfully in (.\d*)ms/)
});

it('integration : webpack multi compiler : module-errors', async() => {
Expand Down
Loading

0 comments on commit aa98706

Please sign in to comment.