Skip to content

Commit d0f8b2b

Browse files
committed
fix griffel build error on windows
1 parent ccddff3 commit d0f8b2b

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Modern desktop RSS reader",
55
"main": "./dist/electron.js",
66
"scripts": {
7+
"postinstall": "node patch-griffel.js",
78
"build": "webpack --config ./webpack.config.js",
89
"electron": "electron ./dist/electron.js",
910
"start": "npm run build && npm run electron",

patch-griffel.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Patches @griffel/webpack-plugin to fix a Windows path issue when the project
2+
// path contains spaces. The ESM file uses `new URL(import.meta.url).pathname`
3+
// which returns a URL-encoded string (e.g. %20 for spaces) on Windows, causing
4+
// webpack to fail to resolve the virtual loader. `fileURLToPath` decodes it correctly.
5+
const fs = require("fs")
6+
const path = require("path")
7+
8+
const filePath = path.join(
9+
__dirname,
10+
"node_modules",
11+
"@griffel",
12+
"webpack-plugin",
13+
"src",
14+
"webpackLoader.mjs"
15+
)
16+
17+
if (!fs.existsSync(filePath)) {
18+
console.warn("patch-griffel.js: file not found, skipping patch:", filePath)
19+
process.exit(0)
20+
}
21+
22+
let content = fs.readFileSync(filePath, "utf8")
23+
24+
if (content.includes("fileURLToPath")) {
25+
console.log("patch-griffel.js: already patched, skipping.")
26+
process.exit(0)
27+
}
28+
29+
content = content.replace(
30+
`import * as path from 'node:path';`,
31+
`import * as path from 'node:path';\nimport { fileURLToPath } from 'node:url';`
32+
)
33+
content = content.replace(
34+
`const __dirname = path.dirname(new URL(import.meta.url).pathname);`,
35+
`const __dirname = path.dirname(fileURLToPath(import.meta.url));`
36+
)
37+
38+
fs.writeFileSync(filePath, content, "utf8")
39+
console.log("patch-griffel.js: patched @griffel/webpack-plugin for Windows compatibility.")

0 commit comments

Comments
 (0)