# use pnpm
$ pnpm install -D @node-kit/yarn-workspace-root
# use yarn
$ yarn add -D @node-kit/yarn-workspace-root
# use npm
$ npm install -D @node-kit/yarn-workspace-root
use import
import { yarnWorkspaceRoot, yarnWorkspaceRootSync } from '@node-kit/yarn-workspace-root'
yarnWorkspaceRoot()
// or
yarnWorkspaceRootSync()
use require
const { yarnWorkspaceRoot, yarnWorkspaceRootSync } = require('@node-kit/yarn-workspace-root')
yarnWorkspaceRoot()
// or
yarnWorkspaceRootSync()
- Usage:
yarnWorkspaceRoot(cwd)
&yarnWorkspaceRootSync(cwd)
- Parameters:
Param | Description | Type | Optional value | Required | Default value |
---|---|---|---|---|---|
cwd | running path | string |
- | false |
- |
- Types:
declare type Manifest =
| (Record<string, unknown> & {
packages: any
workspaces: any
})
| null
declare function yarnWorkspaceRoot(cwd?: string): Promise<string | null>
declare function yarnWorkspaceRootSync(cwd?: string): string | null
- Demos:
- simple use
import { yarnWorkspaceRoot, yarnWorkspaceRootSync } from '@node-kit/yarn-workspace-root'
yarnWorkspaceRoot().then(path => {
console.log('The yarn workspace root is: ', path) // /Users/user/path/of/package/root or null
})
console.log('The yarn workspace root is: ', yarnWorkspaceRootSync()) // /Users/user/path/of/package/root or null
Please open an issue here.