1.0.5 • Published 4 years ago

require-fallback-middle v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

require-fallback-middle

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

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 match
  • fallbackDirs: 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 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 🐟