Skip to content

Commit fdf075a

Browse files
aykevldeadprogram
authored andcommitted
Makefile: only read NodeJS version when it is needed
Most make commands don't need to check for the NodeJS version, so only do it when needed. This avoids the following error on Windows for example when NodeJS is not installed: /usr/bin/sh: line 1: node: command not found which: no node in (/c/Users/Ayke/bin:/clangarm64/bin:/usr/local/bin:/usr/bin:/usr/bin:/mingw64/bin:/usr/bin:/c/Users/Ayke/bin:/c/Users/Ayke/.vscode-server/cli/servers/Stable-e54c774e0add60467559eb0d1e229c6452cf8447/server/bin/remote-cli:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Users/Ayke/scoop/apps/mingw-mstorsjo-llvm-ucrt/current/bin:/c/Users/Ayke/scoop/apps/python/current/Scripts:/c/Users/Ayke/scoop/apps/python/current:/c/Users/Ayke/go/bin:/c/Users/Ayke/scoop/shims:/c/Users/Ayke/AppData/Local/Microsoft/WindowsApps:/usr/bin/vendor_perl:/usr/bin/core_perl) Also, some users have been confused by the error message even though in most cases it is harmless and can be ignored.
1 parent 95a7d06 commit fdf075a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

GNUmakefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ wasi-cm:
280280
rsync -rv --delete --exclude go.mod --exclude '*_test.go' --exclude '*_json.go' --exclude '*.md' --exclude LICENSE $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE)/cm)/ ./src/internal/cm
281281

282282
# Check for Node.js used during WASM tests.
283-
NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-)))
284283
MIN_NODEJS_VERSION=18
285284

286285
.PHONY: check-nodejs-version
287286
check-nodejs-version:
288-
ifeq (, $(shell which node))
289-
@echo "Install NodeJS version 18+ to run tests."; exit 1;
290-
endif
291-
@if [ $(NODEJS_VERSION) -lt $(MIN_NODEJS_VERSION) ]; then echo "Install NodeJS version 18+ to run tests."; exit 1; fi
287+
@# Check whether NodeJS is available.
288+
@if ! command -v node 2>&1 >/dev/null; then echo "Install NodeJS version ${MIN_NODEJS_VERSION}+ to run tests."; exit 1; fi
289+
290+
@# Check whether the version is high enough.
291+
@if [ "`node -v | sed 's/v\([0-9]\+\).*/\\1/g'`" -lt $(MIN_NODEJS_VERSION) ]; then echo "Install NodeJS version $(MIN_NODEJS_VERSION)+ to run tests."; exit 1; fi
292292

293293
tinygo: ## Build the TinyGo compiler
294294
@if [ ! -f "$(LLVM_BUILDDIR)/bin/llvm-config" ]; then echo "Fetch and build LLVM first by running:"; echo " $(MAKE) llvm-source"; echo " $(MAKE) $(LLVM_BUILDDIR)"; exit 1; fi

0 commit comments

Comments
 (0)