Skip to content

Commit

Permalink
Trying to solve npm issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Aug 23, 2024
1 parent 72b78ae commit 76ab8be
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions metacall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,9 @@ def install

bash_completion.install bootstrap/"lib/utils/completion.sh" => "npm"

# Post Install NPM
node_modules = HOMEBREW_PREFIX/"lib/node_modules"
node_modules.mkpath
# Kill npm but preserve all other modules across node updates/upgrades.
rm_r node_modules/"npm" if (node_modules/"npm").exist?

cp_r libexec/"lib/node_modules/npm", node_modules
# This symlink doesn't hop into homebrew_prefix/bin automatically so
# we make our own. This is a small consequence of our
# bottle-npm-and-retain-a-private-copy-in-libexec setup
# All other installs **do** symlink to homebrew_prefix/bin correctly.
# We ln rather than cp this because doing so mimics npm's normal install.
ln_sf node_modules/"npm/bin/npm-cli.js", bin/"npm"
ln_sf node_modules/"npm/bin/npx-cli.js", bin/"npx"
ln_sf bin/"npm", HOMEBREW_PREFIX/"bin/npm"
ln_sf bin/"npx", HOMEBREW_PREFIX/"bin/npx"

(node_modules/"npm/npmrc").atomic_write("prefix = #{HOMEBREW_PREFIX}\n")
# Link NPM modules into bin
ln_sf libexec/"lib/node_modules/npm/bin/npm-cli.js", bin/"npm"
ln_sf libexec/"lib/node_modules/npm/bin/npx-cli.js", bin/"npx"

# Set the compiler
cc_compiler = `xcrun --find clang`.tr("\n","")
Expand Down Expand Up @@ -179,6 +164,27 @@ def install
system "cmake", "--build", ".", "--target", "clean"
end

# NPM Post Install
def post_install
node_modules = HOMEBREW_PREFIX/"lib/node_modules"
node_modules.mkpath
# Kill npm but preserve all other modules across node updates/upgrades.
rm_r node_modules/"npm" if (node_modules/"npm").exist?

cp_r libexec/"lib/node_modules/npm", node_modules
# This symlink doesn't hop into homebrew_prefix/bin automatically so
# we make our own. This is a small consequence of our
# bottle-npm-and-retain-a-private-copy-in-libexec setup
# All other installs **do** symlink to homebrew_prefix/bin correctly.
# We ln rather than cp this because doing so mimics npm's normal install.
ln_sf node_modules/"npm/bin/npm-cli.js", bin/"npm"
ln_sf node_modules/"npm/bin/npx-cli.js", bin/"npx"
ln_sf bin/"npm", HOMEBREW_PREFIX/"bin/npm"
ln_sf bin/"npx", HOMEBREW_PREFIX/"bin/npx"

(node_modules/"npm/npmrc").atomic_write("prefix = #{HOMEBREW_PREFIX}\n")
end

test do
(testpath/"test.js").write <<~EOS
console.log("Hello from NodeJS")
Expand Down

0 comments on commit 76ab8be

Please sign in to comment.