Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

typescript - Visual Studio Code - apply rename file refactoring in all ES6 imports

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

question from:https://stackoverflow.com/questions/37747938/visual-studio-code-apply-rename-file-refactoring-in-all-es6-imports

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...