Skip to content

Commit

Permalink
child_process: move exports to bottom for consistent code style
Browse files Browse the repository at this point in the history
PR-URL: #27845
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
  • Loading branch information
himself65 authored and targos committed Jun 3, 2019
1 parent 2ce24a9 commit ea2d550
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ const {

const MAX_BUFFER = 1024 * 1024;

exports.ChildProcess = ChildProcess;

exports.fork = function fork(modulePath /* , args, options */) {
function fork(modulePath /* , args, options */) {
validateString(modulePath, 'modulePath');

// Get options and args arguments.
Expand Down Expand Up @@ -108,10 +106,9 @@ exports.fork = function fork(modulePath /* , args, options */) {
options.shell = false;

return spawn(options.execPath, args, options);
};

}

exports._forkChild = function _forkChild(fd) {
function _forkChild(fd) {
// set process.send()
const p = new Pipe(PipeConstants.IPC);
p.open(fd);
Expand All @@ -123,8 +120,7 @@ exports._forkChild = function _forkChild(fd) {
process.on('removeListener', function onRemoveListener(name) {
if (name === 'message' || name === 'disconnect') control.unref();
});
};

}

function normalizeExecArgs(command, options, callback) {
if (typeof options === 'function') {
Expand All @@ -144,12 +140,12 @@ function normalizeExecArgs(command, options, callback) {
}


exports.exec = function exec(command, options, callback) {
function exec(command, options, callback) {
const opts = normalizeExecArgs(command, options, callback);
return exports.execFile(opts.file,
opts.options,
opts.callback);
};
return module.exports.execFile(opts.file,
opts.options,
opts.callback);
}

const customPromiseExecFunction = (orig) => {
return (...args) => {
Expand All @@ -167,12 +163,12 @@ const customPromiseExecFunction = (orig) => {
};
};

Object.defineProperty(exports.exec, promisify.custom, {
Object.defineProperty(exec, promisify.custom, {
enumerable: false,
value: customPromiseExecFunction(exports.exec)
value: customPromiseExecFunction(exec)
});

exports.execFile = function execFile(file /* , args, options, callback */) {
function execFile(file /* , args, options, callback */) {
let args = [];
let callback;
let options;
Expand Down Expand Up @@ -386,11 +382,11 @@ exports.execFile = function execFile(file /* , args, options, callback */) {
child.addListener('error', errorhandler);

return child;
};
}

Object.defineProperty(exports.execFile, promisify.custom, {
Object.defineProperty(execFile, promisify.custom, {
enumerable: false,
value: customPromiseExecFunction(exports.execFile)
value: customPromiseExecFunction(execFile)
});

function normalizeSpawnArguments(file, args, options) {
Expand Down Expand Up @@ -529,7 +525,7 @@ function normalizeSpawnArguments(file, args, options) {
}


var spawn = exports.spawn = function spawn(file, args, options) {
function spawn(file, args, options) {
const opts = normalizeSpawnArguments(file, args, options);
const child = new ChildProcess();

Expand All @@ -550,7 +546,7 @@ var spawn = exports.spawn = function spawn(file, args, options) {
});

return child;
};
}

function spawnSync(file, args, options) {
const opts = normalizeSpawnArguments(file, args, options);
Expand Down Expand Up @@ -605,7 +601,6 @@ function spawnSync(file, args, options) {

return child_process.spawnSync(opts);
}
exports.spawnSync = spawnSync;


function checkExecSyncError(ret, args, cmd) {
Expand Down Expand Up @@ -643,7 +638,6 @@ function execFileSync(command, args, options) {

return ret.stdout;
}
exports.execFileSync = execFileSync;


function execSync(command, options) {
Expand All @@ -662,7 +656,6 @@ function execSync(command, options) {

return ret.stdout;
}
exports.execSync = execSync;


function validateTimeout(timeout) {
Expand Down Expand Up @@ -690,3 +683,15 @@ function sanitizeKillSignal(killSignal) {
killSignal);
}
}

module.exports = {
_forkChild,
ChildProcess,
exec,
execFile,
execFileSync,
execSync,
fork,
spawn,
spawnSync
};

0 comments on commit ea2d550

Please sign in to comment.