Skip to content

scripts,package.json: mv format logic to .sh file#257

Open
knocte wants to merge 3 commits into
masterfrom
wip/fixPreCommitScriptOnWindows
Open

scripts,package.json: mv format logic to .sh file#257
knocte wants to merge 3 commits into
masterfrom
wip/fixPreCommitScriptOnWindows

Conversation

@knocte
Copy link
Copy Markdown
Contributor

@knocte knocte commented May 18, 2026

This way:

  • The logic is more readable.
  • It fixes execution on MINGW64(Windows) terminal.

@knocte knocte force-pushed the wip/fixPreCommitScriptOnWindows branch from 0605f0d to d170ea5 Compare May 18, 2026 09:25
@knocte knocte changed the title scripts,package.json: move 'format' logic to .sh file scripts,package.json: mv format logic to .sh file May 18, 2026
This way:
* The logic is more readable.
* It fixes execution on MINGW64(Windows) terminal.
@knocte knocte force-pushed the wip/fixPreCommitScriptOnWindows branch from d170ea5 to 812edc6 Compare May 18, 2026 10:04
@webwarrior-ws
Copy link
Copy Markdown
Collaborator

npm run format runs fine on Windows in git terminal, but fails in PowerShell and cmd.exe with

> format
> bash ./scripts/format.sh

Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

@knocte
Copy link
Copy Markdown
Contributor Author

knocte commented May 18, 2026

but fails in PowerShell and cmd.exe with

Less priority to fix those cases, but I'm curious, if you add shx in the devDependencies section (I think via npm install --save-dev or something like that), and you replace bash with sh in that line of the scripts section of package.json, does it work? (Test in the 3 cases please)

@webwarrior-ws
Copy link
Copy Markdown
Collaborator

but fails in PowerShell and cmd.exe with

Less priority to fix those cases, but I'm curious, if you add shx in the devDependencies section (I think via npm install --save-dev or something like that), and you replace bash with sh in that line of the scripts section of package.json, does it work? (Test in the 3 cases please)

Powershell & cmd.exe:

'sh' is not recognized as an internal or external command,
operable program or batch file.

Git terminal: works normally.

shx in devDependencies doesn't change any of that.

@knocte
Copy link
Copy Markdown
Contributor Author

knocte commented May 18, 2026

'sh' is not recognized as an internal or external command,

I meant shx, not sh, sorry; test again

@webwarrior-ws
Copy link
Copy Markdown
Collaborator

'sh' is not recognized as an internal or external command,

I meant shx, not sh, sorry; test again

> format
> shx ./scripts/format.sh

Error: Invalid ShellJS command: ./scripts/format.sh.

shx: A wrapper for shelljs UNIX commands.

Usage: shx [shx-options] <command> [cmd-options] [cmd-args]
...

In all terminals.

@knocte
Copy link
Copy Markdown
Contributor Author

knocte commented May 18, 2026

Alright, I'm giving up with Powershell&cmd.exe for now (at least for this PR). Please update to latest commit of this PR and test now npm run format:check with MINGW64

@webwarrior-ws
Copy link
Copy Markdown
Collaborator

Alright, I'm giving up with Powershell&cmd.exe for now (at least for this PR). Please update to latest commit of this PR and test now npm run format:check with MINGW64

$ npm run format:check

> format:check
> bash ./scripts/format.sh --check

/c/Program Files/nodejs/npx
2.8.3
Checking formatting...
All matched files use Prettier code style!

@knocte
Copy link
Copy Markdown
Contributor Author

knocte commented May 18, 2026

Try now the negative case (making the formatting of a .ts file incorrect, introduce an extra trailing space for example).

@webwarrior-ws
Copy link
Copy Markdown
Collaborator

Try now the negative case (making the formatting of a .ts file incorrect, introduce an extra trailing space for example).

$ npm run format:check

> format:check
> bash ./scripts/format.sh --check

/c/Program Files/nodejs/npx
2.8.3
Checking formatting...
[warn] commitlint.config.ts
[warn] Code style issues fixed in the above file.

Changes to formatting were indeed rolled back.

@knocte
Copy link
Copy Markdown
Contributor Author

knocte commented May 18, 2026

What do you mean rolled back? AFAIU --check doesn't do the changes and then rolls them back, it checks if the files need changes. And if they do, it exits with exitCode>0, did it do that? would this work as a pre-commit?

@webwarrior-ws
Copy link
Copy Markdown
Collaborator

What do you mean rolled back? AFAIU --check doesn't do the changes and then rolls them back, it checks if the files need changes. And if they do, it exits with exitCode>0, did it do that? would this work as a pre-commit?

./scripts/format.sh doesn't use that --check flag and always does the same thing

@webwarrior-ws
Copy link
Copy Markdown
Collaborator

I see. It does pass --check flag. But prettier still writes changes to files if --write flag is present

Same motivation as previous commit.
@knocte knocte force-pushed the wip/fixPreCommitScriptOnWindows branch 3 times, most recently from a77c982 to f148f2f Compare May 18, 2026 15:12
@knocte
Copy link
Copy Markdown
Contributor Author

knocte commented May 18, 2026

still writes changes to files if --write flag is present

Ah good catch. Fixed. Please test again.

@knocte knocte force-pushed the wip/fixPreCommitScriptOnWindows branch 2 times, most recently from d0ce322 to e28beed Compare May 18, 2026 15:28
Instead of having it at the pre-commit script, we move it to
format.sh so that 'npm run format' can check formatting for
both prettier and fantomless. This way both tools get
centralized in just one place (even the CI step is just one
now). And this should all work with MINGW64.

NOTE: We've had to use 'dotnet dnx' instead of just 'dnx' for 2
reasons:
1. dnx is not available in MINGW64 terminal, while dnx.cmd and
dotnet dnx is.
2. dnx is not available in Ubuntu OOTB, but dotnet dnx is.
@knocte knocte force-pushed the wip/fixPreCommitScriptOnWindows branch from e28beed to daac565 Compare May 18, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants