1.0.5 • Published 4 years ago
require-fallback-middle v1.0.5
require-fallback-middle
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
npm install require-fallback-middle
# or use yarn
yarn add require-fallback-middle
Usage
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 matchfallbackDirs
: The registered module match (Default:(id, parent) => [process.cwd(), dirname(parent?.filename) || __dirname]
)Returns: require-resolve-hook result
Contributing
- Fork it!
- Create your new branch:
git checkout -b feature-new
orgit 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)'
orgit 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 🐟