Skip to content

Improve ESLint and Babel help messages, when enabling ESLint integration #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/plugins/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ If you prefer to create a ${chalk.yellow('.eslintrc.js')} file by yourself, here

${chalk.yellow(`// .eslintrc.js
module.exports = {
root: true,
parser: '@babel/eslint-parser',
extends: ['eslint:recommended'],
}
Expand All @@ -51,13 +52,37 @@ Install ${chalk.yellow('@babel/eslint-parser')} to prevent potential parsing iss
const babelConfig = babelLoaderUtil.getLoaders(webpackConfig)[0].options;
// cacheDirectory is a custom loader option, not a Babel option
delete babelConfig['cacheDirectory'];

(babelConfig['presets'] || []).forEach(preset => {
if (!Array.isArray(preset)) {
return;
}

if (typeof preset[0] === 'string' && preset[0].includes('@babel') && preset[0].includes('preset-env')) {
// The goal is to replace the preset string with a require.resolve() call, executed at runtime.
// Since we output the Babel config as JSON, we need to replace it with a placeholder.
preset[0] = '__PATH_TO_BABEL_PRESET_ENV__';

// The option "targets" is not necessary
delete preset[1]['targets'];

// If needed, specify the core-js version to use
if (preset[1]['corejs'] === null) {
preset[1]['corejs'] = packageHelper.getPackageVersion('core-js');
}
}
});

message += `

You will also need to specify your Babel config in a separate file. The current
configuration Encore has been adding for your is:

${chalk.yellow(`// babel.config.js
module.exports = ${JSON.stringify(babelConfig, null, 4)}
module.exports = ${
JSON.stringify(babelConfig, null, 4)
.replace('"__PATH_TO_BABEL_PRESET_ENV__"', 'require.resolve("@babel/preset-env")')
}
`)}`;

if (webpackConfig.babelConfigurationCallback) {
Expand Down
Loading