2023-09-13 17:25:11 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed npm/index.js
|
|
|
|
var src []byte
|
|
|
|
|
|
|
|
func reduce(fns []string) {
|
|
|
|
script := path.Join(os.TempDir(), fmt.Sprintf("fx-%v.js", version))
|
|
|
|
_, err := os.Stat(script)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
err := os.WriteFile(script, src, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deno := false
|
|
|
|
bin, err := exec.LookPath("node")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
bin, err = exec.LookPath("deno")
|
|
|
|
if err != nil {
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "Node.js or Deno is required to run fx with reducers.\n")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
deno = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 10:02:26 +03:00
|
|
|
env := os.Environ()
|
2023-09-13 17:25:11 +03:00
|
|
|
var args []string
|
2023-09-19 10:02:26 +03:00
|
|
|
|
2023-09-13 17:25:11 +03:00
|
|
|
if deno {
|
|
|
|
args = []string{"run", "-A", script}
|
2023-09-19 10:02:26 +03:00
|
|
|
env = append(env, "V8_FLAGS=--max-old-space-size=16384")
|
2023-09-13 17:25:11 +03:00
|
|
|
} else {
|
|
|
|
args = []string{script}
|
2023-09-19 10:02:26 +03:00
|
|
|
env = append(env, "NODE_OPTIONS=--max-old-space-size=16384")
|
2023-09-13 17:25:11 +03:00
|
|
|
}
|
2023-09-19 10:02:26 +03:00
|
|
|
|
2023-09-13 17:25:11 +03:00
|
|
|
args = append(args, fns...)
|
|
|
|
|
|
|
|
cmd := exec.Command(bin, args...)
|
2023-09-19 10:02:26 +03:00
|
|
|
cmd.Env = env
|
2023-09-13 17:25:11 +03:00
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err = cmd.Run()
|
|
|
|
|
|
|
|
switch err := err.(type) {
|
|
|
|
case nil:
|
|
|
|
os.Exit(0)
|
|
|
|
case *exec.ExitError:
|
|
|
|
os.Exit(err.ExitCode())
|
|
|
|
default:
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|