1.1.6 • Published 3 years ago
root-package-json v1.1.6
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-jsonExample
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.jsmy-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:
stringorURL - optional, defaults to
process.cwd() - Directory to use as base directory.
- See
parse-cwd.
- Type: