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

Always run config resolver #884

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

davidlj95
Copy link
Contributor

@davidlj95 davidlj95 commented Dec 20, 2024

After upgrading Knip to latest version 5.41.1 from 5.38.2 in an Angular project found out that a file that was previously correctly tracked as production entry was suddenly appearing as unused file (specifically, src/main.ts) when using knip in production mode. I've been working with the Angular plugin recently, so first thought was I may have messed up something. That file is added as production entry because appears in browser option of the build target in angular.json.

However, that piece of code hasn't changed and the file should be added as production entry. After manually bisecting which version introduced the bug, seems it appears in 5.39.2. In there, there's a plugin housekeeping commit that removes the empty production array from the plugin. However, due to a check when running plugins, the resolveConfig function won't be executed when running in production mode if no production key is present in the plugin. Hence when removing that empty production array from the Angular plugin, the resolveConfig function wasn't ran and the production entry src/main.ts wasn't added.

Given the issue, I could have brought back the production empty array to the Angular plugin. However, I think that it's better to always run the resolveConfig function if is defined. Both in production and non-production modes. Because several plugins actually use the toProductionEntry function as part of resolveConfig. So this issue could happen in the case that production key is removed and all production entries are added as part of resolveConfig. Let me know if there's something else I may be missing though!

Copy link

pkg-pr-new bot commented Dec 20, 2024

Open in Stackblitz

npm i https://pkg.pr.new/knip@884

commit: 42ee9cb

@webpro
Copy link
Collaborator

webpro commented Dec 22, 2024

Thanks! Appreciate the thoroughness. Not even sure why I didn't do it yet, but it's good to enforce more correctness/strictness in resolveConfig implementations in production mode.

@webpro webpro merged commit 94474cb into webpro-nl:main Dec 22, 2024
23 checks passed
webpro added a commit that referenced this pull request Dec 22, 2024
@davidlj95 davidlj95 deleted the always-run-config-resolver branch December 23, 2024 11:07
@webpro
Copy link
Collaborator

webpro commented Jan 9, 2025

🚀 This pull request is included in v5.42.0. See Release 5.42.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

2 participants