Skip to content

Commit 64d4c49

Browse files
committed
chore: lint
1 parent 7dac067 commit 64d4c49

File tree

8 files changed

+57
-39
lines changed

8 files changed

+57
-39
lines changed

.eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"extends": [
3-
"plugin:node/recommended",
3+
"plugin:n/recommended",
44
"plugin:putout/recommended"
55
],
66
"plugins": [
77
"putout",
8-
"node"
8+
"n"
99
]
1010
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ npm-debug.log
44

55
*.swp
66

7-
.putoutcache
87
.nyc_output
8+
.idea
9+
yarn-error.log
10+
coverage

.madrun.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export default {
66
'lint:fresh': () => run('lint', '--fresh'),
77
'fix:lint': () => run('lint', '--fix'),
88
};
9-

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33

44
madrun.js
55

6+
yarn-error.log
7+
coverage

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# Spawnify [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
1+
# Spawnify [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
22

3-
[NPMIMGURL]: https://img.shields.io/npm/v/spawnify.svg?style=flat
4-
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/spawnify/master.svg?style=flat
5-
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/spawnify.svg?style=flat
6-
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
7-
[NPMURL]: https://npmjs.org/package/spawnify "npm"
8-
[BuildStatusURL]: https://travis-ci.org/coderaiser/spawnify "Build Status"
9-
[DependencyStatusURL]: https://david-dm.org/coderaiser/spawnify "Dependency Status"
10-
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
3+
[NPMIMGURL]: https://img.shields.io/npm/v/spawnify.svg?style=flat
4+
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/spawnify/master.svg?style=flat
5+
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
6+
[NPMURL]: https://npmjs.org/package/spawnify "npm"
7+
[BuildStatusURL]: https://travis-ci.org/coderaiser/spawnify "Build Status"
8+
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
119

1210
Create new processes, change directories, auto switch between spawn and exec.
1311

@@ -21,7 +19,9 @@ npm i spawnify --save
2119

2220
```js
2321
const spawnify = require('spawnify');
24-
const spawn = spawnify('ls -lha', {cwd: __dirname});
22+
const spawn = spawnify('ls -lha', {
23+
cwd: __dirname,
24+
});
2525

2626
spawn.on('error', (error) => {
2727
console.error(error.message);

bin/spawnify.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ if (!command) {
2424
spawn = null;
2525
});
2626
}
27-

lib/spawnify.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const isString = (a) => typeof a === 'string';
34
const path = require('path');
45
const {EventEmitter} = require('events');
56
const util = require('util');
@@ -10,10 +11,9 @@ const tryCatch = require('try-catch');
1011
const tildify = require('tildify');
1112
const untildify = require('untildify');
1213

13-
const WIN = process.platform === 'win32';
14-
1514
const find = require('glob');
1615
const win = require('win32');
16+
const WIN = process.platform === 'win32';
1717

1818
const newLine = (error) => {
1919
error.message += '\n';
@@ -56,10 +56,20 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
5656
const isCDWin = regExpCDWin.test(command);
5757

5858
const symbolsExec = [
59-
'~', '>', '<', '#',
60-
'*', '&', '{', '}',
61-
'|', '\'', '"', ';',
62-
'`', '$',
59+
'~',
60+
'>',
61+
'<',
62+
'#',
63+
'*',
64+
'&',
65+
'{',
66+
'}',
67+
'|',
68+
`'`,
69+
'"',
70+
';',
71+
'`',
72+
'$',
6373
];
6474

6575
const isSymbol = isContain(command, symbolsExec);
@@ -68,13 +78,12 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
6878
assert(command, 'options could not be empty!');
6979

7080
if (isCD || isCDWin && WIN || isVolume) {
71-
command = command
72-
.replace(WIN ? regExpCDWin : regExpCD, '');
81+
command = command.replace(WIN ? regExpCDWin : regExpCD, '');
7382

7483
this._onCD(command || '~', dir);
7584
} else {
7685
if (WIN)
77-
command = 'cmd /C ' + command;
86+
command = `cmd /C ${command}`;
7887

7988
const [firstChar] = command;
8089

@@ -190,7 +199,8 @@ Spawnify.prototype._setListeners = function setListeners(child) {
190199
});
191200

192201
if (child.stdout) {
193-
child.stdout
202+
child
203+
.stdout
194204
.pipe(win.unicodify())
195205
.setEncoding('utf8')
196206
.on('data', (data) => {
@@ -203,7 +213,9 @@ Spawnify.prototype._setListeners = function setListeners(child) {
203213
}
204214

205215
if (child.stderr) {
206-
child.stderr.pipe(win.unicodify())
216+
child
217+
.stderr
218+
.pipe(win.unicodify())
207219
.setEncoding('utf8')
208220
.on('data', (error) => {
209221
this._emit('error', Error(error));
@@ -261,8 +273,8 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
261273
const strs = [
262274
CD,
263275
paramDir,
264-
'\'' + paramDir + '\'',
265-
'"' + paramDir + '"',
276+
`'${paramDir}'`,
277+
`"${paramDir}"`,
266278
];
267279

268280
for (const str of strs) {
@@ -279,7 +291,9 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
279291
}
280292

281293
if (!isWildCard)
282-
return this._set('exec', command, {cwd: paramDir});
294+
return this._set('exec', command, {
295+
cwd: paramDir,
296+
});
283297

284298
find(paramDir, (error, dirs) => {
285299
let cwd;
@@ -299,7 +313,7 @@ Spawnify.prototype._getFirstWord = function getFirstWord(str) {
299313
const regStrQuotes = '^"(.*)"';
300314
const regExp = RegExp(regStr + regStrEnd);
301315
const regExpQuotes = RegExp(regStrQuotes + regStrEnd + '?');
302-
const is = typeof str === 'string';
316+
const is = isString(str);
303317

304318
if (!is)
305319
return str;
@@ -314,15 +328,18 @@ Spawnify.prototype._getFirstWord = function getFirstWord(str) {
314328
};
315329

316330
function getRegStrEnd() {
317-
const chars = ['s', ';', '&&', '\\', '|'];
331+
const chars = [
332+
's',
333+
';',
334+
'&&',
335+
'\\',
336+
'|',
337+
];
318338
const escaped = chars
319-
.map((char) => {
320-
return '\\' + char;
321-
}).join('|');
339+
.map((char) => `\${char}`)
340+
.join('|');
322341

323-
const regStr = '(' + escaped + ')';
324-
325-
return regStr;
342+
return `(${escaped})`;
326343
}
327344

328345
function isContain(str, symbols) {
@@ -333,4 +350,3 @@ function isContain(str, symbols) {
333350
return str.includes(symbol);
334351
});
335352
}
336-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "spawnify",
33
"version": "7.0.2",
4+
"type": "commonjs",
45
"author": "coderaiser <[email protected]> (https://github.com/coderaiser)",
56
"description": "Create new processes, change directories, auto switch between spawn and exec",
67
"homepage": "http://github.com/coderaiser/spawnify",
@@ -30,7 +31,6 @@
3031
"devDependencies": {
3132
"eslint": "^8.46.0",
3233
"eslint-plugin-n": "^16.0.1",
33-
"eslint-plugin-node": "^11.0.0",
3434
"eslint-plugin-putout": "^19.0.4",
3535
"madrun": "^9.3.1",
3636
"putout": "^31.0.5"

0 commit comments

Comments
 (0)