from-root
Uses find-root module to help build paths from project's root folder.
usage
Say you have this folder structure:
- project/
- package.json
- conf/
- config.js
- services/
- twitter-stream/
- worker.js
- twitter-stream/
worker.js could load conf.js this way:
const fromRoot = ;const config = ;
instead of:
const config = );
Indeed, if the location of worker.js changes, but the conf folder keeps its location, we'd have to update the require relative path.
Furthermore, fromRoot("conf","config.js") makes it clear where the required file is.
installation
> npm install from-root
migration
You may want to try this script to migrate to from-root.
N.B.: Make sure you can safely role back as changes are made in place. The script is still naive and works only if all your relative paths go back to the root folder.
cd your_project/npm i -g from-rootfind -name "*.js" | xargs grep "\.\." | cut -f"1" -d":" | xargs migrate-files-to-from-root