Skip to content

Commit

Permalink
chore: run all windows shims tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored and wraithgar committed Jun 26, 2023
1 parent a2fa41e commit 332dec3
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 104 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,38 @@ jobs:
run: node . test -w smoke-tests --ignore-scripts
- name: Check Git Status
run: node scripts/git-dirty.js

windows-shims:
name: Windows Shims Tests
runs-on: windows-latest
defaults:
run:
shell: cmd
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm
- name: Check Git Status
run: node scripts/git-dirty.js
- name: Reset Deps
run: node scripts/resetdeps.js
- name: Setup WSL
uses: Vampire/setup-wsl@v2.0.1
- name: Setup Cygwin
uses: egor-tensin/setup-cygwin@v4.0.1
with:
install-dir: C:\cygwin64
- name: Run Windows Shims Tests
run: node . test --ignore-scripts -- test/bin/windows-shims.js --no-coverage
env:
WINDOWS_SHIMS_TEST: true
- name: Check Git Status
run: node scripts/git-dirty.js
27 changes: 22 additions & 5 deletions bin/npm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
IS_WSL="true"
fi

function no_node_dir {
# if this didn't work, then everything else below will fail
echo "Could not determine Node.js install directory" >&2
exit 1
}

NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
NODE_EXE="$basedir/node"
Expand All @@ -21,13 +31,20 @@ fi

# this path is passed to node.exe, so it needs to match whatever
# kind of paths Node.js thinks it's using, typically win32 paths.
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
if [ $? -ne 0 ]; then
# this fails under WSL 1 so add an additional message. we also suppress stderr above
# because the actual error raised is not helpful. in WSL 1 node.exe cannot handle
# output redirection properly. See https://github.com/microsoft/WSL/issues/2370
if [ "$IS_WSL" == "true" ]; then
echo "WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2
fi
no_node_dir
fi
NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
if [ $? -ne 0 ]; then
# if this didn't work, then everything else below will fail
echo "Could not determine Node.js install directory" >&2
exit 1
no_node_dir
fi
NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"

Expand All @@ -37,7 +54,7 @@ NPM_WSL_PATH="/.."
# WSL can run Windows binaries, so we have to give it the win32 path
# however, WSL bash tests against posix paths, so we need to construct that
# to know if npm is installed globally.
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
if [ "$IS_WSL" == "true" ]; then
NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
fi
if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
Expand Down
27 changes: 22 additions & 5 deletions bin/npx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
IS_WSL="true"
fi

function no_node_dir {
# if this didn't work, then everything else below will fail
echo "Could not determine Node.js install directory" >&2
exit 1
}

NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
NODE_EXE="$basedir/node"
Expand All @@ -21,14 +31,21 @@ fi

# this path is passed to node.exe, so it needs to match whatever
# kind of paths Node.js thinks it's using, typically win32 paths.
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
if [ $? -ne 0 ]; then
# this fails under WSL 1 so add an additional message. we also suppress stderr above
# because the actual error raised is not helpful. in WSL 1 node.exe cannot handle
# output redirection properly. See https://github.com/microsoft/WSL/issues/2370
if [ "$IS_WSL" == "true" ]; then
echo "WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2
fi
no_node_dir
fi
NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
NPX_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npx-cli.js"
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
if [ $? -ne 0 ]; then
# if this didn't work, then everything else below will fail
echo "Could not determine Node.js install directory" >&2
exit 1
no_node_dir
fi
NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"

Expand All @@ -38,7 +55,7 @@ NPX_WSL_PATH="/.."
# WSL can run Windows binaries, so we have to give it the win32 path
# however, WSL bash tests against posix paths, so we need to construct that
# to know if npm is installed globally.
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
if [ "$IS_WSL" == "true" ]; then
NPX_WSL_PATH=`wslpath "$NPM_PREFIX_NPX_CLI_JS"`
fi
if [ -f "$NPM_PREFIX_NPX_CLI_JS" ] || [ -f "$NPX_WSL_PATH" ]; then
Expand Down
21 changes: 21 additions & 0 deletions scripts/template-oss/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@
run: {{rootNpmPath}} test -w smoke-tests --ignore-scripts
- name: Check Git Status
run: node scripts/git-dirty.js

windows-shims:
name: Windows Shims Tests
runs-on: windows-latest
defaults:
run:
shell: cmd
steps:
{{> stepsSetup }}
- name: Setup WSL
uses: Vampire/setup-wsl@v2.0.1
- name: Setup Cygwin
uses: egor-tensin/setup-cygwin@v4.0.1
with:
install-dir: C:\cygwin64
- name: Run Windows Shims Tests
run: {{rootNpmPath}} test --ignore-scripts -- test/bin/windows-shims.js --no-coverage
env:
WINDOWS_SHIMS_TEST: true
- name: Check Git Status
run: node scripts/git-dirty.js
Loading

0 comments on commit 332dec3

Please sign in to comment.