Files
MINGW-packages/mingw-w64-nodejs/0012-Use-shell-wrapper-script-for-npm-on-MSYS2-mingw-w64.patch
2023-06-26 07:52:58 +08:00

57 lines
2.1 KiB
Diff

From 94d3d4f85a245f474091a5e241e249ecbc2c12a1 Mon Sep 17 00:00:00 2001
From: Alexey Pavlov <alexpux@gmail.com>
Date: Thu, 12 Apr 2018 10:20:30 +0200
Subject: [PATCH 12/23] Use shell wrapper script for npm on MSYS2 mingw-w64
---
tools/install.py | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/tools/install.py b/tools/install.py
index f13f2ecd..7f4b1829 100755
--- a/tools/install.py
+++ b/tools/install.py
@@ -101,7 +101,16 @@ def package_files(action, name, bins):
if action == uninstall:
action([link_path], 'bin/' + bin_name)
elif action == install:
- try_symlink('../lib/node_modules/' + name + '/' + bin_target, link_path)
+ # Use MSYS2 shell script wrapper.
+ if sys.platform == 'win32':
+ # Copy the wrapper shell scripts
+ try_copy('deps/npm/bin/' + bin_name, link_path)
+ # the wrappers are shell scripts so the shebang must run sh, not node
+ s = open(link_path, 'r').read()
+ s = re.sub(r'#!.*\n', '#!' + '/usr/bin/env sh' + '\n', s)
+ open(link_path, 'w').write(s)
+ else:
+ try_symlink('../lib/node_modules/' + name + '/' + bin_target, link_path)
else:
assert 0 # unhandled action type
@@ -129,8 +138,19 @@ def corepack_files(action):
action([link_path], 'bin/node-gyp')
elif action == install:
try_symlink('../lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js', link_path)
- else:
- assert 0 # unhandled action type
+ elif sys.platform == 'win32':
+ link_path = abspath(install_path, 'bin/node-gyp')
+ if action == uninstall:
+ action([link_path], 'bin/node-gyp')
+ elif action == install:
+ # Copy the wrapper shell script
+ try_copy('deps/npm/bin/node-gyp-bin/node-gyp', link_path)
+ # deps/npm/bin/node-gyp-bin/node-gyp is a shell script so the shebang must run sh, not node
+ s = open(link_path, 'r').read()
+ s = re.sub(r'#!.*\n', '#!' + '/usr/bin/env sh' + '\n', s)
+ open(link_path, 'w').write(s)
+ else:
+ assert 0 # unhandled action type
def subdir_files(path, dest, action):
ret = {}
--
2.17.0.windows.1