Skip to content

Commit 90bbfed

Browse files
authored
fix(windows): hopefully windows can run this this (#56)
1 parent 03d2ee3 commit 90bbfed

3 files changed

Lines changed: 101 additions & 27 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"scripts": {
1111
"prepare": "bun run --cwd web svelte-kit sync || echo ''",
12-
"postinstall": "./scripts/post-install.sh",
12+
"postinstall": "bun scripts/post-install.ts",
1313
"format": "eslint --fix . && prettier -w .",
1414
"web:dev": "bun run --cwd web vite dev",
1515
"web:build": "bun run --cwd web vite build"

scripts/post-install.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

scripts/post-install.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bun
2+
3+
import { execSync } from "node:child_process";
4+
import { existsSync, readdirSync, statSync } from "node:fs";
5+
import { dirname, join } from "node:path";
6+
7+
// Run simple-git-hooks
8+
try {
9+
execSync("bunx simple-git-hooks", { stdio: "inherit" });
10+
} catch (error) {
11+
console.error("Failed to run simple-git-hooks:", error);
12+
process.exit(1);
13+
}
14+
15+
// Check if PLAYWRIGHT_BROWSERS_PATH is set
16+
const playwrightBrowsersPath = process.env.PLAYWRIGHT_BROWSERS_PATH;
17+
if (!playwrightBrowsersPath) {
18+
console.error(" ❌ PLAYWRIGHT_BROWSERS_PATH is not set.");
19+
process.exit(1);
20+
}
21+
22+
// Find Chromium locales directory
23+
function findChromiumLocalesDir(dir: string): string | null {
24+
if (!existsSync(dir)) {
25+
return null;
26+
}
27+
28+
try {
29+
const entries = readdirSync(dir, { withFileTypes: true });
30+
31+
for (const entry of entries) {
32+
const fullPath = join(dir, entry.name);
33+
34+
if (entry.isDirectory()) {
35+
// Check if this directory is named "locales" (case-insensitive)
36+
if (entry.name.toLowerCase() === "locales") {
37+
return fullPath;
38+
}
39+
// Recursively search in subdirectories
40+
const found = findChromiumLocalesDir(fullPath);
41+
if (found) {
42+
return found;
43+
}
44+
}
45+
}
46+
} catch (error) {
47+
// Ignore permission errors and continue
48+
}
49+
50+
return null;
51+
}
52+
53+
const currentChromiumLocalesDir = findChromiumLocalesDir(playwrightBrowsersPath);
54+
const currentChromiumDir = currentChromiumLocalesDir ? dirname(currentChromiumLocalesDir) : null;
55+
56+
let chromiumFound = false;
57+
58+
if (currentChromiumDir && existsSync(currentChromiumDir)) {
59+
try {
60+
const files = readdirSync(currentChromiumDir);
61+
62+
for (const file of files) {
63+
const filePath = join(currentChromiumDir, file);
64+
65+
try {
66+
const stats = statSync(filePath);
67+
68+
// Check if it's a file (not a directory) and name starts with "chrom" (case-insensitive)
69+
if (stats.isFile() && file.toLowerCase().startsWith("chrom")) {
70+
// On Unix-like systems, also check if it's executable
71+
// On Windows, all files can be executed if they have the right extension
72+
const isExecutable = process.platform === "win32" || (stats.mode & 0o111) !== 0; // Check if executable (Unix)
73+
74+
if (isExecutable) {
75+
chromiumFound = true;
76+
break;
77+
}
78+
}
79+
} catch (error) {
80+
// Skip files we can't stat
81+
continue;
82+
}
83+
}
84+
} catch (error) {
85+
// If we can't read the directory, assume Chromium is not found
86+
chromiumFound = false;
87+
}
88+
}
89+
90+
if (!chromiumFound) {
91+
console.log(" ℹ️ Installing Chromium browser via Playwright...");
92+
try {
93+
execSync("bunx playwright install chromium --only-shell", {
94+
stdio: "inherit",
95+
});
96+
} catch (error) {
97+
console.error("Failed to install Chromium:", error);
98+
process.exit(1);
99+
}
100+
}

0 commit comments

Comments
 (0)