1
0
Fork 0
golang-github-dop251-goja-n.../process/module.go
Daniel Baumann 21b930d007
Adding upstream version 0.0~git20250409.f7acab6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-05-22 11:36:18 +02:00

37 lines
659 B
Go

package process
import (
"os"
"strings"
"github.com/dop251/goja"
"github.com/dop251/goja_nodejs/require"
)
const ModuleName = "process"
type Process struct {
env map[string]string
}
func Require(runtime *goja.Runtime, module *goja.Object) {
p := &Process{
env: make(map[string]string),
}
for _, e := range os.Environ() {
envKeyValue := strings.SplitN(e, "=", 2)
p.env[envKeyValue[0]] = envKeyValue[1]
}
o := module.Get("exports").(*goja.Object)
o.Set("env", p.env)
}
func Enable(runtime *goja.Runtime) {
runtime.Set("process", require.Require(runtime, ModuleName))
}
func init() {
require.RegisterCoreModule(ModuleName, Require)
}