From 72b78ae30900127e7f9e7913496e309c398600f6 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Fri, 23 Aug 2024 07:35:07 +0200 Subject: [PATCH] Improved recipe. --- .github/workflows/test.yml | 37 +++++----------------------------- metacall.rb | 41 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 53 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7458f8..a87232c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,38 +27,11 @@ jobs: fetch-depth: 0 # Clean up previous dependencies in order to avoid conflicts with brew - - name: Clean - run: | - brew uninstall --force --ignore-dependencies node - brew cleanup -s node - brew cleanup --prune-prefix - brew uninstall --force --ignore-dependencies python@3.11 - brew cleanup -s python@3.11 - brew cleanup --prune-prefix - brew uninstall --force --ignore-dependencies python@3.12 - brew cleanup -s python@3.12 - brew cleanup --prune-prefix - sudo rm -rf /System/Library/Frameworks/Python.framework/ - brew cleanup --prune-prefix - sudo rm -rf /usr/local/bin/2to3 - sudo rm -rf /usr/local/bin/2to3-3.11 - sudo rm -rf /usr/local/bin/2to3-3.12 - sudo rm -rf /usr/local/bin/idle3 - sudo rm -rf /usr/local/bin/idle3.11 - sudo rm -rf /usr/local/bin/idle3.12 - sudo rm -rf /usr/local/bin/pydoc3 - sudo rm -rf /usr/local/bin/pydoc3.11 - sudo rm -rf /usr/local/bin/pydoc3.12 - sudo rm -rf /usr/local/bin/python3 - sudo rm -rf /usr/local/bin/python3-config - sudo rm -rf /usr/local/bin/python3.11 - sudo rm -rf /usr/local/bin/python3.12 - sudo rm -rf /usr/local/bin/python3.11-config - sudo rm -rf /usr/local/bin/python3.12-config - brew uninstall --force --ignore-dependencies ruby - brew cleanup -s ruby - brew cleanup --prune-prefix - sudo rm -rf $(brew --repo homebrew/core) + - name: Uninstall brew completely + run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" + + - name: Install brew + run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Build Homebrew recipe - name: Build diff --git a/metacall.rb b/metacall.rb index 09b5538..f5a6106 100644 --- a/metacall.rb +++ b/metacall.rb @@ -88,6 +88,25 @@ 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") + # Set the compiler cc_compiler = `xcrun --find clang`.tr("\n","") cxx_compiler = `xcrun --find clang++`.tr("\n","") @@ -111,6 +130,7 @@ def install -DNodeJS_CMAKE_DEBUG=ON -DNodeJS_LIBRARY=#{lib}/libnode.127.dylib -DNodeJS_EXECUTABLE=#{bin}/node + -DNPM_ROOT=#{bin} -DOPTION_BUILD_LOADERS_JAVA=OFF -DOPTION_BUILD_LOADERS_JS=OFF -DOPTION_BUILD_LOADERS_C=OFF @@ -159,27 +179,6 @@ 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")