@withstudiocms/internal_helpers
Version:
Internal helper utilities for StudioCMS
22 lines (21 loc) • 1.1 kB
TypeScript
import fs from 'node:fs';
import type { AstroIntegrationLogger } from 'astro';
interface FileIO {
readFileSync: typeof fs.readFileSync;
writeFileSync: typeof fs.writeFileSync;
}
/**
* Fetches the latest version of a given npm package from the npm registry.
*
* @param packageName - The name of the npm package to fetch the latest version for.
* @param logger - An instance of `AstroIntegrationLogger` used to log errors if the fetch fails.
* @param cacheJsonFile - File URL for dev-mode cache (optional).
* @param isDevMode - When true, uses/updates a 1h TTL cache in `cacheJsonFile`.
* @param io - Optional file IO overrides for testing.
* @returns A promise that resolves to the latest version of the package as a string,
* or `null` if an error occurs during the fetch process.
*
* @throws Will throw an error if the HTTP response from the npm registry is not successful.
*/
export declare function getLatestVersion(packageName: string, logger: AstroIntegrationLogger, cacheJsonFile: URL | undefined, isDevMode: boolean, io?: FileIO): Promise<string | null>;
export {};