From b382ae6803ce21ead2a91682fc58126f3786f15b Mon Sep 17 00:00:00 2001 From: matt korwel Date: Thu, 30 Oct 2025 13:15:49 -0700 Subject: [PATCH] feat: Prevent self-imports and fix build loop (#12309) --- eslint.config.js | 25 +++++++++++++++++++ package.json | 5 +++- .../oauth-credential-storage.test.ts | 4 +-- .../code_assist/oauth-credential-storage.ts | 2 +- .../core/src/mcp/oauth-token-storage.test.ts | 4 +-- packages/core/src/mcp/oauth-token-storage.ts | 2 +- packages/core/src/telemetry/loggers.test.ts | 2 +- 7 files changed, 36 insertions(+), 8 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 4012f3d1e9..1a1b5652d4 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -161,6 +161,31 @@ export default tseslint.config( 'default-case': 'error', }, }, + { + // Prevent self-imports in packages + files: ['packages/core/src/**/*.{ts,tsx}'], + rules: { + 'no-restricted-imports': [ + 'error', + { + name: '@google/gemini-cli-core', + message: 'Please use relative imports within the @google/gemini-cli-core package.', + }, + ], + }, + }, + { + files: ['packages/cli/src/**/*.{ts,tsx}'], + rules: { + 'no-restricted-imports': [ + 'error', + { + name: '@google/gemini-cli', + message: 'Please use relative imports within the @google/gemini-cli package.', + }, + ], + }, + }, { files: ['packages/*/src/**/*.test.{ts,tsx}'], plugins: { diff --git a/package.json b/package.json index 3275a0f360..b8b56bbc7f 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,10 @@ "lint-staged": { "*.{js,jsx,ts,tsx}": [ "prettier --write", - "eslint --fix --max-warnings 0" + "eslint --fix --max-warnings 0 --no-warn-ignored" + ], + "eslint.config.js": [ + "prettier --write" ], "*.{json,md}": [ "prettier --write" diff --git a/packages/core/src/code_assist/oauth-credential-storage.test.ts b/packages/core/src/code_assist/oauth-credential-storage.test.ts index f588742495..c3fff6a59b 100644 --- a/packages/core/src/code_assist/oauth-credential-storage.test.ts +++ b/packages/core/src/code_assist/oauth-credential-storage.test.ts @@ -8,7 +8,7 @@ import { type Credentials } from 'google-auth-library'; import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { OAuthCredentialStorage } from './oauth-credential-storage.js'; import type { OAuthCredentials } from '../mcp/token-storage/types.js'; -import { coreEvents } from '@google/gemini-cli-core'; +import { coreEvents } from '../utils/events.js'; import * as path from 'node:path'; import * as os from 'node:os'; @@ -31,7 +31,7 @@ vi.mock('node:fs', () => ({ })); vi.mock('node:os'); vi.mock('node:path'); -vi.mock('@google/gemini-cli-core', () => ({ +vi.mock('../utils/events.js', () => ({ coreEvents: { emitFeedback: vi.fn(), }, diff --git a/packages/core/src/code_assist/oauth-credential-storage.ts b/packages/core/src/code_assist/oauth-credential-storage.ts index 0165a5647e..2f1c78d1df 100644 --- a/packages/core/src/code_assist/oauth-credential-storage.ts +++ b/packages/core/src/code_assist/oauth-credential-storage.ts @@ -12,7 +12,7 @@ import * as path from 'node:path'; import * as os from 'node:os'; import { promises as fs } from 'node:fs'; import { GEMINI_DIR } from '../utils/paths.js'; -import { coreEvents } from '@google/gemini-cli-core'; +import { coreEvents } from '../utils/events.js'; const KEYCHAIN_SERVICE_NAME = 'gemini-cli-oauth'; const MAIN_ACCOUNT_KEY = 'main-account'; diff --git a/packages/core/src/mcp/oauth-token-storage.test.ts b/packages/core/src/mcp/oauth-token-storage.test.ts index 16abf5a6ad..d882109ca3 100644 --- a/packages/core/src/mcp/oauth-token-storage.test.ts +++ b/packages/core/src/mcp/oauth-token-storage.test.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { coreEvents } from '@google/gemini-cli-core'; +import { coreEvents } from '../utils/events.js'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { promises as fs } from 'node:fs'; import * as path from 'node:path'; @@ -34,7 +34,7 @@ vi.mock('../config/storage.js', () => ({ }, })); -vi.mock('@google/gemini-cli-core', () => ({ +vi.mock('../utils/events.js', () => ({ coreEvents: { emitFeedback: vi.fn(), }, diff --git a/packages/core/src/mcp/oauth-token-storage.ts b/packages/core/src/mcp/oauth-token-storage.ts index 66ccba29b6..fd11299c8b 100644 --- a/packages/core/src/mcp/oauth-token-storage.ts +++ b/packages/core/src/mcp/oauth-token-storage.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { coreEvents } from '@google/gemini-cli-core'; +import { coreEvents } from '../utils/events.js'; import { promises as fs } from 'node:fs'; import * as path from 'node:path'; import { Storage } from '../config/storage.js'; diff --git a/packages/core/src/telemetry/loggers.test.ts b/packages/core/src/telemetry/loggers.test.ts index b1ab4c5398..aa9e0a005c 100644 --- a/packages/core/src/telemetry/loggers.test.ts +++ b/packages/core/src/telemetry/loggers.test.ts @@ -92,7 +92,7 @@ import * as metrics from './metrics.js'; import { FileOperation } from './metrics.js'; import * as sdk from './sdk.js'; import { vi, describe, beforeEach, it, expect, afterEach } from 'vitest'; -import { type GeminiCLIExtension } from '@google/gemini-cli-core'; +import { type GeminiCLIExtension } from '../config/config.js'; import { FinishReason, type CallableTool,