1.1.6 • Published 2 years ago

root-package-json v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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.
1.0.1

2 years ago

1.0.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

0.0.0

2 years ago