From e04212e0f950f0b07af3af6b16aa2024ce0dbde1 Mon Sep 17 00:00:00 2001 From: Jack Hickey <133868041+nginx-jack@users.noreply.github.com> Date: Wed, 10 Sep 2025 16:05:44 +0100 Subject: [PATCH] Biome: Use biome.json version as main --- .gitignore | 5 ++- Makefile | 99 +++++++++++++++++++++++++++++++++++------- scripts/lint-commit.sh | 2 +- 3 files changed, 88 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index d43ef99e..4106b57e 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ exampleSite/hugo # Playwright /coverage */test-results -*/playwright-report \ No newline at end of file +*/playwright-report + +# Biome +biome.rb diff --git a/Makefile b/Makefile index 2235dba1..5bcc8425 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,74 @@ -BIOME_BASE_CMD := $(if $(shell which biome),biome,npx @biomejs/biome@2.2.2) +# Read the Biome version from biome.json "$schema" +# Uses BSD/GNU compatible sed with -E for extended regex. +BIOME_VERSION := $(shell sed -nE 's/.*schemas\/([0-9]+\.[0-9]+\.[0-9]+)\/schema\.json.*/\1/p' biome.json) + +# Detect local biome and its version (if any) +HAVE_BIOME := $(shell command -v biome >/dev/null 2>&1 && echo yes || echo no) +LOCAL_BIOME_VERSION := $(shell biome --version 2>/dev/null | sed -E 's/[^0-9]*([0-9]+\.[0-9]+\.[0-9]+).*/\1/') + +# Choose which command to run. Prefer local only if versions match. +ifeq ($(strip $(BIOME_VERSION)),) + $(warning Could not determine Biome version from biome.json; defaulting to npx @biomejs/biome) + BIOME_BASE_CMD := npx -y @biomejs/biome +else + ifeq ($(HAVE_BIOME),yes) + ifeq ($(LOCAL_BIOME_VERSION),$(BIOME_VERSION)) + BIOME_BASE_CMD := biome + else + $(warning Found biome $(LOCAL_BIOME_VERSION) on PATH, but required $(BIOME_VERSION). Falling back to npx.) + BIOME_BASE_CMD := npx -y @biomejs/biome@$(BIOME_VERSION) + endif + else + BIOME_BASE_CMD := npx -y @biomejs/biome@$(BIOME_VERSION) + endif +endif + +# Optional: allow forcing use of local biome anyway (not recommended) +# Usage: make ... FORCE_LOCAL_BIOME=1 +ifeq ($(FORCE_LOCAL_BIOME),1) + BIOME_BASE_CMD := biome +endif + WRITE_FLAG := --write -.PHONY: list help -list help:: - $(info Available Make targets:) +.PHONY: list help biome-format biome-lint biome-all setup-pre-commit tests build-example-site check-biome install-help tests-update-screenshots + +list help: + @echo "Available Make targets:" @echo "" - @echo " list | help: Print these available make targets" + @echo " list | help: Print these available make targets" @echo "" - @echo " biome-format: Runs the biome formatter." - @echo " biome-lint: Runs the biome linter." - @echo " biome-all: Runs both the lint and formatting commands." - @echo " build-example-site: Builds hugo exampleSite." - @echo "(Set BIOME_ARGS to add additional arguments to biome command (ex: make biome-all BIOME_ARGS=write))" + @echo " biome-format: Runs the biome formatter." + @echo " biome-lint: Runs the biome linter." + @echo " biome-all: Runs both the lint and formatting commands." + @echo "(Set BIOME_ARGS=write to enable --write, e.g.: make biome-all BIOME_ARGS=write)" + @echo "" + @echo " build-example-site: Builds hugo exampleSite." @echo "" - @echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)" + @echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)" @echo "" - @echo " tests: Runs playwright against the new theme." - @echo " tests-update-screenshots: Runs playwright against the new theme." + @echo " tests: Runs playwright against the new theme." + @echo " tests-update-screenshots: Runs playwright against the new theme and generates screenshots." + @echo "" + @echo " check-biome: Shows required vs local biome versions and the command that will run." + @echo " install-help: Shows how to install Biome globally via brew or npm." -.PHONY: biome-format biome-lint biome-all setup-pre-commit tests build-example-site FLAG := ifeq ($(BIOME_ARGS), write) - FLAG := $(WRITE_FLAG) +FLAG := $(WRITE_FLAG) endif biome-format: $(BIOME_BASE_CMD) format $(FLAG) + biome-lint: $(BIOME_BASE_CMD) lint $(FLAG) + biome-all: $(BIOME_BASE_CMD) check $(FLAG) setup-pre-commit: - @if ! command -v pre-commit &> /dev/null; then \ + @if ! command -v pre-commit >/dev/null 2>&1; then \ echo "WARNING: 'pre-commit' is not installed. Please install it using: pip install pre-commit or brew install pre-commit"; \ else \ echo "pre-commit is installed! Proceeding with hook installation."; \ @@ -43,7 +79,38 @@ setup-pre-commit: build-example-site: cd exampleSite && hugo mod get && hugo build --gc -e production + tests: cd tests && npx playwright test + tests-update-screenshots: cd tests && npx playwright test --update-snapshots + +check-biome: + @echo "Required Biome version: $(BIOME_VERSION)" + @echo "System Biome version: $(LOCAL_BIOME_VERSION)" + @echo "Command that will run: $(BIOME_BASE_CMD)" + @if ! command -v biome >/dev/null 2>&1 || [ "$(LOCAL_BIOME_VERSION)" != "$(BIOME_VERSION)" ]; then \ + echo ""; \ + echo "โš ๏ธ Local biome version does not match required."; \ + $(MAKE) install-help; \ + fi + +install-help: + @echo "" + @echo "๐Ÿ› ๏ธ Install options for biome v$(BIOME_VERSION):" + @echo "" + @echo "1) ๐Ÿงช Install manually via Homebrew (advanced):" + @echo " # Find the correct commit SHA for biome $(BIOME_VERSION) here:" + @echo " # https://github.com/Homebrew/homebrew-core/commits/master/Formula/biome.rb" + @echo " curl -sSL https://raw.githubusercontent.com/Homebrew/homebrew-core//Formula/biome.rb -o biome.rb" + @echo " brew install ./biome.rb" + @echo " brew pin biome" + @echo "" + @echo "2) ๐Ÿš€ Install via npm (global):" + @echo " npm install -g @biomejs/biome@$(BIOME_VERSION)" + @echo "" + @echo "3) ๐Ÿงฐ Use temporarily via npx (auto fallback in Makefile):" + @echo " npx -y @biomejs/biome@$(BIOME_VERSION) " + @echo "" + @echo "Note: This Makefile will automatically fall back to npx if the right version is not found locally." diff --git a/scripts/lint-commit.sh b/scripts/lint-commit.sh index 5b644523..8ccbc6df 100755 --- a/scripts/lint-commit.sh +++ b/scripts/lint-commit.sh @@ -72,4 +72,4 @@ while read -r line; do fi done <"$commit_file" -exit 0 \ No newline at end of file +exit 0