Skip to content

Commit

Permalink
fix: correctly identify more wsl distributions, closes npm/cli#5903 (#56
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nlf committed Dec 12, 2022
1 parent 1818b5f commit 38f272a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const open = (_args, opts = {}, extra = {}) => {
let platform = process.platform
// process.platform === 'linux' may actually indicate WSL, if that's the case
// we want to treat things as win32 anyway so the host can open the argument
if (platform === 'linux' && os.release().includes('Microsoft')) {
if (platform === 'linux' && os.release().toLowerCase().includes('microsoft')) {
platform = 'win32'
}

Expand Down
26 changes: 26 additions & 0 deletions test/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,32 @@ t.test('process.platform === linux', (t) => {
t.ok(proc.called)
})

t.test('when os.release() includes microsoft treats as win32', async (t) => {
const comSpec = process.env.ComSpec
process.env.ComSpec = 'C:\\Windows\\System32\\cmd.exe'
t.teardown(() => {
process.env.ComSPec = comSpec
})

const promiseSpawnMock = t.mock('../lib/index.js', {
os: {
release: () => 'microsoft',
},
})

const proc = spawk.spawn('C:\\Windows\\System32\\cmd.exe',
['/d', '/s', '/c', 'start "" https://google.com'],
{ shell: false })

const result = await promiseSpawnMock.open('https://google.com')
t.hasStrict(result, {
code: 0,
signal: undefined,
})

t.ok(proc.called)
})

t.end()
})

Expand Down

0 comments on commit 38f272a

Please sign in to comment.