Skip to content

Conversation

@greg-at-moderne
Copy link
Contributor

@greg-at-moderne greg-at-moderne commented Dec 5, 2025

Adds a new recipe for adding npm dependencies to package.json, along with refactoring to share code across dependency recipes.

Changes

  • New AddDependency recipe: Adds dependencies to package.json with lock file updates, supporting all dependency scopes (dependencies, devDependencies, peerDependencies, optionalDependencies)
  • Shared accumulator pattern: Extracted DependencyRecipeAccumulator and helpers (storeInstallResult, runInstallIfNeeded, updateNodeResolutionMarker) to package-manager.ts for reuse across dependency recipes
  • JSON type guards: Added isLiteral(), isObject(), isArray(), isIdentifier(), isMember() to json/tree.ts for cleaner type narrowing
  • Centralized DependencyScope type: Moved to node-resolution-result.ts, excluding bundledDependencies (which uses incompatible string[] structure)
  • Cleanup: Removed unused exports from package-manager.ts (runAddPackage, isLockFile, getPackageManagerConfig, etc.)

Adds a new recipe for adding npm dependencies to `package.json`, along with refactoring to share code across dependency recipes.

### Changes

- **New `AddDependency` recipe**: Adds dependencies to `package.json` with lock file updates, supporting all dependency scopes (`dependencies`, `devDependencies`, `peerDependencies`, `optionalDependencies`)
- **Shared accumulator pattern**: Extracted `DependencyRecipeAccumulator` and helpers (`storeInstallResult`, `runInstallIfNeeded`, `updateNodeResolutionMarker`) to `package-manager.ts` for reuse across dependency recipes
- **JSON type guards**: Added `isLiteral()`, `isObject()`, `isArray()`, `isIdentifier()`, `isMember()` to `json/tree.ts` for cleaner type narrowing
- **Centralized `DependencyScope` type**: Moved to `node-resolution-result.ts`, excluding `bundledDependencies` (which uses incompatible `string[]` structure)
- **Cleanup**: Removed unused exports from `package-manager.ts` (`runAddPackage`, `isLockFile`, `getPackageManagerConfig`, etc.)
@knutwannheden knutwannheden changed the title Add the AddDependency JS recipe JavaScript: New AddDependency recipe Dec 11, 2025
@knutwannheden knutwannheden marked this pull request as ready for review December 11, 2025 08:29
@knutwannheden knutwannheden merged commit 55a65c1 into main Dec 11, 2025
2 checks passed
@knutwannheden knutwannheden deleted the greg-js-AddDependency branch December 11, 2025 08:52
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants