|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This is a workaround for a node-gyp bug that has not fully been investigated |
| 4 | +# due to problems reproducing it outside of CI environments (even though it |
| 5 | +# occurs both in evergreen and github actions). |
| 6 | +# Something seems to go wrong when node-gyp extracts the Node.js header tarball, |
| 7 | +# on Windows specifically (this is most likely because node-tar treats |
| 8 | +# the overwriting of existing files differently on Windows than on other OS -- |
| 9 | +# for good reasons, but still). |
| 10 | +# The most likely cause of this issue is that node-gyp somehow extracts the |
| 11 | +# same headers tarball twice, in parallel, in the same location, with race |
| 12 | +# conditions in the tar extraction code leading to issues. |
| 13 | +# The extraction result ends up in %LOCALAPPDATA%\node-gyp\Cache. |
| 14 | +# Manually extracting the tarballs will solve this issue, so we're doing that |
| 15 | +# here. |
| 16 | +# For actually resolving the bug, we would probably need somebody with a local |
| 17 | +# reproduction. However, it seems likely that other people will also encounter |
| 18 | +# this issue, so there's also a good chance that this workaround will just |
| 19 | +# not be needed with a future node-gyp version. |
| 20 | + |
| 21 | +if [ x"$NODE_JS_VERSION" = x"" ]; then |
| 22 | + if node -v; then |
| 23 | + export NODE_JS_VERSION=$(node -p 'process.version.slice(1)') |
| 24 | + else |
| 25 | + echo "Need NODE_JS_VERSION to be set or Node.js to be installed for node-gyp bug workaround script" |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +fi |
| 29 | + |
| 30 | +if [ x"$LOCALAPPDATA" = x"" ]; then |
| 31 | + echo "No LOCALAPPDATA set, ignoring node-gyp bug workaround script" |
| 32 | + exit |
| 33 | +fi |
| 34 | + |
| 35 | +set -x |
| 36 | +CACHEDIR="$LOCALAPPDATA/node-gyp/Cache" |
| 37 | +rm -rvf "$CACHEDIR" |
| 38 | +mkdir -p "$CACHEDIR/$NODE_JS_VERSION" |
| 39 | +cd "$CACHEDIR/$NODE_JS_VERSION" |
| 40 | +curl -sSfLO "https://nodejs.org/download/release/v$NODE_JS_VERSION/node-v$NODE_JS_VERSION-headers.tar.gz" |
| 41 | +tar --strip-components=1 -xvzf "node-v$NODE_JS_VERSION-headers.tar.gz" |
| 42 | +for arch in x64 x86 arm64; do |
| 43 | + mkdir $arch |
| 44 | + pushd $arch |
| 45 | + curl -sSfLO "https://nodejs.org/download/release/v$NODE_JS_VERSION/win-$arch/node.lib" || echo "no $arch v$NODE_JS_VERSION .lib file" |
| 46 | + popd |
| 47 | +done |
| 48 | + |
| 49 | +# Finally, store the right installVersion value for current node-gyp versions |
| 50 | +echo 9 > installVersion |
0 commit comments