# require-fallback-middle

> Module to fallback the Node.js require and require.resolve function

Latest version **1.0.5** (published 2020-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install require-fallback-middle
pnpm add require-fallback-middle
yarn add require-fallback-middle
bun add require-fallback-middle
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-10-30 |
| First published | 2020-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 3 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | imcuttle |
| Maintainers | moyuyc |
| Keywords | imcuttle, require, resolve, hook, require-fallback-middle |

## Links

- npm: https://www.npmjs.com/package/require-fallback-middle
- Repository: https://github.com/imcuttle/require-fallback-middle
- Homepage: https://github.com/imcuttle/require-fallback-middle#readme
- Issues: https://github.com/imcuttle/require-fallback-middle/issues
- npm.io page: https://npm.io/package/require-fallback-middle

## Dependencies (3)

- [caller-path](https://npm.io/package/caller-path.md) ^3.0.0
- [resolve-from](https://npm.io/package/resolve-from.md) ^5.0.0
- [require-resolve-hook](https://npm.io/package/require-resolve-hook.md) ^1.0.1

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2020-10-30
- 1.0.4 — 2020-10-28
- 1.0.3 — 2020-10-28
- 1.0.2 — 2020-10-28
- 1.0.1 — 2020-10-27
- 1.0.0 — 2020-10-27

## README

# require-fallback-middle

[![Build status](https://img.shields.io/travis/imcuttle/require-fallback-middle/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/require-fallback-middle)
[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/require-fallback-middle.svg?style=flat-square)](https://codecov.io/github/imcuttle/require-fallback-middle?branch=master)
[![NPM version](https://img.shields.io/npm/v/require-fallback-middle.svg?style=flat-square)](https://www.npmjs.com/package/require-fallback-middle)
[![NPM Downloads](https://img.shields.io/npm/dm/require-fallback-middle.svg?style=flat-square&maxAge=43200)](https://www.npmjs.com/package/require-fallback-middle)
[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io/)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](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, <a href="mailto:imcuttle@163.com">imcuttle@163.com</a>.

## License

MIT - [imcuttle](https://github.com/imcuttle) 🐟

---
_Source: https://npm.io/package/require-fallback-middle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
