fix(devcontainers-cli): add PNPM_HOME for pnpm package manager#433
fix(devcontainers-cli): add PNPM_HOME for pnpm package manager#433
Conversation
| shell, | ||
| "-c", | ||
| "apk add nodejs npm && npm install -g pnpm", | ||
| `wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh -`, |
There was a problem hiding this comment.
Purely testing purpose, done to not rely on NPM.
| @@ -12,12 +12,12 @@ if ! command -v docker > /dev/null 2>&1; then | |||
| fi | |||
|
|
|||
| # Determine the package manager to use: npm, pnpm, or yarn | |||
There was a problem hiding this comment.
Changed the ordering to use PNPM as a last option, if NPM is installed too.
| && echo "🥳 @devcontainers/cli has been installed into $(which devcontainer)!" | ||
| elif [ "$PACKAGE_MANAGER" = "pnpm" ]; then | ||
| # if PNPM_HOME is not set, set it to the bin directory of the script | ||
| if [ -z "$PNPM_HOME" ]; then |
There was a problem hiding this comment.
Main part of the fix, adding $PNPM_HOME if not set yet.
devcontainers-cli/run.sh
Outdated
| # if PNPM_HOME is not set, set it to the bin directory of the script | ||
| if [ -z "$PNPM_HOME" ]; then | ||
| export PNPM_HOME="$CODER_SCRIPT_BIN_DIR" | ||
| fi |
There was a problem hiding this comment.
Just for my education, how does that work? What is CODER_SCRIPT_BIN_DIR?
There was a problem hiding this comment.
Typically /tmp/coder-script-data/bin, a place where all scripts can place binaries and they will be part of PATH (guaranteed by agent).
mafredri
left a comment
There was a problem hiding this comment.
Suggesting a minor improvement to the script but otherwise looks alright.
devcontainers-cli/run.sh
Outdated
| $PACKAGE_MANAGER install -g @devcontainers/cli \ | ||
| && echo "🥳 @devcontainers/cli has been installed into $(which devcontainer)!" | ||
| elif [ "$PACKAGE_MANAGER" = "pnpm" ]; then | ||
| # if PNPM_HOME is not set, set it to the bin directory of the script |
There was a problem hiding this comment.
This comment could better explain why we need to do this, for posterity.
devcontainers-cli/run.sh
Outdated
| # if PNPM_HOME is not set, set it to the bin directory of the script | ||
| if [ -z "$PNPM_HOME" ]; then | ||
| export PNPM_HOME="$CODER_SCRIPT_BIN_DIR" | ||
| fi |
There was a problem hiding this comment.
Typically /tmp/coder-script-data/bin, a place where all scripts can place binaries and they will be part of PATH (guaranteed by agent).
devcontainers-cli/run.sh
Outdated
| && echo "🥳 @devcontainers/cli has been installed into $(which devcontainer)!" | ||
| elif [ "$PACKAGE_MANAGER" = "yarn" ]; then | ||
| $PACKAGE_MANAGER global add @devcontainers/cli \ | ||
| && echo "🥳 @devcontainers/cli has been installed into $(which devcontainer)!" |
There was a problem hiding this comment.
It'd be nice to factor out this repetition, might I suggest the following?
install() {
if [ "$PACKAGE_MANAGER" = "npm" ]; then
npm install -g @devcontainers/cli
elif [ "$PACKAGE_MANAGER" = "pnpm" ]; then
# <reason we set this>
if [ -z "$PNPM_HOME" ]; then
PNPM_HOME="$CODER_SCRIPT_BIN_DIR"
export PNPM_HOME
fi
pnpm add -g @devcontainers/cli
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
yarn global add @devcontainers/cli
fi
}
if ! install; then
echo "Failed to install @devcontainers/cli" >&2
exit 1
fi
if ! command -v devcontainer > /dev/null 2>&1; then
echo "Installation completed but 'devcontainer' command not found in PATH" >&2
exit 1
fi
echo "🥳 @devcontainers/cli has been installed into $(which devcontainer)!"
exit 0 Adds a bit more detail and validates the binary is present.
|
Make version |
|
@mafredri for version constraints, I am thinking of introducing labels like |
PNPM requires
$PNPM_HOMEto be set to install packages.This PR is a follow-up on the one creating @devcontainers-cli module - to ensure PNPM_HOME is set, based on values set by Coder.