build(docs): make check:docs PowerShell-compatible#44824
build(docs): make check:docs PowerShell-compatible#44824tianxingleo wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR replaces the Key concern:
Minor:
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: scripts/format-docs.mjs
Line: 64
Comment:
**`spawnSync` won't resolve `.cmd` shims on Windows**
`oxfmt` is an npm devDependency. When installed by npm/pnpm on Windows, the binary is exposed via a `node_modules/.bin/oxfmt.cmd` batch-file shim — there is no `oxfmt.exe` in that directory. Node.js's `child_process.spawnSync` on Windows calls `CreateProcess` directly, which only searches for `.com`/`.exe` extensions and **does not** honor `PATHEXT`, so it will fail to locate `oxfmt.cmd` even if `node_modules/.bin` is on `PATH`. The result would be `ENOENT` (captured silently in `result.error`), causing the script to exit with code 1 with no useful diagnostic — the very Windows compatibility problem this PR is meant to fix.
Two straightforward options:
**Option A — `shell: true` on Windows** (minimal change):
```suggestion
const result = spawnSync("oxfmt", [mode, ...chunk], {
stdio: "inherit",
shell: process.platform === "win32",
});
```
**Option B — add `cross-spawn`** as a dev dependency and replace `spawnSync` with `crossSpawn.sync`, which handles the `.cmd` lookup transparently on all platforms.
Note: the `spawnSync("git", ...)` call in `runGitList` is unaffected because `git` is distributed as a native `git.exe` on Windows.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: scripts/format-docs.mjs
Line: 30-32
Comment:
**Silent failure when command is not found**
When `spawnSync` fails to launch the child process (e.g., `git` or `oxfmt` not in `PATH`), Node.js sets `result.status = null` and `result.error` to an `Error` with code `ENOENT`. The current check `result.status !== 0` correctly catches this case (`null !== 0` is `true`), but the error is discarded silently — the user just sees a bare exit code 1 with no explanation.
Consider logging `result.error` before exiting:
```suggestion
if (result.status !== 0) {
if (result.error) {
console.error(`format:docs: failed to run git: ${result.error.message}`);
}
process.exit(result.status ?? 1);
}
```
The same pattern applies to the `spawnSync` call in `runOxfmt` (line 64–68).
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 3af3ebd |
| const chunks = chunkFiles(files); | ||
|
|
||
| for (const chunk of chunks) { | ||
| const result = spawnSync("oxfmt", [mode, ...chunk], { |
There was a problem hiding this comment.
spawnSync won't resolve .cmd shims on Windows
oxfmt is an npm devDependency. When installed by npm/pnpm on Windows, the binary is exposed via a node_modules/.bin/oxfmt.cmd batch-file shim — there is no oxfmt.exe in that directory. Node.js's child_process.spawnSync on Windows calls CreateProcess directly, which only searches for .com/.exe extensions and does not honor PATHEXT, so it will fail to locate oxfmt.cmd even if node_modules/.bin is on PATH. The result would be ENOENT (captured silently in result.error), causing the script to exit with code 1 with no useful diagnostic — the very Windows compatibility problem this PR is meant to fix.
Two straightforward options:
Option A — shell: true on Windows (minimal change):
| const result = spawnSync("oxfmt", [mode, ...chunk], { | |
| const result = spawnSync("oxfmt", [mode, ...chunk], { | |
| stdio: "inherit", | |
| shell: process.platform === "win32", | |
| }); |
Option B — add cross-spawn as a dev dependency and replace spawnSync with crossSpawn.sync, which handles the .cmd lookup transparently on all platforms.
Note: the spawnSync("git", ...) call in runGitList is unaffected because git is distributed as a native git.exe on Windows.
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/format-docs.mjs
Line: 64
Comment:
**`spawnSync` won't resolve `.cmd` shims on Windows**
`oxfmt` is an npm devDependency. When installed by npm/pnpm on Windows, the binary is exposed via a `node_modules/.bin/oxfmt.cmd` batch-file shim — there is no `oxfmt.exe` in that directory. Node.js's `child_process.spawnSync` on Windows calls `CreateProcess` directly, which only searches for `.com`/`.exe` extensions and **does not** honor `PATHEXT`, so it will fail to locate `oxfmt.cmd` even if `node_modules/.bin` is on `PATH`. The result would be `ENOENT` (captured silently in `result.error`), causing the script to exit with code 1 with no useful diagnostic — the very Windows compatibility problem this PR is meant to fix.
Two straightforward options:
**Option A — `shell: true` on Windows** (minimal change):
```suggestion
const result = spawnSync("oxfmt", [mode, ...chunk], {
stdio: "inherit",
shell: process.platform === "win32",
});
```
**Option B — add `cross-spawn`** as a dev dependency and replace `spawnSync` with `crossSpawn.sync`, which handles the `.cmd` lookup transparently on all platforms.
Note: the `spawnSync("git", ...)` call in `runGitList` is unaffected because `git` is distributed as a native `git.exe` on Windows.
How can I resolve this? If you propose a fix, please make it concise.| if (result.status !== 0) { | ||
| process.exit(result.status ?? 1); | ||
| } |
There was a problem hiding this comment.
Silent failure when command is not found
When spawnSync fails to launch the child process (e.g., git or oxfmt not in PATH), Node.js sets result.status = null and result.error to an Error with code ENOENT. The current check result.status !== 0 correctly catches this case (null !== 0 is true), but the error is discarded silently — the user just sees a bare exit code 1 with no explanation.
Consider logging result.error before exiting:
| if (result.status !== 0) { | |
| process.exit(result.status ?? 1); | |
| } | |
| if (result.status !== 0) { | |
| if (result.error) { | |
| console.error(`format:docs: failed to run git: ${result.error.message}`); | |
| } | |
| process.exit(result.status ?? 1); | |
| } |
The same pattern applies to the spawnSync call in runOxfmt (line 64–68).
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/format-docs.mjs
Line: 30-32
Comment:
**Silent failure when command is not found**
When `spawnSync` fails to launch the child process (e.g., `git` or `oxfmt` not in `PATH`), Node.js sets `result.status = null` and `result.error` to an `Error` with code `ENOENT`. The current check `result.status !== 0` correctly catches this case (`null !== 0` is `true`), but the error is discarded silently — the user just sees a bare exit code 1 with no explanation.
Consider logging `result.error` before exiting:
```suggestion
if (result.status !== 0) {
if (result.error) {
console.error(`format:docs: failed to run git: ${result.error.message}`);
}
process.exit(result.status ?? 1);
}
```
The same pattern applies to the `spawnSync` call in `runOxfmt` (line 64–68).
How can I resolve this? If you propose a fix, please make it concise.
Summary
Fixes #44293.
pnpm check:docspreviously depended onxargs, which is unavailable in native Windows PowerShell by default.This PR replaces the shell pipeline with a cross-platform Node script that:
git ls-files -zoxfmtdirectly withoutxargsChanges
scripts/format-docs.mjsformat:docs->node scripts/format-docs.mjs --writeformat:docs:check->node scripts/format-docs.mjs --checkValidation
node --check scripts/format-docs.mjs