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

Function getWslVersion

deps/npm/test/bin/windows-shims.js:156–174  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

154 }
155
156 const getWslVersion = (cmd) => {
157 const defaultVersion = 1
158 try {
159 const opts = { shell: cmd, env: process.env }
160 const wsl = spawnPath('wslpath', [`'${which('wsl')}'`], opts).stdout
161 const distrosRaw = spawnPath(wsl, ['-l', '-v'], { ...opts, stdioString: false }).stdout
162 const distros = spawnPath('iconv', ['-f', 'unicode'], { ...opts, input: distrosRaw }).stdout
163 const distroArgs = distros
164 .replace(/\r\n/g, '\n')
165 .split('\n')
166 .slice(1)
167 .find(d => d.startsWith('*'))
168 .replace(/\s+/g, ' ')
169 .split(' ')
170 return Number(distroArgs[distroArgs.length - 1]) || defaultVersion
171 } catch {
172 return defaultVersion
173 }
174 }
175
176 for (const shim of Object.keys(SHIMS)) {
177 chmodSync(join(path, shim), 0o755)

Callers 1

windows-shims.jsFile · 0.85

Calls 4

spawnPathFunction · 0.85
findMethod · 0.65
sliceMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected