# root-package-json

> Find the root package.json from an npm workspace.

Latest version **1.1.6** (published 2022-08-15) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install root-package-json
pnpm add root-package-json
yarn add root-package-json
bun add root-package-json
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2022-08-15 |
| First published | 2022-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | jacobley |
| Maintainers | jacobley |
| Keywords | root, package.json, workspace |

## Links

- npm: https://www.npmjs.com/package/root-package-json
- Repository: https://github.com/jacobley/jacobley
- Homepage: https://github.com/JacobLey/jacobley/tree/main/tools/root-package-json#readme
- Issues: https://github.com/jacobley/jacobley/issues
- npm.io page: https://npm.io/package/root-package-json

## Dependencies (1)

- [find-import](https://npm.io/package/find-import.md) ^1.0.6

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

- 1.1.6 (latest) — 2022-08-15
- 1.1.6-dev.fa783e47c382b9afadfa91565821e24bb5c1e9cc10a990ab601f8dcaccaee134 (dev) — 2022-08-15
- 1.1.6-dev.1e6fb2eb001cea38d49407180d13e11c4ed1c25c — 2022-08-15
- 1.1.6-dev.697f230e2586211200939a7282971fdc282e1fcbb753b1b4c553ae5304245ece — 2022-08-14
- 1.1.6-dev.6d40ad53c428177f21d8b184fccd23db6500aa4c — 2022-08-14
- 1.1.5 — 2022-08-10
- 1.1.5-dev.6be1ab8c0b2a7d4470063977820208e4e0727594036a97df81233b10d46f61ec — 2022-08-10
- 1.1.5-dev.6150c44a1e003315375046a34cb8cb25c1c54c47 — 2022-08-10
- 1.1.4 — 2022-07-06
- 1.1.4-dev.65eea049d16a94bc5cd57c60c6a4c095364edf40dc46d4c6ff8ca97c5b3d5c31 — 2022-07-05
- 1.1.4-dev.4c46e6462b38fb852efea6fa0f1f3a68da9ec757 — 2022-07-05
- 1.1.3 — 2022-07-02
- 1.1.3-dev.022241558d665f66a6cdb12df1cdb2913b3fdada999ef8ca152a72ec2b5b670a — 2022-07-02
- 1.1.3-dev.10ecc458d18ddb1ff68d3faff4994e4f0737d5f9 — 2022-07-02
- 1.1.2 — 2022-07-01
- … 33 more at https://npm.io/package/root-package-json/versions

## README

<div style="text-align:center">

<h1>root-package-json</h1>
<p>Find the root package.json from an npm workspace.</p>

[![npm package](https://badge.fury.io/js/root-package-json.svg)](https://www.npmjs.com/package/root-package-json)
[![License](https://img.shields.io/npm/l/root-package-json.svg)](https://github.com/JacobLey/jacobley/blob/main/common/config/publish/LICENSE)
[![Quality](https://img.shields.io/npms-io/quality-score/root-package-json.svg)](https://github.com/JacobLey/jacobley/blob/main/tools/root-package-json)

</div>

## Contents
- [Introduction](#introduction)
- [Install](#install)
- [Example](#example)
- [Usage](#usage)
- [API](#api)

<a name="Introduction"></a>
## Introduction

Returns the path and contents of the root-most `package.json`.

Package manager agnostic.

Useful for situations where multiple `package.json`s may exist in parent directories, due to `node_modules` or workspaces.

<a name="Install"></a>
## Install

```sh
npm i root-package-json
```

<a name="Example"></a>
## Example

Given file structure
```
/
└─┬ root
  ├─┬ node_modules
  │ └─┬ root-package-json
  │   └── package.json // { name: 'root-package-json' }
  ├─┬ packages
  │ └─┬ my-package
  │   ├── my-file.js
  │   └── package.json // { name: 'my-package' }
  └── package.json // { name: 'monorepo-root' }
                └── example.js
```

`my-file.js`
```ts
import { rootPackageJson } from 'root-package-json';

const rootPackage = await rootPackageJson();

console.log(rootPackage);
// {
//    filePath: '/root/package.json',
//    package: { name: 'monorepo-root' }
// }
```

<a name="Usage"></a>
## Usage

`root-package-json` is an ESM module. That means it _must_ be `import`ed. To load from a CJS module, use dynamic import `const { rootPackageJson } = await import('root-package-json');`.

<a name="Api"></a>
## API

### rootPackageJson(options?)

Returns promise that resolves to either the root package.json, or null if none can be found.

#### options

* cwd
  * Type: `string` or `URL`
  * optional, defaults to `process.cwd()`
  * Directory to use as base directory.
  * See [`parse-cwd`](https://www.npmjs.com/package/parse-cwd).

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