mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 23:41:36 +00:00
Fix npm-spec plugin installs when npm pack output is empty (#21039)
* fix(plugins): recover npm pack archive when stdout is empty * test(plugins): create npm pack archive in metadata mock --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { expect } from "vitest";
|
||||
import type { SpawnResult } from "../process/exec.js";
|
||||
import type { CommandOptions, SpawnResult } from "../process/exec.js";
|
||||
import { expectSingleNpmInstallIgnoreScriptsCall } from "./exec-assertions.js";
|
||||
|
||||
export type InstallResultLike = {
|
||||
@@ -40,10 +42,31 @@ export async function expectUnsupportedNpmSpec(
|
||||
}
|
||||
|
||||
export function mockNpmPackMetadataResult(
|
||||
run: { mockResolvedValue: (value: SpawnResult) => unknown },
|
||||
run: {
|
||||
mockImplementation: (
|
||||
implementation: (
|
||||
argv: string[],
|
||||
optionsOrTimeout: number | CommandOptions,
|
||||
) => Promise<SpawnResult>,
|
||||
) => unknown;
|
||||
},
|
||||
metadata: NpmPackMetadata,
|
||||
) {
|
||||
run.mockResolvedValue(createSuccessfulSpawnResult(JSON.stringify([metadata])));
|
||||
run.mockImplementation(async (argv, optionsOrTimeout) => {
|
||||
if (argv[0] !== "npm" || argv[1] !== "pack") {
|
||||
throw new Error(`unexpected command: ${argv.join(" ")}`);
|
||||
}
|
||||
|
||||
const cwd =
|
||||
typeof optionsOrTimeout === "object" && optionsOrTimeout !== null
|
||||
? optionsOrTimeout.cwd
|
||||
: undefined;
|
||||
if (cwd) {
|
||||
fs.writeFileSync(path.join(cwd, metadata.filename), "");
|
||||
}
|
||||
|
||||
return createSuccessfulSpawnResult(JSON.stringify([metadata]));
|
||||
});
|
||||
}
|
||||
|
||||
export function expectIntegrityDriftRejected(params: {
|
||||
|
||||
Reference in New Issue
Block a user