microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.77k stars 12.46k forks source link

Moving files or folders in a monorepo setup does not adapt imports #59136

Open Hademumel opened 4 months ago

Hademumel commented 4 months ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Create a monorepo setup that uses npm workspaces and typescript project references.
  2. Create imports across workspace packages, e.g. import from @packageName.
  3. Move a file or a folder that gets imported in various packages.

Result: Not all imports get adapted, you have to correct them manually. Especially imports in packages that are not involved in the move (other than source or target package) do not get adapted.

Expectation: All imports that reference the moved file or folder should get adapted automatically.

I really love VS Code but move refactorings are not really supported at the moment. IMHO this is a basic feature for a code editor and should also be supported for monorepo setups. I know several colleagues that moved away from VSCode to Webstorm for this reason.

vscodenpa commented 4 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.90.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

mjbvz commented 4 months ago

Please share an example project plus steps to reproduce the issue

Hademumel commented 4 months ago

You can find an example project in this repo https://github.com/Hademumel/npm-ts-workspaces-example.git

Steps to reproduce:

  1. Move the file math.ts from the x-core package to one of the math folders in the same package or in the x-app package.
  2. Confirm the prompt when asked if imports should get adapted. (the refactoring is only working when the corresponding setting is set to "prompt", when set to "always" its not working for me)

I found out that the refactoring (adaptation of imports) sometimes works when you have the files with references opened. This should not be necessary though. The move operation should find all references and adapt the imports accordingly.

dkamins commented 2 months ago

The 2024 VS Code regression with @aliased imports no longer updating on file moves has been identified. There is a short-term workaround, but your feedback and comments are essential to getting this escalated properly for a real fix.

For background, root cause, why it's complicated, related issues, workaround, and next steps, see the full analysis of the regression here:

Join the discussion there and let's get this resolved!