Skip to content

Handle TS7 @typescript-eslint config crashes in plugin-kit import validation#1561

Merged
stipsan merged 2 commits into
mainfrom
copilot/fix-test-job-failure
Jul 13, 2026
Merged

Handle TS7 @typescript-eslint config crashes in plugin-kit import validation#1561
stipsan merged 2 commits into
mainfrom
copilot/fix-test-job-failure

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

The CI test job was failing in @sanity/plugin-kit because verify-package / verify-studio import checks crashed when ESLint loaded project config under TypeScript 7 (@typescript-eslint Cjs runtime error). This change keeps import validation functional by falling back to a config-isolated ESLint run for that failure mode.

  • Root issue addressed

    • validateImports() aborted on ESLint initialization/runtime errors caused by upstream TS7 + @typescript-eslint config loading behavior.
    • Result: expected migration/import diagnostics were replaced by generic ESLint failure output, breaking verify command behavior and snapshots.
  • Behavior change in import validation

    • Keep existing ESLint path as default.
    • On the specific TS7 crash signature (@typescript-eslint + reading 'Cjs'), retry linting with:
      • useEslintrc: false
      • same no-restricted-imports rules
      • explicit parser defaults (ecmaVersion: 'latest', sourceType: 'module')
    • This preserves deterministic import checks even when fixture/user ESLint config cannot be loaded under TS7.
  • Release metadata

    • Added a patch changeset for @sanity/plugin-kit.
try {
  results = await eslint.lintFiles([glob])
} catch (error) {
  if (isTypescriptEslintCjsCrash(error)) {
    const fallback = new ESLint({
      cwd: basePath,
      useEslintrc: false,
      overrideConfig: eslintConfig,
    })
    results = await fallback.lintFiles([glob])
  } else {
    throw error
  }
}

Note

Low Risk
Narrow fallback only on a known TS7 ESLint crash signature; default lint path and import rules are unchanged.

Overview
validateImports in @sanity/plugin-kit no longer fails outright when ESLint blows up loading project config under TypeScript 7 (@typescript-eslint / reading 'Cjs'). That crash was breaking verify-package and verify-studio import validation in CI.

The shared no-restricted-imports override is extracted and now includes explicit parserOptions (ecmaVersion: 'latest', sourceType: 'module'). On that specific error, linting retries with useEslintrc: false and the same override so Sanity v2 import rules still run without loading broken user ESLint config.

A patch changeset records the @sanity/plugin-kit release note.

Reviewed by Cursor Bugbot for commit f0c4595. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
plugins-studio Ready Ready Preview, Comment Jul 13, 2026 1:41pm

Request Review

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f0c4595

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sanity/plugin-kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI changed the title [WIP] Fix failing GitHub Actions job test Handle TS7 @typescript-eslint config crashes in plugin-kit import validation Jul 13, 2026
Copilot AI requested a review from stipsan July 13, 2026 13:43
@stipsan
stipsan marked this pull request as ready for review July 13, 2026 13:56
Copilot AI review requested due to automatic review settings July 13, 2026 13:56
@stipsan
stipsan requested a review from a team as a code owner July 13, 2026 13:56
@stipsan
stipsan merged commit f310d68 into main Jul 13, 2026
14 checks passed
@stipsan
stipsan deleted the copilot/fix-test-job-failure branch July 13, 2026 13:57
@squiggler-app squiggler-app Bot mentioned this pull request Jul 13, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f0c4595. Configure here.

overrideConfig: eslintConfig,
})
results = await fallbackEslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')])
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback skips unparseable TypeScript

Medium Severity

When the TS7 @typescript-eslint retry runs, ESLint uses the default Espree parser (no TypeScript parser in overrideConfig). Typical plugin .ts/.tsx files then fail parsing, and the pipeline keeps only no-restricted-imports messages and drops files with none—so restricted imports in those files can go unreported while validateImports still returns success.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f0c4595. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates @sanity/plugin-kit’s import validation to avoid crashing verify-package / verify-studio when ESLint initialization fails due to a TypeScript 7 + @typescript-eslint config runtime error, by retrying linting with user config disabled.

Changes:

  • Extracts the shared no-restricted-imports override config into a reusable eslintConfig object (and adds basic parserOptions).
  • Adds a targeted fallback retry (useEslintrc: false) when ESLint throws a specific @typescript-eslint / "reading 'Cjs'" crash signature.
  • Adds a patch changeset for @sanity/plugin-kit.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/@sanity/plugin-kit/src/dependencies/import-linter.ts Adds an ESLint fallback path for TS7 @typescript-eslint config crashes during import validation.
.changeset/green-stingrays-dress.md Records a patch release note for the import-check fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to 77
let results
try {
results = await eslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')])
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
const shouldRetryWithoutUserConfig =
message.includes('@typescript-eslint') && message.includes("reading 'Cjs'")

if (!shouldRetryWithoutUserConfig) {
throw error
}

log.debug('Retrying ESLint import check without user config: %s', message)
const fallbackEslint = new ESLint({
cwd: basePath,
useEslintrc: false,
overrideConfig: eslintConfig,
})
results = await fallbackEslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')])
}

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.

3 participants