Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

rpr

0.1.4 • Public • Published

RPR (Resolve Project Root)

Resolves '~/...' to a project root

This little utility modifies the built-in path.resolve(...) function so that you can resolve paths relative to a project root. Because require(...) uses path.resolve(...), this also modifies the behvaior of require(...).

Example

./utils.js

 
module.exports.square = (x) => {
  return x * x;
}

./index.js

require('rpr')(__dirname);
 
const custom = require('~/path/file.js');
 
custom();

./path/file.js

const { square } = require('~/utils.js');
 
module.exports = () => {
  console.log( square(2) );  
}

API

rpr([directory])

  • directory {String} a path to set as the project directory (Default: process.cwd())

Install

npm i rpr

DownloadsWeekly Downloads

10

Version

0.1.4

License

MIT

Last publish

Collaborators

  • avatar