DEV Community

Federico Sordillo
Federico Sordillo

Posted on • Edited on

9 2

Refactoring absolute paths to relative ones

This is hardly a post, more like simple advice to anyone willing to move his/her codebase to relative paths.

I came to despise magic paths as I believe they solve no problem and usually introduce several non-trivial compilation bugs as soon as you move things around a little.

I did this kind of refactoring several times in the past and noticed that often people just go brute force at the problem, rewriting all the absolute paths one by one and wasting hours of their time.

A simple way to critically reduce the time spent on the task is to use VSCode regexp pattern matching to only target files located at a specific depth level. Assuming you have a magic path pointing to your components folder and a project structure like this:



...
├── package.json
└── src
    └── components


Enter fullscreen mode Exit fullscreen mode

You can refactor it by a simple find and replace:
Alt Text

And then you just go recursively:
Alt Text

Hope this will save someone some minutes :)

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (1)

Collapse
 
gekh profile image
German Khokhlov

thanks, helped a lot

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay