I've typescript application build with ES6 modules.
How do I rename ts or js file representing a module without breaking ES6 import that referenced the renamed file?
e.g: rename MyModule.ts
to RenamedModule.ts
-> change import * from './MyModule'
to import * from './RenamedModule'
in all files;
Is there an VSCode extension or typescript service that would rename module path in all ES6 imports when renaming file?
EDIT:
vote for this vscode feature on GitHub
Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.
Select Edit > Refactor > Rename. Right-click the code and select Rename.
I was just looking for the same thing and found this VSCode extension:
move-ts
It is very young, but seems to be under active development. I tested it on my Windows machine and immediately ran into an issue with backslashes being used. There is, however, already a pull request to fix this (not by me). As soon as this is fixed, I think this might be what you (we) are looking for. EDIT: As of 2017-May-11, the windows issue is fixed.
There is an ongoing discussion for a "refactor move file" suggestion for Typescript itself here, but it seems to be very early stage. It seems, until this is built, this functionality is unlikely to be included in VSCode itself, as this open ticket for VSCode explains, which tracks the main feature request you linked to in your edit.
Vscode nows supports this feature. It's strange, when I did a file rename on a js file, it didn't work.
However, when I did a drag and drop of a file, vscode put up a dialog asking me if it should update all the paths for me. There's an option to have it always do it, which I selected.
After that I tried doing the file rename again on a js file, and it refactored all of my paths. I'm curious to know if others had the same experience as I did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With