Skip to content

Commit 7454d30

Browse files
committed
Auto-detect browser availability for Storybook
Make the browser opening behavior smart: - Detect if xdg-open is available - Only add --no-open flag if it's not available - Allows Storybook to open browser on machines that support it - Prevents xdg-open ENOENT errors on headless machines This way it works seamlessly on both developer machines with browsers and headless CI/test machines.
1 parent 1c90fc8 commit 7454d30

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ define check_node_version
6363
fi
6464
endef
6565

66+
# Detect if browser opener is available that Storybook can use
67+
# Storybook uses 'open' package which tries xdg-open on Linux, open on macOS, start on Windows
68+
HAS_BROWSER_OPENER := $(shell command -v xdg-open >/dev/null 2>&1 && echo "yes" || echo "no")
69+
STORYBOOK_OPEN_FLAG := $(if $(filter yes,$(HAS_BROWSER_OPENER)),,--no-open)
70+
6671
TS_SOURCES := $(shell find src -type f \( -name '*.ts' -o -name '*.tsx' \))
6772

6873
# Default target
@@ -262,7 +267,7 @@ docs-watch: ## Watch and rebuild documentation
262267
## Storybook
263268
storybook: node_modules/.installed ## Start Storybook development server
264269
$(check_node_version)
265-
@bun x storybook dev -p 6006 --no-open
270+
@bun x storybook dev -p 6006 $(STORYBOOK_OPEN_FLAG)
266271

267272
storybook-build: node_modules/.installed src/version.ts ## Build static Storybook
268273
$(check_node_version)

0 commit comments

Comments
 (0)