MCPcopy Create free account
hub / github.com/Schniz/fnm / execute

Method execute

e2e/shellcode/script.ts:40–115  ·  view source on GitHub ↗
(
    shell: Pick<
      Shell,
      "binaryName" | "launchArgs" | "currentlySupported" | "forceFile"
    >
  )

Source from the content-addressed store, hash-verified

38 }
39
40 async execute(
41 shell: Pick<
42 Shell,
43 "binaryName" | "launchArgs" | "currentlySupported" | "forceFile"
44 >
45 ): Promise<void> {
46 if (!shell.currentlySupported()) {
47 return
48 }
49
50 const args = [...shell.launchArgs()]
51
52 if (shell.forceFile) {
53 let filename = join(testTmpDir(), "script")
54 if (typeof shell.forceFile === "string") {
55 filename = filename + shell.forceFile
56 }
57 await writeFile(filename, [...this.lines, "exit 0"].join("\n"))
58 args.push(filename)
59 }
60
61 const child = execa(shell.binaryName(), args, {
62 stdio: [shell.forceFile ? "ignore" : "pipe", "pipe", "pipe"],
63 cwd: testCwd(),
64 env: (() => {
65 const newProcessEnv: Record<string, string> = {
66 ...this.extraEnvVars,
67 ...removeAllFnmEnvVars(process.env),
68 PATH: [testBinDir(), fnmTargetDir(), process.env.PATH]
69 .filter(Boolean)
70 .join(path.delimiter),
71 FNM_DIR: this.config.fnmDir,
72 FNM_NODE_DIST_MIRROR: "http://localhost:8080",
73 }
74
75 delete newProcessEnv.NODE_OPTIONS
76 return newProcessEnv
77 })(),
78 extendEnv: false,
79 reject: false,
80 })
81
82 if (child.stdin) {
83 const childStdin = child.stdin
84
85 for (const line of this.lines) {
86 await write(childStdin, `${line}\n`)
87 }
88
89 await write(childStdin, "exit 0\n")
90 }
91
92 const { stdout, stderr } = streamOutputsAndBuffer(child)
93
94 const finished = await child
95
96 if (finished.failed) {
97 console.error(

Callers 15

basic.test.tsFile · 0.80
nvmrc-lts.test.tsFile · 0.80
latest.test.tsFile · 0.80
aliases.test.tsFile · 0.80
log-level.test.tsFile · 0.80
uninstall.test.tsFile · 0.80
exec.test.tsFile · 0.80
env.test.tsFile · 0.80

Calls 8

testTmpDirFunction · 0.85
testCwdFunction · 0.85
removeAllFnmEnvVarsFunction · 0.85
testBinDirFunction · 0.85
fnmTargetDirFunction · 0.85
writeFunction · 0.85
streamOutputsAndBufferFunction · 0.85
padAllLinesFunction · 0.85

Tested by

no test coverage detected