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

feat: watch mode config change #2797

Closed
wants to merge 5 commits into from
Closed

Conversation

evenstensberg
Copy link
Member

What kind of change does this PR introduce?
Fixes #15

Did you add tests for your changes?
No
If relevant, did you update the documentation?
N/A
Summary
Need to check if CLIplugin is added to the config, otherwise there will be a memory leak

Does this PR introduce a breaking change?

No
Other information
N/A

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Wrong solution

@@ -1581,7 +1580,7 @@ class WebpackCLI {
return loadedConfig;
};

const config = { options: {}, path: new WeakMap() };
const config = { options: {}, path: new Map() };
Copy link
Member

Choose a reason for hiding this comment

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

Leaking

Copy link
Member Author

Choose a reason for hiding this comment

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

We're not using config.path anywhere, what's to leak?

Copy link
Member

Choose a reason for hiding this comment

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

Look at CLI plugin

@webpack-bot
Copy link

@evenstensberg Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@alexander-akait Please review the new changes.

@evenstensberg
Copy link
Member Author

PTAL

@evenstensberg evenstensberg marked this pull request as ready for review June 25, 2021 19:06
@evenstensberg evenstensberg requested a review from a team as a code owner June 25, 2021 19:06
async tryRequireThenImport(module, handleError = true) {
let result;

try {
delete require.cache[module];
Copy link
Member

Choose a reason for hiding this comment

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

Unsafe and very bad for perf

Copy link
Member Author

Choose a reason for hiding this comment

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

its cache for one file, perf wont change that much because of this

);
if (alreadyHasPLugin) {
return configOptions;
}
Copy link
Member

Choose a reason for hiding this comment

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

Rerun applyOptions is very bad idea, it has very bad performance and it is not safe too


if (options.watch) {
// eslint-disable-next-line
for (const [_, filePath] of compiler.config.path.entries()) {
Copy link
Member

Choose a reason for hiding this comment

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

You can do the same using WeakMap

Copy link
Member Author

Choose a reason for hiding this comment

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

cant iterate over a weakmap

Copy link
Member

Choose a reason for hiding this comment

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

You have configuration keys

for (const [_, filePath] of compiler.config.path.entries()) {
// eslint-disable-next-line
fs.watchFile(filePath, async () => {
compiler = await this.createCompiler(options, callback);
Copy link
Member

Choose a reason for hiding this comment

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

It should rerun commander, not create compiler

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Ideally we should not rerun command whole, webpack can revalidate own options and run new compilation(s), everything webpack needs to know is path to configuration(s) for each compiler, so this task should be done on webpack side, not here, to be honestly it is not hard to implement, medium difficult

@evenstensberg
Copy link
Member Author

@alexander-akait you have the source, maybe you can have a look at it?

@evenstensberg
Copy link
Member Author

Some points:

  1. We only have to worry about the compiler re-rednering after a config change is noticed
  2. We only have access to the configuration at this level

Due this, I think this is the right level of abstraction. Since the CLI is the one that reads a config, I think this is where we naturally add this feature. I don't understand why webpack itself should re-validate a config, core should only be worried about doing a compilation.

WDYT?

@alexander-akait
Copy link
Member

@evenstensberg Because only webpack knows about dependencies

@evenstensberg
Copy link
Member Author

We just want config changes, not dependency changes. Watchmode + watch a config file

@alexander-akait
Copy link
Member

In this case we don't look at import/require inside webpack.config.js/package.json and etc, so reload will not work for many cases

@evenstensberg
Copy link
Member Author

The watch API will sniff those changes if the text inside the config changes. this is what we want

@alexander-akait
Copy link
Member

We should watch dependencies too like package.json/import/require and etc

@evenstensberg
Copy link
Member Author

No need, if we refer to the original issue

@alexander-akait
Copy link
Member

It is require to right implementation

@evenstensberg
Copy link
Member Author

@alexander-akait
Copy link
Member

I wanted to close it, because it is invalid, we need to improve it on webpack side, we need:

  • move buildDependecies from options.cache.buildDependencies to top options (it will be useful for any configuration, not only for webpack itself)
  • implement watchRun hook and get files from compilation.modifiedFiles, if we have confiugration file there restart our CLI

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

Successfully merging this pull request may close these issues.

[Feature]: Watch for webpack config changes in watch mode
3 participants