Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/39392-write-form-move-destination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/cli': patch
---

fix(cli): `os migrate meta --from 18 --write` writes a moved form as a `form` item, or leaves it in its view; it no longer deletes it from the source and writes it nowhere

Clause-②: no
Metadata-protocol: none

Who sees it: a developer upgrading a project with view forms (`form`, `formViews.KEY`, `viewKind: 'form'` items) to protocol 19 with `os migrate meta --from 18 --write`.

- **A moved form is written, with its view block taken out only then.** Before, `--write` listed each form move to `forms[name=OBJECT.KEY]` as written, deleted the block from the view file and wrote no `form` item, so the form (a public intake form included) was gone, the re-run said "no mechanical change remains" and `os validate` could pass. Now the form is written into the stack's `forms:` list with the body the chain converted, and the write report names that line beside the view site (`forms[name=OBJECT.KEY] ← views[i].formViews.KEY`; `--json` adds `movedTo` to the written site).
- **A form's translation tails move the same way.** A `_views.KEY.title` or `submitBehavior` tail moves into the bundle's `forms['OBJECT.KEY']` in the same file, instead of being deleted.
- **Where the destination cannot be written, nothing of the move is.** When the stack's `forms` is built by a call (`forms: exportsOf(forms)`) or another value `--write` cannot edit, the view block stays where it is, the move is listed under "left for you to apply by hand" with the reason, and the run exits 1. Move such a form into your `forms` barrel by hand as a `form` item named `OBJECT.KEY`, then run the command again.
- An internal record form (a record-form slot, no public link, no action that opens it) is still deleted, as before.

If you already ran `--write` on 19.0.0-next.4 or earlier: restore the deleted `form` / `formViews` blocks from version control (or from a `--out` snapshot taken before the write) and run `os migrate meta --from 18 --write` again.
11 changes: 10 additions & 1 deletion packages/cli/src/commands/migrate/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ export function writeOutcomeJson(outcome: WriteOutcome) {
path: w.application.path,
file: w.file,
line: w.line,
// A move to another place of the stack: where its destination was written.
...(w.movedTo ? { movedTo: w.movedTo } : {}),
})),
manual: plan.manual.map((m) => ({
conversionId: m.application.conversionId,
Expand Down Expand Up @@ -842,7 +844,8 @@ function printWriteOutcome(outcome: WriteOutcome, appliedCount: number): void {
console.log('');
} else {
// The files holding the chain's edits; a file holding only the range is the range group's.
const chainFiles = plan.rewrites.filter((r) => plan.written.some((w) => w.file === r.file));
// A moved item's destination counts too: it is the half that keeps the content.
const chainFiles = plan.rewrites.filter((r) => plan.written.some((w) => w.file === r.file || w.movedTo?.file === r.file));
// A partial write says so on its first line, and what it left and why (#38922).
const left = plan.manual.length > 0 ? `; ${plan.manual.length} left because of ${leftBecause(plan)}, listed below` : '';
console.log(chalk.bold(
Expand All @@ -853,6 +856,12 @@ function printWriteOutcome(outcome: WriteOutcome, appliedCount: number): void {
for (const w of plan.written.filter((x) => x.file === r.file)) {
console.log(` ${chalk.dim(`:${w.line}`)} ${w.application.path} ${chalk.dim(`(${w.application.conversionId})`)}`);
}
for (const w of plan.written.filter((x) => x.movedTo?.file === r.file)) {
console.log(
` ${chalk.dim(`:${w.movedTo!.line}`)} ${w.application.to} ← ${w.application.path} `
+ chalk.dim(`(${w.application.conversionId})`),
);
}
}
console.log('');
}
Expand Down
Loading
Loading