Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rfr

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rfr - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

.travis.yml

27

lib/rfr.js
/**
* The main file of node-rfr.
*
* @author Su Su <s@warmsea.net>
*/
var constants = require('./constants');
if (constants.isGlobal) {
console.warn('Using rfr as a global module is error-prone');
}
/**
* The default root.
* @type {String}
*/
var defaultRoot = constants.defaultRoot;
if (defaultRoot === null) {
defaultRoot = process.env.RFR_ROOT || process.env.PWD || '';
}
/**
* Trim a root and add tailing slash if not exists.

@@ -104,5 +116,10 @@ * @param {String} root A root.

function createVersion(config) {
if (!(config || (typeof config.root !== 'string'))) {
if (!(config && (typeof config.root === 'string'
|| config.root === null || config.root === undefined))) {
throw new Error('"config.root" is required and must be a string');
}
var root = config.root;
if (root === null || root === undefined) {
root = defaultRoot;
}

@@ -112,6 +129,6 @@ return createRfr(function(idFromRoot) {

throw new Error('A string is required for the argument of ' +
'a user created RFR version.');
'a user created RFR version.');
}
return require(normalizeId(idFromRoot, this.root));
}, config.root);
}, root);
}

@@ -134,4 +151,4 @@

}
}, process.env.RFR_ROOT || process.env.PWD || process.cwd() || '/', true);
}, defaultRoot, true);
module.exports = rfr;

15

package.json
{
"name": "rfr",
"author": "Su Su <s@warmsea.net>",
"version": "1.1.1",
"version": "1.2.0",
"description": "Require From project Root tool for Node.js.",
"license": "MIT",
"keywords": [
"node",
"rfr",
"require",
"project",
"root"

@@ -21,3 +20,11 @@ ],

},
"main": "lib/rfr.js"
"devDependencies": {
"coveralls": "*",
"istanbul": "*",
"mocha": "*"
},
"main": "index.js",
"scripts": {
"test": "PATH=$(npm bin):$PATH istanbul cover _mocha --report lcovonly -- -R spec --check-leaks"
}
}
node-rfr
========
[![NPM Version][https://img.shields.io/npm/v/rfr.svg?style=flat]](https://npmjs.org/package/rfr)
[![Build Status](http://img.shields.io/travis/warmsea/node-rfr.svg?style=flat)](https://travis-ci.org/warmsea/node-rfr)
[![Coverage Status](https://img.shields.io/coveralls/warmsea/node-rfr.svg?style=flat)](https://coveralls.io/r/warmsea/node-rfr?branch=master)
**node-rfr** is a *<b>R</b>equire <b>F</b>rom (project) <b>R</b>oot* tool for

@@ -41,16 +45,40 @@ Node.js.

Customize the Root
------------------
The Default Root
----------------
By default, the root path is the current working path where you run the
program. If you want to use another path as the root, set it to the environment
variable named `RFR_ROOT` before you require **node-rfr**. For example, run
the program like this:
If not specified, a default root will be applied according to where the
*node-rfr* is located. Typically, the module folder "rfr" will be located
in a "node_modules" folder. In this case, the folder contains "node_modules"
will used as the default root.
```bash
RFR_ROOT=<some_path> node run.js
For example, in the following project. The "project" folder will be used as the
default root.
```
project
|--package.json
|--run.js
`--node_modules
`--rfr (Default root: project)
```
Or set (or get) it with the `.root` property:
This allows **node-rfr** to be used in a module.
```
project
|--package.json
|--run.js
`--node_modules
|--rfr (Default root: project)
`--my_module
`--node_modules
`--rfr (Default root: project/node_modules/my_module)
```
Customize the Root
------------------
If you want to use another path as the root, set (and get) it with the
`.root` property:
```javascript

@@ -120,2 +148,4 @@ var rfr = require('rfr');

**2014-11-17 v1.2.0** Change default root strategy. Now can be used in modules.
**2014-10-24 v1.1.1** Adds `.root` and `.isMaster` and `.resolve()`.

@@ -122,0 +152,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc