
























@@ -212,6 +212,23 @@ function npmPack(spec, destinationDir) {
212212return path.isAbsolute(filename) ? filename : path.join(destinationDir, filename);
213213}
214214215+export function parseNpmReadmeMetadata(raw) {
216+let parsed;
217+try {
218+parsed = JSON.parse(raw);
219+} catch {
220+return "";
221+}
222+return typeof parsed === "string" ? parsed.trim() : "";
223+}
224+225+function npmViewReadme(spec) {
226+return execFileSync("npm", ["view", spec, "readme", "--json", "--prefer-online"], {
227+encoding: "utf8",
228+stdio: ["ignore", "pipe", "pipe"],
229+});
230+}
231+215232function sleep(ms) {
216233return new Promise((resolve) => setTimeout(resolve, ms));
217234}
@@ -236,6 +253,36 @@ async function packPublishedPackage(spec, destinationDir) {
236253throw lastError;
237254}
238255256+async function verifyPublishedPackageReadme(spec) {
257+const attempts = Number.parseInt(
258+process.env.OPENCLAW_PLUGIN_NPM_README_VERIFY_ATTEMPTS ?? "6",
259+10,
260+);
261+const delayMs = Number.parseInt(
262+process.env.OPENCLAW_PLUGIN_NPM_README_VERIFY_DELAY_MS ?? "10000",
263+10,
264+);
265+let lastError;
266+for (let attempt = 1; attempt <= attempts; attempt += 1) {
267+try {
268+const readme = parseNpmReadmeMetadata(npmViewReadme(spec));
269+if (readme) {
270+return readme;
271+}
272+lastError = new Error(`npm view ${spec} readme returned empty metadata`);
273+} catch (error) {
274+lastError = error;
275+}
276+if (attempt < attempts) {
277+console.error(
278+`npm readme metadata for ${spec} not ready (attempt ${attempt}/${attempts}); retrying in ${delayMs}ms...`,
279+);
280+await sleep(delayMs);
281+}
282+}
283+throw lastError;
284+}
285+239286function listFiles(rootDir, prefix = "") {
240287const files = [];
241288for (const entry of fs.readdirSync(path.join(rootDir, prefix), { withFileTypes: true })) {
@@ -273,10 +320,12 @@ export async function verifyPublishedPluginRuntime(spec) {
273320if (errors.length > 0) {
274321throw new Error(errors.join("\n"));
275322}
323+const readme = await verifyPublishedPackageReadme(spec);
276324return {
277325packageName: packedPackage.packageJson.name,
278326version: packedPackage.packageJson.version,
279327fileCount: packedPackage.files.length,
328+readmeLength: readme.length,
280329};
281330} finally {
282331fs.rmSync(workingDir, { force: true, recursive: true });
@@ -290,7 +339,7 @@ async function main(argv) {
290339}
291340const result = await verifyPublishedPluginRuntime(spec);
292341console.log(
293-`plugin-npm-published-runtime-check: ${result.packageName}@${result.version} OK (${result.fileCount} files)`,
342+`plugin-npm-published-runtime-check: ${result.packageName}@${result.version} OK (${result.fileCount} files, ${result.readmeLength} readme chars)`,
294343);
295344}
296345此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。