Skip to content

[experimental] export: a package linked from a folder inside the project is a package, so --reverse gives the page back - #12733

Closed
josephfarina wants to merge 7 commits into
mainfrom
josephfarina/rl-export-linked-package
Closed

josephfarina wants to merge 7 commits into
mainfrom
josephfarina/rl-export-linked-package

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Someone exports a page that imports a package linked from a folder inside the same project: npm link, a file: dependency, or a workspace package that node_modules links to its own folder. Then they give the file back with astryx experimental export --reverse. The reverse refuses the file as damaged, so the page cannot come back, even though the export looked fine.

Problem and solution fit

  • Why it happens: Node gives the export the real path of a linked package's modules. That path is inside the project and outside node_modules, so the export carried those modules as page files. The page imports them by package name, so the reverse never reached them from the page, and it read the carried set as damaged.
  • Why it harms the task: --reverse is the way back to an editable page, and it fails for a common project layout.
  • Why that matters: linked and workspace packages are a normal way to share code inside one project.

The fix treats a package that node_modules links to a folder inside the project as a package. The export still compiles and draws it as today, with the same styles, server render and page script, but it does not carry its modules as page files or follow their imports as page files. Images a linked package imports stay carried.

Expected behavior and authority

--reverse gives back the page as written, with exact: true when every carried file comes back (architecture:cli-surface, the export guide). A package is not a page file, wherever its folder is.

Smallest restoration

  • foundation/render/page-worker.mjs: linkedPackageRoots() lists the top level (with @scope/*) of each node_modules folder from the page's folder up. An entry that is a symlink whose real path is inside the carried folder, outside node_modules and not a folder that holds the page is a linked package root. The node_modules folders of each linked package (and of the folders above it) are read too, as a workspace links one package into another. Compiling, the server render and the page's script are unchanged.
  • When there is a linked root, the file carries what the page reaches by a path, the way --reverse walks it: from the page through each relative or path-alias import of a carried module (modules, JSON, stylesheets, ?raw files). A linked package's files that the page reaches only through the package's name stay the package's, and so do the project files that only the package's modules import: none is carried or named as not carried. Images stay carried, because the page's script reads them from the file, and an image that only a linked package's module names as a string (drawn later by the script) is still carried and rewritten for the script.
  • foundation/render/render-page.mjs: with a linked root, a stylesheet another one pulls in with @import is carried when any carried stylesheet imports it, whichever imported it first.
  • With no link, the set of roots is empty, and every path is as before (neither step runs).

Evidence

  • Reproduction before the change: an npm link layout, a file: dependency, a linked package with CSS, JSON and an image, and a workspace root that links its own package each export, then --reverse refuses the file as damaged.
  • Result after the change: each exports, --reverse is exact, and a second export gives the same file. For the linked layouts, the markup, the stylesheet and the page's script are byte-identical before and after; only the embedded source block and the list of carried files in the note at the top of the file are smaller.
  • Representative unchanged path: a pnpm workspace app whose package sits outside the project, a pnpm store, a CommonJS package, a plain ES module package, and a page that imports a linked folder's files by a relative path give byte-identical files before and after.
  • A 3,935-case export and --reverse corpus (no links into a carried folder) is byte-identical before and after, apart from pages that differ between two runs of the same CLI (random values, clocks): 0 exit-code changes, 0 message changes, 0 --reverse changes.
  • Regression tests: api/render/render.test.mjs ("what a page imports"): the link and file: round trips, the linked package's styles, JSON and images, a linked folder the page imports by a relative path (carried, exact: true), a linked folder the page imports through a path alias (carried, exact: true, nothing missing when restored outside the project), a linked package that loads before the page's own module reaches its files and stylesheets by their paths (carried, exact: true), a linked package stylesheet that @imports another (inlined, not carried, exact: true), a stylesheet that both the package's and the page's own stylesheets import (carried), a project file that only the linked package imports (not carried, nothing missing), a workspace package that another linked package links in (not carried, exact: true), an image only a linked package's module names for the script (carried), the workspace control, and the unchanged layouts.

Scope

Components: cli export (foundation/render/page-worker.mjs)

  • 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

  • pnpm exec vitest run --project node packages/cli/api/render packages/cli/foundation/render packages/cli/test/export-name.test.mjs packages/cli/foundation/doc-compiler/doc-loads.test.mjs packages/cli/test/lazy-dependencies.test.mjs packages/cli/clients/cli/commands/text-json-parity.test.mjs (all pass at this head).
  • node scripts/check-changesets.mjs.
  • eslint and the CLI typechecks.

preflight: pass 14b1187 (test-node left to the batch: 1646 files)

@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 19, 2026 4:44am 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 19, 2026, 4:52 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

@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.

Changes requested: one regression in which files the export carries.

The fix works for pages that import a linked package by its name: the three new tests fail on the base with ERR_RENDER_SOURCE_DAMAGED and pass here, and the markup, stylesheet and page script are unchanged.

Blocking

  • page-worker.mjs:1926-1935 (and the same folder-only test at :786, :814 and :866) drops a file that the page imports by a relative path from a linked folder, such as ./vendor/badge/src/index.js while node_modules/@acme/rel links vendor/badge, without carrying it or recording it as not carried, so a page that came back exactly before now comes back with exact: false and that file in missing; carry such a target when a carried module imports it by a relative path, skip a linked stylesheet or JSON file only when its importer is not carried, and add a test for that layout.

Once that is fixed and tested, the rest of the change is ready.

Claims and files checked

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

Claims

  • Changeset: a package that node_modules links into the project is treated as a package, and --reverse gives the page back exactly: verified for imports by package name (the three new tests in render.test.mjs pass here and fail on the base); false for a page that imports the linked folder by a relative path (the blocking finding).
  • Changeset: the page looks and runs the same: verified; the stylesheet, page script and rendered markup are byte-identical between base and head for the linked layouts.
  • Body: before the change, --reverse refuses such a file as damaged: verified (ERR_RENDER_SOURCE_DAMAGED on the base for all three layouts).
  • Body: Node gives the export the real path, so it carried those modules as page files: verified (isLocal is path-based, page-worker.mjs:228; the base carries the package modules).
  • Body: the export still compiles and draws the package with the same styles, server render and script: verified (same comparison).
  • Body: a linked package's modules are not carried or followed as page files: verified (page-worker.mjs:1183, :1926).
  • Body: images a linked package imports stay carried: verified (render.test.mjs:565 expects vendor/kit/src/parts/logo.png; the asset site at page-worker.mjs:880 is unchanged).
  • Body: linkedPackageRoots() reads each node_modules folder (with @scope/*) from the page's folder up and keeps symlinks into the carried folder, outside node_modules, that do not hold the page: verified (page-worker.mjs:243-283).
  • Body: a file under such a root still compiles but is not carried or followed: verified; this is also the source of the blocking finding.
  • Body: with no link, every path is as before: verified (an empty root list short-circuits at page-worker.mjs:286; a no-link page renders the same on base and head).
  • Body: the pnpm workspace app, the pnpm store, a CommonJS package and a plain ES module package behave as before: verified (the head test passes; none of them links into the carried folder).
  • Body: for the linked layouts only the embedded source block changes, and it is smaller: verified (it is about half the size; the note's list of carried files shrinks with it).
  • Body: a second export gives the same file: verified for the rendered markup, which the tests compare.
  • Body: one defect is restored, with no new public API and no internal context: verified.
  • Body: the listed Vitest suite passes at this head, as do eslint and the CLI typechecks: verified (24 files and 860 tests passed, 3 skipped; eslint and both typecheck projects pass).

Files

  • .changeset/export-linked-package.md: clear (a patch for an experimental command; its claim holds for package-name imports).
  • packages/cli/api/render/render.test.mjs: finding; no test covers a relative import into a linked folder.
  • packages/cli/foundation/render/page-worker.mjs: finding; the blocking relative-import drop.

Automated review (maintainer link)

@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.

Changes requested: two fixes before this can land.

The earlier relative-import regression is fixed: a page that imports a linked folder's files by a relative path now gets a file byte-identical to the base's and comes back exactly, and three of the new tests fail on the base and pass here.

Blocking

  • Miss: .changeset/export-linked-package.md fails node scripts/check-changesets.mjs (run by the Lint workflow's repository guardrails step) because its body has no [category] tag and credits @josephfarina on the headline instead of on its own line, so start it with [experimental] as spec:AST-017 FR22 requires and move the credit to its own line.
  • When a page imports a linked package by name and a later module of its own reaches a stylesheet inside that package by a relative path (own.js importing ./vendor/kit/src/parts/badge.css, or a package file such as label.js importing ./label.css), page-worker.mjs:901-903 decides that stylesheet's carry only at its first import, so the file neither carries nor records it while its note says the page can come back exactly, and --reverse returns exact: false with the stylesheet in missing; carry such a stylesheet in the post-render walk (or take the decision out of the inline-once guard) and add a test where the package loads before the page's own module reaches its file.
Claims and files checked

Review mode: incremental; reason: none

  • Claim: a package linked into the project (npm link, a file dependency, a workspace package) is treated as a package, so the reverse gives the page back exactly. Verified: red-first tests fail on the base with a damaged-source refusal and pass here; probes.
  • Claim: the page looks and runs the same. Verified: stylesheet, page script and markup are byte-identical to the base's.
  • Claim: the changeset is a valid release note. False: no category tag, credit not on its own line (changeset check exits 1).
  • Claim: on the base, the reverse refuses these layouts as damaged. Verified: red-first runs for the npm link, styles/JSON/image and workspace-root layouts.
  • Claim: the search lists each node_modules from the page's folder up, with scopes, and keeps links into the carried folder that sit outside node_modules and do not hold the page. Verified: page-worker.mjs:243-283.
  • Claim: a linked file that a carried file imports by a relative path is carried as before. Verified for direct and mixed imports (new relative-import test, probes); false when the package loaded first (second blocking finding).
  • Claim: stylesheet, JSON and raw imports use the same importer check. Partly false: the stylesheet check runs once per stylesheet (page-worker.mjs:901-903).
  • Claim: with no link, every path is as before. Verified: code, and byte-identical files for the no-link, pnpm store, pnpm workspace app and ES module layouts.
  • Claim: images a linked package imports stay carried. Verified: the styles/JSON/images test.
  • Claim: each fixed layout exports, reverses exactly, and a second export gives the same file. Verified: probes.
  • Claim: a CommonJS package is unchanged. Verified by its round trip on the head; not compared byte-for-byte with the base.
  • Claim: a 3,935-case corpus is byte-identical. Not reproducible here; the corpus is not in the repository.
  • Claim: the listed tests, eslint and the CLI typechecks pass. Verified: 861 passed, 3 skipped; eslint and typecheck exit 0.
  • File .changeset/export-linked-package.md: finding (category tag and credit line).
  • File packages/cli/api/render/render.test.mjs: clear; the late-loading layout has no test yet (second finding).
  • File packages/cli/foundation/render/page-worker.mjs: finding (stylesheet carry at lines 901-903).

Automated review (maintainer link)

@josephfarina
josephfarina changed the base branch from josephfarina/rl-reverse-alias-on-236ff3e to main November 19, 2026 03:47
@josephfarina
josephfarina force-pushed the josephfarina/rl-export-linked-package branch from 49f0d4a to 3f5bd34 Compare November 19, 2026 04:02

@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: CI has not run on this head yet, because the pull request is a draft and its latest commits skip CI.

Pages that import a package linked inside their own project now come back exactly from --reverse: eight of the ten new tests fail on main with the damaged-source refusal and pass here, and the exported file's markup, styles and script are unchanged. Both earlier findings (a relative import into a linked folder, and a linked stylesheet reached after the package loaded) are fixed and covered by tests.

Claims and files checked

Review mode: full; reason: rebase

  • Claim: a package linked into the project (npm link, a file dependency, a workspace package) is treated as a package, so the reverse gives the page back exactly. Verified: eight new tests fail on main with a damaged-source refusal and pass here.
  • Claim: the page looks and runs the same. Verified: the markup, stylesheet and script match main's byte for byte in every linked layout probed.
  • Claim: the release note is a valid experimental patch note. Verified: the changeset check passes.
  • Claim: on main, the reverse refuses these layouts as damaged. Verified: red-first runs.
  • Claim: the search reads each node_modules folder from the page's folder up, with scopes, keeps links into the carried folder that sit outside node_modules and do not hold the page, and also reads each linked package's node_modules. Verified: page-worker.mjs:245-300 and the nested workspace test.
  • Claim: with a link, the file carries what the page reaches by a path, through relative and path-alias imports of modules, JSON, stylesheets and raw files. Verified: page-worker.mjs:1685-1723 and the relative, alias and late-reach tests.
  • Claim: a linked package's files reached only by its name, and project files only it imports, are neither carried nor named as not carried. Verified: the project-file test and probes.
  • Claim: images stay carried, including one a linked module names only as a string for the script. Verified: the styles, JSON and images test and the script-image test.
  • Claim: with a link, a stylesheet another pulls in with @import is carried when any carried stylesheet imports it, whichever imported it first. Verified: render-page.mjs:1419-1437, the shared-stylesheet test, and probes in both load orders.
  • Claim: with no link, every path is as before. Verified: code, and identical files for layouts with no link and for a project whose link the page never uses.
  • Claim: each fixed layout exports, reverses exactly, and the restored page renders the same markup again. Verified: tests and probes.
  • Claim: the pnpm workspace app, pnpm store, CommonJS, ES module and relative-import layouts are unchanged. Verified: the same size, markup, styles, script and carried files as main.
  • Claim: a 3,935-case corpus is byte-identical before and after. Not reproducible here: the corpus is not in the repository.
  • Claim: the listed tests, the changeset check, eslint and the CLI typechecks pass. Verified: 868 passed and 3 skipped; the other checks exit 0.
  • File .changeset/export-linked-package.md: clear.
  • File packages/cli/api/render/render.test.mjs: clear.
  • File packages/cli/foundation/render/page-worker.mjs: clear.
  • File packages/cli/foundation/render/render-page.mjs: clear.

Automated review (maintainer link)

@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: CI has not run on this head yet, because its latest commit skips CI.

Pages that import a package linked inside their own project (npm link, a file: dependency, a workspace package) now come back exactly from --reverse: eight of the ten new tests fail on the base with the damaged-source refusal and pass here. The latest commit makes the late-image test check the script for the image path in any quote style, so it can now fail; no other code changed since the last review.

Claims and files checked

Review mode: incremental; reason: none

  • Claim: a package linked inside the project (npm link, a file dependency, a workspace package) is treated as a package, its modules are no longer carried, and the reverse gives the page back exactly instead of refusing it. Verified: eight new tests fail on the base with a damaged-source refusal and pass here.
  • Claim: the page looks and runs the same. Verified: earlier base-against-head probes, on product code unchanged since, show the same markup, stylesheet and script for every linked layout.
  • Claim: the release note is a valid experimental patch note. Verified: the changeset check passes.
  • Claim: Node reports a linked package's real path inside the project, so the export carried its modules and the reverse never reached them. Verified: the base's refusal names exactly those modules.
  • Claim: the page still compiles and draws as before, with the same styles, server render and script. Verified: the compile path is unchanged; only the carried list changes.
  • Claim: images a linked package imports stay carried. Verified: the styles, JSON and images test.
  • Claim: the search reads each node_modules folder from the page's folder up, with scopes, keeps links into the project that sit outside node_modules and do not hold the page, and also reads each linked package's node_modules. Verified: page-worker.mjs:245-305 and the nested workspace test.
  • Claim: with a link, the file carries what the page reaches by a path, through relative or path-alias imports of modules, JSON, stylesheets and raw files. Verified: page-worker.mjs:1685-1723 and the relative, alias and late-reach tests.
  • Claim: a linked package's files reached only by its name, and project files only it imports, are neither carried nor named as not carried. Verified: the project-file test.
  • Claim: an image only a linked module names for the script is carried and rewritten for it. Verified: the late-image test, which now fails if the script keeps the path in any quote style.
  • Claim: with a link, a stylesheet another pulls in with @import is carried when any carried stylesheet imports it, whichever imported it first. Verified: render-page.mjs:304 and :1419-1437, and the shared-stylesheet test.
  • Claim: with no link, every path is as before. Verified: each new branch runs only with a link, and the unchanged-layout test passes.
  • Claim: each fixed layout exports, reverses exactly, and renders the same again. Verified: each test renders the restored page again and gets the same markup.
  • Claim: the workspace app, pnpm store, CommonJS, ES module and relative-import layouts give byte-identical files. Verified: earlier probes on the same product code give the same bytes.
  • Claim: a 3,935-case corpus is byte-identical before and after. Not reproducible here: the corpus is not in the repository.
  • Claim: the listed tests, the changeset check, eslint and the CLI typechecks pass. Verified: 868 passed and 3 skipped; the other checks exit 0.
  • Claim: the author's preflight passed at this head. Not reproducible here; the scoped checks it names pass.
  • Claim: one defect is restored, with no tagalong, no new public API, default or interaction, and no internal context. Verified: one carry rule changes, no export or option changes, and no internal reference is added.
  • File .changeset/export-linked-package.md: clear.
  • File packages/cli/api/render/render.test.mjs: clear.
  • File packages/cli/foundation/render/page-worker.mjs: clear.
  • File packages/cli/foundation/render/render-page.mjs: clear.

Automated review (maintainer link)

josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12367 [experimental] export: checks the file it wrote and names the one file to share
  Author: @josephfarina
- #12405 [experimental] export: the size output names each part of the file under its JSON key
  Author: @josephfarina
- #12295 fix(Markdown): keep task lists inside their column
  Author: @josephfarina
- #12696 docs: Toast needs no provider; Table hooks name their row-type generic
  Author: @josephfarina
- #12733 [experimental] export: a package linked from a folder inside the project is a package, so --reverse gives the page back
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12859.

@github-actions
github-actions Bot deleted the josephfarina/rl-export-linked-package branch November 20, 2026 06:06

This branch was successfully deployed

1 active deployment
Preview — 14b11870 Deployed Nov 19, 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