Skip to content

Add pks rm and bump the version to 0.6.0 - #70

Merged
dduugg merged 3 commits into
mainfrom
pks-rm-subcommand
Oct 11, 2026
Merged

dduugg merged 3 commits into
mainfrom
pks-rm-subcommand

Conversation

@dduugg

@dduugg dduugg commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

pks rm packs/foo deletes a pack along with what other packs say about it. It removes the pack from their dependencies, ignored_dependencies and visible_to lists, drops the violations their package_todo.yml files record on it (deleting a todo file that ends up empty), and then deletes the pack's directory. Deleting the directory by hand leaves pks validate failing on dependencies that name a missing pack (packwerk-extensions rejects such visible_to entries too) and pks check failing on stale todo entries.

Unless given --force, it refuses to remove a pack that other packs may still use, because once the pack is gone check can't see their references to it:

  • If other packs reference its constants, it lists each one as file:line:column and the constant.
  • If it has Ruby files under lib/ (other than lib/tasks/) that are outside the autoload roots, the Zeitwerk resolver never learns their constants, so references to them can't be checked. Gem-style packs keep their code there, and without this check a gem pack used across a large app was deleted without objection. The experimental parser reads definitions from every file, so the check is skipped with it.

The root pack can't be removed, and neither can a pack with other packs nested inside it, even with --force.

This PR also bumps the version to 0.6.0, so merging it releases v0.6.0.

Fixes #16.

Release

  • auto-release.yml dispatches the v0.6.0 release once this lands on main, since Cargo.toml's version has no tag yet. 0.6.0 is a minor bump because pks rm is a new feature.
  • ## Unreleased in the CHANGELOG is now ## 0.6.0, the heading dist takes the release notes from.
  • e09f637 adds an entry for the warm-cache speedup from Skip reading source files on a warm cache hit via mtime + length #59, the one user-visible change since 0.5.0 that didn't have one.

How this relates to #60

Commits

  • 0841234 makes package_todo.yml writes return errors instead of panicking, so rm can report them.
  • 15a463e adds rm.
  • e09f637 bumps the version and prepares the CHANGELOG.

Design notes

  • Todo files lose only the removed pack's entries. Regenerating them with pks update would also pick up any unrelated drift.
  • The directory is deleted last. A partial delete can take package.yml with it, and then rm could no longer find the pack to clean up the references to it.

Who this affects

  • pks rm is new.
  • pks update reports a failure to write a todo file as an error and exits 2, where it used to panic.

Test plan

  • tests/rm_test.rs: a removal that touches every kind of reference, checked byte for byte and followed by passing validate and check; refusals for references, for unresolvable lib/ code, and for both at once, each leaving the fixture unchanged; --force; the root pack; nested packs; an unknown pack; and a trailing slash.
  • Breaking the lib/tasks/ exclusion fails a test.
  • On copies of two large apps, refusals listed 2,461 and 248 references and changed nothing. After forced removals, the todo files had lost only the removed pack's blocks and validate passed in both. check matched its baseline in one, and in the other reported the leftover references against the pack that defines an enclosing namespace, which is how the resolver already treats a missing constant.
  • pks --version prints pks 0.6.0, and CHANGELOG.md has the exact ## 0.6.0 heading that auto-release.yml checks for.
  • cargo test (333 passed, 2 ignored), fmt, and clippy with -Dwarnings.
  • CI passes.

@github-project-automation github-project-automation Bot moved this to Triage in Modularity Oct 2, 2026
@dduugg dduugg changed the title Add pks rm to delete a pack and the references to it Add pks rm and bump the version to 0.6.0 Oct 2, 2026
@iMacTia

iMacTia commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Heya, really keen on getting v0.6.0 released with the ERB fix.
I understand this is currently blocked by #60, is there anything I could do to help move this forward?
If #60 won't budge anytime soon, could we rebase this on top of main and postpone that fix to 0.7.0?

`write_package_todo_to_disk` and `delete_package_todo_from_disk`
unwrapped every IO result, so a failed write or delete panicked.
`pks rm` rewrites or deletes a single pack's todo file and should report
a failure like any other error, so both now return a `Result`, and
`write_violations_to_disk` passes it up to `update`. An `update` that
cannot write a todo file now prints the error and exits 2, where it used
to panic and exit 101.

The `File::create` before each write is gone too: `fs::write` creates
the file itself.
`pks rm packs/foo` deletes the pack's directory after removing it from
other packs' `dependencies`, `ignored_dependencies` and `visible_to`
lists, and dropping the violations their package_todo.yml files record
on it. Deleting only the directory leaves `validate` failing on
dependencies that name a missing pack (packwerk-extensions rejects such
`visible_to` entries too), and `check` failing on stale todo entries.

Each package.yml it changes is rewritten through `write_pack_to_disk`,
as `add-dependency` does, so the file loses its comments and takes
pks's key order. #60 edits these lists as text instead, and once it
lands `rm` can do the same.

Unless given `--force`, it refuses while other packs may still use the
pack, because once the pack is gone `check` cannot see their references
to it:

- Other packs reference its constants. Each reference is listed as
  file:line:column and constant.
- It has Ruby files under lib/, other than lib/tasks/, that the Zeitwerk
  resolver doesn't know because they are outside the autoload roots.
  Gem-style packs keep their code there. Without this check, a widely
  used gem pack in a large app was deleted without objection. The
  experimental parser reads definitions from every file, so the check is
  skipped with it.

The root pack can't be removed, and neither can a pack with other packs
nested inside it, even with `--force`, since the nested packs would go
without their references being removed.

Fixes #16.
`pks rm` is a new command, and pre-1.0 a new feature wants a minor bump.
Once this merges, auto-release.yml tags and releases v0.6.0, since
Cargo.toml's version has no tag yet.

Retitle `## Unreleased` to `## 0.6.0`, the heading dist takes the
release notes from, and add an entry for the one user-visible change in
this release that didn't have one: the warm-cache speedup from skipping
files that haven't changed (#59).
@dduugg
dduugg force-pushed the pks-rm-subcommand branch from 320accf to e09f637 Compare October 11, 2026 20:13
@dduugg

dduugg commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the nudge. I've rebuilt this on main without #60, so it can merge on its own and release 0.6.0 with the ERB fixes.

The cost is that pks rm now rewrites each package.yml it changes, the way add-dependency does, so those files lose their comments and key order until #60 lands. The tests for #60's behavior are still in tests/rm_test.rs, ignored, for #60 to enable once it switches rm over.

@dduugg
dduugg marked this pull request as ready for review October 11, 2026 21:12
@dduugg
dduugg requested a review from a team as a code owner October 11, 2026 21:12
@dduugg
dduugg merged commit bf6919b into main Oct 11, 2026
16 checks passed
@dduugg
dduugg deleted the pks-rm-subcommand branch October 11, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add a pks rm <pack> subcommand

2 participants