Skip to content

docs: use nodejs commands for creating files on Windows (#4728)#4730

Merged
escapedcat merged 3 commits intoconventional-changelog:masterfrom
festoney8:docs/fix-escape-issue
Apr 25, 2026
Merged

docs: use nodejs commands for creating files on Windows (#4728)#4730
escapedcat merged 3 commits intoconventional-changelog:masterfrom
festoney8:docs/fix-escape-issue

Conversation

@festoney8
Copy link
Copy Markdown
Contributor

@festoney8 festoney8 commented Apr 22, 2026

Description

This PR updates the doc to use node.js commands for creating files on Windows. And makes a clear distinction for the setup guide between Linux/macOS and Windows.

It brings some benefits:

Windows commands before and after:

# before
echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

# after
node -e "fs.writeFileSync('commitlint.config.js', process.argv[1])" "export default { extends: ['@commitlint/config-conventional'] };"
# before
echo "pnpm dlx commitlint --edit `$1" > .husky/commit-msg

# after
node -e "fs.writeFileSync('.husky/commit-msg', 'pnpm dlx commitlint --edit $'+'1\n')"

Motivation and Context

The original doc specifically pointed out encoding issues on Windows, and instructed users to create files manually.

Commands may behave different on various shells in Powershell v5 or v7, Git Bash, Windows CMD.

This change runs a js script which consistently creates UTF-8 files across all platforms. Additionally, single-quoted strings and string concat are used in the commands to avoid special character issues.

How Has This Been Tested?

Tested on

  • Node.js v18
  • Node.js v24
  • windows powershell v5
  • windows powershell v7
  • windows cmd
  • windows Git Bash

Previous commands on windows + node v24

D:\Code\test-echo
❯ echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

D:\Code\test-echo via  v24.12.0
❯ echo "pnpm dlx commitlint --edit `$1" > .husky/commit-msg

D:\Code\test-echo via  v24.12.0
❯ file -i .\commitlint.config.js
.\commitlint.config.js: application/javascript; charset=utf-16le

D:\Code\test-echo via  v24.12.0
❯ file -i .\.husky\commit-msg
.\.husky\commit-msg: text/plain; charset=utf-16le

D:\Code\test-echo via  v24.12.0
❯ cat .husky/commit-msg
pnpm dlx commitlint --edit $1

D:\Code\test-echo via  v24.12.0
❯ cat .\commitlint.config.js
export default { extends: ['@commitlint/config-conventional'] };

New commands on windows + node v24

D:\Code\test-commands
> node -e "fs.writeFileSync('commitlint.config.js', process.argv[1])" "export default { extends: ['@commitlint/config-conventional'] };"

D:\Code\test-commands via  v24.12.0
> cat commitlint.config.js
export default { extends: ['@commitlint/config-conventional'] };

D:\Code\test-commands via  v24.12.0
> node -e "fs.writeFileSync('.husky/commit-msg', 'pnpm dlx commitlint --edit $'+'1\n')"

D:\Code\test-commands via  v24.12.0
> cat .husky/commit-msg
pnpm dlx commitlint --edit $1

D:\Code\test-commands via  v24.12.0
> node -e "fs.writeFileSync('.husky/commit-msg', 'pnpm commitlint $'+'{1}\n')"

D:\Code\test-commands via  v24.12.0
> cat .husky/commit-msg
pnpm commitlint ${1}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Fix PowerShell escape character issue in Windows commands

🐞 Bug fix 📝 Documentation

Grey Divider

Walkthroughs

Description
• Remove trailing backtick from PowerShell commands in documentation
• Trailing backtick escapes closing quote, causing malformed commands
• Clarify Windows commands are specifically for PowerShell users
• Fix applied consistently across all package manager sections
Diagram
flowchart LR
  A["PowerShell Commands<br/>with trailing backtick"] -- "Remove invalid<br/>trailing backtick" --> B["Corrected Commands<br/>with proper escaping"]
  C["Generic Windows<br/>user comment"] -- "Clarify target<br/>audience" --> D["PowerShell-specific<br/>user comment"]
Loading

Grey Divider

File Changes

1. docs/guides/local-setup.md 🐞 Bug fix +10/-10

Fix PowerShell escape sequences in setup documentation

• Removed trailing backtick from PowerShell command examples in npm section
• Removed trailing backtick from PowerShell command examples in yarn section
• Removed trailing backtick from PowerShell command examples in pnpm section
• Removed trailing backtick from PowerShell command examples in bun and deno sections
• Updated comments from "Windows users" to "Windows PowerShell users" for clarity across all
 sections

docs/guides/local-setup.md


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Apr 22, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Non-UTF8 hook output🐞 Bug ☼ Reliability
Description
The PowerShell-specific examples write .husky/commit-msg using echo "..." > ..., but this docs
set already warns that PowerShell echo redirection may create non‑UTF‑8 files, which can break
hook execution. This pattern is repeated for npm/yarn/pnpm/bun/deno PowerShell snippets.
Code

docs/guides/local-setup.md[R41-42]

+# Windows PowerShell users should use ` to escape dollar signs
+echo "npx --no -- commitlint --edit `$1" > .husky/commit-msg
Evidence
local-setup.md warns Windows users that Husky files must be UTF-8 encoded, yet the PowerShell
command writes the hook using echo ... >, which the repo’s getting-started.md explicitly warns
can create non‑UTF‑8 (e.g., UTF‑16LE) files in PowerShell and recommends using `Out-File -Encoding
utf8` instead.

docs/guides/local-setup.md[23-42]
docs/guides/getting-started.md[39-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PowerShell commands in `docs/guides/local-setup.md` write `.husky/commit-msg` using `echo "..." > .husky/commit-msg`. Elsewhere in the docs, we already warn that `echo` redirection in Windows PowerShell can create non‑UTF‑8 files (e.g., UTF‑16LE), which can cause tooling/hook failures.
## Issue Context
`docs/guides/local-setup.md` also warns that Husky files must be UTF-8 encoded; the PowerShell snippets should therefore use an explicit UTF-8 write method (similar to the guidance in `docs/guides/getting-started.md`).
## Fix Focus Areas
Update each “Windows PowerShell users…” command to write UTF-8 explicitly (e.g., using `Out-File -Encoding utf8` or `Set-Content -Encoding utf8`) while preserving the backtick escape before `$1`:
- docs/guides/local-setup.md[41-42]
- docs/guides/local-setup.md[64-65]
- docs/guides/local-setup.md[90-91]
- docs/guides/local-setup.md[113-114]
- docs/guides/local-setup.md[129-130]
(Optionally: consider using a `powershell`-typed fenced code block for the PowerShell-only line(s) to reduce copy/paste mistakes, but the key fix is explicit UTF-8 output.)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread docs/guides/local-setup.md Outdated
@festoney8
Copy link
Copy Markdown
Contributor Author

festoney8 commented Apr 22, 2026

The bot pointed out a compatibility problem. In PowerShell v5 command echo "xxx" > file will create an UTF-16 LE file, but in PowerShell v7 it's an UTF-8 file.

Do I need to completely resolve the encoding issue using some node command? @escapedcat

For example:

node -e "fs.writeFileSync('.husky/commit-msg', 'pnpm dlx commitlint --edit \x241\n')"

This works well in all platforms all shells

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Windows PowerShell command examples in the local setup guide by removing a trailing backtick that breaks quoted strings, and clarifies that the Windows-specific escaping applies to PowerShell users.

Changes:

  • Remove the trailing backtick from PowerShell echo commands that write .husky/commit-msg.
  • Update the inline guidance to explicitly target Windows PowerShell users (not all Windows shells).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/guides/local-setup.md Outdated
Comment thread docs/guides/local-setup.md Outdated
Comment thread docs/guides/local-setup.md Outdated
Comment thread docs/guides/local-setup.md Outdated
Comment thread docs/guides/local-setup.md Outdated
@escapedcat
Copy link
Copy Markdown
Member

The bot pointed out a compatibility problem. In PowerShell v5 command echo "xxx" > file will create an UTF-16 LE file, but in PowerShell v7 it's an UTF-8 file.

Maybe just mention this in the docs? I'm not familiar with Windows

@escapedcat
Copy link
Copy Markdown
Member

Have a look at the copilot comments and see if they are valid, thanks!

@festoney8
Copy link
Copy Markdown
Contributor Author

Have a look at the copilot comments and see if they are valid, thanks!

The PowerShell commands provided by Copilot work well.

Actually, the encoding issue has also occurred once with Prettier years ago and finally it's resolved by a node command in this PR.

Either PowerShell or node command can solve the problem. The former requires specifying the operating system in doc, while the latter does not, though the command may look a bit weird.

@escapedcat
Copy link
Copy Markdown
Member

Let's go with you suggestion for now

@festoney8
Copy link
Copy Markdown
Contributor Author

festoney8 commented Apr 23, 2026

I updated the PR and ran bunch of tests, shouldn't be any issues I guess.

Still feels a bit odd using hex in commands, but it works nicely :D

@festoney8 festoney8 changed the title docs: remove trailing backtick in windows commands (#4728) docs: use nodejs commands for creating files (#4728) Apr 23, 2026
@escapedcat
Copy link
Copy Markdown
Member

Still feels a bit odd using hex in commands, but it works nicely :D

Yeah, looks weird, but if this is what prettier suggest I guess we're fine? Or maybe we leave the current way and add a comment that the "node" way works for all systems including Windows? In that way users have the choice?

@festoney8
Copy link
Copy Markdown
Contributor Author

festoney8 commented Apr 24, 2026

Yeah, looks weird, but if this is what prettier suggest I guess we're fine? Or maybe we leave the current way and add a comment that the "node" way works for all systems including Windows? In that way users have the choice?

If there's no good solution, I'll just keep current way for linux/macos and only require the windows system to use the node command.

And how about this?

Just pass filename and command as parameters, longer but no hex no escape character.

node -e "fs.writeFileSync(process.argv[1], process.argv[2])" <filename> <command>
# example 1
node -e "fs.writeFileSync(process.argv[1], process.argv[2])" '.husky/commit-msg' 'pnpm dlx commitlint --edit $1'
# example 2
node -e "fs.writeFileSync(process.argv[1], process.argv[2])" "commitlint.config.js" "export default { extends: ['@commitlint/config-conventional'] };"

Or only pass one parameter

node -e "fs.writeFileSync(<filename>, process.argv[1])" <command>
# example 1
node -e "fs.writeFileSync('.husky/commit-msg', process.argv[1])" 'pnpm dlx commitlint --edit $1'
# example 2
node -e "fs.writeFileSync('commitlint.config.js', process.argv[1])" "export default { extends: ['@commitlint/config-conventional'] };"

@escapedcat
Copy link
Copy Markdown
Member

Let's go with "one".

Since the encoding/escape issues only affect Windows, I'd prefer to keep the familiar echo commands as the default and add a Windows-specific note recommending the node -e form. That way most users see the simpler snippet, and Windows users get a clear fix without hex in the command. What do you think?

@festoney8
Copy link
Copy Markdown
Contributor Author

no problem, I'll change the doc like this

@festoney8
Copy link
Copy Markdown
Contributor Author

festoney8 commented Apr 24, 2026

Unfortunately, passing one parameter to node command causes issues in Windows CMD.

But I found a simpler way: since powershell recognizes $1 , Git bash recognizes ${1} and CMD treat dollar sign as normal character, simply splitting after dollar will works perfectly. like this

node -e "fs.writeFileSync('.husky/commit-msg', 'bunx commitlint --edit $'+'1\n')"

Since all the issues are windows related, I'm planning to completely separate them by system.

The linux/maxOS block will keep the previous. In this way, I only need to solve the problems of shells on windows by node command.

How about using tabs and nested tabs?

Getting started section

image

Local setup section

image

@festoney8 festoney8 changed the title docs: use nodejs commands for creating files (#4728) docs: use nodejs commands for creating files on Windows (#4728) Apr 25, 2026
@escapedcat escapedcat requested a review from Copilot April 25, 2026 04:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/guides/local-setup.md
Comment thread docs/guides/local-setup.md
Comment thread docs/guides/local-setup.md
Comment thread docs/guides/local-setup.md
Comment thread docs/guides/local-setup.md
Comment thread docs/guides/local-setup.md
Comment thread docs/guides/local-setup.md
Comment thread docs/guides/getting-started.md
Comment thread docs/guides/local-setup.md
@festoney8
Copy link
Copy Markdown
Contributor Author

Forget about copilot's suggestions, pretty buggy. Node has supported this since version 5.

I've tested the command in various shells on Windows and it works fine.

root@node18:~# fnm use 4
Using Node v4.9.1
root@node18:~# node -v
v4.9.1
root@node18:~# node -e "console.log(typeof fs.writeFileSync)"
[eval]:1
console.log(typeof fs.writeFileSync)
                   ^

ReferenceError: fs is not defined
    at [eval]:1:20
    at Object.exports.runInThisContext (vm.js:54:17)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:409:26)
    at node.js:648:27
    at nextTickCallbackWith0Args (node.js:489:9)
    at process._tickCallback (node.js:418:13)
root@node18:~# fnm use 5
Using Node v5.12.0
root@node18:~# node -v
v5.12.0
root@node18:~# node -e "console.log(typeof fs.writeFileSync)"
function
root@node18:~# node -e "console.log(global.fs === fs)"
true

@escapedcat
Copy link
Copy Markdown
Member

Thanks for being so patient!

@escapedcat escapedcat merged commit abb9117 into conventional-changelog:master Apr 25, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

fix: Escape dollar sign for Windows local setup commands

3 participants