mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-26 22:11:57 -07:00
refactor(core): Move getPackageJson utility to core package (#12224)
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {
|
||||
readPackageUp,
|
||||
type PackageJson as BasePackageJson,
|
||||
} from 'read-package-up';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import path from 'node: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<PackageJson | undefined> {
|
||||
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;
|
||||
}
|
||||
@@ -4,9 +4,14 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { getPackageJson } from './package.js';
|
||||
import { getPackageJson } from '@google/gemini-cli-core';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import path from 'node:path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export async function getCliVersion(): Promise<string> {
|
||||
const pkgJson = await getPackageJson();
|
||||
const pkgJson = await getPackageJson(__dirname);
|
||||
return process.env['CLI_VERSION'] || pkgJson?.version || 'unknown';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user