UNPKG

572 BJavaScriptView Raw
1import process from 'node:process';
2import os from 'node:os';
3import fs from 'node:fs';
4import isInsideContainer from 'is-inside-container';
5
6const isWsl = () => {
7 if (process.platform !== 'linux') {
8 return false;
9 }
10
11 if (os.release().toLowerCase().includes('microsoft')) {
12 if (isInsideContainer()) {
13 return false;
14 }
15
16 return true;
17 }
18
19 try {
20 return fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')
21 ? !isInsideContainer() : false;
22 } catch {
23 return false;
24 }
25};
26
27export default process.env.__IS_WSL_TEST__ ? isWsl : isWsl();