feat(config): top-level workspaces schema + --workspace selector#848
Open
BYK wants to merge 2 commits into
Open
feat(config): top-level workspaces schema + --workspace selector#848BYK wants to merge 2 commits into
BYK wants to merge 2 commits into
Conversation
Introduces native, target-agnostic "workspaces" so a single .craft.yml can define multiple independently-versioned release units (e.g. cli@, mcp@). This is the schema + resolver + selector groundwork; it is fully backward compatible and inert when no `workspaces` key is present. - schema: add a top-level `workspaces` map. Each workspace mirrors the release-relevant subset of the top-level config (targets, github, releaseBranchPrefix, changelog, versioning, providers, ...) and inherits unspecified fields from the top level. A workspace's `github` block is partial so it can override just `projectPath` while inheriting owner/repo. - resolver: `getConfiguration()` returns a resolved VIEW — the base config merged with the selected workspace's overrides — so all existing accessors (getGitTagPrefix, getGlobalGitHubConfig, getVersioningPolicy, providers, expandWorkspaceTargets) become workspace-aware without individual changes. - selector: global `--workspace <name>` option (env `CRAFT_WORKSPACE`). The selection is applied BEFORE yargs parsing because command builders (notably `publish`, which derives its --target choices from config.targets) run before middleware; the `publish` builder also falls back gracefully if the config can't be resolved at parse time. - validation: selecting an unknown/absent workspace, or omitting the selection when workspaces are defined, fails fast with a helpful message. Gated behind minVersion >= 2.27.0. - checkMinimalConfigVersion: a dev/pre-release build of X.Y.Z (e.g. 2.27.0-dev.0) now satisfies a minVersion of up to X.Y.Z, so a feature can be dogfooded from a dev build before its release is cut. Released builds are unaffected. NOTE: this "workspace" (a release unit) is distinct from the npm target's existing `workspaces: true` field (npm package discovery within one target). Part of #842. Follow-ups will thread the selection through prepare/publish and the publish-issue action layer.
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4e2d8f4. Configure here.
- resolver: a workspace `github` override that only sets projectPath (with no top-level github) no longer produces a truthy-but-incomplete github object. The merged github is adopted only when it has both owner and repo; otherwise it is left unset so getGlobalGitHubConfig() still falls back to git-remote detection. (Bugbot High) - extractWorkspaceSelection: no longer greedily consumes the token after a bare `--workspace` (e.g. `--workspace --dry-run`) as the value, and no longer suppresses CRAFT_WORKSPACE when the flag has no value. Moved to utils/helpers so it is unit-testable without importing the CLI entrypoint (which has import side effects), and added coverage. (Bugbot Medium) - index: removed the redundant post-parse workspace middleware. The pre-parse extraction is the single source of truth; the middleware re-applied the parsed (possibly empty) --workspace value and clobbered a valid CRAFT_WORKSPACE fallback for a bare flag. Adversarial review verdict: solid/merge. Verified end-to-end with the built binary. Part of #842.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
PR B of the workspaces redesign (design doc:
.opencode/plans/workspaces-redesign-design.md, tracking #842). Adds a first-class, target-agnostic top-levelworkspaces:config key plus a--workspaceselector so a single.craft.ymlcan describe multiple independently-versioned release units (e.g.cli@,mcp@).This PR is the schema + resolver + selector groundwork only. It is fully backward-compatible and inert when no
workspaceskey is present — the full suite (1078 tests) passes unchanged. Threading the selection throughprepare/publishand the publish-issue action layer comes in follow-up PRs (C/D).What's in it
schemas/project_config.ts): a top-levelworkspacesmap. Each workspace mirrors the release-relevant subset of the top-level config and inherits unspecified fields from the top level. The workspacegithubblock is partial so it can override justprojectPathwhile inheritingowner/repo.config.ts):getConfiguration()returns a resolved view — base config merged with the selected workspace's overrides — sogetGitTagPrefix,getGlobalGitHubConfig,getVersioningPolicy, providers, andexpandWorkspaceTargets(config.targets)all become workspace-aware with no per-accessor changes.index.ts): global--workspace <name>(envCRAFT_WORKSPACE). Applied before yargs parsing because command builders (notablypublish, which derives--targetchoices fromconfig.targets) run before middleware. Verified end-to-end.minVersion >= 2.27.0.checkMinimalConfigVersiondev-build relaxation: a pre-release build ofX.Y.Z(e.g.2.27.0-dev.0) now satisfies aminVersionup toX.Y.Z, so features can be dogfooded from a dev build before their release is cut. Released builds are unaffected; a genuinely-too-newminVersion(e.g.2.28.0) is still correctly rejected.Review — critical bug caught & fixed
Adversarial review found a CRITICAL bug (C1): the
publishbuilder callsgetConfiguration()at parse time, which runs before the--workspacemiddleware — so with a workspaces config it threw "select a workspace" before the selection was applied, breakingcraft publishfor the very feature this ships. Fixed by resolving the workspace from raw argv/env before.parse(), plus a graceful fallback in thepublishbuilder. Verified end-to-end with a built binary:craft targets --workspace cli→ resolves the cli workspace's targets ✓CRAFT_WORKSPACE=cliand--workspace=mcpforms both work ✓cli, mcp✓Unknown workspace "nope". Available workspaces: cli, mcp.✓Testing
pnpm test(1078 passed, 1 skipped),tsc,pnpm lint(0 errors),prettier --checkall clean. New tests cover schema parsing, the resolver merge (overrides win / base inherited / partial github), all error paths, the minVersion gate, cache re-resolution on selection change, and the publish-builder contract (regression for C1).Part of #842.
🤖 Generated with opencode