Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolveWorkspace, resolveWorkspacePkgs, resolveWorkspacePkgsGraph #118

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,42 @@ import { findWorkspaceDir } from 'pkg-types'
const workspaceDir = await findWorkspaceDir('.')
```

### `resolveWorkspace`

Find monorepo workspace config (support: `pnpm`, `yarn`, `npm`, `lerna`), will return `root` path, `type` of monorepo manager, `workspaces` config.

If fails, throws an error.

```js
import { resolveWorkspace } from 'pkg-types'
const {
root,
type,
workspaces,
} = await resolveWorkspace('.')
```

### `resolveWorkspacePkgs`

Find monorepo workspace packages and read each package `package.json`

```js
import { resolveWorkspacePkgs } from 'pkg-types'
const { type, root, packages } = await resolveWorkspacePkgs('.')
console.log(root) // { dir: 'fully/resolved/root/path', pakcageJson: { ... } }
console.log(packages) // [ { dir: 'fully/resolved/foo/path', pakcageJson: { ... } } ]
danielroe marked this conversation as resolved.
Show resolved Hide resolved
```

### `resolveWorkspacePkgsGraph`

Find monorepo workspace packages graph sort by `devDependency` and `dependency`

```js
import { resolveWorkspacePkgsGraph } from 'pkg-types'
const pkgsGraph = await resolveWorkspacePkgsGraph('.')
console.log(pkgsGraph) // [['foo'], ['bar']]
```

## Types

**Note:** In order to make types working, you need to install `typescript` as a devDependency.
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
"test:types": "tsc --noEmit --module esnext --skipLibCheck --moduleResolution node ./test/*.test.ts"
},
"dependencies": {
"@pnpm/sort-packages": "^5.0.1",
"globby": "^13.1.3",
"jsonc-parser": "^3.2.0",
"mlly": "^1.1.1",
"pathe": "^1.1.0"
"pathe": "^1.1.0",
"yaml": "^2.2.1"
},
"devDependencies": {
"@types/node": "^18.13.0",
Expand Down
51 changes: 28 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading