react-doctor/unused-file reports sanity.blueprint.ts in a Sanity Studio project. The fix is one line plus a regression test, and it is ready on a fork, but this repository rejects pull requests from forks for non-collaborators (CreatePullRequest is denied and the REST endpoint returns 404). This issue carries the patch instead, in the same shape as #1731.
The change is reviewable as PunGrumpy/react-doctor#1 on the fork, branch fix/sanity-blueprint-entry, commit 7cb6c8bc3, changeset included. If fork access can be enabled, I can open the pull request here.
What the project looks like
A Sanity Studio that uses Blueprints (@sanity/blueprints) keeps its function definitions in sanity.blueprint.ts at the project root:
import { defineBlueprint, defineDocumentFunction } from "@sanity/blueprints";
export default defineBlueprint({
resources: [
defineDocumentFunction({
name: "auto-redirect",
src: "./functions/auto-redirect",
}),
],
});
Nothing imports this file. The Sanity CLI loads it by filename when you run sanity blueprints deploy, the same way it loads sanity.config.ts and sanity.cli.ts. The Sanity Blueprints docs name the file sanity.blueprint.ts.
With react-doctor/unused-file enabled, the scan reports:
⚠ unused-file
apps/studio/sanity.blueprint.ts
Why the file is reported
FRAMEWORK_PATTERNS in packages/core/src/project-analysis/collect/entries.ts lists the Sanity convention files as alwaysUsed: ["sanity.config.{ts,js}", "sanity.cli.{ts,js}"]. sanity.blueprint.{ts,js} is missing from that list, so the import graph never reaches the blueprint or the modules it imports, such as functions/*.
The patch
--- a/packages/core/src/project-analysis/collect/entries.ts
+++ b/packages/core/src/project-analysis/collect/entries.ts
@@ -2726,7 +2726,7 @@ const FRAMEWORK_PATTERNS: ToolingPluginDefinition[] = [
enablers: ["sanity", "@sanity/cli"],
enablerPrefixes: ["@sanity/"],
entryPatterns: [],
- alwaysUsed: ["sanity.config.{ts,js}", "sanity.cli.{ts,js}"],
+ alwaysUsed: ["sanity.config.{ts,js}", "sanity.cli.{ts,js}", "sanity.blueprint.{ts,js}"],
},
How the test proves it
The branch adds treats Sanity blueprint configuration as a convention entry to packages/core/tests/project-analysis.test.ts. It builds a project with sanity.config.ts, a sanity.blueprint.ts that imports functions/auto-redirect.ts, and an orphan module, then asserts that only the orphan is reported:
const result = await analyzeProject({ rootDirectory });
const unusedFilePaths = relativePaths(rootDirectory, result.unusedFiles);
expect(unusedFilePaths).toEqual(["src/orphan.ts"]);
Without the patch, the test fails because sanity.blueprint.ts and functions/auto-redirect.ts are reported as unused. With the patch, all 136 tests in the file pass:
pnpm --filter @react-doctor/core exec vp test tests/project-analysis.test.ts
react-doctor/unused-filereportssanity.blueprint.tsin a Sanity Studio project. The fix is one line plus a regression test, and it is ready on a fork, but this repository rejects pull requests from forks for non-collaborators (CreatePullRequestis denied and the REST endpoint returns 404). This issue carries the patch instead, in the same shape as #1731.The change is reviewable as PunGrumpy/react-doctor#1 on the fork, branch
fix/sanity-blueprint-entry, commit7cb6c8bc3, changeset included. If fork access can be enabled, I can open the pull request here.What the project looks like
A Sanity Studio that uses Blueprints (
@sanity/blueprints) keeps its function definitions insanity.blueprint.tsat the project root:Nothing imports this file. The Sanity CLI loads it by filename when you run
sanity blueprints deploy, the same way it loadssanity.config.tsandsanity.cli.ts. The Sanity Blueprints docs name the filesanity.blueprint.ts.With
react-doctor/unused-fileenabled, the scan reports:Why the file is reported
FRAMEWORK_PATTERNSinpackages/core/src/project-analysis/collect/entries.tslists the Sanity convention files asalwaysUsed: ["sanity.config.{ts,js}", "sanity.cli.{ts,js}"].sanity.blueprint.{ts,js}is missing from that list, so the import graph never reaches the blueprint or the modules it imports, such asfunctions/*.The patch
How the test proves it
The branch adds
treats Sanity blueprint configuration as a convention entrytopackages/core/tests/project-analysis.test.ts. It builds a project withsanity.config.ts, asanity.blueprint.tsthat importsfunctions/auto-redirect.ts, and an orphan module, then asserts that only the orphan is reported:Without the patch, the test fails because
sanity.blueprint.tsandfunctions/auto-redirect.tsare reported as unused. With the patch, all 136 tests in the file pass: