Skip to content

Commit 210df2c

Browse files
committed
fix(docs): resolve lighthouse audit directory creation issue in Bazel environment
1 parent f591920 commit 210df2c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/tools/lighthouse-audit.mjs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,25 @@ async function cleanupAndPrepareReportsDir() {
169169
await fs.promises.rm(reportsDir, {recursive: true});
170170
} catch {}
171171

172-
await fs.promises.mkdir(reportsDir, {recursive: true});
172+
try {
173+
await fs.promises.mkdir(reportsDir, {recursive: true});
174+
} catch (err) {
175+
// If mkdir fails, try to create the entire path structure
176+
const pathParts = reportsDir.split(path.sep);
177+
let currentPath = pathParts[0] || path.sep;
178+
179+
for (let i = 1; i < pathParts.length; i++) {
180+
currentPath = path.join(currentPath, pathParts[i]);
181+
try {
182+
await fs.promises.mkdir(currentPath);
183+
} catch (mkdirErr) {
184+
// Ignore EEXIST errors, but throw others
185+
if (mkdirErr.code !== 'EEXIST') {
186+
throw mkdirErr;
187+
}
188+
}
189+
}
190+
}
173191
}
174192

175193
/**

0 commit comments

Comments
 (0)