Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function pkgRequireFactory(packageDir) {
return requireInPkg;
}

function createInstance(currentDirectory) {
function createInstance(currentDirectory, options) {
options = options || {};

if (
!currentDirectory
|| typeof currentDirectory !== 'string'
Expand All @@ -52,7 +54,7 @@ function createInstance(currentDirectory) {
);
}

var packageDir = findPackageDir(currentDirectory);
var packageDir = !options.forceRoot ? findPackageDir(currentDirectory) : currentDirectory;
return pkgRequireFactory(packageDir);
}

Expand Down