Skip to content

Commit 8248bd8

Browse files
authored
add npx alias (#39)
1 parent c40bce5 commit 8248bd8

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/artifacts-helper/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Configures Codespace to authenticate with Azure Artifact feeds
2121
| nugetAlias | Create alias for nuget | boolean | true |
2222
| npmAlias | Create alias for npm | boolean | true |
2323
| yarnAlias | Create alias for yarn | boolean | true |
24+
| npxAlias | Create alias for npx | boolean | true |
2425

2526
## Customizations
2627

src/artifacts-helper/devcontainer-feature.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
"type": "boolean",
3434
"default": true,
3535
"description": "Create alias for yarn"
36+
},
37+
"npxAlias": {
38+
"type": "boolean",
39+
"default": true,
40+
"description": "Create alias for npx"
3641
}
3742
},
3843
"installsAfter": [

src/artifacts-helper/install.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ALIAS_DOTNET="${DOTNETALIAS:-"true"}"
88
ALIAS_NUGET="${NUGETALIAS:-"true"}"
99
ALIAS_NPM="${NPMALIAS:-"true"}"
1010
ALIAS_YARN="${YARNALIAS:-"true"}"
11+
ALIAS_NPX="${NPXALIAS:-"true"}"
1112

1213
# Source /etc/os-release to get OS info
1314
. /etc/os-release
@@ -59,6 +60,8 @@ cp ./scripts/run-yarn.sh /usr/local/bin/run-yarn.sh
5960
chmod +rx /usr/local/bin/run-yarn.sh
6061
cp ./scripts/write-npm.sh /usr/local/bin/write-npm.sh
6162
chmod +rx /usr/local/bin/write-npm.sh
63+
cp ./scripts/run-npx.sh /usr/local/bin/run-npx.sh
64+
chmod +rx /usr/local/bin/run-npx.sh
6265

6366

6467
if command -v sudo >/dev/null 2>&1; then
@@ -78,6 +81,10 @@ if command -v sudo >/dev/null 2>&1; then
7881
if [ "${ALIAS_YARN}" = "true" ]; then
7982
sudo -u ${_REMOTE_USER} bash -c "echo 'alias yarn=/usr/local/bin/run-yarn.sh' >> ~/.bashrc"
8083
sudo -u ${_REMOTE_USER} bash -c "echo 'alias yarn=/usr/local/bin/run-yarn.sh' >> ~/.zshrc"
84+
fi
85+
if [ "${ALIAS_NPX}" = "true" ]; then
86+
sudo -u ${_REMOTE_USER} bash -c "echo 'alias npx=/usr/local/bin/run-npx.sh' >> ~/.bashrc"
87+
sudo -u ${_REMOTE_USER} bash -c "echo 'alias npx=/usr/local/bin/run-npx.sh' >> ~/.zshrc"
8188
fi
8289
sudo -u ${_REMOTE_USER} bash -c "/tmp/install-provider.sh ${USENET6}"
8390
rm /tmp/install-provider.sh
@@ -105,6 +112,11 @@ if [ "${ALIAS_YARN}" = "true" ]; then
105112
sudo -u ${_REMOTE_USER} bash -c "echo 'alias yarn=/usr/local/bin/run-yarn.sh' >> /etc/zsh/zshrc || true
106113
fi
107114

115+
if [ "${ALIAS_NPX}" = "true" ]; then
116+
sudo -u ${_REMOTE_USER} bash -c "echo 'alias npx=/usr/local/bin/run-npx.sh' >> /etc/bash.bashrc || true
117+
sudo -u ${_REMOTE_USER} bash -c "echo 'alias npx=/usr/local/bin/run-npx.sh' >> /etc/zsh/zshrc || true
118+
fi
119+
108120
rm /tmp/install-provider.sh
109121

110122
exit 0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
if [ -f "${HOME}/ado-auth-helper" ]; then
4+
export ARTIFACTS_ACCESSTOKEN=$(${HOME}/ado-auth-helper get-access-token)
5+
fi
6+
7+
# Find the npm executable so we do not run the bash alias again
8+
NPX_EXE=$(which npx)
9+
10+
${NPX_EXE} "$@"
11+
EXIT_CODE=$?
12+
unset NPX_EXE
13+
14+
if [ -f "${HOME}/ado-auth-helper" ]; then
15+
unset ARTIFACTS_ACCESSTOKEN
16+
fi
17+
18+
exit $EXIT_CODE

0 commit comments

Comments
 (0)