Comparing version 0.2.0 to 0.3.0
17
index.js
@@ -28,7 +28,9 @@ 'use strict'; | ||
var safeResolve = function (modulePath) { | ||
var safeResolve = function (cb, modulePath) { | ||
try { | ||
return require.resolve(modulePath); | ||
} | ||
catch (e) {} | ||
catch (e) { | ||
cb && cb(); | ||
} | ||
}; | ||
@@ -66,3 +68,12 @@ | ||
var moduleName = getModuleName(modulePath); | ||
modulePath = (opts.skipFailures ? safeResolve : require.resolve)(modulePath); | ||
var resolve = opts.skipFailures | ||
? safeResolve.bind(null, | ||
typeof opts.skipFailures == 'function' && | ||
function () { | ||
opts.skipFailures(moduleName, modulePath); | ||
}) | ||
: require.resolve; | ||
modulePath = resolve(modulePath); | ||
return modulePath ? [moduleName, modulePath] : undefined; | ||
@@ -69,0 +80,0 @@ }).filter(Boolean)); |
{ | ||
"name": "acquire", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Require all modules from the node_modules directory, using Node module resolution algorithm to discover it", | ||
@@ -5,0 +5,0 @@ "author": "Eugene Sharygin <eush77@gmail.com>", |
@@ -29,11 +29,11 @@ [![npm](https://nodei.co/npm/acquire.png)](https://nodei.co/npm/acquire/) | ||
| Option | Type | Required? | Default | | ||
| :----------- | :------ | :-------: | :---------- | | ||
| basedir | string | No | `__dirname` | | ||
| depth | number | No | `1` | | ||
| skipFailures | boolean | No | `false` | | ||
| Option | Type | Required? | Default | | ||
| :----------- | :--------------- | :-------: | :---------- | | ||
| basedir | string | No | `__dirname` | | ||
| depth | number | No | `1` | | ||
| skipFailures | boolean/function | No | `false` | | ||
If `opts.depth` is finite, it specifies the number of `node_modules` directories up the directory tree to traverse into. If `opts.depth` is `Infinity`, traversal ends at the file system root. | ||
`opts.skipFailures` skips modules that fail to `require()` (e.g. plugins for Grunt). | ||
If `opts.skipFailures` is `true`, modules that fail to `require()` (e.g. plugins for Grunt) are skipped. If `opts.skipFailures` is a function, it is called as `opts.skipFailures(moduleName, modulePath)` for each failure. | ||
@@ -40,0 +40,0 @@ ### `acquire.resolve([opts])` |
5904
63