Skip to content

feat(cms): detect Sanity sites and suggest their project - #87

Merged
flowtricks merged 2 commits into
flowtricks:mainfrom
SylvainDruaux:feat/sanity-detect-project
Nov 17, 2026
Merged

flowtricks merged 2 commits into
flowtricks:mainfrom
SylvainDruaux:feat/sanity-detect-project

Conversation

@SylvainDruaux

Copy link
Copy Markdown
Contributor

Stacki didn't notice when a site uses Sanity: CMS connections looked like a site without any CMS, and after "Log in with Sanity" nothing was preselected when the project id lives in code (astro.config.mjs, studio/sanity.cli.ts) rather than in .env.

1. The login suggests the project from config files (a1a3edb)

  • When no .env names the project, the suggestion also reads a projectId: '…' string literal from astro.config.*, sanity.config.* and sanity.cli.*, at the root and in studio/.
  • Files are read, never run. It reuses sanitySource.ts, so commented-out ids and ids built at run time (process.env…) don't count.
  • The .env id still comes first, and only a project the person belongs to is suggested. The dataset still comes from .env.

2. CMS connections says when a site uses Sanity (a9e9f9f)

  • When package.json lists @sanity/astro or sanity and there's no Sanity connection yet, one line shows above the buttons: "This site uses Sanity. Connect it to edit its content in Stacki."
  • It goes away once connected. Studio gets it too, with no server change.
  • To reuse hasDependency without breaking the feature import rule, it moves unchanged from loopCatalog.ts to src/lib/packageManifest.ts, with its tests.

Full gate: 1154/1154. Tested in the app on an Astro + Sanity site: the hint shows without a connection and goes away after login, and the project and dataset are preselected. Non-English lines are marked // review.

Note: this touches sanityLogin.ts near the same lines as #86, so whichever merges second may need a small rebase.

"Log in with Sanity" suggested a project only when a .env file named it (*SANITY_PROJECT_ID). Many sites write the id in code instead: a site with an embedded Studio typically has projectId in astro.config.mjs and in studio/sanity.config.ts or studio/sanity.cli.ts, so nothing was preselected.

The suggestion now also reads a projectId string literal from astro.config.*, sanity.config.* and sanity.cli.*, at the root and in studio/, without running them. It reuses sanitySource.ts, so comments and ids built at run time (process.env…) do not count. The .env id comes first, and only a project the person belongs to is suggested, so a stale id is passed over. The dataset still comes from .env. Files, file size and ids are bounded.
Stacki never noticed that a site uses Sanity: CMS connections looked the same as for a site without it. When package.json lists @sanity/astro or sanity and no Sanity connection exists, CMS connections now says "This site uses Sanity. Connect it to edit its content in Stacki." The line goes away once connected. Studio shows it too, with no server change.

hasDependency moves unchanged from features/props/loopCatalog.ts to src/lib/packageManifest.ts, because features may not import each other along this edge; its tests move with it. The new file is added to Studio's shared source list. Non-English lines are marked for review.
@flowtricks
flowtricks merged commit 1cc5871 into flowtricks:main Nov 17, 2026
18 of 22 checks passed
@SylvainDruaux
SylvainDruaux deleted the feat/sanity-detect-project branch November 17, 2026 17:59
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.

2 participants