Skip to content

Commit 9e9b613

Browse files
fix(cli): the browser download unpacks on machines without an unzip command (#5433)
* fix(cli): the browser download unpacks on machines without an unzip command * fix(cli): a corrupt browser download on the yauzl path is retried and named * revert(cli): drop the cause-chain reader; @puppeteer/browsers never passes the cause through
1 parent bf7f6de commit 9e9b613

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

‎.fallowrc.jsonc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@
426426
// as a direct dep to guarantee installation even when transitive
427427
// resolution fails (corrupted cache, dedup edge cases).
428428
"debug",
429+
// @puppeteer/browsers' optional peer: its zip fallback when no system `unzip` exists.
430+
"yauzl",
429431
// Loaded through the optional package loader for Gemini vision captioning.
430432
"@google/genai",
431433
"puppeteer",

‎bun.lock‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/cli/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"postcss": "^8.5.8",
4848
"prettier": "^3.8.1",
4949
"puppeteer-core": "^25.10.0",
50-
"sharp": "^0.35.0"
50+
"sharp": "^0.35.0",
51+
"yauzl": "^3.4.0"
5152
},
5253
"devDependencies": {
5354
"@clack/prompts": "^1.1.0",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
2+
import { createServer } from "node:http";
3+
import type { AddressInfo } from "node:net";
4+
import { tmpdir } from "node:os";
5+
import { join, relative } from "node:path";
6+
import {
7+
Browser,
8+
computeExecutablePath,
9+
detectBrowserPlatform,
10+
install,
11+
} from "@puppeteer/browsers";
12+
import AdmZip from "adm-zip";
13+
import { afterEach, expect, it, vi } from "vitest";
14+
15+
afterEach(() => {
16+
vi.unstubAllEnvs();
17+
});
18+
19+
// Windows unzips with tar.exe by absolute path, so an empty PATH only hides `unzip` elsewhere.
20+
it.skipIf(process.platform === "win32")(
21+
"unpacks the browser download on a machine without an unzip command",
22+
async () => {
23+
const root = mkdtempSync(join(tmpdir(), "hf-unzip-fallback-"));
24+
const platform = detectBrowserPlatform();
25+
if (!platform) throw new Error("unsupported test platform");
26+
const cacheDir = join(root, "cache");
27+
const options = { cacheDir, browser: Browser.CHROMEHEADLESSSHELL, buildId: "1.0.0", platform };
28+
const executablePath = computeExecutablePath(options);
29+
const archive = new AdmZip();
30+
archive.addFile(
31+
relative(join(cacheDir, Browser.CHROMEHEADLESSSHELL, `${platform}-1.0.0`), executablePath),
32+
Buffer.from("browser"),
33+
);
34+
const zipBytes = archive.toBuffer();
35+
const server = createServer((_request, response) => response.end(zipBytes));
36+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
37+
vi.stubEnv("PATH", join(root, "empty-bin"));
38+
try {
39+
const { port } = server.address() as AddressInfo;
40+
41+
await install({ ...options, baseUrl: `http://127.0.0.1:${port}` });
42+
43+
expect(existsSync(executablePath)).toBe(true);
44+
} finally {
45+
server.close();
46+
rmSync(root, { recursive: true, force: true });
47+
}
48+
},
49+
);

0 commit comments

Comments
 (0)