|
1 | | -import { execFileSync, spawnSync } from "node:child_process"; |
| 1 | +import { spawnSync } from "node:child_process"; |
2 | 2 | import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs"; |
3 | 3 | import { createRequire } from "node:module"; |
4 | 4 | import os from "node:os"; |
5 | 5 | import { dirname, join, relative, resolve } from "node:path"; |
6 | 6 | import { fileURLToPath, pathToFileURL } from "node:url"; |
| 7 | +import * as tar from "tar"; |
7 | 8 | import { describe, expect, it } from "vitest"; |
8 | 9 | import { pluginSdkEntrypoints } from "./entrypoints.js"; |
9 | 10 |
|
@@ -198,18 +199,23 @@ function packOpenClawToTempDir(packDir: string): string { |
198 | 199 | return join(packDir, filename); |
199 | 200 | } |
200 | 201 |
|
201 | | -function readPackedRootPackageJson(archivePath: string): { |
| 202 | +async function readPackedRootPackageJson(archivePath: string): Promise<{ |
202 | 203 | dependencies?: Record<string, string>; |
203 | | -} { |
204 | | - return JSON.parse( |
205 | | - execFileSync("tar", ["-xOf", archivePath, "package/package.json"], { |
206 | | - encoding: "utf8", |
207 | | - maxBuffer: NPM_PACK_MAX_BUFFER_BYTES, |
208 | | - stdio: ["ignore", "pipe", "pipe"], |
209 | | - }), |
210 | | - ) as { |
211 | | - dependencies?: Record<string, string>; |
212 | | - }; |
| 204 | +}> { |
| 205 | + const extractDir = mkdtempSync(join(os.tmpdir(), "openclaw-packed-root-package-json-")); |
| 206 | + try { |
| 207 | + await tar.x({ |
| 208 | + file: archivePath, |
| 209 | + cwd: extractDir, |
| 210 | + filter: (entryPath) => entryPath === "package/package.json", |
| 211 | + strict: true, |
| 212 | + }); |
| 213 | + return JSON.parse(readFileSync(join(extractDir, "package", "package.json"), "utf8")) as { |
| 214 | + dependencies?: Record<string, string>; |
| 215 | + }; |
| 216 | + } finally { |
| 217 | + rmSync(extractDir, { recursive: true, force: true }); |
| 218 | + } |
213 | 219 | } |
214 | 220 |
|
215 | 221 | function readGeneratedFacadeTypeMap(): string { |
@@ -332,14 +338,14 @@ describe("plugin-sdk package contract guardrails", () => { |
332 | 338 | expect(resolvedPath).toContain("@matrix-org/matrix-sdk-crypto-wasm"); |
333 | 339 | }); |
334 | 340 |
|
335 | | - it("keeps matrix crypto WASM in the packed artifact manifest", () => { |
| 341 | + it("keeps matrix crypto WASM in the packed artifact manifest", async () => { |
336 | 342 | const tempRoot = mkdtempSync(join(os.tmpdir(), "openclaw-matrix-wasm-pack-")); |
337 | 343 | try { |
338 | 344 | const packDir = join(tempRoot, "pack"); |
339 | 345 | mkdirSync(packDir, { recursive: true }); |
340 | 346 |
|
341 | 347 | const archivePath = packOpenClawToTempDir(packDir); |
342 | | - const packedPackageJson = readPackedRootPackageJson(archivePath); |
| 348 | + const packedPackageJson = await readPackedRootPackageJson(archivePath); |
343 | 349 | const matrixPackageJson = readMatrixPackageJson(); |
344 | 350 |
|
345 | 351 | expect(packedPackageJson.dependencies?.["@matrix-org/matrix-sdk-crypto-wasm"]).toBe( |
|
0 commit comments