Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

workspace-root

saqqdy94.3kMIT3.3.1TypeScript support: included

A simple utility to get the workspace root

node-kit, workspace, lerna-workspace, pnpm-workspace, yarn-workspace, workspace-root

readme

workspace-root

A simple utility to get the workspace root

NPM version Codacy Badge Test coverage npm download License

Sonar

Install

# use pnpm
$ pnpm install -D workspace-root

# use yarn
$ yarn add -D workspace-root

# use npm
$ npm install -D workspace-root

Usage

use import

import { workspaceRoot, workspaceRootSync } from 'workspace-root'

workspaceRoot()
// or
workspaceRootSync()

use require

const { workspaceRoot, workspaceRootSync } = require('workspace-root')

workspaceRoot()
// or
workspaceRootSync()

API reference

  • Usage: workspaceRoot(cwd) & workspaceRootSync(cwd)
  • Parameters:
Param Description Type Optional value Required Default value
cwd running path string - false -
  • Types:
declare function workspaceRoot(cwd?: string): Promise<string | null>

declare function workspaceRootSync(cwd?: string): string | null
  • Demos:

  • simple use

import { workspaceRoot, workspaceRootSync } from 'workspace-root'

workspaceRoot().then(path => {
  console.log('The workspace root is: ', path) // /Users/user/path/of/package/root or null
})

console.log('The workspace root is: ', workspaceRootSync()) // /Users/user/path/of/package/root or null

Issues & Support

Please open an issue here.

License

MIT