Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-stingrays-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sanity/plugin-kit": patch
---

Fix `verify-package`/`verify-studio` import checks to fall back when `@typescript-eslint` fails to load with TypeScript 7.
91 changes: 58 additions & 33 deletions packages/@sanity/plugin-kit/src/dependencies/import-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,69 @@ const removedImportSuffix = `imports where removed in Sanity v3. Please refer to

export async function validateImports({basePath}: {basePath: string}): Promise<string[]> {
log.debug('Running ESLint with Sanity Studio import hints...')
const eslintConfig: ESLint.Options['overrideConfig'] = {
ignorePatterns: ['node_modules'],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
...mergedPackages.map((packageName) => ({
group: [`${packageName}*`],
message: `Use sanity instead of ${packageName}.`,
})),
{
group: ['config:*'],
message: `config: imports are no longer supported. Please see the new plugin API for alternatives: ${urls.migrationGuideStudio}`,
},
{
group: ['part:*'],
message: `part: ${removedImportSuffix}`,
},
{
group: ['all:part:*'],
message: `all:part: ${removedImportSuffix}`,
},
{
group: ['sanity:*'],
message: `sanity: ${removedImportSuffix}`,
},
],
},
],
},
}

const eslint = new ESLint({
cwd: basePath,
overrideConfig: {
ignorePatterns: ['node_modules'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
...mergedPackages.map((packageName) => ({
group: [`${packageName}*`],
message: `Use sanity instead of ${packageName}.`,
})),
{
group: ['config:*'],
message: `config: imports are no longer supported. Please see the new plugin API for alternatives: ${urls.migrationGuideStudio}`,
},
{
group: ['part:*'],
message: `part: ${removedImportSuffix}`,
},
{
group: ['all:part:*'],
message: `all:part: ${removedImportSuffix}`,
},
{
group: ['sanity:*'],
message: `sanity: ${removedImportSuffix}`,
},
],
},
],
},
},
overrideConfig: eslintConfig,
})

try {
const results = await eslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')])
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}')])
}

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.


Comment on lines +57 to 77
const onlyImportErrors = results
.map((r) => {
Expand Down