From 209381f06f7ef5f95f6e4c7433b6ec858e4cf595 Mon Sep 17 00:00:00 2001 From: Brandon Keiji Date: Fri, 13 Jun 2025 22:18:05 +0000 Subject: fix: add micromatch to package deps (#1020) --- packages/cli/src/utils/package.ts | 38 ++++++++++++++++++++++++++++++++++++++ packages/cli/src/utils/sandbox.ts | 9 +++------ packages/core/package.json | 2 ++ 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 packages/cli/src/utils/package.ts (limited to 'packages') diff --git a/packages/cli/src/utils/package.ts b/packages/cli/src/utils/package.ts new file mode 100644 index 00000000..d53a0234 --- /dev/null +++ b/packages/cli/src/utils/package.ts @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + readPackageUp, + type PackageJson as BasePackageJson, +} from 'read-package-up'; +import { fileURLToPath } from 'url'; +import path from 'path'; + +export type PackageJson = BasePackageJson & { + config?: { + sandboxImageUri?: string; + }; +}; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +let packageJson: PackageJson | undefined; + +export async function getPackageJson(): Promise { + if (packageJson) { + return packageJson; + } + + const result = await readPackageUp({ cwd: __dirname }); + if (!result) { + // TODO: Maybe bubble this up as an error. + return; + } + + packageJson = result.packageJson; + return packageJson; +} diff --git a/packages/cli/src/utils/sandbox.ts b/packages/cli/src/utils/sandbox.ts index 74e45136..12fb6629 100644 --- a/packages/cli/src/utils/sandbox.ts +++ b/packages/cli/src/utils/sandbox.ts @@ -10,7 +10,7 @@ import path from 'node:path'; import fs from 'node:fs'; import { readFile } from 'node:fs/promises'; import { quote } from 'shell-quote'; -import { readPackageUp } from 'read-package-up'; +import { getPackageJson } from './package.js'; import commandExists from 'command-exists'; import { USER_SETTINGS_DIR, @@ -102,13 +102,10 @@ async function shouldUseCurrentUserInSandbox(): Promise { async function getSandboxImageName( isCustomProjectSandbox: boolean, ): Promise { - const packageJsonResult = await readPackageUp(); - const packageJsonConfig = packageJsonResult?.packageJson.config as - | { sandboxImageUri?: string } - | undefined; + const packageJson = await getPackageJson(); return ( process.env.GEMINI_SANDBOX_IMAGE ?? - packageJsonConfig?.sandboxImageUri ?? + packageJson?.config?.sandboxImageUri ?? (isCustomProjectSandbox ? LOCAL_DEV_SANDBOX_IMAGE_NAME + '-' + path.basename(path.resolve()) : LOCAL_DEV_SANDBOX_IMAGE_NAME) diff --git a/packages/core/package.json b/packages/core/package.json index c216905b..511167ec 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -35,6 +35,7 @@ "glob": "^10.4.5", "google-auth-library": "^9.11.0", "ignore": "^7.0.0", + "micromatch": "^4.0.8", "open": "^10.1.2", "shell-quote": "^1.8.2", "simple-git": "^3.28.0", @@ -45,6 +46,7 @@ "devDependencies": { "@types/diff": "^7.0.2", "@types/dotenv": "^6.1.1", + "@types/micromatch": "^4.0.8", "@types/minimatch": "^5.1.2", "@types/ws": "^8.5.10", "typescript": "^5.3.3", -- cgit v1.2.3