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

fix: always bundle config file, fix config hmr #5779

Merged
merged 3 commits into from
Nov 26, 2021

Conversation

sanyuan0704
Copy link
Contributor

@sanyuan0704 sanyuan0704 commented Nov 21, 2021

Description

Fix #5780.In resolveConfig, using dependencies variable to record the deps that config file used, but if config file is js, the dependencies info will be lost.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Shinigami92
Shinigami92 previously approved these changes Nov 21, 2021
@@ -853,6 +853,8 @@ export async function loadConfigFromFile(
if (!isTS && !isMjs) {
// 1. try to directly require the module (assuming commonjs)
try {
const bundled = await bundleConfigFile(resolvedPath)
dependencies = bundled.dependencies
// clear cache in case of server restart
delete require.cache[require.resolve(resolvedPath)]
userConfig = require(resolvedPath)
Copy link
Member

Choose a reason for hiding this comment

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

I feel the deps collection should be executed after the success required otherwise if there are syntax errors in the config will throw the error message from esbuild first and be less DX friendly to me.

Meanwhile, note that for now only the cache of root config has been cleared on requiring, meaning even if you collect the deps for HMR, it will still require the old nest module cache, which will make this only a partial fix. I'd feel it's better to always bundle and exclude the config file for consistency. (/cc https://github.com/egoist/bundle-require)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the case, there will still be the problem of cache not being updated for nested dependencies. Therefore, the collection of dependencies is still needed in this way, but the configuration file is integrated into the bundle every time the dependency is updated. Does that mean so? (By the way, the dependency should be after require for DX, thanks for reminding)

Copy link
Contributor Author

@sanyuan0704 sanyuan0704 Nov 23, 2021

Choose a reason for hiding this comment

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

@antfu I'd like to always bundle and require the bundled code.That is to say all the code in the if branch will be removed.

if (!isTS && !isMjs){
  // code
}

And i have tried in my pr branch, it solves the cache problem.The code in the pr has updated.

@antfu antfu changed the title fix: config file dep is lost when using js fix: always bundle config file, fix config hmr Nov 26, 2021
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.

When dependencies of config file change, dev server doesn't restart as espect.
5 participants