Skip to content

unused-file: sanity.blueprint.ts is a Sanity convention entry (patch + branch ready) #1747

Description

@PunGrumpy

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions