Skip to content

Monorepo: a package's patch and replace reach workspaces that do not depend on it #65

Closed

Description

@tenphi

In short

  • In a monorepo, a patch or replace from one workspace's dependency changes the shared unit for every workspace, including workspaces that do not depend on that package.
  • Spec 3.6 says "Each workspace is resolved on its own dependencies", so a workspace that depends only on @tenphi/glaze should get Glaze's own rule and skill.
  • Seen on 0.10.0 with @tenphi/cookbook, which patches Glaze's, Tasty's and the lint plugin's rules and, since 0.10, replaces Glaze's glaze-theme skill.

Reproduction

npm workspaces, harnesspm 0.10.0 at the root:

Workspace Dependencies
ui @tenphi/glaze 3.1.1. It builds its own theme with glaze().
site @tenphi/cookbook, whose harness extends Glaze and patches glaze:rules/colors and replaces glaze:skills/glaze-theme

After npx harnesspm init:

$ npx harnesspm -C ui help @tenphi/glaze
...
### Glaze colors (glaze:rules/colors)

Always on. Changed by @tenphi/cookbook: this is the text agents get here.

$ npx harnesspm why glaze:skills/glaze-theme
owner       dependency @tenphi/glaze 3.1.1
source      node_modules/.harnesspm/pkgs/@tenphi/cookbook/harness/skills/glaze-theme/SKILL.md
replaced    by @tenphi/cookbook: ...
original    node_modules/.harnesspm/pkgs/@tenphi/glaze/harness/skills/glaze-theme/SKILL.md

So the agent in ui reads Cookbook's text ("colors come from theme.palette in docs.config.ts", "do not make a Glaze theme of your own"), which is wrong for a workspace with its own glaze() theme. The only glaze-theme skill in the repository is Cookbook's, and Glaze's own skill is not linked anywhere.

The same happens with two harnesses that patch the same section: a workspace on @cube-dev/ui-kit shows "Changed by @cube-dev/ui-kit, @tenphi/cookbook" when another workspace depends on Cookbook.

Why

  • Rule 5 of spec 3.6 keeps one version per package for the whole repository, and the overrides are applied to that one unit.
  • Rule 2 writes units that every workspace shares once, at the root, and skills always go to the root.
  • Rule 1 (each workspace resolved on its own dependencies) is honored for which packages a workspace gets, but not for the overrides that a package in another workspace applies to them.

Proposal

  • Rules: resolve a shared rule's text per workspace, with only the patches and replacements from packages in that workspace's closure. When the texts differ, write the rule in each workspace's block instead of once at the root, and let help and -C <workspace> help print that workspace's text.
  • Skills: a skill is written once at the root, so one replacement can't fit every workspace. Options: keep the original skill when some workspace that uses the package does not depend on the replacing package and warn; or link the replacement under its own name next to the original. Either way, say which choice harnesspm made in why.
  • Until then, the spec and the monorepo guide could say that a package's patches and replacements reach every workspace that uses the patched package.

Cookbook works around it for now: its patches say "in a Cookbook site", and its skill names the original skill for Glaze code outside a site (tenphi/cookbook#210).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions