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(misc): don't clear node_modules require cache #22907

Merged

Conversation

AgentEnder
Copy link
Member

Current Behavior

When loading a config file within a createNodes plugin, we bust the require cache to ensure we get fresh contents. This is required otherwise project configuration isn't updated as we update the tools configuration.

However, removing node_modules from cache can cause some weird edge cases when any of those modules contained a Symbol, as once reloaded it will be considered a different symbol.

Expected Behavior

We don't clear node modules from require cache, to avoid causing funky behavior around Symbols.

Related Issue(s)

Fixes #

@AgentEnder AgentEnder requested review from a team as code owners April 19, 2024 13:19
Copy link

vercel bot commented Apr 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Apr 19, 2024 7:44pm


export function clearRequireCache() {
for (const k of Object.keys(require.cache)) {
if (!packageInstallationDirectories.some((dir) => k.includes(dir))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the relative + startsWith check rather than includes

Copy link
Member Author

Choose a reason for hiding this comment

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

relative + startsWith wouldn't handle npm workspaces right? e.g. apps/my-app/node_modules/jest if the app has a different version of jest installed

packages/jest/src/plugins/plugin.ts Show resolved Hide resolved
packages/devkit/src/utils/config-utils.ts Show resolved Hide resolved
@AgentEnder AgentEnder force-pushed the fix/dont-clear-node-modules-req-cache branch from da543bc to 68520b2 Compare April 19, 2024 15:14
@AgentEnder AgentEnder requested a review from FrozenPandaz April 19, 2024 15:35
@AgentEnder AgentEnder force-pushed the fix/dont-clear-node-modules-req-cache branch from 68520b2 to fb78c78 Compare April 19, 2024 19:43
@FrozenPandaz FrozenPandaz merged commit 80b5514 into nrwl:master Apr 19, 2024
6 checks passed
FrozenPandaz pushed a commit that referenced this pull request Apr 20, 2024
AgentEnder added a commit to AgentEnder/nx that referenced this pull request Apr 23, 2024
Copy link

github-actions bot commented May 2, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants