Skip to content

Commit 695d51c

Browse files
committed
feature(spawnify) getHome -> untildify
1 parent 1c43f23 commit 695d51c

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

lib/spawnify.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
exec = child_process.exec,
1111
tryCatch = require('try-catch'),
12+
untildify = require('untildify'),
1213

1314
WIN = process.platform === 'win32',
1415
spawn = child_process.spawn,
@@ -30,7 +31,7 @@
3031
assert(command, 'command could not be empty!');
3132

3233
if (options && options.cwd)
33-
options.cwd = parseDir(options.cwd);
34+
options.cwd = untildify(options.cwd);
3435
else
3536
options = {
3637
cwd: process.cwd()
@@ -41,22 +42,12 @@
4142
return spawnify;
4243
};
4344

44-
function getHome() {
45-
var HOME_WIN = process.env.HOMEPATH,
46-
HOME_UNIX = process.env.HOME,
47-
HOME = HOME_WIN || HOME_UNIX;
48-
49-
return HOME;
50-
}
51-
5245
function parseDir(dir) {
53-
var home = getHome(),
54-
cwd = process.cwd();
46+
var cwd = process.cwd();
5547

5648
assert(dir, 'dir should be string!');
5749

58-
dir = dir.replace(/^~/, home)
59-
.replace(/^\./, cwd);
50+
dir = dir.replace(/^\./, cwd);
6051

6152
return dir;
6253
}
@@ -245,17 +236,14 @@
245236
var wasError, strs,
246237
self = this,
247238
CD = 'cd ',
248-
HOME = getHome(),
249239

250240
isChangeVolume = win.isChangeVolume(command),
251241
isVolume = win.isVolume(command),
252242
paramDir,
253243

254-
regExpHome = RegExp('^~'),
255244
regExpRoot = RegExp('^[/\\\\]'),
256245

257246
isWildCard,
258-
isHome = regExpHome.test(command) && !WIN,
259247
isRoot;
260248

261249
this.on('error', function() {
@@ -267,10 +255,7 @@
267255
this._emit('path', paramDir);
268256
});
269257

270-
if (isHome)
271-
command = command.replace('~', HOME);
272-
273-
paramDir = command;
258+
paramDir = untildify(command);
274259
isWildCard = isContain(paramDir, ['*', '?']);
275260

276261
if (!paramDir && !WIN)
@@ -293,7 +278,7 @@
293278
command = command.replace(str, '');
294279
});
295280

296-
if (!isHome && !isRoot)
281+
if (!isRoot)
297282
paramDir = path.join(currDir, paramDir);
298283

299284
if (isWildCard)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"glob": "~7.0.0",
1313
"try-catch": "~1.0.0",
14+
"untildify": "~2.1.0",
1415
"win32": "~0.9.4"
1516
},
1617
"license": "MIT",

0 commit comments

Comments
 (0)