https://github.com/smelukov/revelation
Fast node.js modules resolver
https://github.com/smelukov/revelation
jest nodejs resolver webpack
Last synced: about 1 year ago
JSON representation
Fast node.js modules resolver
- Host: GitHub
- URL: https://github.com/smelukov/revelation
- Owner: smelukov
- License: mit
- Created: 2023-03-22T17:46:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-20T12:02:17.000Z (about 3 years ago)
- Last Synced: 2025-04-09T19:16:56.083Z (about 1 year ago)
- Topics: jest, nodejs, resolver, webpack
- Language: TypeScript
- Homepage:
- Size: 532 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# revelation
[](https://badge.fury.io/js/revelation-resolver)
Fast node.js modules resolver.
## Why
- supports webpack-like [mainFiles](https://webpack.js.org/configuration/resolve/#resolvemainfiles) option
- provides [packageJSONModifier](#packagejsonmodifier-packagejsonmodifier) option to modify or collect any `package.json`
- works fast
## Install
```shell
npm i revelation-resolver --save
# or
yarn add revelation-resolver
# or
pnpm add revelation-resolver --save-prod
```
## Using
```typescript
import Revelation from 'revelation-resolver';
const resolver = new Revelation();
console.log(resolver.resolve('/base/dir', './foo'));
```
## API
### constructor(options: Options)
Possible options:
```typescript
type Options = {
fileSystem?: typeof fs; // default: require('node:fs')
mainFiles?: string[]; // default: ['index']
modules?: string[]; // default: ['node_modules']
mainFields?: string[]; // default: ['main', 'browser']
extensions?: string[]; // default: ['.js']
packageJSONModifier?: PackageJSONModifier;
}
type PackageJSONModifier = (
absPath: string,
packageJSON: Record,
) => Record | null | undefined;
```
#### `fileSystem: typeof fs`
Target file system (e.g. [memfs](https://www.npmjs.com/package/memfs))
`require('node:fs')` by default
#### `mainFiles: string[]`
A list of main files in directories
`['index']` by default
#### modules?: string[]
A list of directories to resolve modules from, might be absolute path or folder name
`['node_modules']` by default
#### mainFields?: string[]
A list of main fields in description files
`['main', 'browser']` by default
#### extensions?: string[]
A list of extensions which should be tried for files
`['.js']` by default
#### packageJSONModifier?: PackageJSONModifier
A function that will be executing for every `package.json` (once for every `package.json`) for modifying purposes
### resolve(basedir: string, request: string): string | null
Resolves `request` from `basedir`.
`request` may be absolute, relative or package-based path.
## Using with jest
__rev-resolver.js:__
```js
const Revelation = require('revelation-resolver').default;
const rev = new Revelation(options);
module.exports = (request, options) => rev.resolve(options.basedir, request);
```
__jest.config.js:__
```js
module.exports = {
resolver: './path/to/rev-resolver'
};
```