metaforecast/node_modules/is-wsl/index.js

32 lines
558 B
JavaScript
Raw Normal View History

2021-01-12 12:43:41 +00:00
'use strict';
const os = require('os');
const fs = require('fs');
const isDocker = require('is-docker');
const isWsl = () => {
if (process.platform !== 'linux') {
return false;
}
if (os.release().toLowerCase().includes('microsoft')) {
if (isDocker()) {
return false;
}
return true;
}
try {
return fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft') ?
!isDocker() : false;
} catch (_) {
return false;
}
};
if (process.env.__IS_WSL_TEST__) {
module.exports = isWsl;
} else {
module.exports = isWsl();
}