Skip to content

Commit 2585918

Browse files
fix(devcontainers-cli): allow yarn to install when packageManager not yarn (#287)
On our dogfood workspaces, we fail to install `@devcontainers/cli` with `yarn` because our agent directory `/home/coder/coder` contains a `package.json` with `packageManager` being set to `pnpm`. This change instead ensures to run `yarn global add` inside the `$CODER_SCRIPT_DATA_DIR` so that we don't read a `package.json` and cause things to break.
1 parent 3efc22c commit 2585918

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

registry/coder/modules/devcontainers-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The devcontainers-cli module provides an easy way to install [`@devcontainers/cl
1515
```tf
1616
module "devcontainers-cli" {
1717
source = "registry.coder.com/coder/devcontainers-cli/coder"
18-
version = "1.0.31"
18+
version = "1.0.32"
1919
agent_id = coder_agent.example.id
2020
}
2121
```

registry/coder/modules/devcontainers-cli/main.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ const executeScriptInContainerWithPackageManager = async (
4545

4646
console.log(path);
4747

48+
await execContainer(id, [shell, "-c", "mkdir -p /tmp/coder-script-data"]);
49+
4850
const resp = await execContainer(
4951
id,
5052
[shell, "-c", instance.script],
5153
[
5254
"--env",
5355
"CODER_SCRIPT_BIN_DIR=/tmp/coder-script-data/bin",
5456
"--env",
57+
"CODER_SCRIPT_DATA_DIR=/tmp/coder-script-data",
58+
"--env",
5559
`PATH=${path}:/tmp/coder-script-data/bin`,
5660
],
5761
);

registry/coder/modules/devcontainers-cli/run.sh

100644100755
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env sh
22

3+
# We want to cd into `$CODER_SCRIPT_DATA_DIR` as the current directory
4+
# might contain a `package.json` with `packageManager` set to something
5+
# other than the detected package manager. When this happens, it can
6+
# cause the installation to fail.
7+
cd "$CODER_SCRIPT_DATA_DIR"
8+
39
# If @devcontainers/cli is already installed, we can skip
410
if command -v devcontainer >/dev/null 2>&1; then
511
echo "🥳 @devcontainers/cli is already installed into $(which devcontainer)!"
@@ -34,7 +40,7 @@ install() {
3440
# so that the devcontainer command is available
3541
if [ -z "$PNPM_HOME" ]; then
3642
PNPM_HOME="$CODER_SCRIPT_BIN_DIR"
37-
export M_HOME
43+
export PNPM_HOME
3844
fi
3945
pnpm add -g @devcontainers/cli
4046
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then

0 commit comments

Comments
 (0)