Skip to content

Commit 6f4e998

Browse files
authored
fix varlock executable finding logic on windows (#204)
1 parent 51f1953 commit 6f4e998

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

.changeset/nine-hoops-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"varlock": patch
3+
---
4+
5+
fix logic around finding the varlock executable to work with windows .cmd files

packages/utils/src/git-utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ export async function checkIsFileGitIgnored(path: string, warnIfNotGitRepo = fal
66
return true;
77
} catch (err) {
88
const stderr = (err as any).stderr as string;
9-
// git is not installed, so we don't know
10-
if ((err as any).status === 127 || stderr.includes('not found')) return undefined;
9+
// git is not installed, so we can't check
10+
if (
11+
(err as any).status === 127
12+
|| stderr.includes('not found')
13+
|| stderr.includes('not recognized') // windows
14+
) {
15+
return undefined;
16+
}
17+
1118
// other file related issues could throw this
1219
if ((err as any).code === 'ENOENT') return undefined;
1320
// `git check-ignore -q` exits with code 1 but no other error if is not ignored

packages/varlock/src/lib/exec-sync-varlock.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import path from 'node:path';
22
import fs from 'node:fs';
3+
import os from 'node:os';
34
import { execSync } from 'node:child_process';
45

56
// weird tsup issue using `typeof execSync` from node:child_process
67
// see https://github.com/egoist/tsup/issues/1367
78
import type { execSync as execSyncType } from 'child_process';
89

10+
const platform = os.platform();
11+
const isWindows = platform.match(/^win/i);
12+
13+
914
/**
1015
* small helper to call execSync and call the varlock cli
1116
*
@@ -30,8 +35,9 @@ export function execSyncVarlock(
3035
});
3136
return result.toString();
3237
} catch (err) {
33-
// code 127 means not found
34-
if ((err as any).status !== 127) throw err;
38+
// code 127 means not found (on linux only)
39+
if (!isWindows && (err as any).status !== 127) throw err;
40+
// on windows, we'll just do the extra checks anyway
3541
}
3642

3743
// if varlock was not found, it either means it is not installed
@@ -47,8 +53,6 @@ export function execSyncVarlock(
4753
...opts,
4854
stdio: 'pipe',
4955
});
50-
// const commandArgs = command.split(' ').filter(Boolean);
51-
// const result = execFileSync(possibleVarlockPath, commandArgs, opts);
5256
return result.toString();
5357
} else {
5458
throw new Error('Unable to find varlock executable');

0 commit comments

Comments
 (0)