https://github.com/imcuttle/resolve-from-fallback
Resolve the path of a module like `require.resolve()` but from some fallback path
https://github.com/imcuttle/resolve-from-fallback
Last synced: over 1 year ago
JSON representation
Resolve the path of a module like `require.resolve()` but from some fallback path
- Host: GitHub
- URL: https://github.com/imcuttle/resolve-from-fallback
- Owner: imcuttle
- License: mit
- Created: 2020-10-29T03:36:21.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T14:24:12.000Z (over 4 years ago)
- Last Synced: 2025-03-23T02:34:05.581Z (over 1 year ago)
- Language: TypeScript
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: License
Awesome Lists containing this project
README
# resolve-from-fallback
[](https://travis-ci.org/imcuttle/resolve-from-fallback)
[](https://codecov.io/github/imcuttle/resolve-from-fallback?branch=master)
[](https://www.npmjs.com/package/resolve-from-fallback)
[](https://www.npmjs.com/package/resolve-from-fallback)
[](https://prettier.io/)
[](https://conventionalcommits.org)
> Resolve the path of a module like `require.resolve()` but from some fallback path
## Installation
```bash
npm install resolve-from-fallback
# or use yarn
yarn add resolve-from-fallback
```
## Usage
```javascript
const resolveFromFallback = require('resolve-from-fallback')
const resolveLocal = (id) => resolveFromFallback([process.cwd(), __dirname], id)
resolveLocal('react') // resolve react path from `process.cwd()` or `__dirname`
resolveLocal('not_found') // Throw MODULE_NOT_FOUND error
resolveLocal.silent([process.cwd(), __dirname], 'not_found') // Return undefined
```
## 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) 🐟