index.js 426 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const os = require('os');
  3. const fs = require('fs');
  4. const isWsl = () => {
  5. if (process.platform !== 'linux') {
  6. return false;
  7. }
  8. if (os.release().includes('Microsoft')) {
  9. return true;
  10. }
  11. try {
  12. return fs.readFileSync('/proc/version', 'utf8').includes('Microsoft');
  13. } catch (err) {
  14. return false;
  15. }
  16. };
  17. if (process.env.__IS_WSL_TEST__) {
  18. module.exports = isWsl;
  19. } else {
  20. module.exports = isWsl();
  21. }