Skip to content

Commit 03be83a

Browse files
committed
simplify
1 parent 6b6bf70 commit 03be83a

13 files changed

Lines changed: 116 additions & 310 deletions

File tree

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches:
77
- main
88
paths:
9-
- "src/**"
9+
- "src/**"
1010
- ".github/workflows/release.yaml"
1111

1212
jobs:

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
feature:
24-
- mise-node
24+
- mise-bootstrap
2525
baseImage:
2626
- mcr.microsoft.com/devcontainers/base:ubuntu
2727
- mcr.microsoft.com/devcontainers/base:debian

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A collection of [devcontainer features](https://containers.dev/implementors/feat
66

77
| Feature | Reference |
88
| --- | --- |
9-
| [mise-node](src/mise-node) | `ghcr.io/payloadcms/devcontainer-features/mise-node:1` |
9+
| [mise-bootstrap](src/mise-bootstrap) | `ghcr.io/payloadcms/devcontainer-features/mise-bootstrap:1` |
1010

1111
## Usage
1212

@@ -16,7 +16,7 @@ Reference a feature in your `.devcontainer/devcontainer.json`:
1616
{
1717
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
1818
"features": {
19-
"ghcr.io/payloadcms/devcontainer-features/mise-node:1": {}
19+
"ghcr.io/payloadcms/devcontainer-features/mise-bootstrap:1": {}
2020
}
2121
}
2222
```

src/mise-bootstrap/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# mise project bootstrap (`mise-bootstrap`)
2+
3+
Bootstraps a project on container create. The mise binary is provided by the upstream [`ghcr.io/devcontainers-extra/features/mise`](https://github.com/devcontainers-extra/features/tree/main/src/mise) feature (declared as a `dependsOn`, so it's installed automatically). On container create, this feature runs in the workspace folder:
4+
5+
1. `mise trust -y` + `mise install -y` against `mise.toml` / `.tool-versions`.
6+
2. Detects the JS package manager from the lockfile and runs its install.
7+
8+
## Example usage
9+
10+
```jsonc
11+
{
12+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
13+
"features": {
14+
"ghcr.io/payloadcms/devcontainer-features/mise-bootstrap:1": {}
15+
}
16+
}
17+
```
18+
19+
With a `mise.toml` (or `.tool-versions`) at the workspace root:
20+
21+
```toml
22+
[tools]
23+
node = "20"
24+
pnpm = "9"
25+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "mise-bootstrap",
3+
"version": "1.0.0",
4+
"name": "mise project bootstrap",
5+
"description": "On container create, runs `mise trust` + `mise install` in the workspace and then runs the appropriate JS package manager (pnpm / yarn / npm / bun) based on the project's lockfile.",
6+
"documentationURL": "https://github.com/payloadcms/devcontainer-features/tree/main/src/mise-bootstrap",
7+
"postCreateCommand": "/usr/local/share/mise-bootstrap/postCreate.sh",
8+
"dependsOn": {
9+
"ghcr.io/devcontainers-extra/features/mise:1": {}
10+
},
11+
"installsAfter": [
12+
"ghcr.io/devcontainers/features/common-utils"
13+
]
14+
}

src/mise-bootstrap/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
install -D -m 0755 "$(dirname "$0")/postCreate.sh" /usr/local/share/mise-bootstrap/postCreate.sh

src/mise-bootstrap/postCreate.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# postCreateCommand body
3+
set -euo pipefail
4+
5+
# Tools pinned by mise.toml / .tool-versions at the repo root.
6+
mise trust -y
7+
mise install -y
8+
9+
if [ ! -f package.json ]; then
10+
echo "mise-bootstrap: no package.json — done."
11+
exit 0
12+
fi
13+
14+
detect_pm() {
15+
[ -f pnpm-lock.yaml ] && { echo pnpm; return; }
16+
[ -f bun.lock ] && { echo bun; return; }
17+
[ -f bun.lockb ] && { echo bun; return; }
18+
[ -f yarn.lock ] && { echo yarn; return; }
19+
[ -f package-lock.json ] && { echo npm; return; }
20+
[ -f npm-shrinkwrap.json ] && { echo npm; return; }
21+
echo npm
22+
}
23+
24+
PM="$(detect_pm)"
25+
echo "mise-bootstrap: package manager: ${PM}"
26+
27+
case "${PM}" in
28+
pnpm)
29+
# Project-local pnpm store inside node_modules so named-volume mounts
30+
# of node_modules don't lose the cache.
31+
mise exec -- pnpm config set store-dir "$(pwd)/node_modules/.pnpm-store"
32+
33+
# PNPM_HOME holds globally-installed pnpm bins; ensure it's on PATH.
34+
export PNPM_HOME="$HOME/.local/share/pnpm"
35+
export PATH="$PNPM_HOME:$PATH"
36+
mkdir -p "$PNPM_HOME"
37+
38+
# node-gyp globally so native deps (e.g. sqlite) can build
39+
# against newer Node releases that ship without prebuilt binaries.
40+
mise exec -- pnpm add -g node-gyp
41+
42+
mise exec -- pnpm install --config.confirm-modules-purge=false
43+
;;
44+
bun) mise exec -- bun install ;;
45+
yarn) mise exec -- yarn install ;;
46+
npm)
47+
if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
48+
mise exec -- npm ci
49+
else
50+
mise exec -- npm install
51+
fi
52+
;;
53+
esac

src/mise-node/README.md

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/mise-node/devcontainer-feature.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/mise-node/install.sh

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)