UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

86 lines (85 loc) 3.7 kB
import { n as isPathInside, r as isPathInsideWithRealpath } from "./path-safety-Bi0ppMWC.js"; import "./redact-BtvPPfTi.js"; import { d as pathExists } from "./fs-safe-B6pvPGnf.js"; import { i as readJson } from "./json-files-Bq1lIlQB.js"; import { i as isPrereleaseResolutionAllowed, l as validateRegistryNpmSpec, n as formatPrereleaseResolutionError, o as parseRegistryNpmSpec } from "./npm-registry-spec-CM_p1_uq.js"; import { h as resolveArchiveKind } from "./archive-BfjFIxAJ.js"; import { a as resolveArchiveSourcePath, c as withInstallWorkspace, i as packNpmSpecToArchive } from "./install-source-utils-DPJygB4h.js"; import { n as withExtractedArchiveRoot, t as resolveExistingInstallPath } from "./install-flow-CNwyvboF.js"; import { r as installPackageDir } from "./install-package-dir-kJK8m3kQ.js"; import { t as resolveNpmIntegrityDriftWithDefaultMessage } from "./npm-integrity-xhKlGdxZ.js"; import { i as resolveTimedInstallModeOptions, n as resolveCanonicalInstallTarget, r as resolveInstallModeOptions, t as ensureInstallTargetAvailable } from "./install-target-fP2181xT.js"; //#region src/infra/install-from-npm-spec.ts function isSuccessfulInstallResult(result) { return result.ok; } /** * Validates a registry npm spec, downloads its archive, and delegates final installation. * The caller supplies archive-specific params without `archivePath`; this helper injects * the downloaded archive path and normalizes the npm archive flow result. */ async function installFromValidatedNpmSpecArchive(params) { const spec = params.spec.trim(); const specError = validateRegistryNpmSpec(spec); if (specError) return { ok: false, error: specError }; const flowResult = await withInstallWorkspace(params.tempDirPrefix, async (tmpDir) => { const parsedSpec = parseRegistryNpmSpec(spec); if (!parsedSpec) return { ok: false, error: "unsupported npm spec" }; const packedResult = await packNpmSpecToArchive({ spec, timeoutMs: params.timeoutMs, cwd: tmpDir }); if (!packedResult.ok) return packedResult; const npmResolution = { ...packedResult.metadata, resolvedAt: (/* @__PURE__ */ new Date()).toISOString() }; if (npmResolution.version && !isPrereleaseResolutionAllowed({ spec: parsedSpec, resolvedVersion: npmResolution.version })) return { ok: false, error: formatPrereleaseResolutionError({ spec: parsedSpec, resolvedVersion: npmResolution.version }) }; const driftResult = await resolveNpmIntegrityDriftWithDefaultMessage({ spec, expectedIntegrity: params.expectedIntegrity, resolution: npmResolution, onIntegrityDrift: params.onIntegrityDrift, warn: params.warn }); if (driftResult.error) return { ok: false, error: driftResult.error }; return { ok: true, installResult: await params.installFromArchive({ archivePath: packedResult.archivePath, ...params.archiveInstallParams }), npmResolution, integrityDrift: driftResult.integrityDrift }; }); if (!flowResult.ok) return flowResult; const installResult = flowResult.installResult; if (!isSuccessfulInstallResult(installResult)) return installResult; return { ...installResult, npmResolution: flowResult.npmResolution, ...flowResult.integrityDrift ? { integrityDrift: flowResult.integrityDrift } : {} }; } //#endregion export { ensureInstallTargetAvailable, pathExists as fileExists, installFromValidatedNpmSpecArchive, installPackageDir, isPathInside, isPathInsideWithRealpath, readJson as readJsonFile, resolveArchiveKind, resolveArchiveSourcePath, resolveCanonicalInstallTarget, resolveExistingInstallPath, resolveInstallModeOptions, resolveTimedInstallModeOptions, withExtractedArchiveRoot };