Skip to content

Commit

Permalink
cmd/internal/osinfo: report Node.js version
Browse files Browse the repository at this point in the history
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 #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>
  • Loading branch information
dmitshur authored and gopherbot committed Jan 19, 2023
1 parent f959fb3 commit 440ef8c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/cmd/internal/osinfo/os_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 440ef8c

Please sign in to comment.