Skip to content

Commit 822b689

Browse files
authored
fix: bypass env masking when ensuring package manager (#41)
Always match provided package manager to regex in order to bypass enforced environment masking. This logic now includes updated regex and is isolated in a separate file.
1 parent 455c89c commit 822b689

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

.circleci/test-deploy.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ jobs:
7272
echo "pnpm version $PNPM_LATEST_VERSION not found"
7373
exit 1
7474
fi
75+
ensure-default-pkg-manager-env:
76+
executor: core/node
77+
steps:
78+
- core/ensure_pkg_manager
79+
- run:
80+
name: Validate version
81+
command: |
82+
PNPM_NEXT_10_VERSION=$(npm view pnpm dist-tags.next-10)
83+
if ! pnpm --version | grep -q "$PNPM_NEXT_10_VERSION"; then
84+
echo "pnpm version $PNPM_NEXT_10_VERSION not found"
85+
exit 1
86+
fi
87+
7588
install-dependencies-npm-node-18:
7689
executor:
7790
name: core/node_secrets
@@ -161,6 +174,8 @@ workflows:
161174
filters: *filters
162175
- ensure-pnpm-machine-install:
163176
filters: *filters
177+
- ensure-default-pkg-manager-env:
178+
filters: *filters
164179
- install-dependencies-npm-node-18:
165180
filters: *filters
166181
- install-dependencies-pnpm-node-18:
@@ -185,6 +200,7 @@ workflows:
185200
- ensure-pnpm-version
186201
- ensure-pnpm-fresh-install
187202
- ensure-pnpm-machine-install
203+
- ensure-default-pkg-manager-env
188204
- install-dependencies-npm-node-18
189205
- install-dependencies-pnpm-node-18
190206
- install-dependencies-custom-command

src/commands/ensure_pkg_manager.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ steps:
1717
name: Check Node.js version
1818
command: <<include(scripts/check-node-version.sh)>>
1919
- run:
20-
name: Ensure package manager
20+
name: Export package manager
2121
environment:
2222
PARAM_STR_REF: <<parameters.ref>>
23+
command: <<include(scripts/export-pkg-manager.sh)>>
24+
- run:
25+
name: Ensure package manager
2326
command: <<include(scripts/ensure-pkg-manager.sh)>>

src/scripts/ensure-pkg-manager.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/bin/bash
22

3-
PARAM_STR_REF=$(circleci env subst "${PARAM_STR_REF}")
4-
PKG_MANAGER_WITH_VERSION_REGEX="(npm|pnpm)@(([0-9]+.?){0,2}[0-9]+|[a-z]+-?([0-9]+)?)"
5-
NAME="${PARAM_STR_REF}"
6-
VERSION=""
3+
NAME="${CURRENT_PKG_MANAGER}"
4+
VERSION="${CURRENT_PKG_MANAGER_VERSION}"
75
SUDO=""
86
NPM_SUDO=""
97

@@ -64,13 +62,7 @@ change_pnpm_store_dir_and_exit() {
6462
exit 0
6563
}
6664

67-
if [[ "${PARAM_STR_REF}" =~ ${PKG_MANAGER_WITH_VERSION_REGEX} ]]; then
68-
NAME="${BASH_REMATCH[1]}"
69-
VERSION="${BASH_REMATCH[2]}"
70-
fi
71-
72-
echo "export CURRENT_PKG_MANAGER='${NAME}'" >>"${BASH_ENV}"
73-
echo "Starting to ensure ${NAME} is set for usage"
65+
echo "Starting to ensure '${NAME}' is set for usage"
7466

7567
cd ~ || echo "Cannot navigate to home, possible version mismatch"
7668

src/scripts/export-pkg-manager.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
PARAM_STR_REF=$(circleci env subst "${PARAM_STR_REF}")
4+
PKG_MANAGER_REGEX="^(npm|pnpm)(@(([0-9]+.?){0,2}[0-9]+|[a-z]+-?([0-9]+)?))?$"
5+
NAME=""
6+
VERSION=""
7+
8+
if [[ "${PARAM_STR_REF}" =~ ${PKG_MANAGER_REGEX} ]]; then
9+
NAME="${BASH_REMATCH[1]}"
10+
VERSION="${BASH_REMATCH[3]}"
11+
fi
12+
13+
if [[ -z "${NAME}" ]]; then
14+
echo "Package manager '${NAME}' is not supported"
15+
echo "Please specify supported package manager through parameter or environment"
16+
17+
exit 1
18+
fi
19+
20+
echo "export CURRENT_PKG_MANAGER='${NAME}'" >>"${BASH_ENV}"
21+
echo "export CURRENT_PKG_MANAGER_VERSION='${VERSION}'" >>"${BASH_ENV}"

0 commit comments

Comments
 (0)