Skip to content

fix: handle optional dependencies/devDependencies in package.json parsing#3282

Merged
kamilmysliwiec merged 2 commits intov12.0.0from
copilot/sub-pr-3280
Mar 11, 2026
Merged

fix: handle optional dependencies/devDependencies in package.json parsing#3282
kamilmysliwiec merged 2 commits intov12.0.0from
copilot/sub-pr-3280

Conversation

Copy link

Copilot AI commented Mar 11, 2026

readPackageJson() assumed both dependencies and devDependencies are always present, but both fields are optional per the npm spec. Calling Object.entries() on undefined throws at runtime when either field is absent.

Changes

  • readPackageJson() — Widened return type to mark both fields as optional (Record<string, string> | undefined)
  • getProduction() / getDevelopment() — Added ?? {} nullish coalescing to default absent fields to empty objects
// Before — throws if dependencies/devDependencies is absent
const packageJsonDependencies: Record<string, string> =
  packageJsonContent.dependencies;
for (const [name, version] of Object.entries(packageJsonDependencies)) { ... }

// After — safely returns [] when the field is missing
const packageJsonDependencies: Record<string, string> =
  packageJsonContent.dependencies ?? {};
for (const [name, version] of Object.entries(packageJsonDependencies)) { ... }

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: kamilmysliwiec <23244943+kamilmysliwiec@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix feedback from major release pull request fix: handle optional dependencies/devDependencies in package.json parsing Mar 11, 2026
@kamilmysliwiec kamilmysliwiec marked this pull request as ready for review March 11, 2026 14:59
@kamilmysliwiec kamilmysliwiec merged commit 49b63e2 into v12.0.0 Mar 11, 2026
1 check passed
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.

2 participants