Skip to content

Commit 4a5881d

Browse files
committed
feature(spawnify) drop support of node version < 4.0.0
1 parent 3981a77 commit 4a5881d

File tree

4 files changed

+74
-95
lines changed

4 files changed

+74
-95
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ package-lock.json
22
node_modules
33
npm-debug.log
44

5-
legacy
65
*.swp
76

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ spawn.on('exit', function() {
4646
});
4747
```
4848

49-
## Environments
50-
51-
In old `node.js` environments that not fully supports `es2015`, `spawnify` could be used with:
52-
53-
```js
54-
var spawnify = require('spawnify/legacy');
55-
```
56-
5749
## License
5850

5951
MIT

lib/spawnify.js

Lines changed: 64 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,24 @@ function Spawnify(command, options) {
4949
}
5050

5151
Spawnify.prototype._onMessage = function onMessage(command, options) {
52-
var firstChar,
53-
dir = options.cwd,
54-
isVolume = win.isChangeVolume(command),
55-
56-
regExpCD = /^cd ?/,
57-
regExpCDWin = /^cd ?/i,
58-
59-
isCD = regExpCD.test(command),
60-
isCDWin = regExpCDWin.test(command),
61-
62-
symbolsExec = [
63-
'~', '>', '<', '#',
64-
'*', '&', '{', '}',
65-
'|', '\'','"', ';',
66-
'`', '$'
67-
],
68-
69-
isSymbol = isContain(command, symbolsExec);
70-
52+
const dir = options.cwd;
53+
const isVolume = win.isChangeVolume(command);
54+
55+
const regExpCD = /^cd ?/;
56+
const regExpCDWin = /^cd ?/i;
57+
58+
const isCD = regExpCD.test(command);
59+
const isCDWin = regExpCDWin.test(command);
60+
61+
const symbolsExec = [
62+
'~', '>', '<', '#',
63+
'*', '&', '{', '}',
64+
'|', '\'','"', ';',
65+
'`', '$'
66+
];
67+
68+
const isSymbol = isContain(command, symbolsExec);
69+
7170
assert(command, 'command could not be empty!');
7271
assert(command, 'options could not be empty!');
7372

@@ -78,9 +77,9 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
7877
this._onCD(command || '~', dir);
7978
} else {
8079
if (WIN)
81-
command = 'cmd /C ' + command;
80+
command = 'cmd /C ' + command;
8281

83-
firstChar = command[0];
82+
const firstChar = command[0];
8483

8584
if (firstChar === ' ' || isSymbol)
8685
this._set('exec', command, options);
@@ -90,7 +89,7 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
9089
};
9190

9291
Spawnify.prototype._emit = function emit(event, data) {
93-
const count = (event) => {
92+
const count = (event) => {
9493
const listeners = this.listeners(event);
9594

9695
return listeners.length;
@@ -139,7 +138,7 @@ Spawnify.prototype._set = function set(type, command, options) {
139138
args = command.split(' ');
140139
command = args.shift();
141140

142-
error = tryCatch(function() {
141+
error = tryCatch(() => {
143142
child = spawn(command, args, options);
144143
});
145144
break;
@@ -232,40 +231,35 @@ Spawnify.prototype._setListeners = function setListeners(child) {
232231
};
233232

234233
Spawnify.prototype._onCD = function onCD(command, currDir) {
235-
let wasError, strs,
236-
CD = 'cd ',
237-
238-
isChangeVolume = win.isChangeVolume(command),
239-
isVolume = win.isVolume(command),
240-
paramDir,
241-
242-
regExpRoot = RegExp('^[/\\\\]'),
243-
244-
isWildCard,
245-
isRoot;
234+
let wasError;
235+
236+
const CD = 'cd ';
237+
const isChangeVolume = win.isChangeVolume(command);
238+
const isVolume = win.isVolume(command);
239+
const regExpRoot = RegExp('^[/\\\\]');
246240

247-
this.on('error', function() {
241+
this.on('error', () => {
248242
wasError = true;
249243
});
250244

251-
this.on('close', function() {
245+
this.on('close', () => {
252246
if (!wasError)
253247
this._emit('path', tildify(paramDir));
254248
});
255249

256-
paramDir = untildify(command);
257-
isWildCard = isContain(paramDir, ['*', '?']);
250+
let paramDir = untildify(command);
251+
const isWildCard = isContain(paramDir, ['*', '?']);
258252

259253
if (!paramDir && !WIN)
260254
paramDir = '.';
261255

262256
if (!isChangeVolume || isVolume) {
263-
paramDir = this._getFirstWord(paramDir);
264-
paramDir = path.normalize(paramDir);
257+
paramDir = this._getFirstWord(paramDir);
258+
paramDir = path.normalize(paramDir);
265259

266-
isRoot = regExpRoot.test(paramDir);
260+
const isRoot = regExpRoot.test(paramDir);
267261

268-
strs = [
262+
const strs = [
269263
CD,
270264
paramDir,
271265
'\'' + paramDir + '\'',
@@ -286,43 +280,38 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
286280
}
287281

288282
if (!isWildCard)
289-
this._set('exec', command, {cwd: paramDir});
290-
else
291-
find(paramDir, (error, dirs) => {
292-
let dir;
293-
294-
if (!error)
295-
dir = dirs[0];
296-
297-
paramDir = dir;
298-
this._set('exec', command, {cwd: dir});
283+
return this._set('exec', command, {cwd: paramDir});
284+
285+
find(paramDir, (error, dirs) => {
286+
let cwd;
287+
288+
if (!error)
289+
cwd = dirs[0];
290+
291+
this._set('exec', command, {
292+
cwd
299293
});
294+
});
300295
};
301296

302297
Spawnify.prototype._getFirstWord = function getFirstWord(str) {
303-
var word, result,
304-
regStrEnd = getRegStrEnd(),
305-
regStr = '^(.*?)',
306-
regStrQuotes = '^"(.*)"',
307-
regExp = RegExp(regStr + regStrEnd),
308-
regExpQuotes = RegExp(regStrQuotes + regStrEnd + '?'),
309-
is = typeof str === 'string';
310-
311-
if (is) {
312-
result = str.match(regExpQuotes);
313-
314-
if (result) {
315-
word = result[1];
316-
} else {
317-
result = str.match(regExp);
318-
word = result && result[1];
319-
}
320-
321-
if (!word)
322-
word = str;
323-
}
298+
const regStrEnd = getRegStrEnd();
299+
const regStr = '^(.*?)';
300+
const regStrQuotes = '^"(.*)"';
301+
const regExp = RegExp(regStr + regStrEnd);
302+
const regExpQuotes = RegExp(regStrQuotes + regStrEnd + '?');
303+
const is = typeof str === 'string';
304+
305+
if (!is)
306+
return str;
307+
308+
let result = str.match(regExpQuotes);
324309

325-
return word;
310+
if (result)
311+
return result[1] || str;
312+
313+
result = str.match(regExp);
314+
return result && result[1] || str;
326315
};
327316

328317
function getRegStrEnd() {
@@ -331,7 +320,7 @@ function getRegStrEnd() {
331320
.map((char) => {
332321
return '\\' + char;
333322
}).join('|');
334-
323+
335324
const regStr = '(' + escaped + ')';
336325

337326
return regStr;

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@
55
"description": "Create new processes, change directories, auto switch between spawn and exec",
66
"homepage": "http://github.com/coderaiser/spawnify",
77
"scripts": {
8-
"lint": "eslint lib",
9-
"6to5": "buble lib -o legacy",
10-
"build": "redrun 6to5 legacy",
11-
"legacy": "echo \"module.exports = require('./spawnify');\" > legacy/index.js",
12-
"wisdom": "npm run build"
8+
"lint": "eslint lib"
139
},
1410
"repository": {
1511
"type": "git",
1612
"url": "git://github.com/coderaiser/spawnify.git"
1713
},
14+
"license": "MIT",
15+
"main": "lib/spawnify.js",
16+
"bin": {
17+
"spawnify": "bin/spawnify.js"
18+
},
19+
"engines": {
20+
"node": ">=4.0.0"
21+
},
1822
"dependencies": {
1923
"glob": "^7.1.0",
2024
"tildify": "^1.2.0",
2125
"try-catch": "^1.0.0",
2226
"untildify": "^2.1.0",
2327
"win32": "^1.0.0"
2428
},
25-
"license": "MIT",
26-
"main": "lib/spawnify.js",
27-
"bin": {
28-
"spawnify": "bin/spawnify.js"
29-
},
3029
"devDependencies": {
3130
"buble": "^0.15.1",
3231
"eslint": "^4.0.0"
3332
}
34-
}
33+
}

0 commit comments

Comments
 (0)