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

Package detail

new-find-package-json

hasezoey2.5mMIT2.0.0TypeScript support: included

Find the an package.json in the path provided upwards

package.json, json, find-package-json, directory, package-json, read-package-json

readme

new-find-package-json

Inspired by find-package-json

This package can find (by default) the nearest package.json (upwards).

Usage

Sync:

const findFileFrom = process.cwd();
for (const file of findSync(findFileFrom)) {
  console.log("found file:", file);
}

Async/await (Promises):

const findFileFrom = process.cwd();
for await (const file of findAsync(findFileFrom)) {
  console.log("found file:", file);
}

Note: it is important to not forget to use for await..of instead of just for..of for findAsync

Options

Options for findSync & findAsync:

Index Name Type Default Description
0 input string none (required) The path to search from
1 base string process.cwd() The path to use as an absolute point if input is not absolute
2 fileName string package.json The Filename to search for

.next will return an object with value and done, where value is the absolute path to the file found and undefined if done is true

changelog

2.0.0 (2022-05-24)

⚠ BREAKING CHANGES

  • Typescript "target" is now "es2018", which is a breaking change, but should not affect anything as long as the required nodejs version is used (12.22 or higher)

Features

1.2.0 (2022-05-24)

Dependencies

  • @semantic-release/git: upgrade to 9.0.1 (00f551c)
  • @types/jest: upgrade to 27.5.1 (4f29833)
  • @types/lodash: remove unused dependency (ce54e61)
  • @types/tmp: upgrade to 0.2.3 (b81f2e9)
  • @typescript-eslint/*: upgrade to 5.26.0 (1cb7fed)
  • commitlint: upgrade to 16.3.0 (4b55075)
  • debug: upgrade to 4.1.7 (06e8eea)
  • debug: upgrade to 4.3.4 (4e6eb1b)
  • eslint: upgrade to 8.16.0 (994f66e)
  • eslint-config-prettier: upgrade to 8.5.0 (370cc83)
  • eslint-plugin-prettier: upgrade to 4.0.0 (165a38f)
  • husky: upgrade to 7.0.4 (5841a4a)
  • jest: upgrade to 28.1.0 (23dcba5)
  • lint-staged: upgrade to 11.2.6 (3f5bd59)
  • prettier: upgrade to 2.6.2 (7faa9ce)
  • semantic-release: upgrade to 17.4.7 (0bfef35)
  • ts-jest: upgrade to 28.0.3 (026fa11)
  • tslib: upgrade to 2.4.0 (4f4c17b)
  • typescript: upgrade to 4.4.4 (cbc5a76)

1.1.0 (2021-07-05)

Features

  • index.ts: add function "findSync" (78e0ad0)

1.0.0 (2021-07-05)

Features

  • index.ts: add basic code (c350736)