mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 12:10:34 +00:00
refactor: dedupe cli config cron and install flows
This commit is contained in:
38
src/infra/install-from-npm-spec.ts
Normal file
38
src/infra/install-from-npm-spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { NpmIntegrityDriftPayload } from "./npm-integrity.js";
|
||||
import {
|
||||
finalizeNpmSpecArchiveInstall,
|
||||
installFromNpmSpecArchiveWithInstaller,
|
||||
type NpmSpecArchiveFinalInstallResult,
|
||||
} from "./npm-pack-install.js";
|
||||
import { validateRegistryNpmSpec } from "./npm-registry-spec.js";
|
||||
|
||||
export async function installFromValidatedNpmSpecArchive<
|
||||
TResult extends { ok: boolean },
|
||||
TArchiveInstallParams extends { archivePath: string },
|
||||
>(params: {
|
||||
spec: string;
|
||||
timeoutMs: number;
|
||||
tempDirPrefix: string;
|
||||
expectedIntegrity?: string;
|
||||
onIntegrityDrift?: (payload: NpmIntegrityDriftPayload) => boolean | Promise<boolean>;
|
||||
warn?: (message: string) => void;
|
||||
installFromArchive: (params: TArchiveInstallParams) => Promise<TResult>;
|
||||
archiveInstallParams: Omit<TArchiveInstallParams, "archivePath">;
|
||||
}): Promise<NpmSpecArchiveFinalInstallResult<TResult>> {
|
||||
const spec = params.spec.trim();
|
||||
const specError = validateRegistryNpmSpec(spec);
|
||||
if (specError) {
|
||||
return { ok: false, error: specError };
|
||||
}
|
||||
const flowResult = await installFromNpmSpecArchiveWithInstaller({
|
||||
tempDirPrefix: params.tempDirPrefix,
|
||||
spec,
|
||||
timeoutMs: params.timeoutMs,
|
||||
expectedIntegrity: params.expectedIntegrity,
|
||||
onIntegrityDrift: params.onIntegrityDrift,
|
||||
warn: params.warn,
|
||||
installFromArchive: params.installFromArchive,
|
||||
archiveInstallParams: params.archiveInstallParams,
|
||||
});
|
||||
return finalizeNpmSpecArchiveInstall(flowResult);
|
||||
}
|
||||
Reference in New Issue
Block a user