Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 8b704bd

Browse files
committed
Add Windows support to environment detection. Resolves #438
1 parent 0b3c129 commit 8b704bd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

client/src/util/env.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@ import fs from 'fs';
44
import path from 'path';
55

66
const SHIM_DIR = path.resolve(__dirname, 'shims');
7+
const SHIM_EXTENSION = isWindows() ? 'cmd' : 'sh';
8+
79
if (!fs.existsSync(SHIM_DIR)) {
810
fs.mkdirSync(SHIM_DIR);
911
}
1012

13+
function isWindows(): boolean {
14+
return process.platform === 'win32';
15+
}
16+
17+
function getTemplate(shell: string): string {
18+
let template;
19+
if (isWindows()) {
20+
template = 'SET';
21+
} else {
22+
template = `#!${shell} -i\nexport`;
23+
}
24+
25+
return template;
26+
}
27+
1128
function mkShim(shell: string, shimPath: string): boolean {
12-
const template = `#!${shell} -i\nexport`;
29+
const template = getTemplate(shell);
1330
let result = false;
1431

1532
try {
@@ -25,7 +42,7 @@ function mkShim(shell: string, shimPath: string): boolean {
2542

2643
function getShim(): string {
2744
const shellName: string = path.basename(defaultShell);
28-
const shimPath = path.join(SHIM_DIR, `env.${shellName}`);
45+
const shimPath = path.join(SHIM_DIR, `env.${shellName}.${SHIM_EXTENSION}`);
2946
if (!fs.existsSync(shimPath)) {
3047
mkShim(defaultShell, shimPath);
3148
}
@@ -64,6 +81,8 @@ function processExportLine(line: string): string[] {
6481

6582
const RUBY_ENVIRONMENT_VARIABLES = [
6683
'PATH',
84+
'Path', // Windows
85+
'PATHEXT', // Windows
6786
'RUBY_VERSION',
6887
'RUBY_ROOT',
6988
'GEM_HOME',

0 commit comments

Comments
 (0)