index.js 445 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const os = require('os');
  3. module.exports = () => {
  4. if (process.env.MOCK_HOME_DIR) return process.env.MOCK_HOME_DIR;
  5. if (typeof os.userInfo === 'function') {
  6. try {
  7. const homedir = os.userInfo().homedir;
  8. if (homedir) return homedir;
  9. } catch (err) {
  10. if (err.code !== 'ENOENT') throw err;
  11. }
  12. }
  13. if (typeof os.homedir === 'function') {
  14. return os.homedir();
  15. }
  16. return process.env.HOME;
  17. };