# revelation-resolver

> Fast node.js modules resolver

Latest version **0.1.5** (published 2023-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install revelation-resolver
pnpm add revelation-resolver
yarn add revelation-resolver
bun add revelation-resolver
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2023-04-20 |
| First published | 2023-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Sergey Melyukov |
| Maintainers | smelukov |
| Keywords | resolver, module, path, fs |

## Links

- npm: https://www.npmjs.com/package/revelation-resolver
- Repository: https://github.com/smelukov/revelation
- Homepage: https://github.com/smelukov/revelation#readme
- Issues: https://github.com/smelukov/revelation/issues
- npm.io page: https://npm.io/package/revelation-resolver

## 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

- 0.1.5 (latest) — 2023-04-20
- 0.1.3 — 2023-04-20
- 0.1.2 — 2023-04-19
- 0.1.1 — 2023-04-16
- 0.1.0 — 2023-03-24

## README

# revelation

[![npm version](https://badge.fury.io/js/revelation-resolver.svg)](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<string, unknown>,
) => Record<string, unknown> | 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'
};
```

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