From a5eb1b84ab48b32e81fd604f3fa2a17835ee71e0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 16 May 2018 22:10:35 +0900 Subject: [PATCH] web: Better way to detect NodeJS --- internal/web/js.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/web/js.go b/internal/web/js.go index d4ce5fff2..aacb6ea7a 100644 --- a/internal/web/js.go +++ b/internal/web/js.go @@ -18,12 +18,21 @@ package web import ( "strings" + "sync" "github.com/gopherjs/gopherjs/js" ) +var ( + isNodeJSOnce sync.Once + isNodeJS = false +) + func IsNodeJS() bool { - return js.Global.Get("require") != js.Undefined + isNodeJSOnce.Do(func() { + isNodeJS = js.Global.Get("process") != js.Undefined + }) + return isNodeJS } func IsBrowser() bool {