Skip to content

fix(cli): export loads a served package's subpath exported only to imports - #12727

Closed
josephfarina wants to merge 3 commits into
josephfarina/export-page-ts-js-importsfrom
josephfarina/export-served-import-only
Closed

josephfarina wants to merge 3 commits into
josephfarina/export-page-ts-js-importsfrom
josephfarina/export-served-import-only

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Outside a project, astryx experimental export takes some packages from the CLI's package set. A page that imports a subpath such a package exports only under the import condition fails as if the package were not installed (ERR_RENDER_MISSING_DEPENDENCY), or with "Package subpath ... is not defined by exports". A theme package's ./themes/<name>, which astryx theme add writes into the page, is often exported that way. Inside a project the same import works.

Problem and solution fit

  • Why does it fail? Outside a project, a served package resolves through Node's CommonJS resolver, which reads the require condition, so a subpath exported only under import reads as not exported.
  • Why does it harm the task? The page runs in the project, but cannot be exported from outside one.
  • Why does that matter? Theme packages, the most common served integrations, export their theme subpaths this way.

Expected behavior and authority

The page exports outside a project as it renders inside one. A subpath the package does not export keeps today's answer.

Smallest restoration

  • servedImportTarget in foundation/render/served-packages.mjs gives the file a served package exports for a specifier to an ES module import, as Node resolves it: the target its exports give the subpath under the import, node and default conditions (through conditionalExportFile, a confined lookup package-exports.mjs now exports, built on its existing conditionalExportTarget and resolveTarget), kept inside the package and to a regular file.
  • It runs only where the CommonJS resolve of a served package fails with ERR_PACKAGE_PATH_NOT_EXPORTED: the package-set fallback in page-worker.mjs, resolveServed, and the not-exported check. Everything that resolves today resolves the same.

Evidence

  • Reproduction before the change: a served stand-in package whose ./themes/demo is exported only under import fails with ERR_RENDER_MISSING_DEPENDENCY.
  • Result after the change: the page exports and shows the module's text.
  • Representative unchanged path: a subpath exported only under require loads as before; a subpath the package does not export keeps ERR_RENDER_MISSING_DEPENDENCY with the same message.
  • Regression tests: render.test.mjs "a served package whose subpath exports one condition" (three cases).

Scope

Components: CLI experimental export

  • 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 exec vitest run --project node packages/cli/api/render packages/cli/foundation/render packages/cli/foundation/doc-compiler/doc-loads.test.mjs packages/cli/test/export-name.test.mjs packages/cli/foundation/discovery packages/cli/foundation/runtime packages/cli/api/theme/build (2313 passed, 5 skipped)
  • pnpm -F @astryxdesign/cli run typecheck:strict and typecheck:json-api
  • ESLint on the changed files; Prettier passes on served-packages.mjs, package-exports.mjs and the changeset (page-worker.mjs and render.test.mjs fail Prettier on main as well).

preflight: pass f17dbfc

…ports

Outside a project a page takes some packages from the CLI's package set,
and that path resolves through Node's CommonJS resolver, which reads the
require condition. A subpath exported only under import (a theme
package's ./themes/<name>) failed as not installed. When that resolve of
a served package finds the subpath not exported, the export now takes
the target the package's exports give it under the import, node and
default conditions, kept inside the package. Everything that resolved
before resolves the same, and a subpath not exported at all keeps its
answer.
@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 1:15am UTC

Request Review

@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 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, 1:20 AM UTC

@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. The fix makes astryx experimental export load an import-only subpath of a package-set package outside a project, and its new test fails before the change and passes after it. One shared-code fix is needed before approval:

  • servedImportTarget in packages/cli/foundation/render/served-packages.mjs (lines 118-121) re-implements the package-confinement check of resolveTarget in packages/cli/foundation/discovery/package-exports.mjs, so export one confined lookup from that module (for example conditionalExportFile(exportsField, packageDir, subpath, conditions)) and call it, so that a later change to how export targets are confined also reaches the package-set render.

The require-only and not-exported cases behave as before, and the Vitest set the description names, typecheck:strict, ESLint and the changeset check pass on this head.

Claims and files checked

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

  • Claims:
    • Changeset: outside a project, export loads a package-set subpath exported only under import: verified (render.test.mjs "loads a subpath exported only under import", which fails before the change).
    • Changeset: such a page used to fail as if the package were not installed: verified (that test before the change reports the missing-dependency error).
    • Changeset: a subpath the package does not export keeps its answer: verified ("keeps the answer for a subpath the package does not export" gives the same result before and after).
    • Changeset and description: a theme package's ./themes/<name> is often exported this way: verified in part; the CLI imports a theme as <package>/themes/<slug> and accepts an import-only export for it (theme-imports.mjs:200-206), and how common that is cannot be shown from the repository.
    • Description: outside a project, export takes some packages from the CLI's package set: verified (page-worker.mjs:1043-1068).
    • Description: the failure is the missing-dependency refusal, or Node's "not defined by exports" error: verified (the test before the change; the old fallback re-threw the resolver's error).
    • Description: inside a project the same import works: verified (the same page with the package installed in a project renders the module's value).
    • Description: the cause is Node's CommonJS resolver reading the require condition: verified (page-worker.mjs:1063, served-packages.mjs:72-75).
    • Description: the new helper takes the target under import, node and default through the existing export-map reader, kept inside the package and to a regular file: verified (served-packages.mjs:98-123).
    • Description: it runs only where the CommonJS resolve of a served package fails as not exported, at the package-set fallback, resolveServed and the not-exported check: verified (page-worker.mjs:1063, :1389-1393; served-packages.mjs:76-80).
    • Description: everything that resolves today resolves the same: verified (the new code runs only on that error, the require-only test passes before and after, and the Vitest set the description names passes).
    • Description: three regression tests: verified (all three pass on this head; the import-only one fails before the change).
    • Description: no new public API: verified (no package export path reaches foundation/render).
    • Description: public text has no internal context: verified.
    • Description: typecheck and ESLint pass, Prettier passes on served-packages.mjs and the changeset, and page-worker.mjs and render.test.mjs fail Prettier before the change too: verified.
    • Description: the Vitest run over the render, doc-loads, export-name, discovery and runtime tests passes (1706 passed, 3 skipped): verified (the same set gives 1706 passed, 3 skipped on this head).
  • Files:
    • .changeset/export-served-import-only-subpath.md: clear.
    • packages/cli/api/render/render.test.mjs: clear.
    • packages/cli/foundation/render/page-worker.mjs: clear.
    • packages/cli/foundation/render/served-packages.mjs: finding (copies the confinement check of resolveTarget).

Automated review (maintainer link)

package-exports.mjs exports conditionalExportFile, the confined file a
subpath maps to under given conditions, built on conditionalExportTarget
and resolveTarget. servedImportTarget calls it instead of repeating the
confinement check.

@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. The confinement fix from the last review is in: servedImportTarget now calls the shared conditionalExportFile, and the new tests, the Vitest set the description names, both typechecks and ESLint pass on this head. One shared-code fix remains, which the last review missed:

  • Miss: servedImportTarget in packages/cli/foundation/render/served-packages.mjs (lines 101-112) re-implements the upward node_modules lookup of findNodeModulesPackage in packages/cli/foundation/fs/paths.mjs, so call that helper and pass its packageDir to conditionalExportFile, so that a later fix to the shared lookup also reaches the package-set render.
Claims and files checked

Review mode: incremental; reason: none

  • Changed rules (0): none.
  • Claims:
    • Changeset: outside a project, export loads a package-set subpath exported only under import: verified (render.test.mjs "loads a subpath exported only under import", which fails before the change).
    • Changeset: such a page used to fail as if the package were not installed: verified (before the change that test gets the missing-dependency error).
    • Changeset: a subpath the package does not export keeps its answer: verified ("keeps the answer for a subpath the package does not export").
    • Changeset and description: a theme package's ./themes/<name>, which astryx theme add writes, is often exported this way: verified in part; theme add records <package>/themes/<slug> and accepts an import-only export for it (theme-imports.mjs:200-206), and how common that is cannot be shown from the repository.
    • Description: outside a project, export takes some packages from the CLI's package set: verified (page-worker.mjs:1039-1068).
    • Description: the failure is the missing-dependency refusal, or Node's "not defined by exports" error: verified (the test before the change; the old fallback re-threw the resolver's error).
    • Description: inside a project the same import works: verified (the same page renders with the package installed in a project).
    • Description: the cause is Node's CommonJS resolver reading the require condition: verified (page-worker.mjs:1063, served-packages.mjs:72-75).
    • Description: servedImportTarget takes the target under import, node and default through conditionalExportFile, built on conditionalExportTarget and resolveTarget, kept inside the package and to a regular file: verified (served-packages.mjs:98-120, package-exports.mjs:253-261).
    • Description: it runs only where the CommonJS resolve of a served package fails as not exported, at the package-set fallback, resolveServed and the not-exported check, and everything that resolves today resolves the same: verified (page-worker.mjs:1078-1087, :1389-1393; served-packages.mjs:76-80; the require-only test).
    • Description: three regression tests: verified (all three pass on this head).
    • Description: no new public API: verified (no package export path reaches foundation/render or foundation/discovery).
    • Description: public text has no internal context: verified.
    • Description: the Vitest set passes with 2313 passed and 5 skipped: verified (the same counts on this head).
    • Description: typecheck:strict and typecheck:json-api pass: verified.
    • Description: ESLint passes on the changed files, Prettier passes on served-packages.mjs, package-exports.mjs and the changeset, and page-worker.mjs and render.test.mjs fail Prettier on main as well: verified.
  • Files:
    • .changeset/export-served-import-only-subpath.md: clear.
    • packages/cli/api/render/render.test.mjs: clear.
    • packages/cli/foundation/discovery/package-exports.mjs: clear.
    • packages/cli/foundation/render/page-worker.mjs: clear.
    • packages/cli/foundation/render/served-packages.mjs: finding (re-implements the lookup of findNodeModulesPackage).

Automated review (maintainer link)

…ModulesPackage

servedImportTarget finds the served package's folder with
findNodeModulesPackage, the lookup the worker already uses to decide
where a package-set package comes from, instead of its own upward walk.

@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. Both shared-code fixes from the earlier reviews are in: servedImportTarget now finds the package with findNodeModulesPackage and confines the target with conditionalExportFile, so no copy of either lookup remains. The new import-only test fails before the change and passes on this head, and the Vitest set the description names, both typechecks and ESLint pass. CI has not run on this head yet; it runs once the pull request is ready for review and targets main.

Claims and files checked

Review mode: incremental; reason: none

  • Changed rules (0): none.
  • Claims:
    • Changeset: outside a project, export loads a package-set subpath exported only under import: verified (render.test.mjs "loads a subpath exported only under import" fails on the base and passes on this head).
    • Changeset: such a page used to fail as if the package were not installed: verified (on the base that test gets the missing-dependency error, "The page imports demo-conditions, which is not installed").
    • Changeset: a subpath the package does not export keeps its answer: verified ("keeps the answer for a subpath the package does not export" passes on the base and the head with the same code and message).
    • Changeset and description: a theme package's ./themes/<name>, which astryx theme add writes, is often exported this way: verified in part; theme add records <package>/themes/<slug> and accepts an import-only export for it (theme-imports.mjs:200-206), and how common that is cannot be shown from the repository.
    • Description: outside a project, export takes some packages from the CLI's package set: verified (page-worker.mjs:1043-1068, api/render/_adapter.mjs:481-490).
    • Description: the failure is the missing-dependency error, or Node's "not defined by exports" error: verified (the base test result; before the change the package-set fallback re-threw Node's not-exported error).
    • Description: inside a project the same import works: verified (the same page, with the package installed in a project, renders on this head).
    • Description: the cause is Node's CommonJS resolver reading the require condition: verified (page-worker.mjs:1063, served-packages.mjs:73-76).
    • Description: servedImportTarget takes the target under import, node and default through conditionalExportFile, built on conditionalExportTarget and resolveTarget, kept inside the package and to a regular file: verified (served-packages.mjs:86-119, package-exports.mjs:155-161, :236-261).
    • Description: it runs only where the CommonJS resolve of a served package fails as not exported, at the package-set fallback, resolveServed and the not-exported check, and everything that resolves today resolves the same: verified (page-worker.mjs:1063, :1078-1087, :1389-1393; served-packages.mjs:77-80; the require-only test passes on the base and the head).
    • Description: three regression tests with a reproduction before and a result after: verified (one fails and two pass on the base; all three pass on this head).
    • Description: no new public API, visual representation, default or interaction model: verified (no package export reaches the changed modules, and no command doc changes).
    • Description: public text has no internal context: verified.
    • Description: the Vitest set passes with 2313 passed and 5 skipped: verified (the same counts on this head).
    • Description: typecheck:strict and typecheck:json-api pass: verified.
    • Description: ESLint passes on the changed files, Prettier passes on served-packages.mjs, package-exports.mjs and the changeset, and page-worker.mjs and render.test.mjs fail Prettier on main as well: verified.
    • Latest commit: servedImportTarget finds the package with findNodeModulesPackage, the lookup the worker already uses: verified (served-packages.mjs:102; page-worker.mjs:71).
  • Files:
    • .changeset/export-served-import-only-subpath.md: clear.
    • packages/cli/api/render/render.test.mjs: clear.
    • packages/cli/foundation/discovery/package-exports.mjs: clear.
    • packages/cli/foundation/render/page-worker.mjs: clear.
    • packages/cli/foundation/render/served-packages.mjs: clear.

Automated review (maintainer link)

@josephfarina
josephfarina marked this pull request as ready for review November 19, 2026 03:39
josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12635 fix(cli): export loads and gives back a page whose modules import TypeScript files by .js names
  Author: @josephfarina
- #12727 fix(cli): export loads a served package's subpath exported only to imports
  Author: @josephfarina
- #12224 fix(cli): a {@link} in a template description resolves as astryx docs resolves it
  Author: @josephfarina
- #12278 fix(core): a Theme given a value that is not a theme keeps the page running
  Author: @josephfarina
- #12751 feat(Layout): LayoutContent names its container, so a theme styles a dialog's body apart from its header and footer
  Author: @josephfarina
- #12168 fix(templates): header, footer and toolbar rows wrap for longer translated labels
  Author: @josephfarina
- #12399 [experimental] export: the dropped-text warning checks Core's docs, and text not drawn yet inside Core components that take children no longer warns
  Author: @josephfarina
- #12541 [docs] Core: list the props ComplexSelector, Selector, Toast and ContextMenuItem take
  Author: @josephfarina
- #12676 docs(cli): a short form keeps its own 640 column inside a wide template frame
  Author: @josephfarina
- #12458 fix(core): Field labels use the primary text colour
  Author: @josephfarina
- #12373 [experimental] export: a link to a place in the page stays in the file in a srcdoc viewer frame
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12827.

@github-actions
github-actions Bot deleted the josephfarina/export-served-import-only branch November 20, 2026 06:06

This branch was successfully deployed

1 active deployment
Preview — f17dbfc8 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