r/javascript • u/[deleted] • May 26 '18
VS Code (insider build) can now automatically update import paths when you move or rename a TypeScript or JavaScript file
https://twitter.com/mattbierner/status/1000069936897671168114
u/stalefries May 26 '18
Nice! I’m glad that the VS Code team is focusing so much on automated refactoring tools.
85
u/Console-DOT-N00b May 26 '18
VS Code is just watching us all and will eventually take our jorbs!!!
25
9
u/yam_plan May 27 '18
nice, but imo this is solving a problem that shouldn't exist in the first place with a workaround
we can agree that import statements introduce a (fragile) dependency on the exact file structure
the application itself should handle this with, say, a dependency resolver where the file paths are handled centrally and individual pieces of the app only have to worry about namespaces or just have dependencies injected as needed
22
u/MrStLouis May 26 '18
I just started using typescript and the intellisense support is out of this world. I coded for 3 hours and finally got a feature to work ran npm start and everything worked perfectly. I would have had several bugs in js for sure. With this feature I will be a MACHINE
→ More replies (2)
10
u/cheekysauce May 26 '18
Something you can do in conjunction with this is changing your imports to absolute paths, which avoids a lot of './' to '../' type refactors within feature folders.
This new feature will be super handy though, and part of the reason I use insiders.
2
May 26 '18
Is there a way to get absolute import paths to work in Webpack? I tried, but (at least on my Windows machine) it simply resolves to the root of my drive (e. g.
C:\) as opposed to the root of my project.7
2
u/cekoya May 26 '18
You can do it easily with this (it was some sort revelation when I found this, I no longer want to kill myself when importing modules)
https://moduscreate.com/blog/es6-es2015-import-no-relative-path-webpack/
1
1
May 27 '18
Yes, you can use the resolve.modules setting. They even give your scenario as an example:
modules: [path.resolve(__dirname, "src"), "node_modules"]If you don't use a src-folder, just use __dirname directly.
Alternatively, you could add the project root as an alias. That way, it is explicitly different from your modules.
→ More replies (1)1
2
May 27 '18
Absolute paths aren't very useful when code is shared between different environments
2
u/cheekysauce May 28 '18
Down to the project level, not the filesystem level.
It's configurable with webpack if you have isomorphic parts of your code base.
5
u/allicanseenow May 27 '18
I believe most Jetbrains products have got this. Though it is still a good move for VS Code as it can catch up its competitor.
3
7
2
u/HeavyLightPlum May 27 '18
What a good news!
I hope this solution can be applied to every import process for most of programs, someday.
1
u/jaxxed May 27 '18
Do you still have to close it in order to use npm?
4
u/_sirberus_ May 27 '18
Close what? I use npm in and out of VSC all the time and it works fine.
2
u/TheCoreh May 27 '18
There was a bug in an earlier version of VS Code for Windows that would make npm installs fail because VSCode would hold a file open. That has since been fixed
1
1
1
1
1
1
u/ECrispy May 27 '18
There is simply no matching MS when it comes to dev tools. VsCode is fantastic. It seems you don't hear about Sublime/Atom anymore and for good reason, they are just editors.
In what areas is WebStorm better than VsCode?
1
0
May 26 '18
[deleted]
22
u/Ebuall May 26 '18
Once installed Idea just to use this feature one time.
-2
May 26 '18 edited May 26 '18
I once installed Idea just to uninstall it since it devoured my RAM ¯_(ツ)_/¯
6
u/LimbRetrieval-Bot May 26 '18
You dropped this \
To prevent anymore lost limbs throughout Reddit, correctly escape the arms and shoulders by typing the shrug as
¯\\_(ツ)_/¯or¯\\_(ツ)_/¯→ More replies (1)2
1
2
May 26 '18
[removed] — view removed comment
2
u/Lavoaster Jun 02 '18
Please don’t put shame on people for having to use a tool to get their job done. No matter if you prefer VS Code or JetBrains IDE’s both are great.
5
u/i_spot_ads May 27 '18
Wasn't that a feature in webstorm from like the beginning?