Adding upstream version 0.0~git20250409.f7acab6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
b9b5d88025
commit
21b930d007
51 changed files with 11229 additions and 0 deletions
37
process/module.go
Normal file
37
process/module.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue