Skip to content

Commit

Permalink
feat(node): use versioned folders (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Dec 6, 2021
1 parent 270d643 commit 8ba36f6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 33 deletions.
35 changes: 24 additions & 11 deletions src/usr/local/buildpack/tools/lerna.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ set -e

check_command node

if [[ $EUID -eq 0 ]]; then
unset NPM_CONFIG_PREFIX
fi
tool_path=$(find_tool_path)

npm install -g lerna@${TOOL_VERSION}
function update_env () {
reset_tool_env
export_tool_path "${1}/bin"
}

lerna --version
if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
tool_path=${base_path}/${TOOL_VERSION}

mkdir -p ${tool_path}

if [[ $EUID -eq 0 ]]; then
shell_wrapper lerna
NPM_CONFIG_PREFIX=$tool_path npm install --cache /tmp/empty-cache -g ${TOOL_NAME}@${TOOL_VERSION}

# Clean download cache
NPM_CONFIG_PREFIX=$tool_path npm cache clean --force
# Clean node-gyp cache
rm -rf $HOME/.cache /tmp/empty-cache

update_env ${tool_path}
shell_wrapper ${TOOL_NAME}
else
echo "Already installed, resetting env"
update_env ${tool_path}
fi

# Clean download cache
npm cache clean --force
# Clean node-gyp cache
rm -rf /root/.cache
lerna --version
35 changes: 24 additions & 11 deletions src/usr/local/buildpack/tools/pnpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ set -e

check_command node

if [[ $EUID -eq 0 ]]; then
unset NPM_CONFIG_PREFIX
fi
tool_path=$(find_tool_path)

npm install -g pnpm@${TOOL_VERSION}
function update_env () {
reset_tool_env
export_tool_path "${1}/bin"
}

pnpm --version
if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
tool_path=${base_path}/${TOOL_VERSION}

mkdir -p ${tool_path}

if [[ $EUID -eq 0 ]]; then
shell_wrapper pnpm
NPM_CONFIG_PREFIX=$tool_path npm install --cache /tmp/empty-cache -g ${TOOL_NAME}@${TOOL_VERSION}

# Clean download cache
NPM_CONFIG_PREFIX=$tool_path npm cache clean --force
# Clean node-gyp cache
rm -rf $HOME/.cache /tmp/empty-cache

update_env ${tool_path}
shell_wrapper ${TOOL_NAME}
else
echo "Already installed, resetting env"
update_env ${tool_path}
fi

# Clean download cache
npm cache clean --force
# Clean node-gyp cache
rm -rf /root/.cache
pnpm --version
35 changes: 25 additions & 10 deletions src/usr/local/buildpack/tools/yarn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ set -e

check_command node

if [[ $EUID -eq 0 ]]; then
unset NPM_CONFIG_PREFIX
fi
tool_path=$(find_tool_path)

npm install -g yarn@${TOOL_VERSION}
function update_env () {
reset_tool_env
export_tool_path "${1}/bin"
}

yarn --version
if [[ -z "${tool_path}" ]]; then
INSTALL_DIR=$(get_install_dir)
base_path=${INSTALL_DIR}/${TOOL_NAME}
tool_path=${base_path}/${TOOL_VERSION}

mkdir -p ${tool_path}

NPM_CONFIG_PREFIX=$tool_path npm install --cache /tmp/empty-cache -g ${TOOL_NAME}@${TOOL_VERSION}

shell_wrapper yarn
# Clean download cache
NPM_CONFIG_PREFIX=$tool_path npm cache clean --force
# Clean node-gyp cache
rm -rf $HOME/.cache /tmp/empty-cache

# Clean download cache
npm cache clean --force
# Clean node-gyp cache
rm -rf /root/.cache
update_env ${tool_path}
shell_wrapper ${TOOL_NAME}
else
echo "Already installed, resetting env"
update_env ${tool_path}
fi

yarn --version
6 changes: 5 additions & 1 deletion test/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ USER root
RUN install-tool yarn 1.22.17

# renovate: datasource=npm
RUN install-npm lerna 4.0.0
RUN install-tool lerna 4.0.0

USER 1000

RUN set -ex; \
[ "$(command -v yarn)" = "/usr/local/bin/yarn" ] && echo "works" || exit 1; \
yarn --version

RUN set -ex; \
[ "$(command -v lerna)" = "/usr/local/bin/lerna" ] && echo "works" || exit 1; \
lerna --version

#--------------------------------------
# test: pnpm
#--------------------------------------
Expand Down

0 comments on commit 8ba36f6

Please sign in to comment.