Skip to content

Commit 522a46d

Browse files
freitagbrnfischer
authored andcommitted
Deprecate common.getUserHome, advise using os.homedir instead (shelljs#725)
* Deprecate common.getUserHome, advise using os.homedir instead * Remove common.getUserHome
1 parent e8ec60b commit 522a46d

3 files changed

Lines changed: 8 additions & 20 deletions

File tree

src/cd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var fs = require('fs');
2+
var os = require('os');
23
var common = require('./common');
34

45
common.register('cd', _cd, {});
@@ -8,7 +9,7 @@ common.register('cd', _cd, {});
89
//@ Changes to directory `dir` for the duration of the script. Changes to home
910
//@ directory if no argument is supplied.
1011
function _cd(options, dir) {
11-
if (!dir) dir = common.getUserHome();
12+
if (!dir) dir = os.homedir();
1213

1314
if (dir === '-') {
1415
if (!process.env.OLDPWD) {

src/common.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,6 @@ function ShellString(stdout, stderr, code) {
155155

156156
exports.ShellString = ShellString;
157157

158-
// Return the home directory in a platform-agnostic way, with consideration for
159-
// older versions of node
160-
function getUserHome() {
161-
var result;
162-
if (os.homedir) {
163-
result = os.homedir(); // node 3+
164-
} else {
165-
result = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
166-
}
167-
return result;
168-
}
169-
exports.getUserHome = getUserHome;
170-
171158
// Returns {'alice': true, 'bob': false} when passed a string and dictionary as follows:
172159
// parseOptions('-a', {'a':'alice', 'b':'bob'});
173160
// Returns {'reference': 'string-value', 'bob': false} when passed two dictionaries of the form:
@@ -363,7 +350,7 @@ function wrap(cmd, fn, options) {
363350
});
364351

365352
// Expand the '~' if appropriate
366-
var homeDir = getUserHome();
353+
var homeDir = os.homedir();
367354
args = args.map(function (arg) {
368355
if (typeof arg === 'string' && arg.slice(0, 2) === '~/' || arg === '~') {
369356
return arg.replace(/^~/, homeDir);

test/cd.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import fs from 'fs';
2+
import os from 'os';
23
import path from 'path';
34

45
import test from 'ava';
56

67
import shell from '..';
7-
import common from '../src/common';
88
import utils from './utils/utils';
99

1010
const cur = shell.pwd().toString();
@@ -90,16 +90,16 @@ test('cd + other commands', t => {
9090

9191
test('Tilde expansion', t => {
9292
shell.cd('~');
93-
t.is(process.cwd(), common.getUserHome());
93+
t.is(process.cwd(), os.homedir());
9494
shell.cd('..');
95-
t.not(process.cwd(), common.getUserHome());
95+
t.not(process.cwd(), os.homedir());
9696
shell.cd('~'); // Change back to home
97-
t.is(process.cwd(), common.getUserHome());
97+
t.is(process.cwd(), os.homedir());
9898
});
9999

100100
test('Goes to home directory if no arguments are passed', t => {
101101
const result = shell.cd();
102102
t.falsy(shell.error());
103103
t.is(result.code, 0);
104-
t.is(process.cwd(), common.getUserHome());
104+
t.is(process.cwd(), os.homedir());
105105
});

0 commit comments

Comments
 (0)