npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

ral

1.1.1 • Public • Published

Require ALias Build Status

Require path aliasing.

This module allows you to easily move files and directories in your app without having to update many require calls. Instead you update the relevant alias definition.

The paths aliases to be used are defined in require-paths.json. All the paths are relative to the directory this file is in. To configure this directory you must set ral.basePath before your first usage of ral.

For example if require-paths.json is:

{
   "constants" : "lib/constants"
}

Then the base path can be set in the index.js at the root of the project using:

require('ral').basePath = __dirname;

Then the module at lib/constants can be retrieved with:

require('ral')('constants')

If the location of constants changes, only require-paths.json needs to be updated.

A path can be added after the key. For example given constants above:

require('ral')('constants/something')

will give you lib/constants/something.

Source (~20 lines)

TODO: test on windows

Release Notes:

  • 2014-06-02 0.0.1 Initial Release
  • 2014-06-03 0.1.0 Added tests & process.env.REQUIRE_PATHS
  • 2014-06-03 0.1.1 Locking down node version to >=0.8
  • 2014-06-04 0.1.2 Removing hard coded path separator
  • 2014-07-10 1.0.0 ral is dynamically configurable
  • 2014-10-01 1.1.0 the json object ral uses as its configuration can now be directly modified w ral.pathsConfig =
  • 2014-10-10 1.1.1 helpful errors if key is not found on require-paths

install

npm i ral

Downloadsweekly downloads

1

version

1.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability