-
Notifications
You must be signed in to change notification settings - Fork 58
fix(devcontainers-cli): add PNPM_HOME for pnpm package manager #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -30,7 +30,7 @@ const executeScriptInContainerWithPackageManager = async ( | |||
await execContainer(id, [ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my education, how does that work? What is CODER_SCRIPT_BIN_DIR
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically /tmp/coder-script-data/bin
, a place where all scripts can place binaries and they will be part of PATH
(guaranteed by agent).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
export PNPM_HOME="$CODER_SCRIPT_BIN_DIR" | ||
fi | ||
$PACKAGE_MANAGER add -g @devcontainers/cli \ | ||
&& 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_HOME
to 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.