rails / jsbundling-rails

Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
MIT License
831 stars 143 forks source link

Replace `command` with `which` in tool_exists #192

Open cocco111 opened 5 months ago

cocco111 commented 5 months ago

command is a built-in shell command in linux (at least in debian , ubuntu and similars) If executed in ruby system it return nil (inspecting: 127 command not found) This not happens with which, that is a system command.

I 've done a PR for fast, but if you prefer I can open a simple issue. 🙂 TY

dhh commented 1 month ago

It's fine for it to return nil when the command is not found. It's falsy.

cocco111 commented 1 month ago

Sorry but It seems not ok to me If 'command' is not found returns falsy, but in this situation routine is unable to find 'tool'

dhh commented 1 month ago

I don't understand the concern you're raising:

irb(main):001> system "command -v yarn > /dev/null"
=> true
irb(main):002> system "command -v yorn > /dev/null"
=> false
cocco111 commented 1 month ago

'command' is a shell (sh) command If you execute irb not in a shell but in windows CMD or kind of different terminals, the result will be always falsy, for error 'command not found' referred to 'command' itself

Instead 'which' is an external command, often installed at system level (is an executable in PATH) in both Linux, Windows etc

dhh commented 1 month ago

Ah, I see. So you're hitting this problem running it in a Windows shell? Does the rest of everything work otherwise? We typically don't spend much/any time on compatibility with Windows shell, since WSL offers a much easier road to compatibility. Or is there another shell where this is manifesting itself?

cocco111 commented 1 month ago

Also in linux See these screens WSL2 - Ubuntu

wsl

Real linux - Debian

linux

Both have same problem My opinion: IRB does not spawn on the sh shell who launched it (it's a different process? standalone executable? don't know),