Skip to content

Commit 332dec3

Browse files
lukekarryswraithgar
authored andcommitted
chore: run all windows shims tests
1 parent a2fa41e commit 332dec3

File tree

5 files changed

+283
-104
lines changed

5 files changed

+283
-104
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,38 @@ jobs:
157157
run: node . test -w smoke-tests --ignore-scripts
158158
- name: Check Git Status
159159
run: node scripts/git-dirty.js
160+
161+
windows-shims:
162+
name: Windows Shims Tests
163+
runs-on: windows-latest
164+
defaults:
165+
run:
166+
shell: cmd
167+
steps:
168+
- name: Checkout
169+
uses: actions/checkout@v3
170+
- name: Setup Git User
171+
run: |
172+
git config --global user.email "[email protected]"
173+
git config --global user.name "npm CLI robot"
174+
- name: Setup Node
175+
uses: actions/setup-node@v3
176+
with:
177+
node-version: 18.x
178+
cache: npm
179+
- name: Check Git Status
180+
run: node scripts/git-dirty.js
181+
- name: Reset Deps
182+
run: node scripts/resetdeps.js
183+
- name: Setup WSL
184+
uses: Vampire/[email protected]
185+
- name: Setup Cygwin
186+
uses: egor-tensin/[email protected]
187+
with:
188+
install-dir: C:\cygwin64
189+
- name: Run Windows Shims Tests
190+
run: node . test --ignore-scripts -- test/bin/windows-shims.js --no-coverage
191+
env:
192+
WINDOWS_SHIMS_TEST: true
193+
- name: Check Git Status
194+
run: node scripts/git-dirty.js

bin/npm

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ case `uname` in
1111
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
1212
esac
1313

14+
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
15+
IS_WSL="true"
16+
fi
17+
18+
function no_node_dir {
19+
# if this didn't work, then everything else below will fail
20+
echo "Could not determine Node.js install directory" >&2
21+
exit 1
22+
}
23+
1424
NODE_EXE="$basedir/node.exe"
1525
if ! [ -x "$NODE_EXE" ]; then
1626
NODE_EXE="$basedir/node"
@@ -21,13 +31,20 @@ fi
2131

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

@@ -37,7 +54,7 @@ NPM_WSL_PATH="/.."
3754
# WSL can run Windows binaries, so we have to give it the win32 path
3855
# however, WSL bash tests against posix paths, so we need to construct that
3956
# to know if npm is installed globally.
40-
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
57+
if [ "$IS_WSL" == "true" ]; then
4158
NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
4259
fi
4360
if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then

bin/npx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ case `uname` in
1111
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
1212
esac
1313

14+
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
15+
IS_WSL="true"
16+
fi
17+
18+
function no_node_dir {
19+
# if this didn't work, then everything else below will fail
20+
echo "Could not determine Node.js install directory" >&2
21+
exit 1
22+
}
23+
1424
NODE_EXE="$basedir/node.exe"
1525
if ! [ -x "$NODE_EXE" ]; then
1626
NODE_EXE="$basedir/node"
@@ -21,14 +31,21 @@ fi
2131

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

@@ -38,7 +55,7 @@ NPX_WSL_PATH="/.."
3855
# WSL can run Windows binaries, so we have to give it the win32 path
3956
# however, WSL bash tests against posix paths, so we need to construct that
4057
# to know if npm is installed globally.
41-
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
58+
if [ "$IS_WSL" == "true" ]; then
4259
NPX_WSL_PATH=`wslpath "$NPM_PREFIX_NPX_CLI_JS"`
4360
fi
4461
if [ -f "$NPM_PREFIX_NPX_CLI_JS" ] || [ -f "$NPX_WSL_PATH" ]; then

scripts/template-oss/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,24 @@
1111
run: {{rootNpmPath}} test -w smoke-tests --ignore-scripts
1212
- name: Check Git Status
1313
run: node scripts/git-dirty.js
14+
15+
windows-shims:
16+
name: Windows Shims Tests
17+
runs-on: windows-latest
18+
defaults:
19+
run:
20+
shell: cmd
21+
steps:
22+
{{> stepsSetup }}
23+
- name: Setup WSL
24+
uses: Vampire/[email protected]
25+
- name: Setup Cygwin
26+
uses: egor-tensin/[email protected]
27+
with:
28+
install-dir: C:\cygwin64
29+
- name: Run Windows Shims Tests
30+
run: {{rootNpmPath}} test --ignore-scripts -- test/bin/windows-shims.js --no-coverage
31+
env:
32+
WINDOWS_SHIMS_TEST: true
33+
- name: Check Git Status
34+
run: node scripts/git-dirty.js

0 commit comments

Comments
 (0)