From 920dd2995f30b21f72df3f840d3446c55371c716 Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Fri, 17 Apr 2026 19:31:57 -0700 Subject: [PATCH 1/2] Refactor version propagation into Phase A/B/C architecture Restructure the release plan algorithm into three distinct phases: - Phase A: always fix out-of-range deps (peer deps get "match" bump, regular deps get patch, devDeps skipped) - Phase B: enforce fixed/linked group constraints - Phase C: opt-in proactive propagation via dependencyBumpRules and cascadeTo Key changes: - Peer dep out-of-range bumps now match the triggering bump level (not hardcoded major) - workspace:^ and workspace:~ resolved to ^/~ for range checking - Remove minor-isolated (only patch-isolated remains), add 'none' to suppress propagated bumps - Remove specificDependencyRules (use per-package dependencyBumpRules instead) - DEFAULT_BUMP_RULES: devDependencies is now false, peerDependencies uses bumpAs: "match" - DependencyBumpRule.trigger no longer accepts 'none'; use false for the whole rule - updateInternalDependencies loses 'none' option - Remove getCaretZeroPeerDepWarnings; warnings now emitted inline during Phase A - Add plan.warnings array to ReleasePlan for ^0.x propagation warnings - patch-isolated and none throw errors when they would leave broken ranges Co-Authored-By: Claude Opus 4.6 (1M context) --- .bumpy/propagation-refactor.md | 5 + CLAUDE.md | 97 +- README.md | 11 +- bunfig.toml | 3 + docs/version-propagation.md | 205 ++++ llms.md | 90 +- packages/bumpy/skills/add-change/SKILL.md | 4 +- packages/bumpy/src/commands/add.ts | 3 +- packages/bumpy/src/commands/ci.ts | 17 +- packages/bumpy/src/commands/migrate.ts | 5 +- packages/bumpy/src/commands/publish.ts | 1 + packages/bumpy/src/commands/status.ts | 8 + packages/bumpy/src/commands/version.ts | 8 + packages/bumpy/src/core/config.ts | 3 - packages/bumpy/src/core/release-plan.ts | 417 +++++-- packages/bumpy/src/core/semver.ts | 18 +- packages/bumpy/src/types.ts | 23 +- packages/bumpy/test/core/changeset.test.ts | 20 +- .../bumpy/test/core/publish-pipeline.test.ts | 5 + packages/bumpy/test/core/release-plan.test.ts | 1072 +++++++++++++---- packages/bumpy/test/core/semver.test.ts | 23 +- packages/bumpy/test/helpers.ts | 2 +- 22 files changed, 1496 insertions(+), 544 deletions(-) create mode 100644 .bumpy/propagation-refactor.md create mode 100644 bunfig.toml create mode 100644 docs/version-propagation.md diff --git a/.bumpy/propagation-refactor.md b/.bumpy/propagation-refactor.md new file mode 100644 index 0000000..bcc7988 --- /dev/null +++ b/.bumpy/propagation-refactor.md @@ -0,0 +1,5 @@ +--- +'@varlock/bumpy': minor +--- + +Restructured version propagation into Phase A/B/C architecture. Phase A (out-of-range fixes) always runs — peer deps now match the triggering bump level instead of always forcing major. Added workspace:^ protocol resolution for range checking. Removed minor-isolated and specificDependencyRules. Added none bump type and patch-isolated validation. Added warnings for ^0.x peer dep propagation and workspace:\* on peer deps. diff --git a/CLAUDE.md b/CLAUDE.md index 8ea834d..fefc325 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,105 +7,10 @@ alwaysApply: false Default to using Bun instead of Node.js. - Use `bun ` instead of `node ` or `ts-node ` -- Use `bun test` instead of `jest` or `vitest` -- Use `bun build ` instead of `webpack` or `esbuild` - Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` - Use `bun run - - -``` - -With the following `frontend.tsx`: - -```tsx#frontend.tsx -import React from "react"; -import { createRoot } from "react-dom/client"; - -// import .css files directly and it works -import './index.css'; - -const root = createRoot(document.body); - -export default function Frontend() { - return

Hello, world!

; -} - -root.render(); -``` - -Then, run index.ts - -```sh -bun --hot ./index.ts -``` - -For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`. +Do NOT use `bun test` to run tests. Instead call `bun run test` - which will call the correct test command. diff --git a/README.md b/README.md index 76c2f3c..7a6c415 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,13 @@ Changesets is mature and widely adopted, but has stagnated. The community has hu Changesets hardcodes aggressive behavior: a **minor** bump on a package triggers a **major** bump on all packages that peer-depend on it. This is the #1 community complaint with 8+ open issues and no fix in sight. -Bumpy makes this **fully configurable** at multiple levels, with sensible defaults: +Bumpy splits propagation into three clear phases with sensible defaults: -- **Global rules by dependency type** — e.g., peer dep bumps only propagate on major (not minor) +- **Phase A** — always fixes broken ranges: peer dep bumps match the triggering level, regular deps get patch, dev deps are skipped +- **Phase B** — enforces fixed/linked group constraints +- **Phase C** — opt-in proactive propagation via configurable `dependencyBumpRules` and `cascadeTo` rules +- **Per-changeset control** — `patch-isolated` skips propagation, `none` suppresses a bump, changeset cascades push bumps downstream - **Per-package overrides** — in `package.json["bumpy"]` -- **Per-specific-dependency rules** — "when core bumps, bump me at X" -- **Source-side cascade rules** — "when I bump, cascade to `plugins/*`" (with glob support) -- **Per-changeset cascade overrides** — explicit downstream control in each bump file -- **Isolated bumps** — `minor-isolated` / `patch-isolated` skip propagation entirely ### Custom publish commands diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..63acb91 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,3 @@ + +[test] +root = "packages/bumpy" diff --git a/docs/version-propagation.md b/docs/version-propagation.md new file mode 100644 index 0000000..199b281 --- /dev/null +++ b/docs/version-propagation.md @@ -0,0 +1,205 @@ +# How bumpy calculates version bumps + +When you run `bumpy version` (or `bumpy status` to preview), bumpy reads all pending changeset files and builds a **release plan** — a list of packages to bump and by how much. This document explains the full algorithm, including how bumps propagate to dependent packages and the available settings. + +## Overview + +After collecting explicit bumps from changeset files, bumpy runs a **propagation loop** that repeats until stable: + +- **Phase A** — fix out-of-range dependencies (always runs) +- **Phase B** — enforce fixed/linked group constraints (optional/advanced) +- **Phase C** — apply cascades and proactive propagation rules (optional/advanced) + +## Phase A: Out-of-range check + +For every package in the release plan, bumpy checks each dependent's declared version range. If the new version would fall **outside** that range, the dependent must be bumped so its `package.json` stays valid. + +The bump type applied to the dependent depends on the dependency type: + +| Dependency type | Bump applied to dependent | Why | +| ---------------------- | --------------------------- | -------------------------------------------------------------------- | +| `peerDependencies` | matches the triggering bump | Proportional — a minor bump on the dep → minor bump on the dependent | +| `dependencies` | `patch` | Internal detail — consumers don't see it | +| `optionalDependencies` | `patch` | Internal detail — consumers don't see it | +| `devDependencies` | _(skipped)_ | Doesn't affect published consumers | + +For peer deps, "matches the triggering bump" means if `core` gets a minor bump that breaks the range, `plugin` also gets a minor bump. This keeps version bumps proportional — especially important for `0.x` packages where `^` ranges cause minor bumps to go out of range frequently. + +This phase is a **safety net** — it cannot be skipped. It ensures that published packages always have valid dependency ranges. + +### `workspace:` protocol resolution + +Workspace protocol shorthands (`workspace:^`, `workspace:~`, `workspace:*`) are resolved to actual semver ranges before checking satisfaction. The "current version" used is the dependency's version **before** bumping — we're checking whether the _new_ (post-bump) version still satisfies the _existing_ range: + +| In `package.json` | Resolved to | Example (dep at `1.2.0`) | +| ----------------- | -------------------- | -------------------------- | +| `workspace:^` | `^` | `^1.2.0` | +| `workspace:~` | `~` | `~1.2.0` | +| `workspace:*` | _(always satisfied)_ | never triggers propagation | + +This resolution is only for range checking — bumpy does not modify the `workspace:^` string in the source `package.json`. At publish time, these protocols are resolved to real ranges either by the package manager (in the default `pack` mode) or by bumpy itself (in `in-place` mode or when using custom publish commands). + +Full ranges like `workspace:^1.2.0` are resolved by stripping the `workspace:` prefix. + +`catalog:` protocol references (used by pnpm catalogs) are always treated as satisfied — bumpy cannot resolve the catalog to check the actual range, so it never triggers propagation through catalog deps. + +### `^0.x` caret ranges + +npm's `^` operator behaves differently for `0.x` versions: + +| Range | Means | Example | +| -------- | ---------------- | ------------------------------- | +| `^1.2.3` | `>=1.2.3 <2.0.0` | Minor/patch bumps stay in range | +| `^0.2.3` | `>=0.2.3 <0.3.0` | **Minor bumps break the range** | +| `^0.0.3` | `>=0.0.3 <0.0.4` | **Patch bumps break the range** | + +This means a **minor** bump on a `0.x` package with `^0.x` peer deps will break the range. Since Phase A matches the triggering bump for peer deps, the dependent also gets a **minor** bump — but if the dependent is at `1.x+`, that minor bump is disproportionate to what's really just an internal dependency update. Bumpy warns when this happens. + +> **Tip:** If you're seeing unexpected propagation from `0.x` peer deps, consider using explicit ranges (e.g. `workspace:>=0.2.0` or `>=0.2.0`) instead of `workspace:^` to widen the range and reduce breakage. + +## Phase B: Fixed and linked groups (optional) + +These constraints help keep a group of related packages arbitrarily in sync. This config can be set in root `.bumpy/_config.json` file, and package names can be names or glob patterns. Note that each setting is an array of arrays, since you can have multiple groups. + +### Fixed groups + +Packages in a `fixed` group always share the **same version number**. When any package in the group bumps, all packages get the highest bump level. + +```json +{ "fixed": [["@myorg/core", "@myorg/types"]] } +``` + +Example: propagation bumps `@myorg/types` as patch → `@myorg/core` also gets a patch bump to stay in sync. + +### Linked groups + +Packages in a `linked` group share the **same bump level** but keep independent version numbers. Only packages already in the release plan are affected — linked groups don't pull in packages that have no changesets. Entries can be specific names or glob patterns. + +```json +{ "linked": [["@myorg/plugin-*"]] } +``` + +## Example: multi-level propagation + +`core` gets a minor bump → `utils` has `^1.0.0` dep on `core`, goes out of range (Phase A) → `utils` gets a patch bump → fixed group pulls in `types` to match (Phase B) → `app` depends on `types` and goes out of range (Phase A, next iteration) → `app` gets a patch bump → stable. + +### Phase C: Proactive propagation (optional) + +Most users don't need this, but bumpy provides flexible settings for more complex monorepo workflows. + +Beyond fixing broken ranges, you may want dependents to re-release even when their ranges are still satisfied — for example, to ensure consumers always get the latest internal dependency versions. + +#### Enabling proactive propagation + +Set `updateInternalDependencies` in `.bumpy/_config.json`: + +| Value | Phase A (out-of-range) | Phase C (proactive) | +| -------------------------- | ---------------------- | ----------------------------------------------------------- | +| `"out-of-range"` (default) | Yes | No | +| `"patch"` | Yes | Yes — triggers when any dependency bumps (patch or higher) | +| `"minor"` | Yes | Yes — triggers only when a dependency bumps minor or higher | + +#### Dependency bump rules + +When Phase C is active, **dependency bump rules** control which dependency types trigger proactive bumps and what bump level to apply. +Each rule is either `false` (disabled) or an object with two fields: + +- `trigger` — minimum bump level in the dependency that activates propagation (`"major"`, `"minor"`, or `"patch"`) +- `bumpAs` — what bump to apply to the dependent (`"major"`, `"minor"`, `"patch"`, or `"match"`) + +**Global rules** are set in `.bumpy/_config.json`. The following are the built-in defaults — you only need to specify overrides: + +```json +{ + "dependencyBumpRules": { + "dependencies": { "trigger": "patch", "bumpAs": "patch" }, + "peerDependencies": { "trigger": "major", "bumpAs": "match" }, + "devDependencies": false, + "optionalDependencies": { "trigger": "minor", "bumpAs": "patch" } + } +} +``` + +**Per-package overrides** can be set in `package.json["bumpy"]` to override the global rules for a specific package (as a dependent): + +```json +{ + "bumpy": { + "dependencyBumpRules": { + "devDependencies": { "trigger": "patch", "bumpAs": "patch" } + } + } +} +``` + +For example, a private app might want devDeps to propagate because they're bundled at build time, even though the global default disables devDep propagation. + +**Rule resolution order** (when package A bumps and package B depends on A): + +1. `dependencyBumpRules[depType]` on package B _(most specific)_ +2. `dependencyBumpRules[depType]` in root config +3. Built-in defaults _(least specific)_ + +#### `cascadeTo` config + +Configured on the source package in `package.json["bumpy"]` to push bumps to other packages when it bumps. Keys are package names or glob patterns: + +```json +{ + "bumpy": { + "cascadeTo": { + "@myorg/plugin-*": { "trigger": "minor", "bumpAs": "patch" }, + "@myorg/cli": { "trigger": "patch", "bumpAs": "patch" } + } + } +} +``` + +Unlike dependency bump rules (configured on the _dependent_), `cascadeTo` is configured on the _source_ — useful for expressing "when I change, these downstream packages should also release." + +`cascadeTo` is checked separately from dependency bump rules and can add bumps beyond what the rules produce. All keys support glob patterns (`*`, `**`). + +### Per-changeset overrides + +These are set directly in changeset files for one-off control over a specific release. + +**`patch-isolated`** — bumps the package as a patch but skips all Phase C propagation from it (cascades and proactive bumps). If the bump would break a dependent's declared range, bumpy throws an error rather than silently propagating — you'll need to either widen the range, drop the `-isolated` flag, or explicitly bump the dependent in the changeset. + +```yaml +--- +'@myorg/utils': patch-isolated +--- +Internal refactor, no API changes. +``` + +**`none`** — suppresses a bump on a package that would otherwise be included via propagation. If skipping the bump would leave a dependent's range broken, bumpy throws an error. + +```yaml +--- +'@myorg/core': minor +'@myorg/plugin-a': none +--- +``` + +**Changeset-level cascades** — explicitly cascade bumps to other packages with glob support. The difference from listing packages directly in the changeset is that cascaded packages are marked as dependency bumps (not direct changes), which affects how they appear in changelogs and PR comments. These always apply (no trigger threshold check): + +```yaml +--- +'@myorg/core': + bump: minor + cascade: + '@myorg/plugin-*': patch +--- +``` + +Compare with listing packages directly — these are treated as independent changes and each gets the changeset's summary in their changelog: + +```yaml +--- +'@myorg/core': minor +'@myorg/plugin-a': patch +'@myorg/plugin-b': patch +--- +``` + +> **Note:** `patch-isolated`, `none`, and changeset cascades are not available in the interactive `bumpy add` UI — they are power-user features for changeset files and the `--packages` CLI flag. diff --git a/llms.md b/llms.md index d29e3dc..cc7c29b 100644 --- a/llms.md +++ b/llms.md @@ -57,7 +57,11 @@ Added new encryption provider for secrets management. Internal refactor — no API changes, dependents don't need to bump. ``` -Valid bump types: `major`, `minor`, `patch`, `minor-isolated`, `patch-isolated` +Valid bump types: `major`, `minor`, `patch`, `patch-isolated`, `none` + +`patch-isolated` bumps as a patch but skips Phase C propagation. If the bump would break a dependent's range, bumpy throws an error. + +`none` suppresses a bump on a package that would otherwise be included via propagation. If skipping would leave a broken range, bumpy throws an error. ### Nested format with explicit cascade control @@ -103,22 +107,21 @@ Added new encryption provider. Plugins need a patch bump for compatibility. // Package names/globs to explicitly include (overrides private status and ignore) "include": ["my-vscode-ext", "@myorg/app-*"], - // When to update internal dependency version ranges - // "out-of-range" = only when new version falls outside existing range (default) - // "patch" = always bump dependents - // "minor" = only on minor+ bumps - // "none" = never auto-bump dependents + // When to update internal dependency version ranges (Phase C) + // "out-of-range" = only fix broken ranges via Phase A (default) + // "patch" = also proactively bump dependents on any dep bump + // "minor" = also proactively bump dependents on minor+ dep bumps "updateInternalDependencies": "out-of-range", - // Global rules for how dependency bumps propagate + // Global rules for how dependency bumps propagate (Phase C only) + // Each rule is either false (disabled) or { trigger, bumpAs } "dependencyBumpRules": { // When a regular dependency bumps, what happens to dependents? "dependencies": { "trigger": "patch", "bumpAs": "patch" }, // When a peer dependency bumps, what happens to dependents? - // DEFAULT: only major triggers propagation (changesets uses minor!) - "peerDependencies": { "trigger": "major", "bumpAs": "major" }, + "peerDependencies": { "trigger": "major", "bumpAs": "match" }, // Dev dependencies never propagate by default - "devDependencies": { "trigger": "none", "bumpAs": "patch" }, + "devDependencies": false, "optionalDependencies": { "trigger": "minor", "bumpAs": "patch" }, }, @@ -190,9 +193,6 @@ Any package can have bumpy config in its own `package.json`: "buildCommand": "bun run build", "cascadeTo": { "@myorg/plugin-*": { "trigger": "minor", "bumpAs": "patch" } - }, - "specificDependencyRules": { - "@myorg/core": { "trigger": "minor", "bumpAs": "minor" } } } } @@ -200,18 +200,17 @@ Any package can have bumpy config in its own `package.json`: #### Per-package config fields -| Field | Type | Description | -| ------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------- | -| `managed` | `boolean` | Explicitly opt in (`true`) or out (`false`) of version management. Overrides private/ignore/include. | -| `access` | `"public" \| "restricted"` | npm access level override | -| `publishCommand` | `string \| string[]` | Custom publish command(s). Supports `{{version}}` and `{{name}}` template variables. | -| `buildCommand` | `string` | Build command to run before publishing | -| `registry` | `string` | Custom npm registry URL | -| `skipNpmPublish` | `boolean` | Skip npm publish (use with `publishCommand` for non-npm publishing) | -| `checkPublished` | `string` | Command to check if version is published. Should output the version string. Used for non-npm targets. | -| `dependencyBumpRules` | `object` | Override global dependency bump rules for this package | -| `specificDependencyRules` | `Record` | Rules for specific dependencies by name/glob | -| `cascadeTo` | `Record` | When this package bumps, cascade to these packages (supports globs) | +| Field | Type | Description | +| --------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------- | +| `managed` | `boolean` | Explicitly opt in (`true`) or out (`false`) of version management. Overrides private/ignore/include. | +| `access` | `"public" \| "restricted"` | npm access level override | +| `publishCommand` | `string \| string[]` | Custom publish command(s). Supports `{{version}}` and `{{name}}` template variables. | +| `buildCommand` | `string` | Build command to run before publishing | +| `registry` | `string` | Custom npm registry URL | +| `skipNpmPublish` | `boolean` | Skip npm publish (use with `publishCommand` for non-npm publishing) | +| `checkPublished` | `string` | Command to check if version is published. Should output the version string. Used for non-npm targets. | +| `dependencyBumpRules` | `object` | Override global dependency bump rules for this package (or `false` to disable) | +| `cascadeTo` | `Record` | When this package bumps, cascade to these packages (supports globs) | ## Package Management (include/exclude) @@ -234,30 +233,33 @@ A `DependencyBumpRule` has two fields: { "trigger": "minor", "bumpAs": "patch" } ``` -- `trigger`: what bump level in the dependency triggers propagation. Values: `"major"`, `"minor"`, `"patch"`, `"none"` -- `bumpAs`: what bump to apply to the dependent. Values: `"major"`, `"minor"`, `"patch"`, `"match"` (same as trigger) +- `trigger`: minimum bump level in the dependency that activates propagation. Values: `"major"`, `"minor"`, `"patch"` +- `bumpAs`: what bump to apply to the dependent. Values: `"major"`, `"minor"`, `"patch"`, `"match"` (same level as triggering bump) + +A rule can also be `false` to disable propagation for that dep type entirely. + +Note: dependency bump rules only apply in **Phase C** (proactive propagation). **Phase A** (out-of-range fixes) always runs with hardcoded behavior: peer deps get "match", regular deps get "patch", dev deps are skipped. ### Rule resolution order -When package A bumps and package B depends on A, bumpy looks for a rule in this order: +When package A bumps and package B depends on A, bumpy looks for a Phase C rule in this order: + +1. **Per-package dep type rule** — `dependencyBumpRules[depType]` on package B _(most specific)_ +2. **Global dep type rule** — root config `dependencyBumpRules[depType]` +3. **Built-in defaults** _(least specific)_ -1. **Changeset cascade** — explicit `cascade:` in the changeset file (always applies, no trigger check) -2. **Source cascadeTo** — `cascadeTo` config on package A -3. **Specific dependency rule** — `specificDependencyRules["A"]` on package B -4. **Per-package dep type rule** — `dependencyBumpRules[depType]` on package B -5. **Global dep type rule** — root config `dependencyBumpRules[depType]` -6. **Built-in defaults** +Changeset cascades and `cascadeTo` config are separate from dependency bump rules and always apply. ### Built-in defaults (the key difference from changesets) -| Dependency type | trigger | bumpAs | Changesets behavior | -| ---------------------- | --------- | ------ | ------------------- | -| `dependencies` | patch | patch | Same | -| `peerDependencies` | **major** | major | minor → major (!) | -| `devDependencies` | none | patch | patch → patch | -| `optionalDependencies` | minor | patch | Same | +| Dependency type | Phase C trigger | Phase C bumpAs | Phase A behavior | +| ---------------------- | --------------- | -------------- | ----------------------- | +| `dependencies` | patch | patch | patch (on out-of-range) | +| `peerDependencies` | **major** | **match** | match (on out-of-range) | +| `devDependencies` | _(disabled)_ | — | _(skipped)_ | +| `optionalDependencies` | minor | patch | patch (on out-of-range) | -The critical difference: changesets bumps dependents to **major** when a peer dependency gets a **minor** bump. Bumpy only propagates peer dep bumps on **major** by default. +The critical difference: changesets bumps dependents to **major** when a peer dependency gets a **minor** bump. Bumpy's Phase A matches the triggering bump level for peer deps, and Phase C only triggers on major by default. ## CLI Reference @@ -538,7 +540,7 @@ Or permanently via config: "packages": { "@myorg/internal-*": { "dependencyBumpRules": { - "dependencies": { "trigger": "none", "bumpAs": "patch" } + "dependencies": false } } } @@ -688,8 +690,8 @@ This will: Key behavioral differences after migration: -- Peer dependency minor bumps no longer cascade to major on dependents -- Use `patch-isolated`/`minor-isolated` bump types to skip propagation +- Out-of-range peer dep bumps match the triggering bump level (not always major) +- Use `patch-isolated` to skip Phase C propagation, or `none` to suppress a propagated bump - Per-package config moves to `package.json["bumpy"]` instead of root config only ## AI Integration diff --git a/packages/bumpy/skills/add-change/SKILL.md b/packages/bumpy/skills/add-change/SKILL.md index e91239d..b8b734a 100644 --- a/packages/bumpy/skills/add-change/SKILL.md +++ b/packages/bumpy/skills/add-change/SKILL.md @@ -43,12 +43,14 @@ For each affected package, choose the appropriate bump level: | **minor** | New features: added exports, new options, new functionality | | **patch** | Bug fixes, internal refactors, documentation, dependency updates | -Append `-isolated` (e.g., `patch-isolated`) if the change is purely internal and dependents should NOT be bumped. Use this for: +Use `patch-isolated` if the change is purely internal and dependents should NOT be bumped (skips Phase C propagation). If the bump would break a dependent's declared range, bumpy will throw an error. Use this for: - Internal refactors with no API changes - Dev tooling / test changes - Documentation-only changes +Use `none` in a changeset to suppress a bump on a package that would otherwise be included via propagation. If skipping would leave a broken range, bumpy throws an error. + ### 4. Write a clear summary Write a concise summary (1-3 sentences) describing **what** changed and **why**. This becomes the CHANGELOG entry. Good summaries: diff --git a/packages/bumpy/src/commands/add.ts b/packages/bumpy/src/commands/add.ts index eaedf6c..434f90e 100644 --- a/packages/bumpy/src/commands/add.ts +++ b/packages/bumpy/src/commands/add.ts @@ -22,8 +22,7 @@ const BUMP_CHOICES: { label: string; value: BumpTypeWithIsolated; hint?: string { label: 'patch', value: 'patch' }, { label: 'minor', value: 'minor' }, { label: 'major', value: 'major' }, - { label: 'patch (isolated)', value: 'patch-isolated', hint: 'no cascade' }, - { label: 'minor (isolated)', value: 'minor-isolated', hint: 'no cascade' }, + { label: 'patch (isolated)', value: 'patch-isolated', hint: 'skips propagation' }, ]; const CASCADE_CHOICES: { label: string; value: BumpType }[] = [ diff --git a/packages/bumpy/src/commands/ci.ts b/packages/bumpy/src/commands/ci.ts index 801cf45..5a316a1 100644 --- a/packages/bumpy/src/commands/ci.ts +++ b/packages/bumpy/src/commands/ci.ts @@ -100,11 +100,16 @@ export async function ciCheckCommand(rootDir: string, opts: CheckOptions): Promi const tag = r.isDependencyBump ? ' (dep)' : r.isCascadeBump ? ' (cascade)' : ''; console.log(` ${r.name}: ${r.oldVersion} → ${colorize(r.newVersion, 'cyan')}${tag}`); } + if (plan.warnings.length > 0) { + for (const w of plan.warnings) { + log.warn(w); + } + } // Comment on PR if (shouldComment && prNumber) { const prBranch = detectPrBranch(rootDir); - const comment = formatReleasePlanComment(plan, prChangesets, prNumber, prBranch, pm); + const comment = formatReleasePlanComment(plan, prChangesets, prNumber, prBranch, pm, plan.warnings); await postOrUpdatePrComment(prNumber, comment, rootDir); } } @@ -350,6 +355,7 @@ function formatReleasePlanComment( prNumber: string, prBranch: string | null, pm: PackageManager, + warnings: string[] = [], ): string { const repo = process.env.GITHUB_REPOSITORY; const lines: string[] = []; @@ -398,6 +404,15 @@ function formatReleasePlanComment( } lines.push(''); + if (warnings.length > 0) { + lines.push('#### Warnings'); + lines.push(''); + for (const w of warnings) { + lines.push(`> ⚠️ ${w}`); + } + lines.push(''); + } + const addLink = buildAddChangesetLink(prBranch); if (addLink) { lines.push(`[Click here if you want to add another changeset to this PR](${addLink})\n`); diff --git a/packages/bumpy/src/commands/migrate.ts b/packages/bumpy/src/commands/migrate.ts index 69e1121..f8c8097 100644 --- a/packages/bumpy/src/commands/migrate.ts +++ b/packages/bumpy/src/commands/migrate.ts @@ -93,8 +93,9 @@ export async function migrateCommand(rootDir: string, opts: MigrateOptions): Pro log.success('Migration complete!'); log.dim('Review .bumpy/_config.json and adjust settings as needed.'); log.dim('Key differences from changesets:'); - log.dim(' - peerDependency bumps only propagate on major (not minor)'); - log.dim(" - Use 'patch-isolated'/'minor-isolated' to skip propagation"); + log.dim(' - Out-of-range peer dep bumps match the triggering bump level (not always major)'); + log.dim(" - Use 'patch-isolated' to skip Phase C propagation"); + log.dim(" - Use 'none' in a changeset to suppress a propagated bump"); log.dim(' - Per-package config goes in package.json["bumpy"]'); } diff --git a/packages/bumpy/src/commands/publish.ts b/packages/bumpy/src/commands/publish.ts index 4b79c7a..ad00849 100644 --- a/packages/bumpy/src/commands/publish.ts +++ b/packages/bumpy/src/commands/publish.ts @@ -51,6 +51,7 @@ export async function publishCommand(rootDir: string, opts: PublishCommandOption const releasePlan: ReleasePlan = { changesets: [], releases: toPublish, + warnings: [], }; if (opts.dryRun) { diff --git a/packages/bumpy/src/commands/status.ts b/packages/bumpy/src/commands/status.ts index 8ae35b5..24b9479 100644 --- a/packages/bumpy/src/commands/status.ts +++ b/packages/bumpy/src/commands/status.ts @@ -101,6 +101,14 @@ export async function statusCommand(rootDir: string, opts: StatusOptions): Promi console.log(); } + // Show warnings from the release plan + if (plan.warnings.length > 0) { + for (const w of plan.warnings) { + log.warn(w); + } + console.log(); + } + if (opts.verbose) { log.bold('Changesets:'); for (const cs of plan.changesets) { diff --git a/packages/bumpy/src/commands/version.ts b/packages/bumpy/src/commands/version.ts index 580b875..ce015e9 100644 --- a/packages/bumpy/src/commands/version.ts +++ b/packages/bumpy/src/commands/version.ts @@ -26,6 +26,14 @@ export async function versionCommand(rootDir: string): Promise { return; } + // Show warnings from the release plan + if (plan.warnings.length > 0) { + for (const w of plan.warnings) { + log.warn(w); + } + console.log(); + } + // Show what will happen log.step('Applying version bumps:'); for (const r of plan.releases) { diff --git a/packages/bumpy/src/core/config.ts b/packages/bumpy/src/core/config.ts index f72b5f0..6a47289 100644 --- a/packages/bumpy/src/core/config.ts +++ b/packages/bumpy/src/core/config.ts @@ -117,9 +117,6 @@ function mergePackageConfig(...configs: PackageConfig[]): PackageConfig { if (cfg.dependencyBumpRules) { result.dependencyBumpRules = { ...result.dependencyBumpRules, ...cfg.dependencyBumpRules }; } - if (cfg.specificDependencyRules) { - result.specificDependencyRules = { ...result.specificDependencyRules, ...cfg.specificDependencyRules }; - } if (cfg.cascadeTo) { result.cascadeTo = { ...result.cascadeTo, ...cfg.cascadeTo }; } diff --git a/packages/bumpy/src/core/release-plan.ts b/packages/bumpy/src/core/release-plan.ts index 30b3b10..f4fea3d 100644 --- a/packages/bumpy/src/core/release-plan.ts +++ b/packages/bumpy/src/core/release-plan.ts @@ -1,6 +1,6 @@ import { matchGlob } from './config.ts'; import { DependencyGraph } from './dep-graph.ts'; -import { bumpVersion, satisfies, stripProtocol } from './semver.ts'; +import { bumpVersion, satisfies } from './semver.ts'; import { type BumpyConfig, type BumpType, @@ -20,6 +20,8 @@ import { interface PlannedBump { type: BumpType; isolated: boolean; + /** Explicit 'none' from changeset — suppresses propagation bumps */ + suppressed: boolean; isDependencyBump: boolean; isCascadeBump: boolean; changesets: Set; @@ -28,6 +30,11 @@ interface PlannedBump { /** * Build a release plan from pending changesets, the dependency graph, and config. * This is the core algorithm of bumpy. + * + * The propagation loop runs three phases until stable: + * Phase A — fix out-of-range dependencies (always runs) + * Phase B — enforce fixed/linked group constraints + * Phase C — apply cascades and proactive propagation rules */ export function assembleReleasePlan( changesets: Changeset[], @@ -36,19 +43,26 @@ export function assembleReleasePlan( config: BumpyConfig, ): ReleasePlan { if (changesets.length === 0) { - return { changesets: [], releases: [] }; + return { changesets: [], releases: [], warnings: [] }; } const planned = new Map(); + const warnings: string[] = []; // Step 1: Collect explicit bumps from changesets const cascadeOverrides = new Map>(); // pkg → (glob → bumpType) + const suppressedPackages = new Set(); // packages with explicit 'none' for (const cs of changesets) { for (const release of cs.releases) { if (!packages.has(release.name)) continue; const { bump, isolated } = parseIsolatedBump(release.type); + if (bump === 'none') { + suppressedPackages.add(release.name); + continue; + } + const existing = planned.get(release.name); if (existing) { existing.type = maxBump(existing.type, bump); @@ -59,6 +73,7 @@ export function assembleReleasePlan( planned.set(release.name, { type: bump, isolated, + suppressed: false, isDependencyBump: false, isCascadeBump: false, changesets: new Set([cs.id]), @@ -79,132 +94,299 @@ export function assembleReleasePlan( } } - // Step 2: Apply fixed groups - for (const group of config.fixed) { - let groupBump: BumpType | undefined; - let groupIsolated = true; - for (const nameOrGlob of group) { - for (const [name, bump] of planned) { - if (matchGlob(name, nameOrGlob)) { - groupBump = maxBump(groupBump, bump.type); - if (!bump.isolated) groupIsolated = false; - } - } + // Mark suppressed packages (explicit 'none' in changeset) + for (const name of suppressedPackages) { + if (!planned.has(name)) { + // Create a placeholder that will be removed later + // This prevents propagation from adding this package + planned.set(name, { + type: 'patch', // placeholder, won't be used + isolated: false, + suppressed: true, + isDependencyBump: false, + isCascadeBump: false, + changesets: new Set(), + }); } - if (!groupBump) continue; - // Apply the highest bump to all packages in the group - for (const nameOrGlob of group) { - for (const [name] of packages) { - if (!matchGlob(name, nameOrGlob)) continue; - const existing = planned.get(name); - if (existing) { - existing.type = groupBump; - existing.isolated = groupIsolated; + } + + // Step 2: Propagation loop (iterative until stable) + let changed = true; + let iterations = 0; + const MAX_ITERATIONS = 100; // safety valve + + while (changed && iterations < MAX_ITERATIONS) { + changed = false; + iterations++; + + // Phase A: Fix out-of-range dependencies (always runs) + for (const [pkgName, bump] of planned) { + if (bump.suppressed) continue; + + const pkg = packages.get(pkgName)!; + const newVersion = bumpVersion(pkg.version, bump.type); + const dependents = depGraph.getDependents(pkgName); + + for (const dep of dependents) { + // Skip devDependencies in Phase A + if (dep.depType === 'devDependencies') continue; + + // Check if new version is out of range + const currentVersion = pkg.version; + if (satisfies(newVersion, dep.versionRange, currentVersion)) continue; + + // Determine bump level for the dependent + let depBump: BumpType; + if (dep.depType === 'peerDependencies') { + // Match the triggering bump level + depBump = bump.type; } else { - planned.set(name, { - type: groupBump, - isolated: groupIsolated, - isDependencyBump: false, - isCascadeBump: false, - changesets: new Set(), - }); + // dependencies / optionalDependencies get patch + depBump = 'patch'; + } + + // Check if the dependent is suppressed + const existingDep = planned.get(dep.name); + if (existingDep?.suppressed) { + throw new Error( + `Cannot suppress bump for '${dep.name}' (via 'none' in changeset) — ` + + `'${pkgName}' is bumping to ${newVersion} which breaks the declared range '${dep.versionRange}'. ` + + `Either widen the range or remove the 'none' entry.`, + ); + } + + // Check if isolated would break range + if (bump.isolated) { + throw new Error( + `'patch-isolated' bump for '${pkgName}' would break the range '${dep.versionRange}' ` + + `declared by '${dep.name}'. Either widen the range, drop '-isolated', ` + + `or explicitly bump '${dep.name}' in the changeset.`, + ); + } + + // Warn about ^0.x peer dep propagation + if (dep.depType === 'peerDependencies' && depBump !== 'patch') { + // Resolve workspace:^ to ^ for checking + let resolvedRange = dep.versionRange.replace(/^workspace:/, ''); + if (resolvedRange === '^' || resolvedRange === '~') { + resolvedRange = `${resolvedRange}${pkg.version}`; + } + if (/^\^0(\.|$)/.test(resolvedRange)) { + warnings.push( + `${dep.name} gets a ${depBump} bump because ${pkgName}@${newVersion} is out of range ` + + `for its peer dep "${dep.versionRange}" (resolves to ${resolvedRange}). ` + + `npm treats ^ on 0.x as minor-breaking. Consider using >=0.x ranges for pre-1.0 peer deps.`, + ); + } + } + + if (applyBump(planned, dep.name, depBump, true, false, bump.changesets)) { + changed = true; } } } - } - // Step 3: Apply linked groups (same bump level, independent versions) - for (const group of config.linked) { - let groupBump: BumpType | undefined; - for (const nameOrGlob of group) { - for (const [name, bump] of planned) { - if (matchGlob(name, nameOrGlob)) { - groupBump = maxBump(groupBump, bump.type); + // Phase B: Enforce fixed/linked group constraints + for (const group of config.fixed) { + let groupBump: BumpType | undefined; + let groupIsolated = true; + for (const nameOrGlob of group) { + for (const [name, bump] of planned) { + if (bump.suppressed) continue; + if (matchGlob(name, nameOrGlob)) { + groupBump = maxBump(groupBump, bump.type); + if (!bump.isolated) groupIsolated = false; + } + } + } + if (!groupBump) continue; + for (const nameOrGlob of group) { + for (const [name] of packages) { + if (!matchGlob(name, nameOrGlob)) continue; + const existing = planned.get(name); + if (existing && existing.suppressed) continue; + if (existing) { + const newType = maxBump(existing.type, groupBump); + if (newType !== existing.type) { + existing.type = newType; + existing.isolated = groupIsolated; + changed = true; + } + } else { + planned.set(name, { + type: groupBump, + isolated: groupIsolated, + suppressed: false, + isDependencyBump: false, + isCascadeBump: false, + changesets: new Set(), + }); + changed = true; + } } } } - if (!groupBump) continue; - for (const nameOrGlob of group) { - for (const [name] of packages) { - if (!matchGlob(name, nameOrGlob)) continue; - const existing = planned.get(name); - if (existing) { - existing.type = groupBump; + + // Linked groups (same bump level, independent versions, only already-planned packages) + for (const group of config.linked) { + let groupBump: BumpType | undefined; + for (const nameOrGlob of group) { + for (const [name, bump] of planned) { + if (bump.suppressed) continue; + if (matchGlob(name, nameOrGlob)) { + groupBump = maxBump(groupBump, bump.type); + } + } + } + if (!groupBump) continue; + for (const nameOrGlob of group) { + for (const [name] of packages) { + if (!matchGlob(name, nameOrGlob)) continue; + const existing = planned.get(name); + if (!existing || existing.suppressed) continue; + const newType = maxBump(existing.type, groupBump); + if (newType !== existing.type) { + existing.type = newType; + changed = true; + } } - // linked groups don't add packages that aren't already planned } } - } - // Step 4: Propagate bumps (iterative until stable) - let changed = true; - let iterations = 0; - const MAX_ITERATIONS = 100; // safety valve + // Phase C: Proactive propagation (only when updateInternalDependencies !== 'out-of-range') + if (config.updateInternalDependencies !== 'out-of-range') { + for (const [pkgName, bump] of planned) { + if (bump.suppressed) continue; + if (bump.isolated) continue; - while (changed && iterations < MAX_ITERATIONS) { - changed = false; - iterations++; + // Check minimum threshold for proactive propagation + if (config.updateInternalDependencies === 'minor' && bumpLevel(bump.type) < bumpLevel('minor')) { + continue; + } - for (const [pkgName, bump] of planned) { - if (bump.isolated) continue; - - // 4a: Apply changeset-level cascade overrides - const csOverrides = cascadeOverrides.get(pkgName); - if (csOverrides) { - for (const [pattern, cascadeBumpType] of csOverrides) { - for (const [targetName] of packages) { - if (!matchGlob(targetName, pattern)) continue; - if (applyBump(planned, targetName, cascadeBumpType, false, true, bump.changesets)) { - changed = true; + // C1: Apply changeset-level cascade overrides + const csOverrides = cascadeOverrides.get(pkgName); + if (csOverrides) { + for (const [pattern, cascadeBumpType] of csOverrides) { + for (const [targetName] of packages) { + if (!matchGlob(targetName, pattern)) continue; + const existingTarget = planned.get(targetName); + if (existingTarget?.suppressed) continue; + if (applyBump(planned, targetName, cascadeBumpType, false, true, bump.changesets)) { + changed = true; + } } } } - } - // 4b: Apply source-side cascadeTo config - const pkg = packages.get(pkgName); - const cascadeTo = pkg?.bumpy?.cascadeTo; - if (cascadeTo) { - for (const [pattern, rule] of Object.entries(cascadeTo)) { - if (!shouldTrigger(bump.type, rule.trigger)) continue; - const cascadeBump = rule.bumpAs === 'match' ? bump.type : rule.bumpAs; - for (const [targetName] of packages) { - if (!matchGlob(targetName, pattern)) continue; - if (applyBump(planned, targetName, cascadeBump, false, true, bump.changesets)) { - changed = true; + // C2: Apply source-side cascadeTo config + const pkg = packages.get(pkgName); + const cascadeTo = pkg?.bumpy?.cascadeTo; + if (cascadeTo) { + for (const [pattern, rule] of Object.entries(cascadeTo)) { + if (!shouldTrigger(bump.type, rule.trigger)) continue; + const cascadeBump = rule.bumpAs === 'match' ? bump.type : rule.bumpAs; + for (const [targetName] of packages) { + if (!matchGlob(targetName, pattern)) continue; + const existingTarget = planned.get(targetName); + if (existingTarget?.suppressed) continue; + if (applyBump(planned, targetName, cascadeBump, false, true, bump.changesets)) { + changed = true; + } } } } + + // C3: Apply dependency graph proactive propagation + const dependents = depGraph.getDependents(pkgName); + for (const dep of dependents) { + const rule = resolveRule(dep.name, dep.depType, packages, config); + if (!rule) continue; // disabled for this dep type + if (!shouldTrigger(bump.type, rule.trigger)) continue; + + const existingDep = planned.get(dep.name); + if (existingDep?.suppressed) continue; + + const depBump = rule.bumpAs === 'match' ? bump.type : rule.bumpAs; + if (applyBump(planned, dep.name, depBump, true, false, bump.changesets)) { + changed = true; + } + } } + } else { + // Even in out-of-range mode, still apply changeset cascades and cascadeTo + for (const [pkgName, bump] of planned) { + if (bump.suppressed) continue; + if (bump.isolated) continue; - // 4c: Apply dependency graph propagation - const dependents = depGraph.getDependents(pkgName); - for (const dep of dependents) { - const rule = resolveRule(dep.name, pkgName, dep.depType, packages, config); - if (!shouldTrigger(bump.type, rule.trigger)) continue; + // Changeset-level cascade overrides always apply + const csOverrides = cascadeOverrides.get(pkgName); + if (csOverrides) { + for (const [pattern, cascadeBumpType] of csOverrides) { + for (const [targetName] of packages) { + if (!matchGlob(targetName, pattern)) continue; + const existingTarget = planned.get(targetName); + if (existingTarget?.suppressed) continue; + if (applyBump(planned, targetName, cascadeBumpType, false, true, bump.changesets)) { + changed = true; + } + } + } + } - // Check out-of-range setting - if (config.updateInternalDependencies === 'out-of-range') { - const newVersion = bumpVersion(packages.get(pkgName)!.version, bump.type); - if (satisfies(newVersion, stripProtocol(dep.versionRange))) continue; + // Source-side cascadeTo config always applies + const pkg = packages.get(pkgName); + const cascadeTo = pkg?.bumpy?.cascadeTo; + if (cascadeTo) { + for (const [pattern, rule] of Object.entries(cascadeTo)) { + if (!shouldTrigger(bump.type, rule.trigger)) continue; + const cascadeBump = rule.bumpAs === 'match' ? bump.type : rule.bumpAs; + for (const [targetName] of packages) { + if (!matchGlob(targetName, pattern)) continue; + const existingTarget = planned.get(targetName); + if (existingTarget?.suppressed) continue; + if (applyBump(planned, targetName, cascadeBump, false, true, bump.changesets)) { + changed = true; + } + } + } } - if (config.updateInternalDependencies === 'none') continue; - if (config.updateInternalDependencies === 'minor' && bumpLevel(bump.type) < bumpLevel('minor')) continue; + } + } + } - const depBump = rule.bumpAs === 'match' ? bump.type : rule.bumpAs; - if (applyBump(planned, dep.name, depBump, true, false, bump.changesets)) { - changed = true; + // Step 3: Validate suppressed packages — check that their ranges are still satisfied + for (const [name, bump] of planned) { + if (!bump.suppressed) continue; + // Check all dependencies of this package to ensure none are broken + const pkg = packages.get(name)!; + // Check if any planned bump on a dependency would break this package's range + for (const [depName, depBump] of planned) { + if (depBump.suppressed) continue; + const depPkg = packages.get(depName)!; + const newDepVersion = bumpVersion(depPkg.version, depBump.type); + + // Check all dep types + for (const depType of ['dependencies', 'peerDependencies', 'optionalDependencies'] as const) { + const range = pkg[depType]?.[depName]; + if (!range) continue; + if (!satisfies(newDepVersion, range, depPkg.version)) { + throw new Error( + `Cannot suppress bump for '${name}' (via 'none' in changeset) — ` + + `'${depName}' is bumping to ${newDepVersion} which breaks the declared range '${range}'. ` + + `Either widen the range or remove the 'none' entry.`, + ); } } } } - // Step 5: Calculate new versions - // Note: packages map already contains only managed packages (filtered by discoverPackages) + // Step 4: Calculate new versions (exclude suppressed) const releases: PlannedRelease[] = []; for (const [name, bump] of planned) { + if (bump.suppressed) continue; const pkg = packages.get(name); - if (!pkg) continue; // skip if not in managed packages + if (!pkg) continue; const newVersion = bumpVersion(pkg.version, bump.type); releases.push({ @@ -221,7 +403,19 @@ export function assembleReleasePlan( // Sort by name for stable output releases.sort((a, b) => a.name.localeCompare(b.name)); - return { changesets, releases }; + // Static warning: workspace:* on peer deps + for (const [name, pkg] of packages) { + for (const [depName, range] of Object.entries(pkg.peerDependencies)) { + if (range === 'workspace:*' && packages.has(depName)) { + warnings.push( + `${name} has peer dep "${depName}": "workspace:*" — this will be published as a fixed range ` + + `which may not match your intent. Consider using "workspace:^" instead.`, + ); + } + } + } + + return { changesets, releases, warnings }; } /** Apply a bump to a package, upgrading if already planned. Returns true if anything changed. */ @@ -235,6 +429,7 @@ function applyBump( ): boolean { const existing = planned.get(name); if (existing) { + if (existing.suppressed) return false; const newType = maxBump(existing.type, type); if (newType === existing.type) return false; existing.type = newType; @@ -246,6 +441,7 @@ function applyBump( planned.set(name, { type, isolated: false, + suppressed: false, isDependencyBump, isCascadeBump, changesets: new Set(sourceChangesets), @@ -254,45 +450,34 @@ function applyBump( } /** Check if a bump level meets the trigger threshold */ -function shouldTrigger(bumpType: BumpType, trigger: BumpType | 'none'): boolean { - if (trigger === 'none') return false; +function shouldTrigger(bumpType: BumpType, trigger: BumpType): boolean { return bumpLevel(bumpType) >= bumpLevel(trigger); } /** - * Resolve the dependency bump rule for a specific dependent/dependency pair. - * Priority: specificDependencyRules > per-package depType rules > global depType rules > defaults + * Resolve the dependency bump rule for a specific dependent + dep type. + * Priority: per-package depType rules > global depType rules > defaults + * Returns false if the rule is disabled. */ function resolveRule( dependentName: string, - dependencyName: string, depType: DepType, packages: Map, config: BumpyConfig, -): DependencyBumpRule { +): DependencyBumpRule | false { const dependent = packages.get(dependentName); - // Check specific dependency rules on the dependent - if (dependent?.bumpy?.specificDependencyRules?.[dependencyName]) { - return dependent.bumpy.specificDependencyRules[dependencyName]; - } - // Check glob patterns in specific dependency rules - if (dependent?.bumpy?.specificDependencyRules) { - for (const [pattern, rule] of Object.entries(dependent.bumpy.specificDependencyRules)) { - if (matchGlob(dependencyName, pattern)) return rule; - } - } - // Check per-package dependency type rules - if (dependent?.bumpy?.dependencyBumpRules?.[depType]) { - return dependent.bumpy.dependencyBumpRules[depType]; + if (dependent?.bumpy?.dependencyBumpRules && depType in dependent.bumpy.dependencyBumpRules) { + return dependent.bumpy.dependencyBumpRules[depType]!; } // Check global config - if (config.dependencyBumpRules[depType]) { - return config.dependencyBumpRules[depType]; + if (depType in config.dependencyBumpRules) { + return config.dependencyBumpRules[depType]!; } // Built-in defaults - return DEFAULT_BUMP_RULES[depType] || { trigger: 'patch', bumpAs: 'patch' }; + const defaultRule = DEFAULT_BUMP_RULES[depType]; + return defaultRule !== undefined ? defaultRule : { trigger: 'patch', bumpAs: 'patch' }; } diff --git a/packages/bumpy/src/core/semver.ts b/packages/bumpy/src/core/semver.ts index e261530..627f62a 100644 --- a/packages/bumpy/src/core/semver.ts +++ b/packages/bumpy/src/core/semver.ts @@ -7,12 +7,22 @@ export function bumpVersion(version: string, type: BumpType): string { return result; } -/** Check if a version satisfies a range */ -export function satisfies(version: string, range: string): boolean { - // Handle workspace: protocol — strip and check the underlying range +/** + * Check if a version satisfies a range. + * @param version - The version to check + * @param range - The version range (may include workspace: or catalog: protocol) + * @param currentVersion - The dependency's current version, used to resolve workspace:^ and workspace:~ + */ +export function satisfies(version: string, range: string, currentVersion?: string): boolean { + // Handle workspace: protocol — resolve shorthands using currentVersion if (range.startsWith('workspace:')) { const cleanRange = range.slice('workspace:'.length); - if (!cleanRange || cleanRange === '*' || cleanRange === '^' || cleanRange === '~') return true; + if (!cleanRange || cleanRange === '*') return true; + if (cleanRange === '^' || cleanRange === '~') { + if (!currentVersion) return true; // can't resolve without current version + const resolved = `${cleanRange}${currentVersion}`; + return semver.satisfies(version, resolved); + } return semver.satisfies(version, cleanRange); } // catalog: references can't be range-checked without catalog data, diff --git a/packages/bumpy/src/types.ts b/packages/bumpy/src/types.ts index 30d6230..b9fad89 100644 --- a/packages/bumpy/src/types.ts +++ b/packages/bumpy/src/types.ts @@ -1,7 +1,7 @@ // ---- Bump types ---- export type BumpType = 'major' | 'minor' | 'patch'; -export type BumpTypeWithIsolated = BumpType | 'minor-isolated' | 'patch-isolated'; +export type BumpTypeWithIsolated = BumpType | 'patch-isolated' | 'none'; export const BUMP_LEVELS: Record = { patch: 0, @@ -13,7 +13,10 @@ export function bumpLevel(type: BumpType): number { return BUMP_LEVELS[type]; } -export function parseIsolatedBump(type: BumpTypeWithIsolated): { bump: BumpType; isolated: boolean } { +export function parseIsolatedBump(type: BumpTypeWithIsolated): { bump: BumpType | 'none'; isolated: boolean } { + if (type === 'none') { + return { bump: 'none', isolated: false }; + } if (type.endsWith('-isolated')) { return { bump: type.replace('-isolated', '') as BumpType, isolated: true }; } @@ -29,15 +32,15 @@ export function maxBump(a: BumpType | undefined, b: BumpType): BumpType { export interface DependencyBumpRule { /** What bump level in the dependency triggers propagation */ - trigger: BumpType | 'none'; + trigger: BumpType; /** What bump to apply to the dependent */ bumpAs: BumpType | 'match'; } -export const DEFAULT_BUMP_RULES: Record = { +export const DEFAULT_BUMP_RULES: Record = { dependencies: { trigger: 'patch', bumpAs: 'patch' }, - peerDependencies: { trigger: 'major', bumpAs: 'major' }, - devDependencies: { trigger: 'none', bumpAs: 'patch' }, + peerDependencies: { trigger: 'major', bumpAs: 'match' }, + devDependencies: false, optionalDependencies: { trigger: 'minor', bumpAs: 'patch' }, }; @@ -74,8 +77,8 @@ export interface BumpyConfig { ignore: string[]; /** Package names/globs to explicitly include (overrides private + ignore) */ include: string[]; - updateInternalDependencies: 'patch' | 'minor' | 'out-of-range' | 'none'; - dependencyBumpRules: Partial>; + updateInternalDependencies: 'patch' | 'minor' | 'out-of-range'; + dependencyBumpRules: Partial>; privatePackages: { version: boolean; tag: boolean }; packages: Record; publish: PublishConfig; @@ -109,8 +112,7 @@ export interface PackageConfig { skipNpmPublish?: boolean; /** Command to check if a version is already published. Should output the published version string. */ checkPublished?: string; - dependencyBumpRules?: Partial>; - specificDependencyRules?: Record; + dependencyBumpRules?: Partial>; cascadeTo?: Record; } @@ -216,4 +218,5 @@ export interface PlannedRelease { export interface ReleasePlan { changesets: Changeset[]; releases: PlannedRelease[]; + warnings: string[]; } diff --git a/packages/bumpy/test/core/changeset.test.ts b/packages/bumpy/test/core/changeset.test.ts index 8f5a635..4c05f67 100644 --- a/packages/bumpy/test/core/changeset.test.ts +++ b/packages/bumpy/test/core/changeset.test.ts @@ -21,15 +21,29 @@ Added a new feature to pkg-a expect(cs!.summary).toBe('Added a new feature to pkg-a'); }); - test('parses isolated bump types', () => { + test('parses patch-isolated bump type', () => { const content = `--- -"pkg-a": minor-isolated +"pkg-a": patch-isolated --- Internal change `; const cs = parseChangeset(content, 'test-cs'); - expect(cs!.releases[0]!.type).toBe('minor-isolated'); + expect(cs!.releases[0]!.type).toBe('patch-isolated'); + }); + + test('parses none bump type', () => { + const content = `--- +"pkg-a": minor +"pkg-b": none +--- + +Feature in pkg-a, suppress bump on pkg-b +`; + const cs = parseChangeset(content, 'test-cs'); + expect(cs!.releases).toHaveLength(2); + expect(cs!.releases[0]!.type).toBe('minor'); + expect(cs!.releases[1]!.type).toBe('none'); }); test('parses nested format with cascade', () => { diff --git a/packages/bumpy/test/core/publish-pipeline.test.ts b/packages/bumpy/test/core/publish-pipeline.test.ts index db58cd8..d879de3 100644 --- a/packages/bumpy/test/core/publish-pipeline.test.ts +++ b/packages/bumpy/test/core/publish-pipeline.test.ts @@ -52,6 +52,7 @@ describe('publishPackages', () => { const depGraph = new DependencyGraph(packages); const plan: ReleasePlan = { changesets: [], + warnings: [], releases: [ { name: 'my-pkg', @@ -94,6 +95,7 @@ describe('publishPackages', () => { const depGraph = new DependencyGraph(packages); const plan: ReleasePlan = { changesets: [], + warnings: [], releases: [ { name: 'my-ext', @@ -132,6 +134,7 @@ describe('publishPackages', () => { const depGraph = new DependencyGraph(packages); const plan: ReleasePlan = { changesets: [], + warnings: [], releases: [ { name: 'private-pkg', @@ -179,6 +182,7 @@ describe('publishPackages', () => { const depGraph = new DependencyGraph(packages); const plan: ReleasePlan = { changesets: [], + warnings: [], releases: [ { name: 'core', @@ -225,6 +229,7 @@ describe('publishPackages', () => { const depGraph = new DependencyGraph(packages); const plan: ReleasePlan = { changesets: [], + warnings: [], releases: [ { name: 'app', diff --git a/packages/bumpy/test/core/release-plan.test.ts b/packages/bumpy/test/core/release-plan.test.ts index da64eed..1a5f00b 100644 --- a/packages/bumpy/test/core/release-plan.test.ts +++ b/packages/bumpy/test/core/release-plan.test.ts @@ -38,300 +38,868 @@ describe('assembleReleasePlan', () => { expect(plan.releases[0]!.newVersion).toBe('1.1.0'); }); - test('dependency propagation - patch bump propagates patch to dependents', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig({ updateInternalDependencies: 'patch' })); - - expect(plan.releases).toHaveLength(2); - const coreRelease = plan.releases.find((r) => r.name === 'core')!; - const appRelease = plan.releases.find((r) => r.name === 'app')!; - expect(coreRelease.newVersion).toBe('1.0.1'); - expect(appRelease.type).toBe('patch'); - expect(appRelease.isDependencyBump).toBe(true); - }); - - test('peer dependency minor bump does NOT propagate by default', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); - - expect(plan.releases).toHaveLength(1); - expect(plan.releases[0]!.name).toBe('core'); - }); - - test('peer dependency major bump DOES propagate by default', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); - - expect(plan.releases).toHaveLength(2); - const pluginRelease = plan.releases.find((r) => r.name === 'plugin')!; - expect(pluginRelease.type).toBe('major'); - expect(pluginRelease.isDependencyBump).toBe(true); - }); - - test('isolated bump skips dependency propagation', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [ - { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, - ]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); - - expect(plan.releases).toHaveLength(1); - expect(plan.releases[0]!.name).toBe('core'); - expect(plan.releases[0]!.newVersion).toBe('1.0.1'); - }); - - test('non-isolated changeset overrides isolated for same package', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [ - { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, - { id: 'cs2', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }, - ]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig({ updateInternalDependencies: 'patch' })); - - expect(plan.releases).toHaveLength(2); - }); - - test('out-of-range: skips propagation when version still satisfies range', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['app', makePkg('app', '1.0.0', { dependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; - - const graph = new DependencyGraph(packages); - const config = makeConfig({ updateInternalDependencies: 'out-of-range' }); - const plan = assembleReleasePlan(changesets, packages, graph, config); - - expect(plan.releases).toHaveLength(1); - expect(plan.releases[0]!.name).toBe('core'); - }); - - test('out-of-range: propagates when version leaves range', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['app', makePkg('app', '1.0.0', { dependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; + test('empty changesets returns empty plan', () => { + const packages = new Map([['pkg-a', makePkg('pkg-a', '1.0.0')]]); const graph = new DependencyGraph(packages); - const config = makeConfig({ updateInternalDependencies: 'out-of-range' }); - const plan = assembleReleasePlan(changesets, packages, graph, config); + const plan = assembleReleasePlan([], packages, graph, makeConfig()); - expect(plan.releases).toHaveLength(2); + expect(plan.releases).toHaveLength(0); + expect(plan.changesets).toHaveLength(0); + expect(plan.warnings).toHaveLength(0); }); - test('changeset-level cascade overrides', () => { + test('multi-package changeset bumps all listed packages', () => { const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['plugin-a', makePkg('plugin-a', '1.0.0')], - ['plugin-b', makePkg('plugin-b', '1.0.0')], + ['pkg-a', makePkg('pkg-a', '1.0.0')], + ['pkg-b', makePkg('pkg-b', '2.0.0')], ]); const changesets: Changeset[] = [ { id: 'cs1', releases: [ - { - name: 'core', - type: 'minor', - cascade: { 'plugin-*': 'patch' as const }, - }, + { name: 'pkg-a', type: 'minor' }, + { name: 'pkg-b', type: 'patch' }, ], - summary: 'Feature with cascades', + summary: 'Cross-package change', }, ]; const graph = new DependencyGraph(packages); const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); - expect(plan.releases).toHaveLength(3); - const pluginA = plan.releases.find((r) => r.name === 'plugin-a')!; - const pluginB = plan.releases.find((r) => r.name === 'plugin-b')!; - expect(pluginA.type).toBe('patch'); - expect(pluginA.isCascadeBump).toBe(true); - expect(pluginB.type).toBe('patch'); - expect(pluginB.isCascadeBump).toBe(true); + expect(plan.releases).toHaveLength(2); + expect(plan.releases.find((r) => r.name === 'pkg-a')!.newVersion).toBe('1.1.0'); + expect(plan.releases.find((r) => r.name === 'pkg-b')!.newVersion).toBe('2.0.1'); }); - test('cascadeTo config on source package', () => { - const packages = new Map([ - [ - 'core', - makePkg('core', '1.0.0', { - bumpy: { - cascadeTo: { - 'plugin-*': { trigger: 'minor', bumpAs: 'patch' }, - }, - }, - }), - ], - ['plugin-a', makePkg('plugin-a', '1.0.0')], - ['plugin-b', makePkg('plugin-b', '1.0.0')], - ['unrelated', makePkg('unrelated', '1.0.0')], - ]); + // ---- Phase A: out-of-range checks ---- - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + describe('Phase A: out-of-range', () => { + test('out-of-range peer dep gets "match" bump level (not always major)', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: '^1.0.0' } })], + ]); - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(2); + const pluginRelease = plan.releases.find((r) => r.name === 'plugin')!; + expect(pluginRelease.type).toBe('major'); // matches the triggering bump + expect(pluginRelease.isDependencyBump).toBe(true); + }); + + test('out-of-range regular dep gets patch', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(2); + const appRelease = plan.releases.find((r) => r.name === 'app')!; + expect(appRelease.type).toBe('patch'); // regular deps get patch + expect(appRelease.isDependencyBump).toBe(true); + }); + + test('devDeps are skipped in Phase A', () => { + const packages = new Map([ + ['test-utils', makePkg('test-utils', '1.0.0')], + ['app', makePkg('app', '1.0.0', { devDependencies: { 'test-utils': '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'test-utils', type: 'major' }], summary: 'Breaking' }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + // Even with major bump going out-of-range, devDeps are skipped + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('test-utils'); + }); + + test('workspace:^ resolved correctly for range checking', () => { + const packages = new Map([ + ['core', makePkg('core', '1.2.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: 'workspace:^' } })], + ]); + + // Minor bump: 1.2.0 → 1.3.0, which satisfies ^1.2.0 + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); // app is NOT bumped because 1.3.0 satisfies ^1.2.0 + }); + + test('workspace:^ triggers propagation on major bump', () => { + const packages = new Map([ + ['core', makePkg('core', '1.2.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: 'workspace:^' } })], + ]); + + // Major bump: 1.2.0 → 2.0.0, which does NOT satisfy ^1.2.0 + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(2); // app IS bumped + expect(plan.releases.find((r) => r.name === 'app')!.type).toBe('patch'); + }); + + test('^0.x peer dep minor bump → minor bump on dependent + warning', () => { + const packages = new Map([ + ['core', makePkg('core', '0.2.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: '^0.2.0' } })], + ]); + + // Minor bump: 0.2.0 → 0.3.0, which does NOT satisfy ^0.2.0 (0.x caret range!) + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(2); + const pluginRelease = plan.releases.find((r) => r.name === 'plugin')!; + expect(pluginRelease.type).toBe('minor'); // matches the triggering bump + expect(pluginRelease.isDependencyBump).toBe(true); + + // Should generate a warning about ^0.x propagation + expect(plan.warnings.length).toBeGreaterThan(0); + expect(plan.warnings[0]).toContain('plugin'); + expect(plan.warnings[0]).toContain('^0.2.0'); + }); + + test('Phase A runs even for patch-isolated bumps (but isolated blocks propagation → error)', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: '~1.0.0' } })], + ]); + + // patch-isolated on core: 1.0.0 → 1.0.1, satisfies ~1.0.0 → no issue + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + expect(plan.releases[0]!.newVersion).toBe('1.0.1'); + }); + + test('skips propagation when version still satisfies range', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); + + test('transitive dependency propagation through out-of-range', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['middle', makePkg('middle', '1.0.0', { dependencies: { core: '~1.0.0' } })], + ['app', makePkg('app', '1.0.0', { dependencies: { middle: '~1.0.0' } })], + ]); + + // minor bump on core: 1.0.0 → 1.1.0, breaks ~1.0.0 + // middle gets patch: 1.0.0 → 1.0.1, satisfies ~1.0.0 on app → stops + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases.find((r) => r.name === 'core')).toBeDefined(); + expect(plan.releases.find((r) => r.name === 'middle')).toBeDefined(); + expect(plan.releases.find((r) => r.name === 'app')).toBeUndefined(); + }); + }); - expect(plan.releases).toHaveLength(3); - expect(plan.releases.find((r) => r.name === 'unrelated')).toBeUndefined(); - expect(plan.releases.find((r) => r.name === 'plugin-a')!.type).toBe('patch'); + // ---- Phase B: fixed/linked groups ---- + + describe('Phase B: fixed and linked groups', () => { + test('fixed groups: all packages get highest bump', () => { + const packages = new Map([ + ['pkg-a', makePkg('pkg-a', '1.0.0')], + ['pkg-b', makePkg('pkg-b', '1.0.0')], + ['pkg-c', makePkg('pkg-c', '1.0.0')], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'pkg-a', type: 'minor' }], summary: 'Feature' }, + { id: 'cs2', releases: [{ name: 'pkg-b', type: 'patch' }], summary: 'Fix' }, + ]; + + const graph = new DependencyGraph(packages); + const config = makeConfig({ fixed: [['pkg-a', 'pkg-b', 'pkg-c']] }); + const plan = assembleReleasePlan(changesets, packages, graph, config); + + expect(plan.releases).toHaveLength(3); + for (const r of plan.releases) { + expect(r.type).toBe('minor'); + expect(r.newVersion).toBe('1.1.0'); + } + }); + + test('fixed group re-applied after propagation', () => { + // core and types are in a fixed group. Bumping core causes propagation + // to plugin (via dep), which then should also pull types (fixed group). + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['types', makePkg('types', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { dependencies: { core: '~1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const config = makeConfig({ fixed: [['core', 'types']] }); + const plan = assembleReleasePlan(changesets, packages, graph, config); + + // core gets minor, types gets minor (fixed), plugin gets patch (out-of-range dep) + expect(plan.releases).toHaveLength(3); + expect(plan.releases.find((r) => r.name === 'core')!.type).toBe('minor'); + expect(plan.releases.find((r) => r.name === 'types')!.type).toBe('minor'); + expect(plan.releases.find((r) => r.name === 'plugin')!.type).toBe('patch'); + }); + + test('linked group re-applied after propagation', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin-a', makePkg('plugin-a', '2.0.0', { dependencies: { core: '~1.0.0' } })], + ['plugin-b', makePkg('plugin-b', '3.0.0', { dependencies: { core: '~1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }, + { id: 'cs2', releases: [{ name: 'plugin-a', type: 'minor' }], summary: 'Plugin feature' }, + ]; + + const graph = new DependencyGraph(packages); + const config = makeConfig({ linked: [['plugin-a', 'plugin-b']] }); + const plan = assembleReleasePlan(changesets, packages, graph, config); + + // plugin-a has minor from changeset, plugin-b gets patch from out-of-range propagation + // linked group raises plugin-b to match plugin-a's minor + const pluginA = plan.releases.find((r) => r.name === 'plugin-a')!; + const pluginB = plan.releases.find((r) => r.name === 'plugin-b')!; + expect(pluginA.type).toBe('minor'); + expect(pluginB.type).toBe('minor'); + }); }); - test('specific dependency rules override global rules', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - [ - 'special', - makePkg('special', '1.0.0', { - dependencies: { core: '^1.0.0' }, - bumpy: { - specificDependencyRules: { - core: { trigger: 'none', bumpAs: 'patch' }, + // ---- Phase C: proactive propagation ---- + + describe('Phase C: proactive propagation', () => { + test('cascadeTo works', () => { + const packages = new Map([ + [ + 'core', + makePkg('core', '1.0.0', { + bumpy: { + cascadeTo: { + 'plugin-*': { trigger: 'minor', bumpAs: 'patch' }, + }, }, - }, - }), - ], - ['normal', makePkg('normal', '1.0.0', { dependencies: { core: '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig({ updateInternalDependencies: 'patch' })); - - expect(plan.releases).toHaveLength(2); - expect(plan.releases.find((r) => r.name === 'normal')).toBeDefined(); - expect(plan.releases.find((r) => r.name === 'special')).toBeUndefined(); + }), + ], + ['plugin-a', makePkg('plugin-a', '1.0.0')], + ['plugin-b', makePkg('plugin-b', '1.0.0')], + ['unrelated', makePkg('unrelated', '1.0.0')], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(3); + expect(plan.releases.find((r) => r.name === 'unrelated')).toBeUndefined(); + expect(plan.releases.find((r) => r.name === 'plugin-a')!.type).toBe('patch'); + }); + + test('proactive propagation with updateInternalDependencies: "patch"', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + expect(plan.releases).toHaveLength(2); + const appRelease = plan.releases.find((r) => r.name === 'app')!; + expect(appRelease.type).toBe('patch'); + expect(appRelease.isDependencyBump).toBe(true); + }); + + test('proactive propagation skipped for patch-isolated bumps', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); + + test('peer dependency minor bump does NOT propagate by default (out-of-range mode, range satisfied)', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + // ^1.0.0 satisfies 1.1.0, so no out-of-range propagation + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); + + test('changeset-level cascade overrides', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin-a', makePkg('plugin-a', '1.0.0')], + ['plugin-b', makePkg('plugin-b', '1.0.0')], + ]); + + const changesets: Changeset[] = [ + { + id: 'cs1', + releases: [ + { + name: 'core', + type: 'minor', + cascade: { 'plugin-*': 'patch' as const }, + }, + ], + summary: 'Feature with cascades', + }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(3); + const pluginA = plan.releases.find((r) => r.name === 'plugin-a')!; + const pluginB = plan.releases.find((r) => r.name === 'plugin-b')!; + expect(pluginA.type).toBe('patch'); + expect(pluginA.isCascadeBump).toBe(true); + expect(pluginB.type).toBe('patch'); + expect(pluginB.isCascadeBump).toBe(true); + }); + + test('devDependencies do not propagate by default', () => { + const packages = new Map([ + ['test-utils', makePkg('test-utils', '1.0.0')], + ['app', makePkg('app', '1.0.0', { devDependencies: { 'test-utils': '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'test-utils', type: 'major' }], summary: 'Breaking' }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + // devDeps rule is false by default → never propagates + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('test-utils'); + }); }); - test('fixed groups: all packages get highest bump', () => { - const packages = new Map([ - ['pkg-a', makePkg('pkg-a', '1.0.0')], - ['pkg-b', makePkg('pkg-b', '1.0.0')], - ['pkg-c', makePkg('pkg-c', '1.0.0')], - ]); - - const changesets: Changeset[] = [ - { id: 'cs1', releases: [{ name: 'pkg-a', type: 'minor' }], summary: 'Feature' }, - { id: 'cs2', releases: [{ name: 'pkg-b', type: 'patch' }], summary: 'Fix' }, - ]; - - const graph = new DependencyGraph(packages); - const config = makeConfig({ fixed: [['pkg-a', 'pkg-b', 'pkg-c']] }); - const plan = assembleReleasePlan(changesets, packages, graph, config); - - expect(plan.releases).toHaveLength(3); - for (const r of plan.releases) { - expect(r.type).toBe('minor'); - expect(r.newVersion).toBe('1.1.0'); - } + // ---- patch-isolated behavior ---- + + describe('patch-isolated', () => { + test('patch-isolated skips Phase C propagation', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + expect(plan.releases[0]!.newVersion).toBe('1.0.1'); + }); + + test('non-isolated changeset overrides isolated for same package', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, + { id: 'cs2', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + expect(plan.releases).toHaveLength(2); // core + app (no longer isolated) + }); + + test('patch-isolated that would break range throws error', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: '1.0.0' } })], // exact range + ]); + + const changesets: Changeset[] = [ + { id: 'cs1', releases: [{ name: 'core', type: 'patch-isolated' }], summary: 'Internal' }, + ]; + + const graph = new DependencyGraph(packages); + expect(() => assembleReleasePlan(changesets, packages, graph, makeConfig())).toThrow( + /patch-isolated.*break.*range/, + ); + }); }); - test('devDependencies do not propagate by default', () => { - const packages = new Map([ - ['test-utils', makePkg('test-utils', '1.0.0')], - ['app', makePkg('app', '1.0.0', { devDependencies: { 'test-utils': '^1.0.0' } })], - ]); - - const changesets: Changeset[] = [ - { id: 'cs1', releases: [{ name: 'test-utils', type: 'major' }], summary: 'Breaking' }, - ]; - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); - - expect(plan.releases).toHaveLength(1); - expect(plan.releases[0]!.name).toBe('test-utils'); + // ---- none behavior ---- + + describe('none suppression', () => { + test('none suppresses bump when range is satisfied', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { + id: 'cs1', + releases: [ + { name: 'core', type: 'minor' }, + { name: 'plugin', type: 'none' }, + ], + summary: 'Feature', + }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + // Plugin should NOT be in releases because it's suppressed + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); + + test('none that would break range throws error', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [ + { + id: 'cs1', + releases: [ + { name: 'core', type: 'major' }, + { name: 'plugin', type: 'none' }, + ], + summary: 'Breaking', + }, + ]; + + const graph = new DependencyGraph(packages); + expect(() => assembleReleasePlan(changesets, packages, graph, makeConfig())).toThrow( + /Cannot suppress.*plugin.*none/, + ); + }); }); - test('empty changesets returns empty plan', () => { - const packages = new Map([['pkg-a', makePkg('pkg-a', '1.0.0')]]); - - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan([], packages, graph, makeConfig()); - - expect(plan.releases).toHaveLength(0); - expect(plan.changesets).toHaveLength(0); + // ---- Per-package dependency bump rules ---- + + describe('per-package dependencyBumpRules', () => { + test('per-package rules override global rules', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + [ + 'special', + makePkg('special', '1.0.0', { + dependencies: { core: '^1.0.0' }, + bumpy: { + dependencyBumpRules: { + dependencies: { trigger: 'patch', bumpAs: 'patch' }, + }, + }, + }), + ], + ['normal', makePkg('normal', '1.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + // Both should be bumped because updateInternalDependencies is 'patch' + // and both have dependency bump rules that trigger on patch + expect(plan.releases).toHaveLength(3); + expect(plan.releases.find((r) => r.name === 'special')).toBeDefined(); + expect(plan.releases.find((r) => r.name === 'normal')).toBeDefined(); + }); + + test('per-package rule set to false disables propagation for that dep type', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + [ + 'special', + makePkg('special', '1.0.0', { + dependencies: { core: '^1.0.0' }, + bumpy: { + dependencyBumpRules: { + dependencies: false, + }, + }, + }), + ], + ['normal', makePkg('normal', '1.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + // special should NOT be bumped (rule is false), normal should be + expect(plan.releases).toHaveLength(2); + expect(plan.releases.find((r) => r.name === 'normal')).toBeDefined(); + expect(plan.releases.find((r) => r.name === 'special')).toBeUndefined(); + }); }); - test('transitive dependency propagation', () => { - const packages = new Map([ - ['core', makePkg('core', '1.0.0')], - ['middle', makePkg('middle', '1.0.0', { dependencies: { core: '~1.0.0' } })], - ['app', makePkg('app', '1.0.0', { dependencies: { middle: '~1.0.0' } })], - ]); + // ---- workspace protocol resolution ---- + + describe('workspace protocol resolution', () => { + test('workspace:~ resolved correctly — minor breaks ~range', () => { + const packages = new Map([ + ['core', makePkg('core', '1.2.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: 'workspace:~' } })], + ]); + + // Minor bump: 1.2.0 → 1.3.0, does NOT satisfy ~1.2.0 (>=1.2.0 <1.3.0) + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(2); + expect(plan.releases.find((r) => r.name === 'app')!.type).toBe('patch'); + }); + + test('workspace:~ — patch stays in range', () => { + const packages = new Map([ + ['core', makePkg('core', '1.2.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: 'workspace:~' } })], + ]); + + // Patch bump: 1.2.0 → 1.2.1, satisfies ~1.2.0 + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + }); + + test('workspace:* is always satisfied — no propagation', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '1.0.0', { dependencies: { core: 'workspace:*' } })], + ]); + + // Even a major bump should not propagate + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); + + test('workspace:^ on 0.x peer dep — minor breaks range, gets minor bump', () => { + const packages = new Map([ + ['core', makePkg('core', '0.2.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: 'workspace:^' } })], + ]); + + // Minor bump: 0.2.0 → 0.3.0, workspace:^ resolves to ^0.2.0, breaks range + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(2); + const pluginRelease = plan.releases.find((r) => r.name === 'plugin')!; + expect(pluginRelease.type).toBe('minor'); // matches triggering bump + expect(pluginRelease.isDependencyBump).toBe(true); + expect(plan.warnings.length).toBeGreaterThan(0); + }); + + test('workspace:^ on 0.x peer dep — patch stays in range', () => { + const packages = new Map([ + ['core', makePkg('core', '0.2.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: 'workspace:^' } })], + ]); + + // Patch bump: 0.2.0 → 0.2.1, workspace:^ resolves to ^0.2.0, stays in range + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + }); + }); - const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + // ---- Additional Phase C scenarios ---- + + describe('Phase C: additional scenarios', () => { + test('cascadeTo below trigger threshold does not cascade', () => { + const packages = new Map([ + [ + 'core', + makePkg('core', '1.0.0', { + bumpy: { + cascadeTo: { + 'plugin-*': { trigger: 'minor', bumpAs: 'patch' }, + }, + }, + }), + ], + ['plugin-a', makePkg('plugin-a', '1.0.0')], + ]); + + // Patch bump on core — below minor trigger threshold + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); + + test('updateInternalDependencies: "minor" skips patch bumps', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'patch' }], summary: 'Fix' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'minor' }), + ); + + // Patch bump on core — below minor threshold, app not bumped + expect(plan.releases).toHaveLength(1); + }); + + test('updateInternalDependencies: "minor" propagates minor bumps', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['app', makePkg('app', '2.0.0', { dependencies: { core: '^1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'minor' }), + ); + + expect(plan.releases).toHaveLength(2); + expect(plan.releases.find((r) => r.name === 'app')!.isDependencyBump).toBe(true); + }); + + test('bumpAs: "match" in Phase C proactive propagation', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: '^1.0.0' } })], + ]); + + // Major bump — peerDeps default rule is { trigger: 'major', bumpAs: 'match' } + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'major' }], summary: 'Breaking' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan( + changesets, + packages, + graph, + makeConfig({ updateInternalDependencies: 'patch' }), + ); + + const pluginRelease = plan.releases.find((r) => r.name === 'plugin')!; + // bumpAs: 'match' means plugin gets major (matching core's bump level) + expect(pluginRelease.type).toBe('major'); + }); + }); - const graph = new DependencyGraph(packages); - const config = makeConfig({ updateInternalDependencies: 'out-of-range' }); - const plan = assembleReleasePlan(changesets, packages, graph, config); + // ---- Multi-phase interaction ---- + + describe('multi-phase interaction', () => { + test('Phase A → Phase B → Phase A across iterations', () => { + // core and types in fixed group. plugin depends on types with tight range. + // Bumping core → fixed group bumps types → types out-of-range breaks plugin → plugin bumps + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['types', makePkg('types', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { dependencies: { types: '~1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + const graph = new DependencyGraph(packages); + const config = makeConfig({ fixed: [['core', 'types']] }); + const plan = assembleReleasePlan(changesets, packages, graph, config); + + // core: minor (explicit), types: minor (fixed group), plugin: patch (types out of range) + expect(plan.releases).toHaveLength(3); + expect(plan.releases.find((r) => r.name === 'core')!.type).toBe('minor'); + expect(plan.releases.find((r) => r.name === 'types')!.type).toBe('minor'); + expect(plan.releases.find((r) => r.name === 'plugin')!.type).toBe('patch'); + }); + + test('long transitive chain stabilizes', () => { + // a → b → c → d, each with tight ranges + const packages = new Map([ + ['a', makePkg('a', '1.0.0')], + ['b', makePkg('b', '1.0.0', { dependencies: { a: '~1.0.0' } })], + ['c', makePkg('c', '1.0.0', { dependencies: { b: '~1.0.0' } })], + ['d', makePkg('d', '1.0.0', { dependencies: { c: '~1.0.0' } })], + ]); + + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'a', type: 'minor' }], summary: 'Feature' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + // a: minor (1.1.0, breaks ~1.0.0) + // b: patch (1.0.1, satisfies ~1.0.0 on c) → chain stops + expect(plan.releases).toHaveLength(2); + expect(plan.releases.find((r) => r.name === 'a')!.type).toBe('minor'); + expect(plan.releases.find((r) => r.name === 'b')!.type).toBe('patch'); + expect(plan.releases.find((r) => r.name === 'c')).toBeUndefined(); + }); + }); - expect(plan.releases.find((r) => r.name === 'core')).toBeDefined(); - expect(plan.releases.find((r) => r.name === 'middle')).toBeDefined(); - expect(plan.releases.find((r) => r.name === 'app')).toBeUndefined(); + // ---- none edge cases ---- + + describe('none edge cases', () => { + test('none on a package not otherwise in the plan is a no-op', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['unrelated', makePkg('unrelated', '1.0.0')], + ]); + + const changesets: Changeset[] = [ + { + id: 'cs1', + releases: [ + { name: 'core', type: 'minor' }, + { name: 'unrelated', type: 'none' }, + ], + summary: 'Feature', + }, + ]; + + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + + expect(plan.releases).toHaveLength(1); + expect(plan.releases[0]!.name).toBe('core'); + }); }); - test('multi-package changeset bumps all listed packages', () => { - const packages = new Map([ - ['pkg-a', makePkg('pkg-a', '1.0.0')], - ['pkg-b', makePkg('pkg-b', '2.0.0')], - ]); + // ---- Warnings ---- - const changesets: Changeset[] = [ - { - id: 'cs1', - releases: [ - { name: 'pkg-a', type: 'minor' }, - { name: 'pkg-b', type: 'patch' }, - ], - summary: 'Cross-package change', - }, - ]; + describe('warnings', () => { + test('workspace:* on peer dep generates warning', () => { + const packages = new Map([ + ['core', makePkg('core', '1.0.0')], + ['plugin', makePkg('plugin', '1.0.0', { peerDependencies: { core: 'workspace:*' } })], + ]); - const graph = new DependencyGraph(packages); - const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); + const changesets: Changeset[] = [{ id: 'cs1', releases: [{ name: 'core', type: 'minor' }], summary: 'Feature' }]; + const graph = new DependencyGraph(packages); + const plan = assembleReleasePlan(changesets, packages, graph, makeConfig()); - expect(plan.releases).toHaveLength(2); - expect(plan.releases.find((r) => r.name === 'pkg-a')!.newVersion).toBe('1.1.0'); - expect(plan.releases.find((r) => r.name === 'pkg-b')!.newVersion).toBe('2.0.1'); + expect(plan.warnings.some((w) => w.includes('workspace:*') && w.includes('plugin'))).toBe(true); + }); }); }); diff --git a/packages/bumpy/test/core/semver.test.ts b/packages/bumpy/test/core/semver.test.ts index 1cf3bc8..c61d3f6 100644 --- a/packages/bumpy/test/core/semver.test.ts +++ b/packages/bumpy/test/core/semver.test.ts @@ -61,17 +61,34 @@ describe('satisfies', () => { expect(satisfies('1.0.0', '')).toBe(true); }); - // workspace: protocol handling - test('workspace:^ always satisfies', () => { + // workspace: protocol handling with currentVersion + test('workspace:^ resolved to ^', () => { + // dep is at 1.2.0, workspace:^ → ^1.2.0 + // 1.3.0 satisfies ^1.2.0 + expect(satisfies('1.3.0', 'workspace:^', '1.2.0')).toBe(true); + // 2.0.0 does NOT satisfy ^1.2.0 + expect(satisfies('2.0.0', 'workspace:^', '1.2.0')).toBe(false); + }); + + test('workspace:~ resolved to ~', () => { + // dep is at 1.2.0, workspace:~ → ~1.2.0 + // 1.2.5 satisfies ~1.2.0 + expect(satisfies('1.2.5', 'workspace:~', '1.2.0')).toBe(true); + // 1.3.0 does NOT satisfy ~1.2.0 + expect(satisfies('1.3.0', 'workspace:~', '1.2.0')).toBe(false); + }); + + test('workspace:^ without currentVersion always satisfies (fallback)', () => { expect(satisfies('2.0.0', 'workspace:^')).toBe(true); }); - test('workspace:~ always satisfies', () => { + test('workspace:~ without currentVersion always satisfies (fallback)', () => { expect(satisfies('2.0.0', 'workspace:~')).toBe(true); }); test('workspace:* always satisfies', () => { expect(satisfies('2.0.0', 'workspace:*')).toBe(true); + expect(satisfies('99.0.0', 'workspace:*', '1.0.0')).toBe(true); }); test('workspace: with real range checks the range', () => { diff --git a/packages/bumpy/test/helpers.ts b/packages/bumpy/test/helpers.ts index 5e74793..33cbe4a 100644 --- a/packages/bumpy/test/helpers.ts +++ b/packages/bumpy/test/helpers.ts @@ -70,7 +70,7 @@ export function makeChangeset( /** Create a ReleasePlan for testing */ export function makeReleasePlan(releases: PlannedRelease[], changesets: Changeset[] = []): ReleasePlan { - return { releases, changesets }; + return { releases, changesets, warnings: [] }; } // ---- Temp git repo helpers ---- From b6554b7ccf895b521b7658ad768a0a28399a8aea Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Fri, 17 Apr 2026 21:18:56 -0700 Subject: [PATCH 2/2] Update DIFFERENCES_FROM_CHANGESETS.md for propagation refactor Co-Authored-By: Claude Opus 4.6 (1M context) --- DIFFERENCES_FROM_CHANGESETS.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/DIFFERENCES_FROM_CHANGESETS.md b/DIFFERENCES_FROM_CHANGESETS.md index 0836b81..bd034bd 100644 --- a/DIFFERENCES_FROM_CHANGESETS.md +++ b/DIFFERENCES_FROM_CHANGESETS.md @@ -8,15 +8,36 @@ Bumpy is built as a modern successor to [@changesets/changesets](https://github. ### Sane dependency bump propagation -Changesets hardcodes aggressive behavior: a **minor** bump on a package triggers a **major** bump on all packages that peer-depend on it. This is the single biggest community complaint. Bumpy makes propagation **fully configurable** at 5 levels with sensible defaults (peer deps only trigger on major, dev deps never propagate). +Changesets hardcodes aggressive behavior: a **minor** bump on a package triggers a **major** bump on all packages that peer-depend on it. This is the single biggest community complaint. + +Bumpy splits propagation into three phases inside an iterative loop: + +- **Phase A (always runs):** fixes broken version ranges — peer dep bumps match the triggering bump level, regular deps get patch, dev deps are skipped. Cannot be disabled. +- **Phase B:** enforces fixed/linked group constraints. +- **Phase C (opt-in):** proactive propagation via configurable `dependencyBumpRules` and `cascadeTo` rules. Off by default (`updateInternalDependencies: "out-of-range"`). + +Key differences from changesets: + +- Out-of-range peer dep bumps match the triggering bump level (not always major) — a minor bump on `core` → minor bump on `plugin`, not major +- Dev deps never propagate by default (configurable per-package for bundled devDeps) +- `cascadeTo` config for source-side "when I change, cascade to these packages" +- Per-changeset `none` and `patch-isolated` to suppress propagation on specific changes +- Warns about `^0.x` caret range gotchas and `workspace:*` on peer deps + +See [docs/version-propagation.md](docs/version-propagation.md) for the full algorithm. - [changesets#1011](https://github.com/changesets/changesets/issues/1011) — peerDependencies cause unnecessary major bumps (70+ thumbs-up) - [changesets#822](https://github.com/changesets/changesets/issues/822) — unexpected major version bumps from peer deps - [changesets#1126](https://github.com/changesets/changesets/issues/1126) — peer dep bumping is too aggressive -- [changesets#1228](https://github.com/changesets/changesets/issues/1228) — allow configuring peer dep bump behavior +- [changesets#1228](https://github.com/changesets/changesets/issues/1228) — allow configuring peer dep bump behavior / 0.x versions - [changesets#827](https://github.com/changesets/changesets/issues/827) — peer dep bump propagation should be configurable - [changesets#960](https://github.com/changesets/changesets/issues/960) — unexpected version bumps in monorepos - [changesets#944](https://github.com/changesets/changesets/issues/944) — devDependencies should be configurable (17 thumbs-up) +- [changesets#568](https://github.com/changesets/changesets/issues/568) — allow dependents to not be automatically bumped +- [changesets#1128](https://github.com/changesets/changesets/issues/1128) — `updateInternalDependencies` only on certain packages +- [changesets#808](https://github.com/changesets/changesets/issues/808) — ignore some packages on `updateInternalDependencies` +- [changesets#1819](https://github.com/changesets/changesets/issues/1819) — support major version propagation to dependents (`bumpAs: "match"`) +- [changesets#1735](https://github.com/changesets/changesets/issues/1735) — unidirectional dependency relationships (solved by `cascadeTo`) ### Custom publish commands @@ -34,6 +55,7 @@ Changesets uses `npm publish` even in Yarn/pnpm workspaces, so `workspace:^` and - [changesets#432](https://github.com/changesets/changesets/issues/432) — workspace: ranges not resolved (33 comments) - [changesets#1290](https://github.com/changesets/changesets/issues/1290) — workspace:^ not handled correctly +- [changesets#1421](https://github.com/changesets/changesets/issues/1421) — workspace:^ bumped on patch despite `updateInternalDependencies: "minor"` - [changesets#1229](https://github.com/changesets/changesets/issues/1229) — workspace: protocol causes publish failures - [changesets#1468](https://github.com/changesets/changesets/issues/1468) — workspace:^ published as-is (16 thumbs-up) - [changesets#1454](https://github.com/changesets/changesets/issues/1454) — publishing with Yarn is broken (38 thumbs-up) @@ -119,7 +141,7 @@ Custom changelog formatters with full context (release info, changesets, dates). ### CI without a separate action -`bumpy ci check` and `bumpy ci release` handle PR checks and release automation without needing a separate GitHub Action or bot installation. Just `bunx @varlock/bumpy ci check` in any workflow. +`bumpy ci check` and `bumpy ci release` handle PR checks and release automation without needing a separate GitHub Action or bot installation. Just `bunx @varlock/bumpy ci check` in any workflow. No extra repository to trust, audit, or pin — your CI runs the same package you already depend on. ### Local changeset verification