Skip to content

Commit 8496f24

Browse files
committed
chore(cli/update): adjust for feedback and format
1 parent 8ea0df1 commit 8496f24

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

genkit-tools/cli/src/commands/update.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ import * as fs from 'fs';
2222
import inquirer from 'inquirer';
2323
import * as os from 'os';
2424
import * as path from 'path';
25-
import { PACKAGE_MANAGERS, getPackageManager, PackageManager, UpdateError } from '../utils/global';
25+
import {
26+
PACKAGE_MANAGERS,
27+
PackageManager,
28+
getPackageManager,
29+
} from '../utils/package-manager';
2630
import { detectCLIRuntime } from '../utils/runtime-detector';
31+
import { UpdateError } from '../utils/utils';
2732
import { version as currentVersion, name } from '../utils/version';
2833
import { UPDATE_NOTIFICATIONS_OPT_OUT_CONFIG_TAG } from './config';
2934

@@ -112,7 +117,9 @@ async function getGCSLatestData(): Promise<GCSLatestResponse> {
112117
);
113118

114119
if (response.status !== 200) {
115-
throw new UpdateError(`Failed to fetch GCS latest.json: ${response.statusText}`);
120+
throw new UpdateError(
121+
`Failed to fetch GCS latest.json: ${response.statusText}`
122+
);
116123
}
117124

118125
return response.data as GCSLatestResponse;
@@ -128,7 +135,9 @@ export async function getAvailableVersionsFromNpm(
128135
const response = await axios.get(`https://registry.npmjs.org/${name}`);
129136

130137
if (response.status !== 200) {
131-
throw new UpdateError(`Failed to fetch npm versions: ${response.statusText}`);
138+
throw new UpdateError(
139+
`Failed to fetch npm versions: ${response.statusText}`
140+
);
132141
}
133142

134143
const data: NpmRegistryResponse = response.data;

genkit-tools/cli/src/utils/global.ts renamed to genkit-tools/cli/src/utils/package-manager.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,3 @@ export const PACKAGE_MANAGERS: Record<string, PackageManager> = {
5959
export const getPackageManager = (name: string) => {
6060
return PACKAGE_MANAGERS[name] || PACKAGE_MANAGERS.npm;
6161
};
62-
63-
export class UpdateError extends Error {
64-
constructor(message: string) {
65-
super(message);
66-
this.name = 'UpdateError';
67-
}
68-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export class UpdateError extends Error {
18+
constructor(message: string) {
19+
super(message);
20+
this.name = 'UpdateError';
21+
}
22+
}

genkit-tools/cli/tests/commands/update_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ jest.mock('@genkit-ai/tools-common/utils', () => ({
8787
}));
8888

8989
// Import after mocking
90+
import { getUserSettings } from '@genkit-ai/tools-common/utils';
9091
import axios from 'axios';
92+
import { UPDATE_NOTIFICATIONS_OPT_OUT_CONFIG_TAG } from '../../src/commands/config';
9193
import {
9294
checkForUpdates,
9395
getAvailableVersionsFromNpm,
9496
getLatestVersionFromGCS,
9597
showUpdateNotification,
9698
} from '../../src/commands/update';
9799
import { detectCLIRuntime } from '../../src/utils/runtime-detector';
98-
import { UPDATE_NOTIFICATIONS_OPT_OUT_CONFIG_TAG } from '../../src/commands/config';
99-
import { getUserSettings } from '@genkit-ai/tools-common/utils';
100100

101101
const mockedAxios = axios as jest.Mocked<typeof axios>;
102102
const mockedDetectCLIRuntime = detectCLIRuntime as jest.MockedFunction<

0 commit comments

Comments
 (0)