Skip to content

Commit 87fe72f

Browse files
authored
Use where on Windows to detect devcontainer cli (#130)
1 parent 1fc832c commit 87fe72f

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

plugin/core/devcontainer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ async function runCommand(cmd, args, options = {}) {
6565
/**
6666
* Check if the devcontainer CLI is installed
6767
*
68+
* @param {string} [platform] - Platform to check (defaults to process.platform)
6869
* @returns {Promise<boolean>}
6970
*/
70-
export async function checkDevcontainerCli() {
71+
export async function checkDevcontainerCli(platform = process.platform) {
7172
try {
72-
const result = await runCommand('which', ['devcontainer'])
73+
const command = platform === 'win32' ? 'where' : 'which'
74+
const result = await runCommand(command, ['devcontainer'])
7375
return result.success
7476
} catch {
7577
return false

test/unit/devcontainer.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ describe('checkDevcontainerCli', () => {
100100
const result = await checkDevcontainerCli()
101101
assert.strictEqual(typeof result, 'boolean')
102102
})
103+
104+
test('uses where command on win32', async () => {
105+
// Note: 'where' command might not exist on non-Windows test environments (like Linux CI),
106+
// which causes spawn to throw ENOENT instead of returning an exit code.
107+
// Our checkDevcontainerCli function handles this gracefully with a try/catch, returning false.
108+
const result = await checkDevcontainerCli('win32')
109+
assert.strictEqual(typeof result, 'boolean')
110+
})
111+
112+
test('uses which command on linux/darwin', async () => {
113+
const result = await checkDevcontainerCli('linux')
114+
assert.strictEqual(typeof result, 'boolean')
115+
})
103116
})
104117

105118
describe('list', () => {

0 commit comments

Comments
 (0)