From 0490b6deeb240b6c742ac745f4af37f1e7fbcfc7 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Fri, 23 Aug 2024 02:03:57 +0200 Subject: [PATCH] Add post install. --- metacall.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/metacall.rb b/metacall.rb index 19cdc0f..09b5538 100644 --- a/metacall.rb +++ b/metacall.rb @@ -159,6 +159,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")