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

Support watching of config files #460

Merged
merged 1 commit into from
Jun 16, 2017
Merged

Support watching of config files #460

merged 1 commit into from
Jun 16, 2017

Conversation

alexander-akait
Copy link
Contributor

Please Read the CONTRIBUTING Guidelines
In particular the portion on Commit Message Formatting

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

Loader don't watch configuration files. Also don't adding configuration breaks other loader before babel-loader. And provide invalidate config after change.

What is the new behavior?

Watch on config files.

Does this PR introduce a breaking change?

  • Yes
  • No

If this PR contains a breaking change, please describe the following...

  • Impact:
  • Migration path for existing applications:
  • Github Issue(s) this is regarding:

Other information:
Ref: #456 (comment)
Ref: #456 (comment)

@codecov
Copy link

codecov bot commented Jun 8, 2017

Codecov Report

Merging #460 into master will decrease coverage by 2.31%.
The diff coverage is 83.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #460      +/-   ##
==========================================
- Coverage   81.08%   78.77%   -2.32%     
==========================================
  Files           6        6              
  Lines         185      179       -6     
  Branches       49       46       -3     
==========================================
- Hits          150      141       -9     
  Misses         18       18              
- Partials       17       20       +3
Impacted Files Coverage Δ
src/utils/exists.js 100% <100%> (ø) ⬆️
src/resolve-rc.js 91.66% <100%> (-2.46%) ⬇️
src/utils/read.js 50% <50%> (-25%) ⬇️
src/index.js 83.69% <78.57%> (-2.36%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de2d3f3...fcd3e36. Read the comment docs.

@@ -7,16 +7,10 @@ const fs = require("fs");
* var read = require('./helpers/fsExists')({});
* read('.babelrc'); // file contents...
*/
module.exports = function(cache) {
cache = cache || {};
Copy link
Member

@danez danez Jun 8, 2017

Choose a reason for hiding this comment

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

Removing this cache makes babel-loader got to the file-system to load the config for every file that it compiles, which seems not to be a good idea and would be a major performance hit.
I see that in watch you might want to rebuild with the new config, but I honestly rather go for a performant loader that works for 99% of the people (who can live with restarting watch when the config changes) than a slow but more correct one.
Or can you explain further on this change? Maybe I'm missing something.

Copy link
Contributor Author

@alexander-akait alexander-akait Jun 8, 2017

Choose a reason for hiding this comment

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

@danez now cache provide old config file when changed, i known what it is not best, I'll try to find a solution, also related to resolve-rc.js. While it's possible that caching such a place is just the wrong solution.

Copy link
Contributor Author

@alexander-akait alexander-akait Jun 8, 2017

Choose a reason for hiding this comment

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

@danez main problems not in restarting watch when the config changes, main problems in watch graph (absence config file in dependencies), it is break loader caches before babel-loader

@danez danez changed the title Fixed: watch configuration files. Support watching of config files Jun 8, 2017
@alexander-akait
Copy link
Contributor Author

@danez Sad but I could not find a solution. I don't know what can we do with this, but I feel this is a strong problem. It seems that caching a configuration is a bad idea.

@sokra
Copy link
Member

sokra commented Jun 8, 2017

You can use the filesystem provided via this.fs to the loader. It cached but invalidated by watching.

@danez
Copy link
Member

danez commented Jun 8, 2017

@sokra That is awesome. I was just searching on how to find out what change is triggering the loader run, so that we could invalidate the cache, but that is even easier.

@alexander-akait
Copy link
Contributor Author

@danez friendly ping

/**
* Check if file exists and cache the result
* return the result in cache
*
* @example
* var exists = require('./helpers/fsExists')({});
* exists('.babelrc'); // false
* var exists = require(require('fs'), './helpers/fsExists')({});
Copy link
Member

Choose a reason for hiding this comment

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

This exmaple is wrong I think ;)

Copy link
Member

@danez danez left a comment

Choose a reason for hiding this comment

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

Nice work, can you look at the remaining small nitpicks. Otherwise looks good to me.

cache[filename] ||
(fs.existsSync(filename) && fs.statSync(filename).isFile());
try {
exists = fileSystem.statSync(filename).isFile();
Copy link
Member

Choose a reason for hiding this comment

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

Can we do fs.existsSync(filename) here instead of exception catching. Try catch will make v8 deoptimize this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danez webpack fs doesn't fs.existsSync, because exists is deprecated

Copy link
Member

Choose a reason for hiding this comment

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

I see, maybe webpack would be open to add existsSync as it was undeprecated in 7.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danez hm, your are right, in theory we can create issue and add comment in code, and when issue was resolved change code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danez btw, webpack have many places where use statSync and this does not cause any problems with performance, i think this can be left

/**
* Read the file and cache the result
* return the result in cache
*
* @example
* var read = require('./helpers/fsExists')({});
* read('.babelrc'); // file contents...
* var read = require(require('fs'), './helpers/fsExists')({});
Copy link
Member

Choose a reason for hiding this comment

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

Also funny require

return cache[filename];
};
// Webpack `fs` return Buffer
return fileSystem.readFileSync(filename, "utf8").toString();
Copy link
Member

Choose a reason for hiding this comment

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

As the encoding is specified, we do not need to do .toString() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danez fileSystem.readFileSync in webpack fs doesn't support second argument and always return Buffer, i try to investigate this

Copy link
Contributor Author

@alexander-akait alexander-akait Jun 9, 2017

Choose a reason for hiding this comment

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

@danez seems some fs functions don't support more than one argument https://github.com/webpack/enhanced-resolve/blob/master/lib/CachedInputFileSystem.js#L197.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Practically
fileSystem.readFileSync(filename).toString("utf8"); === fileSystem.readFileSync(filename, "utf8");.
https://github.com/nodejs/node/blob/master/lib/fs.js#L602

@alexander-akait
Copy link
Contributor Author

@danez friendly ping

@danez
Copy link
Member

danez commented Jun 16, 2017

Thank you very much this looks very good. Nice that we found this cool approach with this.fs, so much undocumented nice things in webpack.

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.

3 participants