This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

root-package-json
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

root-package-json

Find the root package.json from an npm workspace.

npm package License Quality

Contents

Introduction

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

Package manager agnostic.

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

Install

npm i root-package-json

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

import { rootPackageJson } from 'root-package-json';

const rootPackage = await rootPackageJson();

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

Usage

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

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.

Package Sidebar

Install

npm i root-package-json

Weekly Downloads

12

Version

1.1.6

License

MIT

Unpacked Size

6.15 kB

Total Files

5

Last publish

Collaborators

  • jacobley