Skip to content

Commit f36782c

Browse files
committed
Writing out babel.config.js for users when using eslint plugin
At some point, in order to use `@babel/eslint-parser`, this became required.
1 parent a4aec57 commit f36782c

File tree

5 files changed

+71
-62
lines changed

5 files changed

+71
-62
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ which you may have installed to enable extra features:
3838

3939
* Removed `Encore.enableEslintLoader()`: use `Encore.enableEslintPlugin()`.
4040

41+
* If using `enableEslintPlugin()` with the `@babel/eslint-parser` parser,
42+
you may now need to create an external Babel configuration file. To see
43+
an example, temporarily delete your `.eslintrc.js` file and run Encore.
44+
The error will show you a Babel configuration file you can use.
45+
4146
## [v1.8.2](https://github.com/symfony/webpack-encore/releases/tag/v1.8.2)
4247

4348
*Mar 17th, 2022*

lib/plugins/eslint.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const hasEslintConfiguration = forceSync(require.resolve('../utils/has-eslint-co
1414
const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars
1515
const applyOptionsCallback = require('../utils/apply-options-callback');
1616
const pluginFeatures = require('../features');
17+
const babelLoaderUtil = require('../loaders/babel');
1718

1819
/**
1920
* Support for ESLint.
@@ -30,22 +31,43 @@ module.exports = function(plugins, webpackConfig) {
3031
const chalk = require('chalk');
3132
const packageHelper = require('../package-helper');
3233

33-
const message = `No ESLint configuration has been found.
34+
let message = `No ESLint configuration has been found.
3435
3536
${chalk.bgGreen.black('', 'FIX', '')} Run command ${chalk.yellow('./node_modules/.bin/eslint --init')} or manually create a ${chalk.yellow('.eslintrc.js')} file at the root of your project.
3637
3738
If you prefer to create a ${chalk.yellow('.eslintrc.js')} file by yourself, here is an example to get you started:
3839
3940
${chalk.yellow(`// .eslintrc.js
4041
module.exports = {
41-
parser: 'babel-eslint',
42+
parser: '@babel/eslint-parser',
4243
extends: ['eslint:recommended'],
4344
}
4445
`)}
4546
46-
Install ${chalk.yellow('babel-eslint')} to prevent potential parsing issues: ${packageHelper.getInstallCommand([[{ name: 'babel-eslint' }]])}
47-
47+
Install ${chalk.yellow('@babel/eslint-parser')} to prevent potential parsing issues: ${packageHelper.getInstallCommand([[{ name: '@babel/eslint-parser' }]])}
4848
`;
49+
if (!webpackConfig.doesBabelRcFileExist()) {
50+
const babelConfig = babelLoaderUtil.getLoaders(webpackConfig)[0].options;
51+
// cacheDirectory is a custom loader option, not a Babel option
52+
delete babelConfig['cacheDirectory'];
53+
message += `
54+
55+
You will also need to specify your Babel config in a separate file. The current
56+
configuration Encore has been adding for your is:
57+
58+
${chalk.yellow(`// babel.config.js
59+
module.exports = ${JSON.stringify(babelConfig, null, 4)}
60+
`)}`;
61+
62+
if (webpackConfig.babelConfigurationCallback) {
63+
message += `\nAdditionally, remove the ${chalk.yellow('.configureBabel()')} in webpack.config.js: this will no longer be used.`;
64+
}
65+
66+
if (webpackConfig.babelPresetEnvOptionsCallback) {
67+
message += `\nAnd remove the ${chalk.yellow('.configureBabelPresetEnv()')} in webpack.config.js: this will no longer be used.`;
68+
}
69+
}
70+
4971
throw new Error(message);
5072
}
5173

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"yargs-parser": "^21.0.0"
5454
},
5555
"devDependencies": {
56+
"@babel/eslint-parser": "^7.17.0",
5657
"@babel/plugin-proposal-class-properties": "^7.0.0",
5758
"@babel/plugin-transform-react-jsx": "^7.0.0",
5859
"@babel/preset-react": "^7.0.0",
@@ -64,7 +65,6 @@
6465
"@vue/babel-preset-jsx": "^1.0.0",
6566
"@vue/compiler-sfc": "^3.0.2",
6667
"autoprefixer": "^10.2.0",
67-
"babel-eslint": "^10.0.1",
6868
"chai": "^4.2.0",
6969
"chai-fs": "^2.0.0",
7070
"chai-subset": "^1.6.0",

test/functional.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ function getIntegrityData(config) {
7373
return entrypointsData.integrity;
7474
}
7575

76+
const originalCwd = process.cwd();
77+
7678
describe('Functional tests using webpack', function() {
7779
// being functional tests, these can take quite long
7880
this.timeout(10000);
@@ -81,6 +83,10 @@ describe('Functional tests using webpack', function() {
8183
testSetup.emptyTmpDir();
8284
});
8385

86+
afterEach(() => {
87+
process.chdir(originalCwd);
88+
});
89+
8490
describe('Basic scenarios.', () => {
8591

8692
it('Builds a few simple entries file + manifest.json', (done) => {
@@ -1841,14 +1847,30 @@ module.exports = {
18411847
path.join(appDir, '.eslintrc.js'),
18421848
`
18431849
module.exports = {
1844-
parser: 'babel-eslint',
1850+
parser: '@babel/eslint-parser',
18451851
rules: {
18461852
'indent': ['error', 2],
18471853
'no-unused-vars': ['error', { 'args': 'all' }]
18481854
}
18491855
} `
18501856
);
18511857

1858+
fs.writeFileSync(
1859+
path.join(appDir, 'babel.config.js'),
1860+
`
1861+
module.exports = {
1862+
presets: [
1863+
['@babel/preset-env', {
1864+
modules: false,
1865+
targets: {},
1866+
useBuiltIns: 'usage',
1867+
corejs: 3,
1868+
}]
1869+
],
1870+
plugins: ['@babel/plugin-syntax-dynamic-import']
1871+
} `
1872+
);
1873+
18521874
process.chdir(appDir);
18531875

18541876
testSetup.runWebpack(config, (webpackAssert, stats) => {

yarn.lock

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
json5 "^2.2.1"
4343
semver "^6.3.0"
4444

45+
"@babel/eslint-parser@^7.17.0":
46+
version "7.17.0"
47+
resolved "https://registry.yarnpkg.com/@babel/eslint-parser/-/eslint-parser-7.17.0.tgz#eabb24ad9f0afa80e5849f8240d0e5facc2d90d6"
48+
integrity sha512-PUEJ7ZBXbRkbq3qqM/jZ2nIuakUBqCYc7Qf52Lj7dlZ6zERnqisdHioL0l4wwQZnmskMeasqUNzLBFKs3nylXA==
49+
dependencies:
50+
eslint-scope "^5.1.1"
51+
eslint-visitor-keys "^2.1.0"
52+
semver "^6.3.0"
53+
4554
"@babel/generator@^7.17.9":
4655
version "7.17.9"
4756
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.17.9.tgz#f4af9fd38fa8de143c29fce3f71852406fc1e2fc"
@@ -259,7 +268,7 @@
259268
chalk "^2.0.0"
260269
js-tokens "^4.0.0"
261270

262-
"@babel/parser@^7.16.4", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9", "@babel/parser@^7.7.0":
271+
"@babel/parser@^7.16.4", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9":
263272
version "7.17.9"
264273
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.17.9.tgz#9c94189a6062f0291418ca021077983058e171ef"
265274
integrity sha512-vqUSBLP8dQHFPdPi9bc5GK9vRkYHJ49fsZdtoJ8EQ8ibpwk5rPKfvNIwChB0KVXcIjcepEBBd2VHC5r9Gy8ueg==
@@ -940,7 +949,7 @@
940949
"@babel/parser" "^7.16.7"
941950
"@babel/types" "^7.16.7"
942951

943-
"@babel/traverse@^7.13.0", "@babel/traverse@^7.16.7", "@babel/traverse@^7.16.8", "@babel/traverse@^7.17.3", "@babel/traverse@^7.17.9", "@babel/traverse@^7.7.0":
952+
"@babel/traverse@^7.13.0", "@babel/traverse@^7.16.7", "@babel/traverse@^7.16.8", "@babel/traverse@^7.17.3", "@babel/traverse@^7.17.9":
944953
version "7.17.9"
945954
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.17.9.tgz#1f9b207435d9ae4a8ed6998b2b82300d83c37a0d"
946955
integrity sha512-PQO8sDIJ8SIwipTPiR71kJQCKQYB5NGImbOviK8K+kg5xkNSYXLBupuX9QhatFowrsvo9Hj8WgArg3W7ijNAQw==
@@ -956,7 +965,7 @@
956965
debug "^4.1.0"
957966
globals "^11.1.0"
958967

959-
"@babel/types@^7.16.0", "@babel/types@^7.16.7", "@babel/types@^7.16.8", "@babel/types@^7.17.0", "@babel/types@^7.4.4", "@babel/types@^7.7.0":
968+
"@babel/types@^7.16.0", "@babel/types@^7.16.7", "@babel/types@^7.16.8", "@babel/types@^7.17.0", "@babel/types@^7.4.4":
960969
version "7.17.0"
961970
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.17.0.tgz#a826e368bccb6b3d84acd76acad5c0d87342390b"
962971
integrity sha512-TmKSNO4D5rzhL5bjWFcVHHLETzfQ/AmbKpKPOSjlP0WoHZ6L911fgoOKY4Alp/emzG4cHJdyN49zpgkbXFEHHw==
@@ -1876,18 +1885,6 @@ aws4@^1.8.0:
18761885
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
18771886
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
18781887

1879-
babel-eslint@^10.0.1:
1880-
version "10.1.0"
1881-
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
1882-
integrity sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==
1883-
dependencies:
1884-
"@babel/code-frame" "^7.0.0"
1885-
"@babel/parser" "^7.7.0"
1886-
"@babel/traverse" "^7.7.0"
1887-
"@babel/types" "^7.7.0"
1888-
eslint-visitor-keys "^1.0.0"
1889-
resolve "^1.12.0"
1890-
18911888
babel-loader@^8.2.2:
18921889
version "8.2.5"
18931890
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.2.5.tgz#d45f585e654d5a5d90f5350a779d7647c5ed512e"
@@ -2906,17 +2903,6 @@ eslint-import-resolver-node@^0.3.6:
29062903
debug "^3.2.7"
29072904
resolve "^1.20.0"
29082905

2909-
eslint-loader@^4.0.0:
2910-
version "4.0.2"
2911-
resolved "https://registry.yarnpkg.com/eslint-loader/-/eslint-loader-4.0.2.tgz#386a1e21bcb613b3cf2d252a3b708023ccfb41ec"
2912-
integrity sha512-EDpXor6lsjtTzZpLUn7KmXs02+nIjGcgees9BYjNkWra3jVq5vVa8IoCKgzT2M7dNNeoMBtaSG83Bd40N3poLw==
2913-
dependencies:
2914-
find-cache-dir "^3.3.1"
2915-
fs-extra "^8.1.0"
2916-
loader-utils "^2.0.0"
2917-
object-hash "^2.0.3"
2918-
schema-utils "^2.6.5"
2919-
29202906
eslint-module-utils@^2.7.3:
29212907
version "2.7.3"
29222908
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.7.3.tgz#ad7e3a10552fdd0642e1e55292781bd6e34876ee"
@@ -2969,7 +2955,7 @@ eslint-plugin-node@^11.1.0:
29692955
resolve "^1.10.1"
29702956
semver "^6.1.0"
29712957

2972-
2958+
[email protected], eslint-scope@^5.1.1:
29732959
version "5.1.1"
29742960
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
29752961
integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==
@@ -2999,12 +2985,12 @@ eslint-utils@^3.0.0:
29992985
dependencies:
30002986
eslint-visitor-keys "^2.0.0"
30012987

3002-
eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
2988+
eslint-visitor-keys@^1.1.0:
30032989
version "1.3.0"
30042990
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
30052991
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==
30062992

3007-
eslint-visitor-keys@^2.0.0:
2993+
eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
30082994
version "2.1.0"
30092995
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
30102996
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
@@ -3419,15 +3405,6 @@ fs-extra@^10.0.0:
34193405
jsonfile "^6.0.1"
34203406
universalify "^2.0.0"
34213407

3422-
fs-extra@^8.1.0:
3423-
version "8.1.0"
3424-
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
3425-
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
3426-
dependencies:
3427-
graceful-fs "^4.2.0"
3428-
jsonfile "^4.0.0"
3429-
universalify "^0.1.0"
3430-
34313408
34323409
version "1.0.3"
34333410
resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.3.tgz#ae3ac92d53bb328efe0e9a1d9541f6ad8d48e2d3"
@@ -4235,13 +4212,6 @@ json5@^2.1.2, json5@^2.2.1:
42354212
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
42364213
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==
42374214

4238-
jsonfile@^4.0.0:
4239-
version "4.0.0"
4240-
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
4241-
integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
4242-
optionalDependencies:
4243-
graceful-fs "^4.1.6"
4244-
42454215
jsonfile@^6.0.1:
42464216
version "6.1.0"
42474217
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
@@ -4749,11 +4719,6 @@ object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
47494719
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
47504720
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
47514721

4752-
object-hash@^2.0.3:
4753-
version "2.2.0"
4754-
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.2.0.tgz#5ad518581eefc443bd763472b8ff2e9c2c0d54a5"
4755-
integrity sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==
4756-
47574722
object-inspect@^1.12.0, object-inspect@^1.9.0:
47584723
version "1.12.0"
47594724
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.0.tgz#6e2c120e868fd1fd18cb4f18c31741d0d6e776f0"
@@ -5687,7 +5652,7 @@ resolve-url-loader@^5.0.0:
56875652
postcss "^8.2.14"
56885653
source-map "0.6.1"
56895654

5690-
resolve@^1.10.1, resolve@^1.12.0, resolve@^1.14.2, resolve@^1.20.0, resolve@^1.22.0, resolve@^1.9.0:
5655+
resolve@^1.10.1, resolve@^1.14.2, resolve@^1.20.0, resolve@^1.22.0, resolve@^1.9.0:
56915656
version "1.22.0"
56925657
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.0.tgz#5e0b8c67c15df57a89bdbabe603a002f21731198"
56935658
integrity sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==
@@ -6403,11 +6368,6 @@ union@~0.5.0:
64036368
dependencies:
64046369
qs "^6.4.0"
64056370

6406-
universalify@^0.1.0:
6407-
version "0.1.2"
6408-
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
6409-
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
6410-
64116371
universalify@^2.0.0:
64126372
version "2.0.0"
64136373
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"

0 commit comments

Comments
 (0)