|
|
|
@ -5,14 +5,23 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func CreateNodejs(args []string) *exec.Cmd {
|
|
|
|
|
cmd := exec.Command("node", "-e", nodejs(args))
|
|
|
|
|
cmd := exec.Command("node", "--input-type=module", "-e", nodejs(args))
|
|
|
|
|
nodePath, exist := os.LookupEnv("NODE_PATH")
|
|
|
|
|
if exist {
|
|
|
|
|
cmd.Dir = path.Dir(nodePath)
|
|
|
|
|
}
|
|
|
|
|
cmd.Env = os.Environ()
|
|
|
|
|
cmd.Env = append(cmd.Env, "NODE_OPTIONS=--max-old-space-size=8192")
|
|
|
|
|
workingDir, err := os.Getwd()
|
|
|
|
|
if err == nil {
|
|
|
|
|
cmd.Env = append(cmd.Env, "FX_CMD="+workingDir)
|
|
|
|
|
}
|
|
|
|
|
return cmd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -59,12 +68,15 @@ func nodejs(args []string) string {
|
|
|
|
|
default:
|
|
|
|
|
rs += fmt.Sprintf(
|
|
|
|
|
`
|
|
|
|
|
f = function ()
|
|
|
|
|
let f = function ()
|
|
|
|
|
{ return %v }
|
|
|
|
|
.call(x)
|
|
|
|
|
x = typeof f === 'function' ? f(x) : f
|
|
|
|
|
`, a)
|
|
|
|
|
}
|
|
|
|
|
rs += `
|
|
|
|
|
x = await x
|
|
|
|
|
`
|
|
|
|
|
// Generate a beautiful error message.
|
|
|
|
|
rs += " } catch (e) {\n"
|
|
|
|
|
pre, post, pointer := trace(args, i)
|
|
|
|
@ -74,7 +86,16 @@ func nodejs(args []string) string {
|
|
|
|
|
)
|
|
|
|
|
rs += " }\n"
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf(templateJs, rs)
|
|
|
|
|
|
|
|
|
|
fxrc := ""
|
|
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
|
if err == nil {
|
|
|
|
|
b, err := os.ReadFile(path.Join(home, ".fxrc.js"))
|
|
|
|
|
if err == nil {
|
|
|
|
|
fxrc = "\n" + string(b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf(templateJs, fxrc, rs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var flatMapRegex = regexp.MustCompile("^(\\.\\w*)+\\[]")
|
|
|
|
|