Skip to content

mfe-forge sync ​

Reconcile every host's federation remotes and remote type declarations with the apps on disk, then regenerate the manifest.

Synopsis ​

text
mfe-forge sync [options]

Description ​

sync is the deterministic counterpart to the incremental host registration done by generate. For each host apps/<scope>/host, it computes the expected state from the apps discovered in the same scope (excluding the host itself) and rewrites generated sections only when they differ. Running it twice in a row makes no further changes.

StepFileWhat is written
Hostsapps/<scope>/host/vite.config.tsThe first remotes: { ... } block is replaced with one <federationName>: 'http://localhost:<port>/assets/remoteEntry.js' entry per app in the scope. Remotes that no longer exist are removed.
Typesapps/<scope>/host/src/remotes/declarations.d.tsThe whole file is regenerated: a header comment and one declare module '<federationName>/App' (a default-exported React.ComponentType) per app. The directory is created if missing.
Manifestmfe-forge.manifest.jsonRegenerated on every non-dry run. See manifest format.

Generated sections are overwritten

Hand-written entries inside remotes: { } and any edits to declarations.d.ts are replaced. Put custom remotes or declarations in separate files.

Options ​

FlagTypeDefaultDescription
--hostsbooleanfalseOnly process host vite.config.ts remotes.
--typesbooleanfalseOnly process declarations.d.ts.
--routesbooleanfalseReports src/App.tsx as unchanged with the reason route metadata is represented in the manifest. No route source is modified.
--dry-runbooleanfalseCompute changes without writing any file, including the manifest.
--diffbooleanfalseHuman output lists only changed files. It does not print a content diff.
--checkbooleanfalseExit with 1 if any file changed (or would change, with --dry-run).
--jsonbooleanfalsePrint a JSON result instead of human output.
-h, --helpbooleanShow help.

Selection rules: with none of --hosts, --types, or --routes, both hosts and types are processed. Combining --hosts and --types also processes both. Passing only --routes skips hosts and types.

--check writes unless combined with --dry-run

--check does not imply --dry-run. sync --check on its own updates the files and exits 1. In CI, use sync --check --dry-run to fail without mutating the checkout.

Output ​

Human output lists one line per processed file, followed by a summary:

text
updated apps/shop/host/vite.config.ts (federation remotes)
ok apps/shop/host/src/remotes/declarations.d.ts (remote declarations)

Sync updated 1 file(s)

With --dry-run, the summary reads Sync would update N file(s). When nothing changed, it reads Sync is up to date.

JSON output:

json
{
  "changed": [
    { "file": "apps/shop/host/vite.config.ts", "changed": true, "reason": "federation remotes" }
  ],
  "files": [
    { "file": "apps/shop/host/vite.config.ts", "changed": true, "reason": "federation remotes" },
    {
      "file": "apps/shop/host/src/remotes/declarations.d.ts",
      "changed": false,
      "reason": "remote declarations"
    }
  ],
  "dryRun": false
}

File paths are relative to the workspace root.

Examples ​

bash
mfe-forge sync
bash
mfe-forge sync --dry-run --diff
bash
mfe-forge sync --check --dry-run --json

Failure modes ​

SituationResult
A host's vite.config.ts has no remotes: { blockA warning on stderr, and a changed: false entry with reason warning: remotes block not found in vite.config.ts. Exit code unaffected.
--check and changes neededExit 1.
No hosts in the projectNothing to process; the manifest is still written (unless --dry-run). Exit 0.
Configuration invalidExit 3.

Limitations

  • Remote URLs are always http://localhost:<port>/.... Environment-specific URLs are not generated, and the manifest's environments field is always empty.
  • Remotes are matched to hosts by scope only. A host cannot consume apps from another scope through sync.
  • The remotes block is located with a non-nested pattern that ends at the first }, so keep remote values as plain strings.

Released under the MIT License.