Repository navigation
feat(cli): keep your edits when you reinstall a catalog item - #3193
Merged
Merged
Conversation
Running add again overwrote whatever was on disk, so a project that had tuned an installed block lost that work without being asked or told. The installer now records a hash of each file as it installs it, and compares before writing. A file that still matches is replaced as before; one that does not is left alone and reported. A file we have no record of counts as changed, which covers both a project that wrote the file itself and one that installed before the record existed. --force restores the old behaviour for when you do want the registry's version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
hyperframes add <item>no longer overwrites files you have edited. It keeps them, says so, and offers--force.Why
Reinstalling an item, or installing something that depends on it, wrote over whatever was on disk. A project that had tuned a block's colours or timing lost that work with no prompt and no message. Since dependencies install silently, you could lose an edit to a file you did not name.
How
The installer records a SHA-256 of each file as it writes it, in
hyperframes.lock.jsonat the project root, and compares before writing again.Three cases, and the middle one is the point:
The last row is deliberate. An unrecorded file covers a project that wrote it by hand and one that installed before this record existed; both would rather keep their file than have it silently replaced. A malformed or truncated record reads as "no record" for the same reason.
The check runs before fetching rather than after, so a file we are going to keep is never overwritten and then restored — a crash in between would lose it for real. Hashing happens after the block marker comment is added, or the next install would read our own marker as your edit.
This sits in
installItem, soadd, the Studio server's dependency install, and template scaffolding all get it.Test plan
Nine tests in
installer.test.tscover each row above,--force, and the marker case. They are load-bearing: with the guard stubbed out, two fail.Also exercised through the real CLI against a scratch project, since the unit tests mock the fetch:
add data-chart— installs, writes the recordadd data-chartagain — printskept compositions/data-chart.html — you have edited this; --force to overwrite, and the comment is still thereadd data-chart --force— the comment is goneadd data-charton the now-untouched file — updates normally, nothing keptWider suite: 102 passing across
packages/cli/src/registryandadd.test.ts.End-to-end, with a variables-bearing item
Run against
split-flap-board(5 declared variables), following what its catalog page tells a reader to do, against the published registry with no override:hyperframes add split-flap-boardinto a fresh project — writescompositions/split-flap-board.htmland records its hashGATE 42 CLOSING, cell count 12 to 16add split-flap-boardagain — printskept compositions/split-flap-board.html — you have edited this; --force to overwrite, both edits intactGATE 42 CLOSINGacross 16 cells, so the preserved file is still valid and the edits actually take effectadd split-flap-board --force— registry version back, text and cell count restoredadd split-flap-boardonce more — treated as untouched, updates normallyWorth knowing for anyone editing a variables-bearing block: the
defaultinsidedata-composition-variablesfeeds the editing UI, while the composition's own script carries a separate hardcoded fallback (num(vars.cellCount, 1, 24, 12)). Changing the declared default alone changes nothing on screen unless a host passes variables in. Both were preserved here; only the second one moved pixels.The dependency plan is covered too:
addinstalls dependencies first and the requested item last, so the record has to accumulate across items rather than be rewritten per item. Two tests pin that — every item keeps its record entry, and an edit to one item survives while another updates normally.