MCPcopy Create free account
hub / github.com/nodejs/node / spawnPath

Function spawnPath

deps/npm/test/bin/windows-shims.js:125–154  ·  view source on GitHub ↗
(cmd, args, { log, stdioString = true, ...opts } = {})

Source from the content-addressed store, hash-verified

123 t.teardown(() => moveRemove(join(path, 'node.exe')))
124
125 const spawnPath = (cmd, args, { log, stdioString = true, ...opts } = {}) => {
126 if (cmd.endsWith('bash.exe')) {
127 // only cygwin *requires* the -l, but the others are ok with it
128 args.unshift('-l')
129 }
130 if (cmd.toLowerCase().endsWith('powershell.exe') || cmd.toLowerCase().endsWith('pwsh.exe')) {
131 // pwsh *requires* the -Command, Windows PowerShell defaults to it
132 args.unshift('-Command')
133 // powershell requires escaping double-quotes for this test
134 args = args.map(elem => elem.replaceAll('"', '\\"'))
135 }
136 const result = spawnSync(`"${cmd}"`, args, {
137 // don't hit the registry for the update check
138 env: { PATH: path, npm_config_update_notifier: 'false' },
139 cwd: path,
140 windowsHide: true,
141 shell: true,
142 ...opts,
143 })
144 if (stdioString) {
145 result.stdout = result.stdout?.toString()?.trim()
146 result.stderr = result.stderr?.toString()?.trim()
147 }
148 return {
149 status: result.status,
150 signal: result.signal,
151 stdout: result.stdout,
152 stderr: result.stderr,
153 }
154 }
155
156 const getWslVersion = (cmd) => {
157 const defaultVersion = 1

Callers 3

getWslVersionFunction · 0.85
windows-shims.jsFile · 0.85
matchCmdFunction · 0.85

Calls 4

unshiftMethod · 0.80
mapMethod · 0.65
spawnSyncFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected