|
1 | 1 | "use strict"; |
2 | 2 |
|
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"); |
9 | 6 |
|
10 | 7 | module.exports = (command, args, options = {}) => { |
11 | 8 | if (!isObject(options)) options = {}; |
12 | 9 | 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) }); |
17 | 11 |
|
18 | 12 | 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))); |
25 | 15 | } |
26 | 16 |
|
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 | | - } |
34 | 17 | return promise.catch(error => { |
35 | 18 | log.warn("%s failed for %s, %O with %#s", command, args, options, error.message); |
36 | 19 | throw error; |
|
0 commit comments