Comparing version 0.1.0 to 0.1.1
@@ -10,11 +10,7 @@ var fs = require('fs') | ||
function requireg(module) { | ||
var resolver, moduleExports | ||
var moduleExports | ||
for (var i = 0, l = resolvers.length; i < l; i += 1) { | ||
resolver = resolvers[i] | ||
if ((resolver = resolver(module)) !== undefined) { | ||
moduleExports = resolver | ||
break | ||
} | ||
} | ||
try { | ||
moduleExports = require(resolve(module)) | ||
} catch (e) {} | ||
@@ -28,4 +24,20 @@ if (moduleExports === undefined) { | ||
requireg.resolve = resolve | ||
requireg.globalize = function () { | ||
global.requireg = requireg | ||
} | ||
function resolve(module) { | ||
var resolver, modulePath | ||
for (var i = 0, l = resolvers.length; i < l; i += 1) { | ||
resolver = resolvers[i] | ||
if (modulePath = resolver(module)) { | ||
break | ||
} | ||
} | ||
return modulePath | ||
} |
@@ -28,3 +28,3 @@ var fs = require('fs') | ||
try { | ||
return require(module) | ||
return require.resolve(module) | ||
} catch (e) {} | ||
@@ -36,3 +36,3 @@ } | ||
function nodePathResolve(module) { | ||
var modulePath, moduleExports | ||
var modulePath | ||
var nodePath = process.env.NODE_PATH | ||
@@ -55,16 +55,9 @@ | ||
} | ||
if (modulePath) { | ||
break; | ||
} | ||
} | ||
try { | ||
moduleExports = require(modulePath) | ||
} catch (e) {} | ||
return moduleExports | ||
return modulePath | ||
} | ||
function userHomeResolve(module) { | ||
var modulePath, moduleExports | ||
var modulePath | ||
var homePath = isWin32 ? process.env['USERPROFILE'] : process.env['HOME'] | ||
@@ -83,13 +76,10 @@ | ||
} | ||
try { | ||
moduleExports = require(modulePath) | ||
} catch (e) {} | ||
return moduleExports | ||
return modulePath | ||
} | ||
// See: https://npmjs.org/doc/files/npm-folders.html#prefix-Configuration | ||
// it uses execPath to discover node_modules based on the node binary location | ||
function globalResolve(module) { | ||
var modulePath, moduleExports | ||
var modulePath | ||
var dirname = path.dirname(process.execPath) | ||
@@ -103,8 +93,4 @@ | ||
modulePath = resolveFn(module, dirname) | ||
try { | ||
moduleExports = require(modulePath) | ||
} catch (e) {} | ||
return moduleExports | ||
return modulePath | ||
} |
{ | ||
"name": "requireg", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Require global modules like a boss", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/h2non/requireg", |
@@ -32,8 +32,17 @@ # requireg [![Build Status](https://secure.travis-ci.org/h2non/node-requireg.png?branch=master)](http://travis-ci.org/h2non/node-requireg) | ||
### Load global modules | ||
```js | ||
var requireg = require('requireg') | ||
// require a globally installed package | ||
var coffee = requireg('coffee-script') | ||
var npm = requireg('npm') | ||
``` | ||
### Resolve module path | ||
```js | ||
var modulePath = requireg.resolve('npm') | ||
// returns '/usr/local/lib/node_modules/npm/lib/npm.js' | ||
``` | ||
### Globalize it | ||
@@ -48,3 +57,3 @@ | ||
```js | ||
var globalModule = requireg('coffee-script') | ||
var globalModule = requireg('npm') | ||
``` | ||
@@ -51,0 +60,0 @@ |
@@ -50,2 +50,7 @@ var expect = require('expect.js') | ||
it('should have the expected module path', function () { | ||
expect(requiregModule.resolve('beaker')) | ||
.to.be.equal(__dirname + '/fixtures/lib/node_modules/beaker/index.js') | ||
}) | ||
}) | ||
@@ -84,2 +89,7 @@ | ||
it('should have the expected module path', function () { | ||
expect(requiregModule.resolve('beaker')) | ||
.to.be.equal(__dirname + '/fixtures/lib/node_modules/beaker/index.js') | ||
}) | ||
}) | ||
@@ -86,0 +96,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9323
168
78
12