# @yarn-tool/get-global-dirs

> 獲取全局安裝目錄的工具，支援 npm、yarn 和 pnpm。Get global installation directories for npm, yarn, and pnpm.

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

## Install

```sh
npm install @yarn-tool/get-global-dirs
pnpm add @yarn-tool/get-global-dirs
yarn add @yarn-tool/get-global-dirs
bun add @yarn-tool/get-global-dirs
```

## 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 | 1.0.6 |
| Published | 2026-09-06 |
| First published | 2026-03-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Maintainers | bluelovers |
| Keywords | global, path, paths, yarn, yarn-tool, pnpm, monorepo, workspaces, npm, lerna, pkg, dependencies, yarnlock, node-modules, packages, package, create-by-yarn-tool |

## Links

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

## Dependencies (2)

- [ini](https://npm.io/package/ini.md) ^7.0.0
- [tslib](https://npm.io/package/tslib.md) >=2.8.1

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

- 1.0.6 (latest) — 2026-09-06
- 1.0.5 — 2026-04-26
- 1.0.4 — 2026-03-12
- 1.0.2 — 2026-03-09
- 1.0.1 — 2026-03-02

## README

# @yarn-tool/get-global-dirs

> ⚠️ **注意事項**

> 此模組基於 [sindresorhus/global-directory](https://github.com/sindresorhus/global-directory/blob/main/index.js) 並作為 CommonJS (CJS) 模組使用。

> 目前版本存在以下限制與已知問題（源自原版或環境差異）：
> - **pnpm YAML 支援缺失**：原版模組尚未支援讀取 pnpm 的 YAML 格式配置（如 `config.yaml`），僅支援 `rc` 格式。
> - **pnpm 套件路徑差異**：在某些環境下，pnpm 的全局套件路徑可能位於 `.../pnpm/store/5/node_modules` 而非預設的 `.../pnpm/global/5/node_modules`。
> - **暫無修復計畫**：目前暫時不打算針對上述原版即存在的 bug 進行修正。

獲取全局安裝目錄的工具，支援 npm、yarn 和 pnpm。

Get global installation directories for npm, yarn, and pnpm.

## 功能特色

- **多套件管理器支援**: 自動偵測並解析 npm、yarn 和 pnpm 的全局目錄
- **跨平台相容**: 支援 Windows、macOS 和 Linux

## 安裝

```bash
yarn add @yarn-tool/get-global-dirs
yarn-tool add @yarn-tool/get-global-dirs
yt add @yarn-tool/get-global-dirs
```

## 使用方法

```typescript
import globalDirectory from '@yarn-tool/get-global-dirs';

// 獲取 npm 全局目錄
console.log(globalDirectory.npm.prefix);
//=> '/usr/local'

console.log(globalDirectory.npm.packages);
//=> '/usr/local/lib/node_modules'

console.log(globalDirectory.npm.binaries);
//=> '/usr/local/bin'

// 獲取 yarn 全局目錄
console.log(globalDirectory.yarn.packages);
//=> '/Users/username/.config/yarn/global/node_modules'

// 獲取 pnpm 全局目錄
console.log(globalDirectory.pnpm.packages);
//=> '/Users/username/Library/pnpm/global/5/node_modules'
```

## API

### globalDirectory

返回一個物件，包含三個屬性：

#### npm: IGlobalDirectoryEntry

- `prefix`: 全局前綴目錄（相當於 `npm prefix --global`）
- `packages`: 全局套件目錄（相當於 `npm root --global`）
- `binaries`: 全局二進位檔目錄（相當於 `npm bin --global`）

#### yarn: IGlobalDirectoryEntry

- `prefix`: Yarn 全局資料目錄
- `packages`: Yarn 全局套件目錄
- `binaries`: Yarn 全局二進位檔目錄

#### pnpm: IGlobalDirectoryEntry

- `prefix`: pnpm 資料目錄
- `packages`: pnpm 全局套件目錄
- `binaries`: pnpm 全局二進位檔目錄

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