Repository navigation
fix(cli): export loads a served package's subpath exported only to imports - #12727
josephfarina wants to merge 3 commits into
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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:
servedImportTargetinpackages/cli/foundation/render/served-packages.mjs(lines 118-121) re-implements the package-confinement check ofresolveTargetinpackages/cli/foundation/discovery/package-exports.mjs, so export one confined lookup from that module (for exampleconditionalExportFile(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 animport-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
requirecondition: verified (page-worker.mjs:1063,served-packages.mjs:72-75). - Description: the new helper takes the target under
import,nodeanddefaultthrough 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,
resolveServedand 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.mjsand the changeset, andpage-worker.mjsandrender.test.mjsfail 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).
- Changeset: outside a project, export loads a package-set subpath exported only under
- 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 ofresolveTarget).
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.
There was a problem hiding this comment.
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:
servedImportTargetinpackages/cli/foundation/render/served-packages.mjs(lines 101-112) re-implements the upwardnode_moduleslookup offindNodeModulesPackageinpackages/cli/foundation/fs/paths.mjs, so call that helper and pass itspackageDirtoconditionalExportFile, 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>, whichastryx theme addwrites, is often exported this way: verified in part; theme add records<package>/themes/<slug>and accepts animport-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
requirecondition: verified (page-worker.mjs:1063,served-packages.mjs:72-75). - Description:
servedImportTargettakes the target underimport,nodeanddefaultthroughconditionalExportFile, built onconditionalExportTargetandresolveTarget, 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,
resolveServedand 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; therequire-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/renderorfoundation/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:strictandtypecheck:json-apipass: verified. - Description: ESLint passes on the changed files, Prettier passes on
served-packages.mjs,package-exports.mjsand the changeset, andpage-worker.mjsandrender.test.mjsfail Prettier on main as well: verified.
- Changeset: outside a project, export loads a package-set subpath exported only under
- 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 offindNodeModulesPackage).
…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.
There was a problem hiding this comment.
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>, whichastryx theme addwrites, is often exported this way: verified in part; theme add records<package>/themes/<slug>and accepts animport-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
requirecondition: verified (page-worker.mjs:1063,served-packages.mjs:73-76). - Description:
servedImportTargettakes the target underimport,nodeanddefaultthroughconditionalExportFile, built onconditionalExportTargetandresolveTarget, 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,
resolveServedand 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; therequire-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:strictandtypecheck:json-apipass: verified. - Description: ESLint passes on the changed files, Prettier passes on
served-packages.mjs,package-exports.mjsand the changeset, andpage-worker.mjsandrender.test.mjsfail Prettier on main as well: verified. - Latest commit:
servedImportTargetfinds the package withfindNodeModulesPackage, the lookup the worker already uses: verified (served-packages.mjs:102;page-worker.mjs:71).
- Changeset: outside a project, export loads a package-set subpath exported only under
- 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.
- #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
|
Landed in #12827. |
User impact
Outside a project,
astryx experimental exporttakes some packages from the CLI's package set. A page that imports a subpath such a package exports only under theimportcondition 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>, whichastryx theme addwrites into the page, is often exported that way. Inside a project the same import works.Problem and solution fit
requirecondition, so a subpath exported only underimportreads as not exported.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
servedImportTargetinfoundation/render/served-packages.mjsgives the file a served package exports for a specifier to an ES module import, as Node resolves it: the target itsexportsgive the subpath under theimport,nodeanddefaultconditions (throughconditionalExportFile, a confined lookuppackage-exports.mjsnow exports, built on its existingconditionalExportTargetandresolveTarget), kept inside the package and to a regular file.ERR_PACKAGE_PATH_NOT_EXPORTED: the package-set fallback inpage-worker.mjs,resolveServed, and the not-exported check. Everything that resolves today resolves the same.Evidence
./themes/demois exported only underimportfails withERR_RENDER_MISSING_DEPENDENCY.requireloads as before; a subpath the package does not export keepsERR_RENDER_MISSING_DEPENDENCYwith the same message.render.test.mjs"a served package whose subpath exports one condition" (three cases).Scope
Components: CLI
experimental exportTesting
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:strictandtypecheck:json-apiserved-packages.mjs,package-exports.mjsand the changeset (page-worker.mjsandrender.test.mjsfail Prettier on main as well).preflight: pass f17dbfc