# @yarn-tool/resolve-package

> 解析 Node.js 套件的根目錄與 package.json 路徑的工具庫 / A utility for resolving package root and package.json paths

Latest version **3.0.10** (published 2026-09-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @yarn-tool/resolve-package
pnpm add @yarn-tool/resolve-package
yarn add @yarn-tool/resolve-package
bun add @yarn-tool/resolve-package
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.10 |
| Published | 2026-09-06 |
| First published | 2020-02-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Maintainers | bluelovers |
| Keywords | yarn-tool, pkg-dir, upath2, resolve, package, json, root, npm, entry, find, up, find-up, findup, look-up, look, file, search, match, parent, parents, folder, directory, walk, walking, path |

## Links

- npm: https://www.npmjs.com/package/@yarn-tool/resolve-package
- Repository: https://github.com/bluelovers/ws-yarn-workspaces
- Homepage: https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/resolve-package#readme
- Issues: https://github.com/bluelovers/ws-yarn-workspaces/issues
- npm.io page: https://npm.io/package/@yarn-tool/resolve-package

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) >=2.8.1
- [@yarn-tool/require-resolve](https://npm.io/package/@yarn-tool/require-resolve.md) ^4.0.9

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.10 (latest) — 2026-09-06
- 3.0.9 — 2026-04-26
- 3.0.8 — 2026-04-26
- 3.0.7 — 2026-03-12
- 3.0.6 — 2026-03-09
- 3.0.3 — 2026-03-04
- 3.0.2 — 2026-03-04
- 3.0.1 — 2026-03-02
- 2.0.12 — 2024-05-03
- 2.0.11 — 2022-11-14
- 2.0.10 — 2022-10-28
- 2.0.9 — 2022-10-01
- 2.0.8 — 2022-09-29
- 2.0.7 — 2022-09-28
- 2.0.6 — 2022-09-27
- … 48 more at https://npm.io/package/@yarn-tool/resolve-package/versions

## README

# @yarn-tool/resolve-package

解析 Node.js 套件的根目錄與 package.json 路徑的工具庫，支援 Node.js 17 以上版本。
A utility for resolving package root and package.json paths, compatible with Node.js 17+.

## 安裝 (Installation)

```bash
# 使用 yarn / Using yarn
yarn add @yarn-tool/resolve-package

# 使用 yarn-tool / Using yarn-tool
yarn-tool add @yarn-tool/resolve-package
# yt 是 yarn-tool 的別名 / yt is an alias for yarn-tool
yt add @yarn-tool/resolve-package

# 使用 pnpm / Using pnpm
pnpm add @yarn-tool/resolve-package

# 使用 npm / Using npm
npm install @yarn-tool/resolve-package
```

## 使用範例 (Usage Example)

```typescript
import { resolvePackageJsonLocation, resolvePackage, resolvePackageRoot } from '@yarn-tool/resolve-package'

// 取得套件的 package.json 路徑 / Get package.json path
console.dir(resolvePackageJsonLocation('tslib'));

// 取得套件根目錄 / Get package root directory
console.dir(resolvePackageRoot('tslib'));

// 取得完整套件資訊 / Get complete package information
const pkg = resolvePackage('tslib');
console.dir(pkg.pkgRoot);        // 套件根目錄 / Package root
console.dir(pkg.pkgJsonLocation); // package.json 路徑 / package.json path
console.dir(pkg.pkg);            // package.json 內容 / package.json content
console.dir(pkg.resolveLocation('lib/index.js')); // 相對路徑解析 / Resolve relative path
```

## API

### `resolvePackageCore(moduleName, options?)`

核心解析函數，嘗試解析模組的入口點位置。

### `resolvePackageRoot(moduleName, options?)`

取得套件的根目錄路徑。

### `resolvePackageJsonLocation(moduleName, options?)`

取得套件的 package.json 檔案位置。

### `createResolveLocationFn(moduleName, options?)`

建立一個相對於套件根目錄解析路徑的函數。

### `readModulePackageJson(moduleName, options?)`

讀取並返回模組的 package.json 內容。

### `resolvePackage(moduleName, options?)`

最完整的解析函數，返回套件根目錄、入口點、package.json 內容及路徑解析函數。

## License

ISC

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