diff --git a/README.md b/README.md index d395865..41d0538 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,14 @@ now you can go write useful code instead of counting how many levels you need to ### `require` create a new instance for the package based on current file directory ```javascript -const pkgRequire = require('pkg-require')(__dirname); +const pkgRequire = require('pkg-require')(__dirname, options); ``` +use the optional options object to provide the following additional settings + +| option | type | default | description | +| --------- | ------- | ------- | ----------- | +| forceRoot | boolean | false | directly use the root path, without looking for a package.json file | + ### `pkgRequire()` require a file by passing its path relative to the directory containing `package.json` diff --git a/index.js b/index.js index e4cf932..ff91ff8 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,9 @@ function pkgRequireFactory(packageDir) { return requireInPkg; } -function createInstance(currentDirectory) { +function createInstance(currentDirectory, options) { + options = options || {}; + if ( !currentDirectory || typeof currentDirectory !== 'string' @@ -52,7 +54,7 @@ function createInstance(currentDirectory) { ); } - var packageDir = findPackageDir(currentDirectory); + var packageDir = !options.forceRoot ? findPackageDir(currentDirectory) : currentDirectory; return pkgRequireFactory(packageDir); }