@@ -306,12 +306,26 @@ function readPackedPackage(tarballPath, extractDir) {
|
306 | 306 | tar.x({ file: tarballPath, cwd: extractDir, sync: true }); |
307 | 307 | const packageDir = path.join(extractDir, "package"); |
308 | 308 | const packageJson = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8")); |
| 309 | +const files = listFiles(packageDir); |
309 | 310 | return { |
310 | 311 | packageJson, |
311 | | -files: listFiles(packageDir), |
| 312 | + files, |
| 313 | +readme: readPackedPackageReadme(packageDir, files), |
312 | 314 | }; |
313 | 315 | } |
314 | 316 | |
| 317 | +export function findPackedPackageReadmePath(files) { |
| 318 | +return files.find((file) => /^readme(?:\.(?:md|markdown|txt|rst))?$/iu.test(file)) ?? ""; |
| 319 | +} |
| 320 | + |
| 321 | +function readPackedPackageReadme(packageDir, files) { |
| 322 | +const readmePath = findPackedPackageReadmePath(files); |
| 323 | +if (!readmePath) { |
| 324 | +return ""; |
| 325 | +} |
| 326 | +return fs.readFileSync(path.join(packageDir, readmePath), "utf8").trim(); |
| 327 | +} |
| 328 | + |
315 | 329 | export async function verifyPublishedPluginRuntime(spec) { |
316 | 330 | const workingDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-npm-runtime.")); |
317 | 331 | try { |
@@ -326,7 +340,18 @@ export async function verifyPublishedPluginRuntime(spec) {
|
326 | 340 | if (errors.length > 0) { |
327 | 341 | throw new Error(errors.join("\n")); |
328 | 342 | } |
329 | | -const readme = await verifyPublishedPackageReadme(spec); |
| 343 | +let readme; |
| 344 | +try { |
| 345 | +readme = await verifyPublishedPackageReadme(spec); |
| 346 | +} catch (error) { |
| 347 | +if (!packedPackage.readme) { |
| 348 | +throw error; |
| 349 | +} |
| 350 | +console.error( |
| 351 | +`npm readme metadata for ${spec} was unavailable; verified README from published tarball instead.`, |
| 352 | +); |
| 353 | +readme = packedPackage.readme; |
| 354 | +} |
330 | 355 | return { |
331 | 356 | packageName: packedPackage.packageJson.name, |
332 | 357 | version: packedPackage.packageJson.version, |
|