https://github.com/imcuttle/require-fallback-middle
Module to fallback the Node.js require and require.resolve function
https://github.com/imcuttle/require-fallback-middle
Last synced: about 1 year ago
JSON representation
Module to fallback the Node.js require and require.resolve function
- Host: GitHub
- URL: https://github.com/imcuttle/require-fallback-middle
- Owner: imcuttle
- License: mit
- Created: 2020-10-27T16:05:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T15:01:59.000Z (over 4 years ago)
- Last Synced: 2025-03-22T10:19:24.358Z (about 1 year ago)
- Language: TypeScript
- Size: 191 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: License
Awesome Lists containing this project
README
# require-fallback-middle
[](https://travis-ci.org/imcuttle/require-fallback-middle)
[](https://codecov.io/github/imcuttle/require-fallback-middle?branch=master)
[](https://www.npmjs.com/package/require-fallback-middle)
[](https://www.npmjs.com/package/require-fallback-middle)
[](https://prettier.io/)
[](https://conventionalcommits.org)
> Module to fallback the Node.js require and require.resolve function
It's useful in global cli, Allow Node.js resolve module in `process.cwd()` (local modules) and global modules.
## Installation
```bash
npm install require-fallback-middle
# or use yarn
yarn add require-fallback-middle
```
## Usage
```javascript
import requireFallbackMiddle from 'require-fallback-middle'
const { unhook } = requireFallbackMiddle()
```
## API
#### `requireFallbackMiddle(match: Match, fallbackDirs?: string[] | ((id: string, parent: Module, isMain: boolean) => string[]))`
- `match`: The registered module match
- `fallbackDirs`: The registered module match (Default: `(id, parent) => [process.cwd(), dirname(parent?.filename) || __dirname]`)
- **Returns:** [require-resolve-hook result](https://github.com/imcuttle/require-resolve-hook/#api)
## Contributing
- Fork it!
- Create your new branch:
`git checkout -b feature-new` or `git checkout -b fix-which-bug`
- Start your magic work now
- Make sure npm test passes
- Commit your changes:
`git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`
- Push to the branch: `git push`
- Submit a pull request :)
## Authors
This library is written and maintained by imcuttle, imcuttle@163.com.
## License
MIT - [imcuttle](https://github.com/imcuttle) 🐟