Back to Explore

sindresorhus/package-directory

GitHub
1 watchersOpen source

Last release:

Find the root directory of a Node.js project or npm package. Useful when you need to locate the package root path from a starting working directory, and it can return the root path (or undefined if it cannot be found) both asynchronously and synchronously.

Project status

  • The source appears actively maintained, with the latest upstream push on 2026-02-01 and a corresponding v8.2.0 update that adds a new ignoreTypeOnlyPackageJson option.
  • The update cadence is somewhat irregular but ongoing, for example v8.2.0 (2026-02-01) followed by v8.1.0 (2025-06-05), roughly 8 months earlier, and older major updates spaced further apart.

AI summary generated

AI-generated from public sources. May be inaccurate. Report

Recent updates

  • v8.2.0

    v8.2.0 introduces a new `ignoreTypeOnlyPackageJson` option to `packageDirectory` and `packageDirectorySync`. When enabled, the library will treat `package.json` files that only contain a `type` field (such as `{ "type": "module" }`) as ESM scope markers instead of package roots.

    Features
  • v8.1.0

    v8.1.0 primarily renames the npm package from `pkg-dir` to `package-directory`, updating the README and type definition test snippets accordingly. The underlying API (`packageDirectory` and `packageDirectorySync`) appears unchanged, but consumers must update how they import and install the package.

    Breaking
  • v8.0.0

    v8.0.0 primarily bumps the supported Node.js runtime to Node 18. It also switches the underlying file-walking dependency used to locate package roots, and updates the published package metadata and TypeScript declarations.

    Breaking
  • v7.0.0

    pkg-dir v7.0.0 primarily targets an updated Node.js support baseline and adjusts TypeScript typings. The release notes call out requiring Node.js 14 and fixing a TypeScript return type, but the actual diff shows more specific typing changes and several environment and dependency updates.

    Breaking
  • v6.0.1

    v6.0.1 is described in the release notes only as a regression fix from v6. The code changes are minimal and update the public API function signatures to make the options argument optional.

  • v6.0.0

    v6.0.0 is a major release that converts pkg-dir to pure ESM and replaces the default export with named exports. It also changes the API so the previous `cwd` argument is provided via an options object, alongside Node.js engine requirement updates.

    Breaking
  • v5.0.0

    v5.0.0 of pkg-dir primarily raises the minimum supported Node.js version to 10. The diff also shows additional maintenance work (CI/dependency updates) and a notable module export interop change that is not described in the release notes.

    Breaking
  • v4.2.0

    Release v4.2.0 primarily updates the runtime dependency `find-up` to v4. The code change in `index.js` is small (return expression refactor), and the test suite was extended to explicitly cover the not-found case. CI configuration was also updated to include Node.js 12.

  • v4.1.0

    v4.1.0 refactors the TypeScript typings to be more compatible with CommonJS module exports. The runtime export shape is also adjusted to add a default export property for interim compatibility, and the TypeScript type-test tooling is updated.

    Breaking
  • v4.0.0

    v4.0.0 introduces TypeScript type definitions and makes behavior changes that can affect existing consumers. The release also raises the minimum supported Node.js version and changes the return value when the project root cannot be found.

    BreakingFeatures