https://github.com/lukechilds/requirable
Enables a module to require itself by name
https://github.com/lukechilds/requirable
ava requirable require test testing
Last synced: 6 months ago
JSON representation
Enables a module to require itself by name
- Host: GitHub
- URL: https://github.com/lukechilds/requirable
- Owner: lukechilds
- License: mit
- Created: 2017-07-25T18:00:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-10T23:26:52.000Z (about 6 years ago)
- Last Synced: 2025-04-24T06:48:54.438Z (6 months ago)
- Topics: ava, requirable, require, test, testing
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# requirable
> Enables a module to require itself by name
[](https://travis-ci.org/lukechilds/requirable)
[](https://coveralls.io/github/lukechilds/requirable?branch=master)
[](https://www.npmjs.com/package/requirable)Mocks the require command to include the current package when the `name` from the current `package.json` is required.
Uses `process.cwd()` to find the current `package.json` so this is only meant to be used in scripts executed from the CLI. This will not work on a published package!
## Install
```shell
npm install --save-dev requirable
```## Usage
```js
require('requirable');
// That's it! `require` has now been patchedconst myPackage = require('package-name')
```## AVA Usage
Some tests runners such as [AVA](https://github.com/avajs/ava) can require packages automatically for you. If you're using AVA add the following to your package.json:
```json
"ava": {
"require": [
"requirable"
]
},
```You can now `require` (or `import`) your package in your AVA tests by name.
e.g instead of:
```js
import test from 'ava';
import myPackage from '../';
```You can now do:
```js
import test from 'ava';
import myPackage from 'package-name';
```## API
### require('requirable')
Patches the require function to be able to require the current module by name.
Returns an object.
#### obj.success
Type: `boolean`
True or false depending on whether we could find `package.json`.
#### obj.path
Type: `undefined`, `string`
Path to the folder containing `package.json`.
#### obj.name
Type: `undefined`, `string`
Name of the module in `package.json`.
## License
MIT © Luke Childs