Skip to content

Commit 985d3d9

Browse files
committed
refactor: upgrade to child-process-ext
1 parent 74b4945 commit 985d3d9

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

lib/get-npm-modules-path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const { resolve } = require("path")
77

88
module.exports = memoize(
99
async () => {
10-
const { stdout } = await runProgram("npm", ["config", "get", "prefix"], {
10+
const { stdoutBuffer } = await runProgram("npm", ["config", "get", "prefix"], {
1111
cwd: process.cwd()
1212
});
13-
const [npmPathPrefix] = String(stdout).split("\n", 1);
13+
const [npmPathPrefix] = String(stdoutBuffer).split("\n", 1);
1414
if (!npmPathPrefix) throw new Error("Could not resolve npm path prefix");
1515
log.notice("npm path prefix: %s", npmPathPrefix);
1616
if (process.platform === "win32") return resolve(npmPathPrefix, "node_modules");

lib/run-program.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
11
"use strict";
22

3-
const isObject = require("es5-ext/object/is-object")
4-
, { spawn } = require("child-process-es6-promise")
5-
, split = require("split")
6-
, log = require("log").get("npm-cross-link");
7-
8-
const winCmdCommands = new Set();
3+
const isObject = require("es5-ext/object/is-object")
4+
, spawn = require("child-process-ext/spawn")
5+
, log = require("log").get("npm-cross-link");
96

107
module.exports = (command, args, options = {}) => {
118
if (!isObject(options)) options = {};
129
const { logger } = options;
13-
let promise = spawn(command + (winCmdCommands.has(command) ? ".cmd" : ""), args, {
14-
cwd: options.cwd
15-
});
16-
const { child } = promise;
10+
const promise = spawn(command, args, { cwd: options.cwd, split: Boolean(logger) });
1711

1812
if (logger) {
19-
child.stdout
20-
.pipe(split(/\r?\n/u, null, { trailing: false }))
21-
.on("data", data => logger.info(String(data)));
22-
child.stderr
23-
.pipe(split(/\r?\n/u, null, { trailing: false }))
24-
.on("data", data => logger.notice(String(data)));
13+
promise.stdout.on("data", data => logger.info(String(data)));
14+
promise.stderr.on("data", data => logger.notice(String(data)));
2515
}
2616

27-
if (process.platform === "win32" && !winCmdCommands.has(command)) {
28-
promise = promise.catch(error => {
29-
if (error.code !== "ENOENT") throw error;
30-
winCmdCommands.add(command);
31-
return module.exports(command, args, options);
32-
});
33-
}
3417
return promise.catch(error => {
3518
log.warn("%s failed for %s, %O with %#s", command, args, options, error.message);
3619
throw error;

lib/setup-repository.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = async (path, repoUrl, options = {}) => {
3737
});
3838
}
3939

40-
const { stdout: localStatus } = await runProgram("git", ["status"], { cwd: path });
40+
const { stdoutBuffer: localStatus } = await runProgram("git", ["status"], { cwd: path });
4141

4242
if (
4343
tryPull &&

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"repository": "medikoo/npm-cross-link",
1010
"dependencies": {
11-
"child-process-es6-promise": "^1.2",
11+
"child-process-ext": "2",
1212
"cjs-module": "^1.5",
1313
"cli-color": "^1.4",
1414
"cli-progress-footer": "^1.1",
@@ -23,8 +23,7 @@
2323
"minimist": "^1.2",
2424
"semver": "^5.6",
2525
"tar": "^4.4.8",
26-
"timers-ext": "^0.1.7",
27-
"split": "^1.0.1"
26+
"timers-ext": "^0.1.7"
2827
},
2928
"devDependencies": {
3029
"eslint": "^5.12",

0 commit comments

Comments
 (0)