Skip to content

feat: add --package-json flag for custom package.json path#214

Open
PranavAgarkar07 wants to merge 1 commit into
millionco:mainfrom
PranavAgarkar07:fix/32-package-json-flag
Open

feat: add --package-json flag for custom package.json path#214
PranavAgarkar07 wants to merge 1 commit into
millionco:mainfrom
PranavAgarkar07:fix/32-package-json-flag

Conversation

@PranavAgarkar07
Copy link
Copy Markdown

@PranavAgarkar07 PranavAgarkar07 commented May 12, 2026

Summary

Adds --package-json <path> CLI flag to allow scanning a directory with a custom package.json location. This is useful when the project's package.json is at a non-standard path or when you want to point react-doctor at a specific workspace's package.json without changing the scan directory.

Changes

  • types.ts: Added packageJsonPath?: string to DiagnoseOptions and ScanOptions
  • cli.ts: Added --package-json <path> CLI option with resolveCliScanOptions mapping
  • scan.ts: Added packageJsonPath to ResolvedScanOptions and mergeScanOptions; passes it to discoverProject
  • discover-project.ts: discoverProject() now accepts optional packageJsonPath — uses ?? fallback to <directory>/package.json (fully backward compatible)
  • index.ts: diagnose() passes options.packageJsonPath to discoverProject
  • README.md: Added --package-json to CLI reference

Testing

  • pnpm build
  • pnpm typecheck
  • pnpm lint

Closes #32


Note

Low Risk
Low risk: adds an optional CLI/API parameter that only affects project detection input, with a backward-compatible default to <directory>/package.json. Main risk is altered caching/detection behavior if callers pass varying paths for the same directory.

Overview
Adds support for scanning a directory using a custom package.json location via new --package-json <path> CLI flag and matching packageJsonPath option in the programmatic diagnose()/scan() APIs.

Project detection (discoverProject) now accepts an optional package.json path (defaulting to <directory>/package.json) and the CLI wiring passes this through, with README updated to document the new flag.

Reviewed by Cursor Bugbot for commit ea3e2b7. Bugbot is set up for automated code reviews on this repo. Configure here.

@reactreview
Copy link
Copy Markdown

reactreview Bot commented May 12, 2026

Note

No issues found

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

@PranavAgarkar07 is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ea3e2b7. Configure here.

};

export const discoverProject = (directory: string): ProjectInfo => {
export const discoverProject = (directory: string, packageJsonPath?: string): ProjectInfo => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache key ignores new packageJsonPath parameter

Medium Severity

The cachedProjectInfos cache is keyed only by directory, but discoverProject now accepts an additional packageJsonPath parameter. If the same directory is queried first without a custom path and then with one (or vice versa), the cache returns the stale result from the first call, silently ignoring the provided packageJsonPath. The cache key needs to incorporate packageJsonPath to distinguish these cases.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ea3e2b7. Configure here.

const packageJsonPath = path.join(directory, "package.json");
if (!isFile(packageJsonPath)) {
const resolvedPackageJsonPath = packageJsonPath ?? path.join(directory, "package.json");
if (!isFile(resolvedPackageJsonPath)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message reports wrong path for custom package.json

Low Severity

When a user provides a custom packageJsonPath via --package-json and the file doesn't exist, PackageJsonNotFoundError(directory) is thrown, producing "No package.json found in {directory}". This is misleading — the missing file is the user-supplied custom path, not the default <directory>/package.json. Before this change the error was always accurate; now it reports the wrong location whenever a custom path is used.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ea3e2b7. Configure here.

};

export const discoverProject = (directory: string): ProjectInfo => {
export const discoverProject = (directory: string, packageJsonPath?: string): ProjectInfo => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache key for discoverProject only uses directory, ignoring the packageJsonPath parameter, causing incorrect cached results when the same directory is used with different package.json paths.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant