Skip to content

Commit 64d5899

Browse files
authored
refactor(exec): remove paramsFile (#807)
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
1 parent 8ab0a3a commit 64d5899

2 files changed

Lines changed: 2 additions & 10 deletions

File tree

src/exec-child.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ if (require.main !== module) {
55
var childProcess = require('child_process');
66
var fs = require('fs');
77

8-
var paramFilePath = process.argv[2];
9-
10-
var serializedParams = fs.readFileSync(paramFilePath, 'utf8');
11-
var params = JSON.parse(serializedParams);
8+
var params = JSON.parse(process.argv[2]);
129

1310
var cmd = params.command;
1411
var execOptions = params.execOptions;

src/exec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function execSync(cmd, opts, pipe) {
2121
}
2222

2323
var tempDir = _tempDir();
24-
var paramsFile = path.resolve(tempDir + '/' + common.randomFileName());
2524
var stderrFile = path.resolve(tempDir + '/' + common.randomFileName());
2625
var stdoutFile = path.resolve(tempDir + '/' + common.randomFileName());
2726

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

36-
if (fs.existsSync(paramsFile)) common.unlinkSync(paramsFile);
3735
if (fs.existsSync(stderrFile)) common.unlinkSync(stderrFile);
3836
if (fs.existsSync(stdoutFile)) common.unlinkSync(stdoutFile);
3937

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

50-
fs.writeFileSync(paramsFile, JSON.stringify(paramsToSerialize), 'utf8');
51-
5248
var execArgs = [
5349
path.join(__dirname, 'exec-child.js'),
54-
paramsFile,
50+
JSON.stringify(paramsToSerialize),
5551
];
5652

5753
/* istanbul ignore else */
@@ -88,7 +84,6 @@ function execSync(cmd, opts, pipe) {
8884
}
8985

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

0 commit comments

Comments
 (0)