bridgetownrb / node-runner

A simple way to execute Javascript in a Ruby context via Node
MIT License
32 stars 4 forks source link

fix: windows support for extensions #1

Closed bglw closed 3 years ago

bglw commented 3 years ago

Hello Bridgetown 👋

First of all, thanks for the lightweight package — we're using it in Bookshop to implement core logic in JavaScript without having to duplicate logic into Ruby.

We're hitting an issue on Windows, where NodeRunner currently fails its test suite on my machine.

Currently, the locate_executable function enumerates all PATHs end checks for the existence of the command (node) in each folder. This works well on UNIX systems, but does not handle the extensions on Windows.

The default node install on Windows is C:\Program Files\nodejs\node.exe — the issue being locate_executable tries C:\Program Files\nodejs\node (which doesn't exist), but then doesn't enumerate each possible executable path.

This patch loops through all extensions in ENV['PATHEXT'] to try find the command file. It resolves the test suite on my Windows machine, and the tests still pass on my Mac.

Tied to: https://github.com/CloudCannon/eleventy-bookshop-starter/issues/1 Tied to: https://github.com/CloudCannon/bookshop/pull/51