https://github.com/leegeunhyeok/esresolve
A powerful module resolver based on esbuild
https://github.com/leegeunhyeok/esresolve
esbuild resolver
Last synced: about 1 month ago
JSON representation
A powerful module resolver based on esbuild
- Host: GitHub
- URL: https://github.com/leegeunhyeok/esresolve
- Owner: leegeunhyeok
- License: mit
- Created: 2024-10-10T18:26:28.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-01-28T08:13:25.000Z (3 months ago)
- Last Synced: 2025-01-28T08:28:38.062Z (3 months ago)
- Topics: esbuild, resolver
- Language: TypeScript
- Homepage: https://npmjs.com/package/esresolve
- Size: 229 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
## Usage
```ts
import { resolve, resolveFrom } from 'esresolve';// 1. Resolve module path from base path.
await resolve('/path/to/workspace', './my-module', {
/* options */
});// 2. You can also resolve multiple modules.
await resolve('/path/to/workspace', ['./foo', './bar'], {
/* options */
});// 3. You can create a resolver with the specified options applied.
const resolver = resolve.create({
/* options */
});
await resolver('/path/to/workspace', './my-module');// 4. Resolve dependencies from specified module.
await resolveFrom('/path/to/module.ts', {
/* options */
});
``````ts
// Resolve result
const result = await resolve('/path/to/workspace', './my-module');//
// [
// {
// request: './my-module',
// path: '/path/to/workspace/src/core/my-module/index.ts',
// }
// ]
```Options
```ts
interface ResolveOptions {
/**
* Specify the working directory path.
*
* Defaults to `current workspace path`.
*
* Documentation: https://esbuild.github.io/api/#working-directory
*/
root?: string;
/**
* File extension of the modules to resolve.
*
* Defaults to `['.tsx', '.ts', '.jsx', '.js', '.css', '.json']`.
*
* Documentation: https://esbuild.github.io/api/#resolve-extensions
*/
extensions?: BuildOptions['resolveExtensions'];
/**
* Controls how the exports field in package.json is interpreted.
*
* Documentation: https://esbuild.github.io/api/#conditions
*/
conditionNames?: BuildOptions['conditions'];
/**
* Specify the field name to reference in package.json when importing the file.
*
* Documentation: https://esbuild.github.io/api/#main-fields
*/
mainFields?: BuildOptions['mainFields'];
/**
* Configuration for aliasing a specified module to replace it with another module.
*
* Documentation: https://esbuild.github.io/api/#alias
*/
alias?: BuildOptions['alias'];
/**
* Path to the `tsconfig.json` file to reference during resolution.
*
* Documentation: https://esbuild.github.io/api/#tsconfig
*/
tsconfig?: BuildOptions['tsconfig'];
/**
* Stringified content of the `tsconfig.json` to reference during resolution.
*
* Documentation: https://esbuild.github.io/api/#tsconfig-raw
*/
tsconfigRaw?: BuildOptions['tsconfigRaw'];
}
```## License
[MIT](./LICENSE)