Skip to content

Commit

Permalink
fix: have toWin32Path bail out early if path is already Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed May 21, 2020
1 parent 11bc863 commit 35fc9ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export function makeTmpDir() {
}

export function toWin32Path(dir: string = ''): string {
if (/[a-z]:\\/iu.test(dir)) {
return dir;
}

return execFileSync('wslpath', ['-w', dir]).toString().trim();
}

Expand Down
11 changes: 11 additions & 0 deletions test/utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ describe('toWin32Path', () => {

assert.ok(execFileSyncStub.calledWith('wslpath', ['-w', '']));
})

describe('when the path is already in Windows format', () => {
it('returns early', () => {
execFileSyncStub.returns(asBuffer(''));

assert.deepStrictEqual(toWin32Path('D:\\'), 'D:\\');
assert.deepStrictEqual(toWin32Path('C:\\'), 'C:\\');

assert.ok(execFileSyncStub.notCalled);
});
})
})

describe('toWSLPath', () => {
Expand Down

0 comments on commit 35fc9ed

Please sign in to comment.