TRAC-137: Add native hosting option in catalyst CLI#3003
Draft
jordanarldt wants to merge 1 commit intoalphafrom
Draft
TRAC-137: Add native hosting option in catalyst CLI#3003jordanarldt wants to merge 1 commit intoalphafrom
jordanarldt wants to merge 1 commit intoalphafrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Contributor
Bundle Size ReportComparing against baseline from No bundle size changes detected. |
67f5265 to
8e3e01f
Compare
8e3e01f to
e13fec9
Compare
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.
Jira: LTRAC-137
What/Why?
Following review of #2995, the team agreed that hosting/deploy concerns belong in
catalyst(the CLI), notcreate-catalyst(the scaffolder). Since the broader plan is to absorbcreate-catalystintocatalystanyway, this PR ports the work from #2995 directly intopackages/catalystas a newcatalyst createcommand, plus a few related improvements that came out of building on that foundation.catalyst createNew top-level command in
packages/catalyst. Replaces the eventual role ofcreate-catalyst create. Behavior summary:catalyst deploy, not at create time.--hosting commerceopts into the full Commerce Hosting setup eagerly (proxy → middleware swap, OpenNext dep,.bigcommerce/project.json,core/.env.localsymlink).setupCoreProjectruns unconditionally at create time, wiringcatalyst build/start/deployscripts and the@bigcommerce/catalystdep intocore/package.jsonregardless of hosting choice. This is what lets the polymorphiccatalyst build/startcommands (below) bridge the create→deploy gap for users who don't choose hosting upfront.catalyst authdevice flow — no parallel auth implementation.Shared
lib/commerce-hosting.tsThe Commerce Hosting setup logic from #2995 is extracted into a reusable module. Exports:
setupCommerceHosting({ projectDir, projectUuid, storeHash?, accessToken? })— synchronous file mutations. Idempotent.promptForCommerceHostingProject(...)—catalyst create --hosting commercesemantics (default-name + auto-create on no collision).selectOrCreateInfrastructureProject(api, linkedProjectUuid?)— generic "select existing or create new" flow used bycatalyst project linkandcatalyst deploy. Decorates the matching project with[linked]when a UUID is passed, and skips the select prompt entirely when the store has zero projects.NoLinkedProjectError— exported sentinel so callers can translate user decline into context-appropriate messaging.runCommerceHostingSetup(...)— orchestrator (prompt → setup) for the create-time flow.Polymorphic
catalyst build/catalyst startBoth commands now dispatch via a new
lib/project-state.tshelper. If the project isn't transformed for Commerce Hosting (middleware.ts+@opennextjs/cloudflaredep), they fall through topnpm exec next build/next start. Otherwise they run the OpenNext pipeline. This is what letssetupCoreProjectalways wirebuild: "npm run generate && catalyst build"/start: "catalyst start"at create time, regardless of hosting choice.catalyst project link/listcatalyst project listnow marks the currently linked project with green[linked].catalyst project linkdoes the same.catalyst deployprojectUuidis missing or 404s, falls through toselectOrCreateInfrastructureProject. Graceful info+exit when the user declines to create one.buildWorkspacePackagesAfter
installDependenciesat create time, if the cloned repo is the catalyst monorepo (hascore/,packages/catalyst,packages/client), runspnpm buildin the workspace packages socorecan resolve them. No-op for non-monorepo scaffolds.Misc / quality
.bigcommerce/cwd pollution.Confeagerly creates its config dir on construction; telemetry was always triggering this even from commands that didn't need project config. Telemetry moved to a user-scopedConf(lib/user-config.ts, lives in OS config dir undercatalyst-cli/). Project state checks now use a separate read-onlygetProjectState()helper that never instantiatesConf.package.jsonfield order (lib/sort-package-json.ts) applied whenever we mutate apackage.json.lib/shared-options.ts(already existed forlogs) now used acrossproject,create, anddeploy— eliminates ~30 lines of duplicated--store-hash/--access-token/--api-host/--project-uuidoption declarations. Each helper accepts an optional description override (deploy uses this to surface its.bigcommerce/project.jsonfallback hint).--envparser (validatesKEY=VALUE, preserves values containing=) and--channel-idparser (validates numeric) extracted as named functions.BIGCOMMERCE_STOREFRONT_API_TOKENtypo fixed — the storefront actually readsBIGCOMMERCE_STOREFRONT_TOKEN(no_API_).Testing
Unit tests: 228 total, all passing. New coverage:
commands/create.spec.ts(new, 12 tests) — happy paths (full flags,--hosting commerce, login-when-creds-missing), parser validation (--channel-id/--envregression tests), ordering invariants (writeEnvbefore install/build), failure handling (cleanup warning on partial state),--hosting commerceprecondition (hasProjectsAccessreturning false).lib/project-state.spec.ts(new, 13 tests) — linked / transformed / fully-set-up detection across realistic project layouts.lib/setup-core-project.spec.ts(new, 5 tests) — script + dep wiring at create time.lib/sort-package-json.spec.ts(new, 5 tests) — canonical field ordering.lib/commerce-hosting.spec.ts— covers prompts, setup, orchestrator, and the newselectOrCreateInfrastructureProject(empty-list, decline,[linked]marker paths).commands/project.spec.ts— extended with empty-list,[linked]-marker, and graceful-decline assertions forlink.commands/deploy.spec.ts— extended with verify-or-prompt cases (linked-but-deleted, no-link), empty-list handling, transformation guard.pnpm --filter @bigcommerce/catalyst test,typecheck,lint, andbuildall clean.Manual verification:
catalyst create --project-name X(interactive, no hosting) — scaffolds, no.bigcommerce/project.json, no proxy → middleware swap.pnpm run buildfalls through tonext build.catalyst create --project-name X --hosting commerce— Commerce Hosting prompt fires before clone. Post-clone: scripts wired,core/.bigcommerce/project.jsonwritten,core/.env.localsymlink created,core/proxy.ts → core/middleware.ts,@opennextjs/cloudflareinstalled.catalyst project link—[linked]shown for the matching project; offers Commerce Hosting setup after linking; declining exits cleanly with guidance.catalyst project list—[linked]marker on the currently linked project.catalyst deployfrom a fresh self-hosted scaffold — prompts for Commerce Hosting setup (transformation guard), then proceeds.catalyst deployagainst a linked-but-deleted project — falls through to select-or-create; declining exits cleanly.Migration
packages/create-catalystis not modified in this PR — the staged #2995 changes there were reverted. A follow-up PR will updatecreate-catalyst createto shim intocatalyst createsopnpm create @bigcommerce/catalystkeeps working without duplicated logic.No env-var or flag breaking changes for end users of existing commands. The
BIGCOMMERCE_STOREFRONT_API_TOKENenv var name (only ever written by the create flow, never read by the storefront) is now correctlyBIGCOMMERCE_STOREFRONT_TOKEN.🤖 Generated with Claude Code