Skip to content

build(docs): make check:docs PowerShell-compatible#44824

Open
tianxingleo wants to merge 1 commit intoopenclaw:mainfrom
tianxingleo:fix/44293-powershell-check-docs
Open

build(docs): make check:docs PowerShell-compatible#44824
tianxingleo wants to merge 1 commit intoopenclaw:mainfrom
tianxingleo:fix/44293-powershell-check-docs

Conversation

@tianxingleo
Copy link
Copy Markdown

Summary

Fixes #44293.

pnpm check:docs previously depended on xargs, which is unavailable in native Windows PowerShell by default.

This PR replaces the shell pipeline with a cross-platform Node script that:

  • collects tracked docs files via git ls-files -z
  • invokes oxfmt directly without xargs
  • chunks file arguments to avoid Windows command-line length issues

Changes

  • add scripts/format-docs.mjs
  • update package scripts:
    • format:docs -> node scripts/format-docs.mjs --write
    • format:docs:check -> node scripts/format-docs.mjs --check

Validation

  • node --check scripts/format-docs.mjs

Note: full pnpm check:docs execution requires project dependencies (including oxfmt) to be installed.

@openclaw-barnacle openclaw-barnacle bot added scripts Repository scripts size: S labels Mar 13, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 13, 2026

Greptile Summary

This PR replaces the xargs-based format:docs and format:docs:check shell pipelines with a cross-platform Node.js script (scripts/format-docs.mjs), addressing the unavailability of xargs in native Windows PowerShell. The chunking strategy for long argument lists and the null-byte-split git ls-files -z parsing are well-implemented.

Key concern:

  • spawnSync("oxfmt", ...) will silently fail on Windows. Because oxfmt is an npm devDependency, pnpm installs it as a node_modules/.bin/oxfmt.cmd batch-file shim on Windows — there is no oxfmt.exe on PATH. Node.js's spawnSync calls CreateProcess directly and does not consult PATHEXT, so it cannot resolve .cmd files. The script will exit with code 1 with no message, which is exactly the failure mode the PR is trying to eliminate. Adding shell: process.platform === "win32" to the runOxfmt spawn options (or using cross-spawn) would fix this.

Minor:

  • result.error is never checked in either runGitList or runOxfmt. When a command is not found, the user gets a silent non-zero exit with no diagnostic output.

Confidence Score: 3/5

  • The PR is likely broken on Windows as-is due to how Node.js spawnSync resolves executables; the core goal of the change may not be achieved.
  • The logic is clean and the approach is sound, but there is a significant platform-specific issue: spawnSync without shell:true cannot find .cmd shims on Windows, which is exactly the platform this PR targets. The fix is small (one option flag) but without it the script would fail on Windows just as the original xargs version did — though for a different reason.
  • scripts/format-docs.mjs — specifically the spawnSync call for oxfmt in runOxfmt (line 64)
Prompt To Fix All 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.

---

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], {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Suggested 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.

Comment on lines +30 to +32
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make pnpm check:docs work in native PowerShell

1 participant