Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .ddev/commands/host/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

## Description: Start ddev and selectively start PM2 services
## Usage: up [nextjs|storybook|all]

SERVICE=${1:-all}

START_UP_SERVICE=${SERVICE} ddev start
Comment on lines +6 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate SERVICE before starting DDEV

Line 8 triggers ddev start before the invalid-argument branch at Lines 23-25. ddev up typo still boots the stack, then exits with usage. Fail fast before startup.

Suggested patch
 SERVICE=${1:-all}
 
-START_UP_SERVICE=${SERVICE} ddev start
+case "$SERVICE" in
+  nextjs|storybook|all) ;;
+  *)
+    echo "Usage: ddev up [nextjs|storybook|all]"
+    exit 1
+    ;;
+esac
+
+START_UP_SERVICE="$SERVICE" ddev start
 
 echo "--- Selective PM2 Startup: $SERVICE ---"
 
-case $SERVICE in
+case "$SERVICE" in
   nextjs)
     ddev exec pm2 start --name next node_modules/.bin/next -- dev --webpack
     ;;
@@
-  *)
-    echo "Usage: ddev up [nextjs|storybook|all]"
-    exit 1
-    ;;
 esac

Also applies to: 12-25

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.ddev/commands/host/up around lines 6 - 8, The script currently invokes
START_UP_SERVICE=${SERVICE} ddev start before validating SERVICE, so passing an
invalid argument (e.g., `ddev up typo`) will boot the stack then fail; move or
add validation of SERVICE (ensure SERVICE is one of the allowed values or
matches existing service names, and treat empty/malformed values) before the
START_UP_SERVICE=${SERVICE} ddev start call, and if invalid print the
usage/error and exit non-zero; update both the main startup path and the
alternate branch that covers lines 12-25 so validation happens before any ddev
start invocation (refer to the SERVICE variable, START_UP_SERVICE assignment,
and the invalid-argument branch to locate places to change).


echo "--- Selective PM2 Startup: $SERVICE ---"

case $SERVICE in
nextjs)
ddev exec pm2 start --name next node_modules/.bin/next -- dev --webpack
;;
storybook)
ddev exec pm2 start --name storybook node_modules/.bin/storybook -- dev --no-open -p 6006
;;
all)
ddev exec pm2 start --name next node_modules/.bin/next -- dev --webpack
ddev exec pm2 start --name storybook node_modules/.bin/storybook -- dev --no-open -p 6006
;;
*)
echo "Usage: ddev up [nextjs|storybook|all]"
exit 1
;;
esac

ddev exec pm2 status
17 changes: 10 additions & 7 deletions .ddev/config.hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
hooks:
post-start:
# Detects to see if the node_modules folder exists
- exec: 'sh -c "[ ! -d node_modules ] && npm ci || return"'
service: web
# pm2 does not live in the node path, so have to call binary directly
- exec: pm2 start --name next node_modules/.bin/next -- dev --webpack
service: web
# pm2 does not live in the node path, so have to call binary directly
- exec: pm2 start --name storybook node_modules/.bin/storybook -- dev --no-open -p 6006
- exec: 'sh -c "[ ! -d node_modules ] && npm ci || true"'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t mask dependency install failures in post-start

Line 4 always succeeds due to || true, even when npm ci fails with missing node_modules. That can cascade into opaque startup failures later in the same post-start flow.

Suggested patch
-    - exec: 'sh -c "[ ! -d node_modules ] && npm ci || true"'
+    - exec: |
+        sh -c '
+          if [ ! -d node_modules ]; then
+            npm ci || {
+              echo "npm ci failed in web service. Run `ddev frontend install` and retry."
+              exit 1
+            }
+          fi
+        '
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.ddev/config.hooks.yaml at line 4, The post-start hook currently masks
installation failures because the exec entry with "[ ! -d node_modules ] && npm
ci || true" always returns success; remove the trailing "|| true" and change the
hook so it runs npm ci only when node_modules is missing but does not swallow
errors (e.g. use a shell conditional that runs npm ci when node_modules is
absent and lets npm's non-zero exit code propagate); update the exec entry (the
post-start exec command string) accordingly so failed installs surface instead
of being ignored.

service: web
- exec-host: |
if [ -z "$START_UP_SERVICE" ]; then
ddev exec pm2 start --name next node_modules/.bin/next -- dev --webpack
ddev exec pm2 start --name storybook node_modules/.bin/storybook -- dev --no-open -p 6006

echo "Next time use one of these for faster startup:"
echo "> ddev up nextjs"
echo "> ddev up storybook"
fi
16 changes: 13 additions & 3 deletions README.project.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,21 @@ have more details about which to use when.

## Starting and stopping the project

After following the "Initial Setup" instructions, you can start the local development server for the app by running:
### Starting up Next.js

```bash
ddev up nextjs
```
Open [https://YOUR-PROJECT.ddev.site/](https://YOUR-PROJECT.ddev.site/) to see the app.

## Starting up Storybook

```bash
ddev start
ddev up storybook
```
Open [https://YOUR-PROJECT.ddev.site/](https://YOUR-PROJECT.ddev.site/) with your browser to see the app. If using storybook, use port `6006` by default to view it: [https://YOUR-PROJECT.ddev.site:6006](https://YOUR-PROJECT.ddev.site:6006).
Open [https://YOUR-PROJECT.ddev.site:6006](https://YOUR-PROJECT.ddev.site:6006) (port 6006) to see Storybook.

### Stopping

To stop `ddev` for the project:
```bash
Expand Down