Skip to content

feat(cli): select targets like rustup selects toolchains - #593

Merged
HalfSweet merged 1 commit into
mainfrom
feat/cli-target-selection
Oct 19, 2026
Merged

HalfSweet merged 1 commit into
mainfrom
feat/cli-target-selection

Conversation

@HalfSweet

Copy link
Copy Markdown
Member

Stacked on #592 (← #591 ← #590 ← #588).

Summary

Every pocket check, compile and build named its target with --target or --host-profile, and the CLI recognized a framework by its package name.

Selection. A verb acts on the first of:

  1. explicit: pocket +<id> <verb> (rustup's position), pocket <verb> +<id>, --target <id>, --host-profile <file> — two that differ are an error, a +id anywhere else before -- is an error;
  2. POCKET_TARGET;
  3. a directory override of the current directory or an ancestor (pocket override set <id> [--path DIR]);
  4. the first entry of targets in the project's pocket.config.ts;
  5. the user default (pocket default <id>).

None present stops with the five ways to name one. Each run prints pocket: target vita · directory override /work/game first. pocket build --all builds every project target in order.

Project configuration. PocketConfig gains targets: catalog ids, { target, manifest }, or { hostProfile, manifest } (the host profile's id names the target and may not equal a catalog id or a command word). The project configuration is the nearest pocket.config.ts above the manifest's directory — the file tools/build.ts reads theme from, so apps/note's own config keeps applying in a checkout — and the lookup stops there. tools/pocket.ts project bundles the file with @pocketjs/framework mapped to the resolved framework, so it evaluates in a project without node_modules (a Bun runtime plugin does not intercept that import; bundling does).

pocket show [--json] reports the framework and its source (POCKETJS_FRAMEWORK_ROOT, checkout, registry, git/file:/link: spec from bun.lock, or link → <path>), the project and its targets, the selection and why, the host, and the catalog with targets this host cannot install marked. Overrides and the default live in <config>/pocket-nexus/settings.json, written by rename.

Framework identity. A framework is any directory whose package.json carries "pocketjs": { "protocol": 1 } (added to this package); the name is not read, so a fork published under another name is recognized. The nearest of a checkout and an installed node_modules/@pocketjs/framework wins (checkout on a tie). The CLI passes --cli-protocol 1 and both sides stop on a mismatch.

pocket create writes pocket.config.ts; its package.json scripts name no target (pocket check, pocket build -- --release, pocket build --output dist/<name>.pocket for ESP-IDF).

New modules: tools/cli/framework.mjs, tools/cli/select.mjs, tools/targets/project.ts. Docs: the CLI reference gains Target selection, Project configuration, show, default, override and Switching to a fork.

Validation

bun test tests/cli.test.ts            # 21 pass: precedence of all five sources, both +id positions, conflicts, misplaced +id,
                                      #   nested overrides, project manifest/hostProfile entries, --all, protocol mismatch, show --json,
                                      #   framework marker/nearest/link resolution
bun test tests/targets-project.test.ts # 5 pass: nearest file stops the lookup, entry paths, diagnostics, POCKETJS_FRAMEWORK_ROOT with --no-install
bun run e2e:install                   # ok ×4: scaffolds select their target from pocket.config.ts against the read-only installed tarball

Every stage of bun tools/test.ts individually: unit 1085 pass / 1 fail (the class-diagnostics --strict-classes case, failing on this machine on main, passing in CI); all later stages pass. bunx tsc --noEmit: only the pre-existing errors in tests/runtime-glyphs.test.ts and tests/pocket3d-icon.test.ts.

@HalfSweet
HalfSweet force-pushed the feat/target-catalog branch from 9f01ea2 to b0cb077 Compare October 19, 2026 07:08
@HalfSweet
HalfSweet force-pushed the feat/cli-target-selection branch from 84d1e11 to 542d50e Compare October 19, 2026 07:08
@HalfSweet
HalfSweet force-pushed the feat/target-catalog branch from b0cb077 to a006551 Compare October 19, 2026 07:28
@HalfSweet
HalfSweet force-pushed the feat/cli-target-selection branch from 542d50e to 21332cc Compare October 19, 2026 07:28
@HalfSweet
HalfSweet force-pushed the feat/target-catalog branch from a006551 to b275ced Compare October 19, 2026 07:35
@HalfSweet
HalfSweet force-pushed the feat/cli-target-selection branch from 21332cc to 6768188 Compare October 19, 2026 07:35
Base automatically changed from feat/target-catalog to main October 19, 2026 07:48
Every pocket check, compile and build named its target with --target or
--host-profile, and the CLI recognized a framework by its package name.

A verb now acts on the first of: an explicit +<id> (before or after the
command), --target or --host-profile; POCKET_TARGET; a directory override
of the current directory or an ancestor; the first entry of `targets` in
the project's pocket.config.ts; the user default. The CLI prints the target
and its source before it runs. pocket build --all builds every project
target in order.

- pocket.config.ts gains `targets`: catalog ids, { target, manifest }, or
  { hostProfile, manifest }. The project configuration is the nearest
  pocket.config.ts above the manifest's directory; tools/pocket.ts project
  bundles it with @pocketjs/framework mapped to the resolved framework.
- pocket show [--json] reports the framework and its source, the project,
  the selection and why, the host, and the catalog. pocket default and
  pocket override keep their state in <config>/pocket-nexus/settings.json.
- A framework is any directory whose package.json carries
  "pocketjs": { "protocol": 1 }; the package name is not read, so a fork
  under another name is recognized. The nearest of a checkout and an
  installed node_modules/@pocketjs/framework wins. The CLI passes
  --cli-protocol and either side stops on a mismatch.
- pocket create writes pocket.config.ts, and its package.json scripts name
  no target.
@HalfSweet
HalfSweet force-pushed the feat/cli-target-selection branch from 6768188 to 7a87fb1 Compare October 19, 2026 07:49
@HalfSweet
HalfSweet merged commit 2bdcbfe into main Oct 19, 2026
9 checks passed
@HalfSweet
HalfSweet deleted the feat/cli-target-selection branch October 19, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant