Skip to content

Commit 11ffff2

Browse files
fix(devcontainers-cli): allow yarn to install when packageManager not yarn
On our dogfood box, 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 the script inside the `$CODER_SCRIPT_DATA_DIR` so that we don't read a `package.json` and cause things to break.
1 parent 3efc22c commit 11ffff2

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ install() {
3838
fi
3939
pnpm add -g @devcontainers/cli
4040
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
41-
yarn global add @devcontainers/cli --prefix "$(dirname "$CODER_SCRIPT_BIN_DIR")"
41+
# We want to cd into `$CODER_SCRIPT_DATA_DIR` as the current directory
42+
# might contain a `package.json` with `packageManager` set to something
43+
# other than `yarn`. When this happens, `yarn global add` will fail to install.
44+
cd "$CODER_SCRIPT_DATA_DIR" && yarn global add @devcontainers/cli --prefix "$(dirname "$CODER_SCRIPT_BIN_DIR")"
4245
fi
4346
}
4447

0 commit comments

Comments
 (0)