Skip to content

Commit b0f8df0

Browse files
authored
fix(Shard): add env, execArgv, and argv for worker-based shards (#10429)
* fix(Shard): add env, execArgv, and argv to worker-based threads * chore: remove process only docs assertion from certain shard options * chore: update comments for Shard.js * refactor: Use SHARE_ENV for worker shard's env * chore: import order --------- Co-authored-by: Cat++ <[email protected]>
1 parent bf83db9 commit b0f8df0

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/discord.js/src/sharding/Shard.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ const path = require('node:path');
55
const process = require('node:process');
66
const { setTimeout, clearTimeout } = require('node:timers');
77
const { setTimeout: sleep } = require('node:timers/promises');
8+
const { SHARE_ENV } = require('node:worker_threads');
89
const { DiscordjsError, ErrorCodes } = require('../errors');
910
const ShardEvents = require('../util/ShardEvents');
1011
const { makeError, makePlainError } = require('../util/Util');
12+
1113
let childProcess = null;
1214
let Worker = null;
1315

@@ -49,13 +51,13 @@ class Shard extends EventEmitter {
4951
this.silent = manager.silent;
5052

5153
/**
52-
* Arguments for the shard's process (only when {@link ShardingManager#mode} is `process`)
54+
* Arguments for the shard's process/worker
5355
* @type {string[]}
5456
*/
5557
this.args = manager.shardArgs ?? [];
5658

5759
/**
58-
* Arguments for the shard's process executable (only when {@link ShardingManager#mode} is `process`)
60+
* Arguments for the shard's process/worker executable
5961
* @type {string[]}
6062
*/
6163
this.execArgv = manager.execArgv;
@@ -136,7 +138,12 @@ class Shard extends EventEmitter {
136138
.on('exit', this._exitListener);
137139
break;
138140
case 'worker':
139-
this.worker = new Worker(path.resolve(this.manager.file), { workerData: this.env })
141+
this.worker = new Worker(path.resolve(this.manager.file), {
142+
workerData: this.env,
143+
env: SHARE_ENV,
144+
execArgv: this.execArgv,
145+
argv: this.args,
146+
})
140147
.on('message', this._handleMessage.bind(this))
141148
.on('exit', this._exitListener);
142149
break;

packages/discord.js/src/sharding/ShardingManager.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class ShardingManager extends EventEmitter {
3737
* @property {boolean} [silent=false] Whether to pass the silent flag to child process
3838
* (only available when mode is set to 'process')
3939
* @property {string[]} [shardArgs=[]] Arguments to pass to the shard script when spawning
40-
* (only available when mode is set to 'process')
4140
* @property {string[]} [execArgv=[]] Arguments to pass to the shard script executable when spawning
42-
* (only available when mode is set to 'process')
4341
* @property {string} [token] Token to use for automatic shard count and passing to shards
4442
*/
4543

0 commit comments

Comments
 (0)