Skip to content

Commit

Permalink
Updates the node formula example to properly use the installed node v…
Browse files Browse the repository at this point in the history
…ersion

The existing example uses a symlink which means that whatever `node` is first in the PATH will be used. This can mean that a Homebrew-installed nodejs executable may not work reliably (since it may execute with a different version of node)

This PR changes it so that using the Homebrew-installed `node` will be used. It also includes common other options (like shell completion) as well as the old symlink solution.
  • Loading branch information
ctaintor committed Jun 20, 2024
1 parent 14d452f commit 83f0c5c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/Node-for-Formula-Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ class Foo < Formula

def install
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink Dir["#{libexec}/bin/*"]

# "link" the executable `foo`, ensuring that the version of node installed by Homebrew is used
# (the created `foo` will set the ENV before exec'ing your executable)
env = { PATH: "#{HOMEBREW_PREFIX/"bin"}:$PATH" }

Check failure on line 108 in docs/Node-for-Formula-Authors.md

View workflow job for this annotation

GitHub Actions / docs

Unnecessary spacing detected.
(bin/"foo").write_env_script "#{libexec}/bin/foo", env

# Uncomment if you simply want to symlink the executable – note that this means the first `node` on the PATH will be used

Check failure on line 111 in docs/Node-for-Formula-Authors.md

View workflow job for this annotation

GitHub Actions / docs

Line is too long. [125/118]
# bin.install_symlink Dir["#{libexec}/bin/*"]

# Uncomment if you want to write the completion scripts for bash, fish, and zsh (assuming your executable has a command "completion" which returns a completion script)

Check failure on line 114 in docs/Node-for-Formula-Authors.md

View workflow job for this annotation

GitHub Actions / docs

Line is too long. [171/118]
# generate_completions_from_executable(libexec/"bin/foo", "completion", base_name: 'foo')
end

test do
Expand Down

0 comments on commit 83f0c5c

Please sign in to comment.