Skip to content

Commit

Permalink
refactor(exec): remove paramsFile (#807)
Browse files Browse the repository at this point in the history
The `paramsFile` is obsolete now that we use `execFileSync()` for our
internal implementation. Instead, we pass parameters to the child
process directly as a single commandline parameter to reduce file I/O.

Issue #782
  • Loading branch information
nfischer committed Nov 16, 2017
1 parent 8ab0a3a commit 64d5899
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/exec-child.js
Expand Up @@ -5,10 +5,7 @@ if (require.main !== module) {
var childProcess = require('child_process');
var fs = require('fs');

var paramFilePath = process.argv[2];

var serializedParams = fs.readFileSync(paramFilePath, 'utf8');
var params = JSON.parse(serializedParams);
var params = JSON.parse(process.argv[2]);

var cmd = params.command;
var execOptions = params.execOptions;
Expand Down
7 changes: 1 addition & 6 deletions src/exec.js
Expand Up @@ -21,7 +21,6 @@ function execSync(cmd, opts, pipe) {
}

var tempDir = _tempDir();
var paramsFile = path.resolve(tempDir + '/' + common.randomFileName());
var stderrFile = path.resolve(tempDir + '/' + common.randomFileName());
var stdoutFile = path.resolve(tempDir + '/' + common.randomFileName());

Expand All @@ -33,7 +32,6 @@ function execSync(cmd, opts, pipe) {
encoding: 'utf8',
}, opts);

if (fs.existsSync(paramsFile)) common.unlinkSync(paramsFile);
if (fs.existsSync(stderrFile)) common.unlinkSync(stderrFile);
if (fs.existsSync(stdoutFile)) common.unlinkSync(stdoutFile);

Expand All @@ -47,11 +45,9 @@ function execSync(cmd, opts, pipe) {
stderrFile: stderrFile,
};

fs.writeFileSync(paramsFile, JSON.stringify(paramsToSerialize), 'utf8');

var execArgs = [
path.join(__dirname, 'exec-child.js'),
paramsFile,
JSON.stringify(paramsToSerialize),
];

/* istanbul ignore else */
Expand Down Expand Up @@ -88,7 +84,6 @@ function execSync(cmd, opts, pipe) {
}

// No biggie if we can't erase the files now -- they're in a temp dir anyway
try { common.unlinkSync(paramsFile); } catch (e) {}
try { common.unlinkSync(stderrFile); } catch (e) {}
try { common.unlinkSync(stdoutFile); } catch (e) {}

Expand Down

0 comments on commit 64d5899

Please sign in to comment.