Skip to content

fix(cli): stored docs routes are the same however Node resolves module imports - #12532

Merged
josephfarina merged 1 commit into
mainfrom
fix/docs-routes-resolution-unrecorded
Nov 18, 2026
Merged

josephfarina merged 1 commit into
mainfrom
fix/docs-routes-resolution-unrecorded

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

User impact

The same commit, packed on two machines, could give two different CLI tarballs. assets/docs-routes.generated.json listed assets/codemods among its inputs on one machine and not on the other, and clients/cli/build-id.generated.json changed with it. Every other file was identical. The build id is meant to stand for the package's contents, so two builds of the same files must give the same id.

Problem and solution fit

  • Why does the file differ? The generator records every file and folder the docs tree touches while it works the routes out (recordReads). That window includes the tree's lazy module imports, and Node's module resolution looks up real paths through fs.realpathSync, which the recorder sees as a probe of each module's folder. assets/codemods holds only modules, so nothing else in the tree records it.
  • Why does it differ between machines? Whether resolution's real-path lookups reach the recorder depends on how that machine's Node resolves modules. Running the generator with --preserve-symlinks, which makes Node resolve without those lookups, reproduces the other machine's file exactly: the same inputs minus assets/codemods, nothing else.
  • Why does the fix close it? The generators register a module.registerHooks resolve hook that runs Node's resolution outside the recording. A module's content is still recorded when it loads, as before. The stored inputs are then what the tree read, on every machine.

Expected behavior and authority

The stored routes and the build id are functions of the published files (published-copy.mjs: "what they read there, folders included, is what an installed package holds"). No record states these generators' inputs.

Smallest restoration

  • published-copy.mjs: resolutionUnrecorded(pkg), runner source that keeps module resolution out of the copy's recorder. Before module.registerHooks (Node 22.15) the run records as it did before.
  • generate-docs-routes.mjs and generate-self-audit.mjs (the same recording pattern) use it. The self-audit's stored file is byte-identical before and after on this machine; it gets the hook so the same drift cannot reach it.
  • The other stored generators: stored docs, template components, command list and manifest record no reads. The component list records reads only under its copy of Core, whose files it reads and never imports, so the CLI modules it imports are outside what it stores. The search catalog records exactly (each path by what the call returned). A module that resolution looks up is the same module that its load then reads, so its stored paths do not depend on whether resolution reaches the recorder. Its stored file was identical on both machines.

Evidence

  • Reproduction before the change: the new test fails because assets/codemods is only in the default run's inputs, not the --preserve-symlinks run's.
  • Result after the change: both runs give byte-identical text. That text equals the default run's old text minus assets/codemods, which matches the machine that left it out.
  • Representative unchanged path: the routes themselves are unchanged; the self-audit file is unchanged; packed docs-routes, packed self-audit, stored-docs and read-record tests pass.
  • Cross-machine pack (pnpm pack in packages/cli, the same commit on two machines with different Node builds): before the change, the two packs differ in docs-routes.generated.json and build-id.generated.json. After it, 0 of 3,473 files differ, and the uncompressed tar is byte-identical, headers included. On the machine that left the folder out, the packs before and after are byte-identical .tgz files. The compressed bytes still differ between the two Node builds, because each Node's zlib compresses differently; the contents do not.

Scope

Components: CLI publish-time generators

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • CI=1 pnpm vitest run --project node packages/cli/scripts packages/cli/test/packed-docs-routes.test.mjs packages/cli/test/packed-self-audit.test.mjs packages/cli/test/packed-stored-docs.test.mjs packages/cli/foundation/doc-compiler/doc-loads.test.mjs packages/cli/foundation/fs/read-record.test.mjs
  • typecheck (no new errors), prettier, pnpm check:changesets

@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 18, 2026 12:57am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 18, 2026, 1:16 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 2c513f4

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: required checks, including the test-node shards that run the new test, have not finished on this head yet.

Keeping Node's module resolution out of what the docs-routes and self-audit generators record restores the rule that the build id stands for the package's contents. Packs of this head under Node 24 and Node 22.13 are identical, where the base packs differ in the stored docs routes and the build id, and the new test fails on the base and passes here. Nothing needs to change.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Changeset, same stored routes and build id on every machine that packs the same files: verified. The head packs under Node 24.20 and 22.13.1 match file for file, and the build id hashes the stored routes file (generate-build-id.mjs:41-66).
  • Changeset, how Node resolves imports no longer changes which folders the stored routes list: verified. On the head, the default and --preserve-symlinks runs give byte-identical text (new test).
  • Before the fix, two packs of one commit differ only in the docs routes and the build id: verified. The base packs under the two Node builds differ in exactly those two files.
  • The recorder logs resolution's real-path lookups as a probe of the module's folder, and assets/codemods is reached only that way: verified (read-record.mjs:68, :127). It is the only input that differs.
  • --preserve-symlinks reproduces the other machine's file, the same inputs minus assets/codemods: verified.
  • The hook keeps resolution unrecorded, while module content is still recorded on load: verified. registry.mjs and integration-discovery.mjs stay inputs by content.
  • Before module.registerHooks (Node 22.15) the run records as before: verified (optional call, published-copy.mjs:75).
  • The self-audit's stored file is byte-identical before and after: verified.
  • Stored docs, template components, command list and manifest record no reads, the component list records only under its Core copy, and the search catalog is unaffected: verified. No recordReads appears in those four, the component list's inputs are rooted at the Core copy (generate-component-list.mjs:60), and the search catalog is identical across Node builds.
  • The routes are unchanged, and the packed docs-routes, packed self-audit, stored-docs and read-record tests pass: verified (235 routes; 182 tests pass).
  • After the fix, the cross-machine packs differ in 0 files: verified on a pack without the type-declaration step. That pack holds 2,880 files, so the 3,473 count is not reproduced.
  • On the machine that left the folder out, packs before and after are byte-identical: verified with Node 22.13.1.
  • One defect restored, no new public API, default or interaction: verified.
  • The listed vitest command, prettier and the changeset check pass: verified.
  • .changeset/docs-routes-same-on-every-machine.md: clear
  • packages/cli/scripts/published-copy.mjs: clear
  • packages/cli/scripts/generate-docs-routes.mjs: clear
  • packages/cli/scripts/generate-self-audit.mjs: clear
  • packages/cli/scripts/generate-docs-routes.test.mjs: clear

Automated review (maintainer link)

@josephfarina
josephfarina merged commit 5747fa2 into main Nov 18, 2026
138 checks passed
@github-actions
github-actions Bot deleted the fix/docs-routes-resolution-unrecorded branch November 18, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 2c513f4f Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant