Skip to content

Set hasAddedOrRemovedSymlinks when discovering an existing file by its link #46569

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

Merged
merged 2 commits into from
Oct 29, 2021

Conversation

andrewbranch
Copy link
Member

Fixes #46564

Symlinks are such a mess... I’m pretty sure resolutionCache.ts is not the right place for this, but it was direct and easy... considered doing this in Program’s tryReuseStructureFromOldProgram or resolveModuleNamesReusingOldState, but would have to do an extra iteration through all its newly resolved modules (it does them in a batch, and iterates through them only enough to see if there are any changes—I would at least have to continue that iteration until seeing a resolution with a symlink change or through the end). I’m open to that approach, though I really hope there’s an even better place for this I’m not seeing.

What’s happening is actually fairly simple. We currently clear the symlink and module specifier caches in a Project during updateGraphWorker if we’ve added or removed any ScriptInfo for a symlinked file. However, this doesn’t cover the case where we discover a symlink that links back to a file that already has a ScriptInfo (i.e., we resolve an existing file at a new, symlinked path). The test case first references /packages/mylib/index.ts by a relative import to its realpath, and builds a module specifier cache with that information. Then, an edit swaps ../packages/mylib for mylib, which resolves to a symlink pointing at the same file. The resolution succeeds, but we fail to notice that this change has updated our knowledge of existing symlinks, which should always make us recompute those caches. My fix simply sets the flag on Project saying we need to clear those caches when the ModuleResolutionCache makes a new resolution to a symlink.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 29, 2021
Comment on lines +3 to +5
// Notable lack of package.json referencing `mylib` as dependency here.
// This is not accurate to the original repro, but I think that's a separate
// bug, which, if fixed, would prevent the later crash.
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to follow up on this separately

Copy link
Member

Choose a reason for hiding this comment

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

Maybe link to the repro? Or provide an issue #.

@andrewbranch andrewbranch merged commit 7742cf2 into microsoft:main Oct 29, 2021
@andrewbranch andrewbranch deleted the bug/46564 branch October 29, 2021 22:47
mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
…s link (microsoft#46569)

* Set hasAddedOrRemovedSymlinks when discovering an existing file by its link

* Make it optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto import from vscode suggestions fail if existing import path doesn't match TypeScript's preference.
4 participants