Repository navigation
fix(cli): name the packages a scaffolded template needs - #6816
thedjpetersen wants to merge 1 commit into
Conversation
Need: most page templates import an icon or chart package (`@heroicons/react`, `recharts`, `lucide-react`). `astryx template <name> <path>` copied them into projects that did not list those packages and reported plain success, so the first build after wiring the page in failed on an unresolved import. `astryx build` recommends these templates as the place to start, which made the break the common path rather than an edge. Model: after writing the file, the copy leaf reads the written file's imports (Babel parse, top-level import/export-from only), drops relative paths, builtins and path aliases, and checks each package against every package.json from the target directory up (so a workspace root counts). Whatever is left is reported as `missingPackages`, with `installCommand`: the project's own package manager (`npm install`, `pnpm add`, `yarn add`, `bun add`), each package pinned to the major line the template's shipping package declares, and `cd <dir> &&` when the project's package.json is not in cwd. The text output prints both fields under a `[warn]` line. `astryx build` adds the same two fields to its start and alternatives, computed for the project where it runs. The file is still written; nothing is installed. Compatibility: additive. `template.copy` and `build.kit` gain fields; every existing field keeps its shape and meaning, and exit codes are unchanged. The docs tree now renders a command example's documented `output` field, so the template command's new example shows its output.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression14 of 420 shot(s) changed. A change here is a question, not a failure: check whether the after is the
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Thanks for the clear repro and the careful write-up. This is on hold for a maintainer decision before it can be approved.
The scaffold and astryx build changes add missingPackages and installCommand as new public behaviour. The current specs cover the additive shape of such fields, but no current record was identified that governs a scaffold or a build recommendation naming the packages a template needs and the install command for them. Approval therefore needs a maintainer to provide or identify that governing spec. That decision also needs to settle two points the PR itself raises: whether build's JSON may carry the package-manager-specific install command, and whether undeclared Astryx packages are counted alongside third-party packages such as the icon and chart libraries.
One smaller item to address once that direction is settled: in a project where the package manager cannot be determined because several lockfiles are present, the new install line falls back to npm install even though detection otherwise stays neutral rather than guessing. Please either omit the install command in that ambiguous state or make the ambiguity visible, so a builder is not pointed at the wrong package manager.
The contract, text-projection and unchanged-path behaviour otherwise look solid, with no change to exit codes or existing fields.
[Automated review]
|
Closing as superseded. #7183 shipped this same feature on main: The maintainers approved the behavior with one condition from this review: when several lockfiles leave the package manager undetermined, the CLI names the missing packages but prints no install command. Main still guesses in that case, so a small follow-up on main applies that condition using the shared package-manager detection. |
Most Astryx page templates import an icon or chart package, such as
@heroicons/reactorrecharts. Whenastryx template <name> <path>scaffolds one into a project that doesn't have those packages, it reports success and the project's next build fails on an unresolved import. This PR makes the scaffold name the missing packages and print the one command that installs them with the project's package manager, in both the text output and the--jsondata.astryx buildmarks the templates it recommends the same way.At a glance
dashboardin a fresh Vite + Astryx project: before, "Copied template…" and thenvite buildexits 1 with no hint. After, the output listsmissingPackages: @heroicons/react, rechartsandinstallCommand: npm install @heroicons/react@2 recharts@3, and running that line makes the build exit 0.missingPackages: [],installCommand: null). Exit codes, existing JSON fields, and build's ranking and commands don't change.template-packages.test.mjs, 7 of which fail on main (the eighth is the unchanged path), plus 12 unit tests for the import reader and install line. 553 focused CLI tests pass.template.copyandbuild.kit). There is no Storybook story because this is CLI output;evidence/repro.shreplaces it.Second view: `astryx build "analytics dashboard"`
Every screenshot, measurement file and repro script for this PR: astryx-pr-evidence/cli-template-deps
User impact
Anyone who scaffolds a page or block template into a project with
astryx template <name> <path>, whether a person or a coding agent followingastryx build. 46 of the 55 page templates (44 of the 52 ready ones) and 86 of the 659 block templates import@heroicons/react,rechartsorlucide-react. A fresh Vite + Astryx project lists none of those. Onmainthe scaffold reportsCopied template to …, exit 0, and the project's next build fails on an unresolved import. Nothing in the text or the--jsondata says why.In a blind agent-built UI benchmark, 18 of 36 builds on
main's template-first workflow ran into exactly this and had to delete the scaffolded code. Once the template-first rule was reverted, 4 of 36 did.After this PR the scaffold still writes the file, then names the packages the file imports that the project doesn't list, plus the one command that installs them with the project's package manager.
astryx buildmarks the templates it recommends the same way, so a builder sees the cost before scaffolding.Problem and solution fit
{template, outputDir, fileName, filesCopied}.Rollup failed to resolve import "recharts"usually rips the page out. It rarely installs the package: nothing told it the template depends on the package, or which version line to use.astryx buildalways names a page template to start from (spec:AST-048FR1). So the broken path is the recommended one, not an edge case. The page frame and spacing the template carries get thrown away together with the imports.The fix closes the gap at the point where it opens. The command that writes the imports now reports the ones the project can't resolve, and it reports them as data an agent can act on (
installCommand), not just as prose.Expected behavior and authority
spec:AST-048(current) makes a page template the start of every page build (FR1/FR2), and each start is runnable exactly as printed (FR5). A start that scaffolds a file which can't build breaks that promise in practice. This PR changes no ranking, start, or command. It adds data next to them, as FR10/FR11 allow ("new data arrives as new fields").spec:AST-017FR13 says every response field sits in the canonical response type, contract tests, the text projection, and the schema docs. The two new fields are in all four. FR5 covers additive fields and says they are non-breaking. FR3 counts exit behavior as part of the contract, and exit codes don't change.docs/contributing/cli-conventions.md: text output is a projection of the JSON with matching field names (missingPackages:/installCommand:lines), there are no prompts, and there are no side effects beyond the file written.Records searched before drafting:
spec:AST-046,spec:AST-047,spec:AST-048,spec:AST-017,architecture:cli-surface, the CLI conventions guide,template-integration.test.mjs, andgit logfor template dependency or install work. No current record or landed change owns "a scaffold names its missing packages", and this PR adds no record. I could not search open pull requests from the environment that prepared this PR, so a reviewer should do a quick duplicate check.Smallest restoration
I compared three models against the code:
template.doc.mjs, and the CLI validates themWhat (a) does:
foundation/discovery/template-packages.mjs(new, about 200 lines):importedPackages(source)does a Babel parse and reads top-levelimport/export … from, including type-only imports, sincetscneeds those resolved too. It ignores relative paths, Node builtins,scheme:ids,#subpath imports, and@/or~/path aliases. Import-like text inside comments, strings, and JSX is not matched.declaredPackages(dir)unions every package.json from the target directory upward (node resolution walks up, so a workspace root's dependencies count), plus each package's own name.templatePackageNeeds(...)returns{missingPackages, installCommand}. The command uses the project's detected package manager (npm install/pnpm add/yarn add/bun add, with npm as the fallback, the same onegetRunPrefixuses). Each package is pinned to the major line (or the minor line below 1.0) that the template's own shipping package declares. For Core templates that is@astryxdesign/cli's devDependencies, so@heroicons/react@2 recharts@3. Ranges it can't read, such as*,catalog:, or unions, install the bare name. No spec contains shell metacharacters, so the line runs as printed in any shell. When the project's package.json isn't incwd, the command starts withcd <dir> &&.foundation/env/package-manager.mjs: addsgetAddPrefix()next togetRunPrefix()/getDlxPrefix().api/template/copy/copy.mjs: after writing, addsmissingPackagesandinstallCommandto thetemplate.copydata. The file is still written, nothing is installed, and the exit code stays 0.api/build/_adapter.mjs+kit/kit.mjs:startand eachalternatives[]entry carry the same two fields, computed for the project where build runs. That is three extra parses per build, about +50 ms on roughly 2.1 s.clients/cli/commands/template.mjs,build.mjs): a[warn]line followed by arecord()with the two fields, named as in the JSON. The record renderer drops both fields when nothing is missing, so the unchanged path prints exactly what it printed before.template.type.mjs/build.type.mjstypedefs, the FunctionDocreturnsplus a new API example, the CommandDoc description plus two new examples (text withoutput, and--json),build.doc.mjs,response-types.doc.mjs, and the regenerated README table.cli-self-docs.mjsnow renders a command example's documentedoutputfield, which the doc type has always declared and no renderer showed. Without it, the new example's output would be invisible inastryx docs cli/commands/template. No existing command example setsoutput, so no other page changes. I can split this out on request.Removed or split, not in this PR: agent-block wording, playbook wording, template edits, auto-install, a flag.
Representative before/after
The CLI output is the example. Scaffolding
dashboardinto a fresh Vite + Astryx project that lists@astryxdesign/core,@astryxdesign/theme-neutral,@stylexjs/stylex,react, andreact-dom:Terminal, after:
astryx build "analytics dashboard", after. The same two lines appear on each alternative:Unchanged path: when the project already lists them, the output is
Copied template to src/pages/again/page.tsxonly, and the data carriesmissingPackages: []andinstallCommand: null.Evidence
[repro.sh](https://github.com/thedjpetersen/astryx-pr-evidence/blob/main/cli-template-deps/repro.sh) <main checkout> <dir> --installcreates a fresh Vite + React + StyleX project with the Astryx packages, scaffoldsdashboard, and builds. On main the scaffold prints onlyCopied template…, andvite buildexits 1 withRollup failed to resolve import "recharts". The CLI gives no install command (before.txt).[warn]line,missingPackages, andinstallCommand, and the--jsondata carries both.vite buildstill exits 1 until the printed command runs. After the script runs the exactinstallCommandfrom the JSON,vite buildexits 0, andtsc -p .over the page exits 0 (after.txt).missingPackages: []andinstallCommand: null(after-installed.txt). A test covers the same case: thetemplate.copydata equals the old four fields plus the two empty ones, and the text contains no[warn]or field lines.packages/cli/api/template/template-packages.test.mjs. With the source changes reverted, it fails 7 of 8. The one that passes is the unchanged-path text test, which should pass on main. With the changes applied, it passes 8 of 8.Measurements
dashboardscaffold →vite build, fresh Vite projectmissingPackages+installCommandprinted; exit 0 after running ittemplate.copyfieldsmissingPackages,installCommand)@heroicons/react×127,recharts×7,lucide-react×5astryx --json build "analytics dashboard"wall time (3 runs)Evidence files (drag into the PR)
<app>astryx build "analytics dashboard"TEMPLATE / OTHER TEMPLATES sectionsCORE_DIST=<dir>to overlay a built Core.Preview story: none. This is CLI output, so there is no Storybook story. The scripted repro above replaces it.
Scope
spec:AST-017FR13. See owner decision 1.Compatibility declaration (
spec:AST-017FR42): tag[fix], classificationcompatible, affected surfaces: CLI machine-readable schema (template.copy,build.kit), CLI text output, CLI docs. No experimental, deprecation, correction, or cleanup ids. Changeset:.changeset/cli-template-missing-packages.md(@astryxdesign/cli: patch).Owner or spec decisions needed
new-feature. The code doesn't change either way.installCommandinbuild.kitis package-manager-specific (for examplepnpm add …). The kit otherwise keeps its JSON package-manager-agnostic.spec:AST-048's platform note says commands appear without the run prefix in JSON, but that concerns Astryx invocations, and an install line without its package manager can't be run. The kit's header comment records this reasoning. If the AST-048 owner prefers,buildcan carry onlymissingPackagesand leave the install line toastryx template. That would be a one-line removal plus a doc edit.@astryxdesign/theme-neutral, and a project without it fails the same way, so this PR reports every undeclared package. In practice Core is always declared where templates are used. Restricting the check to non-Astryx packages would be a one-line filter.Follow-ups (not in this PR)
build.helpstep fortemplate <name> <path>could tell agents to runinstallCommandwhen the scaffold returns one. This is a separate policy discussion, deliberately left alone here.Iconcomponent and the theme icon registry could replace most@heroicons/reactimports. That is a template-content and design decision.astryx template <name>(print source) and--skeletondon't report requirements. They write nothing, so nothing breaks, buttemplate.showcould carrymissingPackageslater.Testing
Global-baseline review receipt (regenerated at this head; 15 matched claims)
Review receipt (
node scripts/review-global-baselines.mjs --authority-commit 217f41d74ec41aee7f6895ea53e8b6035831f3b7 --review-head a9d4a9365a844159925b40df01a7daba29429414 --triggers behavior,public-api,compatibility,testing): 81 matched claims. The applicable ones and how this PR meets them:spec:AST-017FR3 Released contracts include behaviorspec:AST-017FR5 Additive and victim-free restorations are nonbreakingspec:AST-017FR14 No supported CLI behavior is hiddenspec:AST-017FR29 Warnings fit the surface without changing success[warn]line is the text projection of result data, and the exit status stays 0.spec:AST-017FR12 Supported inter-package ranges are contractsspec:AST-017FR42 Contributors declare compatibility intent oncecompatible).spec:AST-002DEC-3 / DEC-6 One canonical name, one responsibilitymissingPackages(what) andinstallCommand(how) have one meaning each, and the same names ontemplate.copyandbuild.kit.architecture:component-test-sufficiencyINV2 / INV5 / INV6cd, workspace-root declarations, integration template version line, comments and strings, unparseable source.spec:AST-030FR11 Each surface owns one test lanetemplate-integration.test.mjs.architecture:container-padding,architecture:public-component-apiINV1–12, other AST-017 lifecycle claims (FR15–FR45)The full receipt JSON is at review-receipt.json.
Commands run (every one bounded with
timeout):pnpm exec vitest run packages/cli/api/template/template-packages.test.mjs: with the source reverted (patch stashed to a file, then re-applied), 7 failed and 1 passed. After, 8 passed.vitest run packages/cli/api/build packages/cli/api/template packages/cli/clients/cli/commands/build* packages/cli/clients/cli/commands/template* packages/cli/foundation/discovery/cli-self-docs* packages/cli/foundation/discovery/template* packages/cli/foundation/env packages/cli/foundation/doc-compiler/doc-loads.test.mjs: 47 files, 553 passed.pnpm -F @astryxdesign/cli test, run once. Under full parallel load on a shared machine it reported timeouts. Every file that failed was re-run at--maxWorkers=4. The only failures left were 17 inpack-check.test.mjs,integration-authoring.test.mjs, andintegration-real-world.test.mjs(npm pack failed). Those same 17 fail identically on unmodifiedmainin this environment, because npm packing is unavailable there. One real failure,doc-loads.test.mjs, which requires listing the new module's lazy@babel/parserload, is fixed in this PR.pnpm run typecheck:strict,typecheck:json-api,typecheck:authoring,typecheck:template-docsinpackages/cli: all clean.strictneeds@astryxdesign/theme-neutralbuilt locally.eslinton every changed.mjsfile: clean.prettier --writeon the new files and ontemplate.doc.mjs, which was prettier-clean on main.node scripts/generate-cli-readme.mjsregenerated the README response table.pnpm check:repopassed through the pre-commit hook.mainand against this branch, with--install. Plustsc -p .in the after project: exit 0.astryx docs cli/commands/templateandastryx docs cli/api/functions/templaterender the new examples, including the sample output.Note
Rebased onto
main@217f41dwith no conflicts. At this head, the focused tests, core typecheck, ESLint andcheck:repowere re-run and pass, and the global-baseline receipt was regenerated (same matched claims). Screenshots and measurements were captured againstmain@eedc844; the regression tests that encode them pass at this head.