Skip to content
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

Move from eslint-loader to eslint-webpack-plugin, close #847 #985

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented May 23, 2021

Hi 👋

This PR is a proposal for #847 which add the eslint-webpack-plugin, since the eslint-loader is deprecated.

There are a lot of changes:

  • BC method .enableEslintLoader() has been removed, in favor of .enableEslintPlugin(). It accepts an object or a function. .enableEslintLoader() has not been removed, so it's not a BC anymore
  • BC ESLint <7 support has been dropped, since the plugin requires ESLint >= 7.
  • BC, I guess No more Encore-specific options, the only option lintVue was too specific and not futur proof (if you want to lint GraphQL, JSON or whatever you want, with ESLint, see last § of Proposal to replace #504 (ESLint/Vue) #574 (comment)). Extensions can easily be configured through Encore.enableEslintPlugin(options => { options.extensions.push('vue'); })
  • eslint.CLIEngine is not used anymore to detect if an ESLint configuration exists, because this class is deprecated since ESLint 7.

However, some tests are failing but I don't know why:

[
  {
    moduleIdentifier: '/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js??ruleSet[1].rules[0].use[0]!/tmp/err9jr/js/eslint.js',
    moduleName: './js/eslint.js',
    message: 'Module build failed (from ../../home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js):\n' +
      "Error: Cannot find module '@babel/plugin-syntax-dynamic-import'\n" +
      'Require stack:\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/index.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/index.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/lib/config/parse-runtime.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/test/helpers/setup.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/test/bin/encore.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/esm-utils.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/mocha.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/cli/one-and-dones.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/cli/options.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/bin/mocha\n' +
      '    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)\n' +
      '    at resolve (internal/modules/cjs/helpers.js:80:19)\n' +
      '    at resolveStandardizedName (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js:96:7)\n' +
      '    at resolvePlugin (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js:40:10)\n' +
      '    at loadPlugin (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js:48:20)\n' +
      '    at loadPlugin.next (<anonymous>)\n' +
      '    at createDescriptor (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:179:16)\n' +
      '    at createDescriptor.next (<anonymous>)\n' +
      '    at step (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:261:32)\n' +
      '    at evaluateAsync (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:291:5)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:44:11\n' +
      '    at Array.forEach (<anonymous>)\n' +
      '    at Function.async (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:43:15)\n' +
      '    at Function.all (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:216:13)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at createDescriptors (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:134:38)\n' +
      '    at createDescriptors.next (<anonymous>)\n' +
      '    at createPluginDescriptors (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:130:17)\n' +
      '    at createPluginDescriptors.next (<anonymous>)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:86:32\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at Function.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/gensync-utils/async.js:16:3)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at step (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:269:25)\n' +
      '    at evaluateAsync (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:291:5)\n' +
      '    at Function.errback (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:113:7)\n' +
      '    at errback (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/gensync-utils/async.js:60:18)\n' +
      '    at async (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:188:31)\n' +
      '    at onFirstPause (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:216:13)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at cachedFunction (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/caching.js:58:46)\n' +
      '    at cachedFunction.next (<anonymous>)\n' +
      '    at mergeChainOpts (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-chain.js:405:34)\n' +
      '    at mergeChainOpts.next (<anonymous>)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-chain.js:364:14\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at buildRootChain (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-chain.js:57:36)\n' +
      '    at buildRootChain.next (<anonymous>)\n' +
      '    at loadPrivatePartialConfig (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/partial.js:85:62)\n' +
      '    at loadPrivatePartialConfig.next (<anonymous>)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/partial.js:131:25\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at step (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:269:25)\n' +
      '    at evaluateAsync (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:291:5)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:93:9\n' +
      '    at new Promise (<anonymous>)\n' +
      '    at async (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:92:14)\n' +
      '    at Object.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:155:26)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at asyncGeneratorStep (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:3:103)\n' +
      '    at _next (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:5:194)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:5:364\n' +
      '    at new Promise (<anonymous>)\n' +
      '    at Object.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:5:97)\n' +
      '    at Object.loader (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:64:18)\n' +
      '    at Object.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:59:12)',
    moduleId: './js/eslint.js',
    moduleTrace: [],
    details: undefined,
    stack: 'ModuleBuildError: Module build failed (from ../../home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js):\n' +
      "Error: Cannot find module '@babel/plugin-syntax-dynamic-import'\n" +
      'Require stack:\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/index.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/index.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/lib/config/parse-runtime.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/test/helpers/setup.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/test/bin/encore.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/esm-utils.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/mocha.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/cli/one-and-dones.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/lib/cli/options.js\n' +
      '- /home/hugo/workspace-os/webpack-encore/node_modules/mocha/bin/mocha\n' +
      '    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)\n' +
      '    at resolve (internal/modules/cjs/helpers.js:80:19)\n' +
      '    at resolveStandardizedName (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js:96:7)\n' +
      '    at resolvePlugin (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js:40:10)\n' +
      '    at loadPlugin (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/files/plugins.js:48:20)\n' +
      '    at loadPlugin.next (<anonymous>)\n' +
      '    at createDescriptor (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:179:16)\n' +
      '    at createDescriptor.next (<anonymous>)\n' +
      '    at step (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:261:32)\n' +
      '    at evaluateAsync (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:291:5)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:44:11\n' +
      '    at Array.forEach (<anonymous>)\n' +
      '    at Function.async (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:43:15)\n' +
      '    at Function.all (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:216:13)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at createDescriptors (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:134:38)\n' +
      '    at createDescriptors.next (<anonymous>)\n' +
      '    at createPluginDescriptors (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:130:17)\n' +
      '    at createPluginDescriptors.next (<anonymous>)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-descriptors.js:86:32\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at Function.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/gensync-utils/async.js:16:3)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at step (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:269:25)\n' +
      '    at evaluateAsync (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:291:5)\n' +
      '    at Function.errback (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:113:7)\n' +
      '    at errback (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/gensync-utils/async.js:60:18)\n' +
      '    at async (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:188:31)\n' +
      '    at onFirstPause (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:216:13)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at cachedFunction (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/caching.js:58:46)\n' +
      '    at cachedFunction.next (<anonymous>)\n' +
      '    at mergeChainOpts (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-chain.js:405:34)\n' +
      '    at mergeChainOpts.next (<anonymous>)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-chain.js:364:14\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at buildRootChain (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/config-chain.js:57:36)\n' +
      '    at buildRootChain.next (<anonymous>)\n' +
      '    at loadPrivatePartialConfig (/home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/partial.js:85:62)\n' +
      '    at loadPrivatePartialConfig.next (<anonymous>)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/@babel/core/lib/config/partial.js:131:25\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at step (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:269:25)\n' +
      '    at evaluateAsync (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:291:5)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:93:9\n' +
      '    at new Promise (<anonymous>)\n' +
      '    at async (/home/hugo/workspace-os/webpack-encore/node_modules/gensync/index.js:92:14)\n' +
      '    at Object.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:155:26)\n' +
      '    at Generator.next (<anonymous>)\n' +
      '    at asyncGeneratorStep (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:3:103)\n' +
      '    at _next (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:5:194)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:5:364\n' +
      '    at new Promise (<anonymous>)\n' +
      '    at Object.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:5:97)\n' +
      '    at Object.loader (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:64:18)\n' +
      '    at Object.<anonymous> (/home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:59:12)\n' +
      '    at processResult (/home/hugo/workspace-os/webpack-encore/node_modules/webpack/lib/NormalModule.js:676:19)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/webpack/lib/NormalModule.js:778:5\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/loader-runner/lib/LoaderRunner.js:399:11\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/loader-runner/lib/LoaderRunner.js:251:18\n' +
      '    at context.callback (/home/hugo/workspace-os/webpack-encore/node_modules/loader-runner/lib/LoaderRunner.js:124:13)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/babel-loader/lib/index.js:59:103'
  },
  {
    message: 'No ESLint configuration found in /tmp/err9jr/js.',
    details: undefined,
    stack: 'Error: No ESLint configuration found in /tmp/err9jr/js.\n' +
      '    at CascadingConfigArrayFactory._finalizeConfigArray (/home/hugo/workspace-os/webpack-encore/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js:508:19)\n' +
      '    at CascadingConfigArrayFactory.getConfigArrayForFile (/home/hugo/workspace-os/webpack-encore/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js:299:21)\n' +
      '    at FileEnumerator._iterateFilesWithFile (/home/hugo/workspace-os/webpack-encore/node_modules/eslint/lib/cli-engine/file-enumerator.js:365:43)\n' +
      '    at FileEnumerator._iterateFiles (/home/hugo/workspace-os/webpack-encore/node_modules/eslint/lib/cli-engine/file-enumerator.js:346:25)\n' +
      '    at FileEnumerator.iterateFiles (/home/hugo/workspace-os/webpack-encore/node_modules/eslint/lib/cli-engine/file-enumerator.js:296:59)\n' +
      '    at iterateFiles.next (<anonymous>)\n' +
      '    at CLIEngine.executeOnFiles (/home/hugo/workspace-os/webpack-encore/node_modules/eslint/lib/cli-engine/cli-engine.js:765:48)\n' +
      '    at ESLint.lintFiles (/home/hugo/workspace-os/webpack-encore/node_modules/eslint/lib/eslint/eslint.js:530:23)\n' +
      '    at lintFiles (/home/hugo/workspace-os/webpack-encore/node_modules/eslint-webpack-plugin/dist/getESLint.js:57:36)\n' +
      '    at lint (/home/hugo/workspace-os/webpack-encore/node_modules/eslint-webpack-plugin/dist/linter.js:93:21)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/eslint-webpack-plugin/dist/index.js:138:11\n' +
      '    at Hook.eval [as callAsync] (eval at create (/home/hugo/workspace-os/webpack-encore/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)\n' +
      '    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/hugo/workspace-os/webpack-encore/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)\n' +
      '    at Compilation.finish (/home/hugo/workspace-os/webpack-encore/node_modules/webpack/lib/Compilation.js:2155:28)\n' +
      '    at /home/hugo/workspace-os/webpack-encore/node_modules/webpack/lib/Compiler.js:1075:19\n' +
      '    at processTicksAndRejections (internal/process/task_queues.js:79:11)'
  }
]
      2) Code splitting with dynamic import
 ERROR  Failed to compile with 1 errors                                                                                                                                       15:54:37

 error  in ./test_tmp/tsnh3r/js/code_splitting_dynamic_import.js                                                                                                              15:54:37

The dependency @babel/plugin-syntax-dynamic-import is present in Encore's package.json, so I don't really understand the issue... 😬
Any help would be appreciated! ❤️
EDIT: fixed, see #985 (comment)

WDYT? Thanks!

@weaverryan
Copy link
Member

Hey @Kocal!

Thanks for jumping on this. Biggest concerns are about the BC stuff. Could we keep enableEslintLoader() and deprecate it (and then add in the new method + functionality)?

BC ESLint <7 support has been dropped, since the plugin requires ESLint >= 7.

I'm ok with that.

I'm also not sure about the test failure unfortunately :/

@Kocal
Copy link
Member Author

Kocal commented May 25, 2021

I've recreated the pull request, .enableEslintLoader() is back again and .enableEslintPlugin has been implemented.

For the failing tests, the funny thing is that they pass when running them one by one... 😬
image

Something wrong must happens before them.

@Kocal
Copy link
Member Author

Kocal commented May 25, 2021

Okay I got it.

The issues were caused by my weird trick which check if an ESLint configuration exists or not (don't ask me why lol):

try {
    (async function() {
        await eslint.calculateConfigForFile('webpack.config.js');
    })();
} catch (e) {
    // ...
}

It looks like I can't do that netheir use the form (async() { try { await ... } catch() {} })(), and due to the 1st form or 2nd form, the exception won't be rejected properly.

So I had three options:

  1. Make this plugin function async, but I have to modify all the functions tree between Encore.getWebpackConfig() and this function (adding async/await where needed), but that's a lot of work and I don't think going full async should be part of this PR
  2. Re-use the deprecated require('eslint').CLIEngine API, but... that's deprecated
  3. find a way to force eslint.calculateConfigForFile() to be synchronous, thanks to sync-rpc. I'm not super fan of this solution, but I think this is the best here. We could remove it later if we plan to make Encore.getWebpackConfig() async

WDYT?

@weaverryan
Copy link
Member

Hmmm. So normally, it's impossible to use an async function in Encore, because we need Encore to run synchronously (we can't wait for some async process to finish before returning the Webpack config via Encore.getWebpackConfig().

But, in your case, this is just to trigger a warning/error, right? It seems to me that we could run that async, sort if "in the background". If I'm picturing everything correctly, the result would be that Webpack builds... then a short time after, an error is thrown. But I'm doing some guessing here :).

@Kocal
Copy link
Member Author

Kocal commented May 31, 2021

Hmmm. So normally, it's impossible to use an async function in Encore, because we need Encore to run synchronously (we can't wait for some async process to finish before returning the Webpack config via Encore.getWebpackConfig().

Considering webpack supports a Promise for configuration, we can make getWebpackConfig() async without breaking things to the end-user. The end-user won't have to modify anything in its configuration.

image

But, in your case, this is just to trigger a warning/error, right? It seems to me that we could run that async, sort if "in the background". If I'm picturing everything correctly, the result would be that Webpack builds... then a short time after, an error is thrown. But I'm doing some guessing here :).

Yeah it's for triggering a warning/error, but also to add the ESLintPlugin to the webpack plugins. We need to run that sync otherwise the plugin won't be added (or added later, after webpack started to run... 🤔).

Also, since the "node.js packages" tends to be async more and more, I'm afraid this will cause more and more issues to Encore.
For example we use Babel in parse-runtime.js to check if a .babelrc exists. Currently their API is sync, but maybe in the future this will be async.
This mode of reasoning also applies for all external dependencies we load inside Encore, like crypto, some webpack API, tmp, url, etc...

WDYT about:

  1. keep the ESLint check sync, thanks to sync-rpc
  2. when this PR is merged, I start to work on making Encore.getWebpackConfig() async?

@stof
Copy link
Member

stof commented May 31, 2021

Considering webpack supports a Promise for configuration, we can make getWebpackConfig() async without breaking things to the end-user. The end-user won't have to modify anything in its configuration.

That's only true if the user does not customize the generated config before returning it. So that would still require a semver-major.

Also, this will likely break the Encore.reset() API meant to allow generating multiple configs (once the config generation is asynchronous, we need to be careful about concurrency issues)

@Kocal
Copy link
Member Author

Kocal commented May 31, 2021

Oh yeah, totally forgot about this... 😥

Well... idk.
The ESLint configuration check can not be done async, or maybe you want to always push the ESLintWebpackPlugin even if there is no ESLint configuration, and check async if a configuration exists? Won't it be a mess with webpack output in the CLI?

@weaverryan
Copy link
Member

Yep - we can try rpc

I was going to say the same thing as Stof, but he already said it better. I think we can still do it (though, I haven’t thought about the reset part), but it would need to be opt in until the next major version (with a deprecation of that flash is not set).

@Kocal
Copy link
Member Author

Kocal commented May 31, 2021

Just my opinion, but for me, in a new major release, it would be really nice if we stop exporting new Encore() but Encore class instead. This way, end users would have the hability to create multiple Encore instances/webpack configurations without calling Encore.reset().

For the async getWebpackConfig(), maybe we can wait to supports Node.js 14+ which adds top-level await. This way end users could write something like this:

const Encore = require('@symfony/webpack-encore');

Encore.addEntry(...);

const config = await Encore.getWebpackConfig();
// do something with config

module.exports = config;

@stof
Copy link
Member

stof commented May 31, 2021

@Kocal top-level await works only in ES modules, not in CommonJS files.

@Kocal
Copy link
Member Author

Kocal commented May 31, 2021

Ah yes that's true...

@Kocal
Copy link
Member Author

Kocal commented Jun 23, 2021

Hi guys 👋

Is there anything else to do here? Using sync-rpc to make eslint.calculateConfigForFile() call sync is alright for you?

Thanks!

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay @Kocal - could you rebase this so we can see some green tests (the tests on main are passing).

index.js Show resolved Hide resolved
@Kocal
Copy link
Member Author

Kocal commented Sep 3, 2021

The PR has been successfully rebased, and a deprecation log has been added!

@Kocal
Copy link
Member Author

Kocal commented Sep 21, 2021

(friendly ping @weaverryan 🙂 )

@antonio-masotti
Copy link

Looking forward for this PR to be merged :)

@weaverryan
Copy link
Member

Thank you @Kocal!

@weaverryan
Copy link
Member

And thank you for always being a support and helper around the Symfony JS ecosystem @Kocal! My apologies for this taking SO long to get merged.

@weaverryan weaverryan merged commit ba177af into symfony:main Jan 21, 2022
@Kocal Kocal deleted the GH-847 branch January 21, 2022 08:03
@Kocal
Copy link
Member Author

Kocal commented Jan 21, 2022

@weaverryan no worries, I know you are super busy! :) and thanks for your words ❤️

@gimler
Copy link
Contributor

gimler commented Jan 27, 2022

@Kocal i think this documentation is outdated and should be updated https://symfony.com/doc/current/frontend/encore/advanced-config.html#having-the-full-control-on-loaders-rules can you do this please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants