diff options
| author | Dmitri Shuralyov <dmitshur@golang.org> | 2023-01-04 20:54:34 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-01-19 22:43:17 +0000 |
| commit | 440ef8c4d24861cbfb01758e7e03fa3b4164f55a (patch) | |
| tree | 0a2883bdc4f0925cf1945e2c57181622afdf5a96 | |
| parent | f959fb3872a32d29c93f10deae31e4e6d79f2da9 (diff) | |
| download | go-440ef8c4d24861cbfb01758e7e03fa3b4164f55a.tar.xz | |
cmd/internal/osinfo: report Node.js version
Seeing the Node.js version that was used during a particular test run
should be helpful during the upcoming migration from Node.js 14 to 18.
Add minimal support for that.
For golang/go#57614.
Change-Id: Id55ba25a7ee4a803788316d4a646cd4b6f4297e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/460655
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Richard Musiol <neelance@gmail.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
| -rw-r--r-- | src/cmd/internal/osinfo/os_js.go | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/cmd/internal/osinfo/os_js.go b/src/cmd/internal/osinfo/os_js.go index 882580d652..f4f03aa312 100644 --- a/src/cmd/internal/osinfo/os_js.go +++ b/src/cmd/internal/osinfo/os_js.go @@ -8,14 +8,31 @@ package osinfo import ( "fmt" + "syscall/js" ) // Version returns the OS version name/number. func Version() (string, error) { - // Version detection on wasm varies depending on the underlying runtime + // Version detection on Wasm varies depending on the underlying runtime // (browser, node, etc), nor is there a standard via something like - // WASI (see https://go.dev/issue/31105). We could attempt multiple - // combinations, but for now we leave this unimplemented for - // simplicity. - return "", fmt.Errorf("unimplemented") + // WASI (see https://go.dev/issue/31105). For now, attempt a few simple + // combinations for the convenience of reading logs at build.golang.org + // and local development. It's not a goal to recognize all environments. + if v, ok := node(); ok { + return "Node.js " + v, nil + } + return "", fmt.Errorf("unrecognized environment") +} + +func node() (version string, ok bool) { + // Try the https://nodejs.org/api/process.html#processversion API. + p := js.Global().Get("process") + if p.IsUndefined() { + return "", false + } + v := p.Get("version") + if v.IsUndefined() { + return "", false + } + return v.String(), true } |
