Skip to content

Commit b5cf091

Browse files
dziezdomistarkov
authored andcommitted
fix(devcontainer): Fix pnpm installation issue in postinstall.sh (#4886)
## Description 1. What is this PR about (link the issue and add a short description) * This PR fixes an issue where `pnpm` was not being correctly installed or configured within the Devcontainer environment when using `postinstall.sh`. * This was causing errors during container startup and when running `pnpm` commands inside the Devcontainer. * The fix ensures `pnpm` is properly set up in `postinstall.sh`, resolving the Devcontainer setup issue. ## Steps for reproduction 1. Start the Webstudio Devcontainer. 2. Expect the Devcontainer to start successfully without `pnpm` related errors. 3. Verify that `pnpm` commands can be executed correctly within the Devcontainer terminal (e.g., `pnpm --version`). ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [x] made a self-review - [x] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [x] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent a82b8f7 commit b5cf091

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

.devcontainer/postinstall.sh

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,55 @@
11
#!/bin/bash
22

3+
echo "Running postinstall.sh"
4+
5+
# Configure FZF and bash history
36
echo 'eval "$(fzf --bash)"' >> /home/node/.bashrc
7+
sudo mkdir -p /home/node/.local/fzf
8+
touch /home/node/.local/fzf/.bash_history
9+
echo 'export HISTFILE=/home/node/.local/fzf/.bash_history' >> "/home/node/.bashrc"
410

5-
mkdir -p /home/node/.local/fzf
11+
# Aggressively clean npm and corepack caches
12+
npm cache clean -f
13+
sudo rm -rf /tmp/corepack-cache
14+
sudo rm -rf /usr/local/lib/node_modules/corepack # Manually remove global corepack
615

7-
touch /home/node/.local/fzf/.bash_history
16+
# Reinstall corepack globally via npm
17+
npm install -g corepack@latest # Install latest corepack version
18+
sudo corepack enable # Re-enable corepack
819

9-
echo 'export HISTFILE=/home/node/.local/fzf/.bash_history' >> "/home/node/.bashrc"
20+
# Check corepack version after reinstall
21+
echo "--- Corepack version after reinstall ---"
22+
corepack --version
23+
echo "--- End corepack version check ---"
1024

25+
26+
# Prepare pnpm (again, after corepack reinstall)
27+
sudo corepack prepare [email protected] --activate
28+
29+
# Go to workspace directory
1130
cd /workspaces/webstudio
12-
sudo corepack enable
13-
corepack install
1431

32+
# Configure pnpm store directory
1533
pnpm config set store-dir $HOME/.pnpm-store
1634

17-
35+
# Clean up directories (optional)
1836
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
1937
find . -name 'lib' -type d -prune -exec rm -rf '{}' +
2038
find . -name 'build' -type d -prune -exec rm -rf '{}' +
2139
find . -name 'dist' -type d -prune -exec rm -rf '{}' +
2240
find . -name '.cache' -type d -prune -exec rm -rf '{}' +
2341
find . -name '.pnpm-store' -type d -prune -exec rm -rf '{}' +
2442

43+
# Install dependencies, build, and migrate
2544
pnpm install
2645
pnpm run build
2746
pnpm migrations migrate
2847

29-
48+
# Add git aliases
3049
cat << 'EOF' >> /home/node/.bashrc
31-
3250
alias gitclean="(git remote | xargs git remote prune) && git branch -vv | egrep '('\$(git remote | xargs | sed -e 's/ /|/g')')/.*: gone]' | awk '{print \$1}' | xargs -r git branch -D"
3351
alias gitrebase="git rebase --interactive main"
3452
EOF
3553

3654

55+
echo "postinstall.sh finished"

0 commit comments

Comments
 (0)