Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: add cwd to cluster.settings #18399

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ changes:
* `exec` {string} File path to worker file. **Default:** `process.argv[1]`
* `args` {Array} String arguments passed to worker.
**Default:** `process.argv.slice(2)`
* `cwd` {string} Current working directory of the worker process. **Default:**
`undefined` (inherits from parent process)
* `silent` {boolean} Whether or not to send output to parent's stdio.
**Default:** `false`
* `stdio` {Array} Configures the stdio of forked processes. Because the
Expand Down
1 change: 1 addition & 0 deletions lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function createWorkerProcess(id, env) {
}

return fork(cluster.settings.exec, cluster.settings.args, {
cwd: cluster.settings.cwd,
env: workerEnv,
silent: cluster.settings.silent,
windowsHide: cluster.settings.windowsHide,
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-cluster-cwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');

if (cluster.isMaster) {
common.refreshTmpDir();

assert.strictEqual(cluster.settings.cwd, undefined);
cluster.fork().on('message', common.mustCall((msg) => {
assert.strictEqual(msg, process.cwd());
}));

cluster.setupMaster({ cwd: common.tmpDir });
assert.strictEqual(cluster.settings.cwd, common.tmpDir);
cluster.fork().on('message', common.mustCall((msg) => {
assert.strictEqual(msg, common.tmpDir);
}));
} else {
process.send(process.cwd());
process.disconnect();
}