MCPcopy
hub / github.com/gopherjs/gopherjs / runNode

Function runNode

tool.go:894–948  ·  view source on GitHub ↗

runNode runs script with args using Node.js in directory dir. If dir is empty string, current directory is used. Is out is not nil, process stderr and stdout are redirected to it, otherwise os.Stdout and os.Stderr are used.

(script string, args []string, dir string, quiet bool, out io.Writer)

Source from the content-addressed store, hash-verified

892// Is out is not nil, process stderr and stdout are redirected to it, otherwise
893// os.Stdout and os.Stderr are used.
894func runNode(script string, args []string, dir string, quiet bool, out io.Writer) error {
895 var allArgs []string
896 if b, _ := strconv.ParseBool(os.Getenv("SOURCE_MAP_SUPPORT")); os.Getenv("SOURCE_MAP_SUPPORT") == "" || b {
897 allArgs = []string{"--enable-source-maps"}
898 }
899
900 if runtime.GOOS != "windows" {
901 // We've seen issues with stack space limits causing
902 // recursion-heavy standard library tests to fail (e.g., see
903 // https://github.com/gopherjs/gopherjs/pull/669#issuecomment-319319483).
904 //
905 // There are two separate limits in non-Windows environments:
906 //
907 // - OS process limit
908 // - Node.js (V8) limit
909 //
910 // GopherJS fetches the current OS process limit, and sets the Node.js limit
911 // to a value slightly below it (otherwise nodejs is likely to segfault).
912 // The backoff size has been determined experimentally on a linux machine,
913 // so it may not be 100% reliable. So both limits are kept in sync and can
914 // be controlled by setting OS process limit. E.g.:
915 //
916 // ulimit -s 10000 && gopherjs test
917 //
918 cur, err := sysutil.RlimitStack()
919 if err != nil {
920 return fmt.Errorf("failed to get stack size limit: %v", err)
921 }
922 cur = cur / 1024 // Convert bytes to KiB.
923 defaultSize := uint64(984) // --stack-size default value.
924 if backoff := uint64(64); cur > defaultSize+backoff {
925 cur = cur - backoff
926 }
927 allArgs = append(allArgs, fmt.Sprintf("--stack_size=%v", cur))
928 }
929
930 allArgs = append(allArgs, script)
931 allArgs = append(allArgs, args...)
932
933 node := exec.Command("node", allArgs...)
934 node.Dir = dir
935 node.Stdin = os.Stdin
936 if out != nil {
937 node.Stdout = out
938 node.Stderr = out
939 } else {
940 node.Stdout = os.Stdout
941 node.Stderr = os.Stderr
942 }
943 err := node.Run()
944 if _, ok := err.(*exec.ExitError); err != nil && !ok {
945 err = fmt.Errorf("could not run Node.js: %s", err.Error())
946 }
947 return err
948}
949
950// runTestDir returns the directory for Node.js to use when running tests for package p.
951// Empty string means current directory.

Callers 1

mainFunction · 0.85

Calls 2

RlimitStackFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…