Skip to content

Commit eb023ef

Browse files
vsemozhetbytaddaleax
authored andcommitted
doc, lib, test: do not re-require needlessly
Backport-PR-URL: #14524 Backport-Reviewed-By: Anna Henningsen <[email protected]> PR-URL: #14244 Reviewed-By: Alexey Orlenko <[email protected]>
1 parent c704c02 commit eb023ef

22 files changed

+67
-74
lines changed

doc/api/child_process.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,9 @@ socket to the child process. The example below spawns two children that each
11361136
handle connections with "normal" or "special" priority:
11371137

11381138
```js
1139-
const normal = require('child_process').fork('child.js', ['normal']);
1140-
const special = require('child_process').fork('child.js', ['special']);
1139+
const { fork } = require('child_process');
1140+
const normal = fork('child.js', ['normal']);
1141+
const special = fork('child.js', ['special']);
11411142

11421143
// Open up the server and send sockets to child. Use pauseOnConnect to prevent
11431144
// the sockets from being read before they are sent to the child process.

lib/_tls_legacy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
'use strict';
2323

24-
require('internal/util').assertCrypto();
24+
const internalUtil = require('internal/util');
25+
internalUtil.assertCrypto();
2526

2627
const assert = require('assert');
2728
const Buffer = require('buffer').Buffer;
2829
const common = require('_tls_common');
2930
const Connection = process.binding('crypto').Connection;
3031
const EventEmitter = require('events');
31-
const internalUtil = require('internal/util');
3232
const stream = require('stream');
3333
const Timer = process.binding('timer_wrap').Timer;
3434
const tls = require('tls');

lib/internal/process.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const util = require('util');
4+
35
var _lazyConstants = null;
46

57
function lazyConstants() {
@@ -178,10 +180,8 @@ function setupKillAndExit() {
178180
}
179181
}
180182

181-
if (err) {
182-
const errnoException = require('util')._errnoException;
183-
throw errnoException(err, 'kill');
184-
}
183+
if (err)
184+
throw util._errnoException(err, 'kill');
185185

186186
return true;
187187
};
@@ -212,8 +212,7 @@ function setupSignalHandlers() {
212212
const err = wrap.start(signum);
213213
if (err) {
214214
wrap.close();
215-
const errnoException = require('util')._errnoException;
216-
throw errnoException(err, 'uv_signal_start');
215+
throw util._errnoException(err, 'uv_signal_start');
217216
}
218217

219218
signalWraps[type] = wrap;
@@ -253,10 +252,9 @@ function setupChannel() {
253252

254253

255254
function setupRawDebug() {
256-
const format = require('util').format;
257255
const rawDebug = process._rawDebug;
258256
process._rawDebug = function() {
259-
rawDebug(format.apply(null, arguments));
257+
rawDebug(util.format.apply(null, arguments));
260258
};
261259
}
262260

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ try {
8585
}
8686

8787
// hack for repl require to work properly with node_modules folders
88-
module.paths = require('module')._nodeModulePaths(module.filename);
88+
module.paths = Module._nodeModulePaths(module.filename);
8989

9090
// If obj.hasOwnProperty has been overridden, then calling
9191
// obj.hasOwnProperty(prop) will break.

test/parallel/test-assert-typedarray-deepequal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require('../common');
44
const assert = require('assert');
5-
const a = require('assert');
65

76
function makeBlock(f) {
87
const args = Array.prototype.slice.call(arguments, 1);
@@ -51,7 +50,8 @@ equalArrayPairs.forEach((arrayPair) => {
5150

5251
notEqualArrayPairs.forEach((arrayPair) => {
5352
assert.throws(
54-
makeBlock(a.deepEqual, arrayPair[0], arrayPair[1]),
55-
a.AssertionError
53+
// eslint-disable-next-line no-restricted-properties
54+
makeBlock(assert.deepEqual, arrayPair[0], arrayPair[1]),
55+
assert.AssertionError
5656
);
5757
});

test/parallel/test-assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'use strict';
2323
const common = require('../common');
2424
const assert = require('assert');
25-
const a = require('assert');
25+
const a = assert;
2626

2727
function makeBlock(f) {
2828
const args = Array.prototype.slice.call(arguments, 1);

test/parallel/test-child-process-fork-and-spawn.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
'use strict';
2323
const common = require('../common');
2424
const assert = require('assert');
25-
const spawn = require('child_process').spawn;
26-
const fork = require('child_process').fork;
25+
const { fork, spawn } = require('child_process');
2726

2827
// Fork, then spawn. The spawned process should not hang.
2928
switch (process.argv[2] || '') {

test/parallel/test-child-process-send-returns-boolean.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const common = require('../common');
33
const assert = require('assert');
44
const path = require('path');
55
const net = require('net');
6-
const fork = require('child_process').fork;
7-
const spawn = require('child_process').spawn;
6+
const { fork, spawn } = require('child_process');
87

98
const emptyFile = path.join(common.fixturesDir, 'empty.js');
109

test/parallel/test-crypto-random.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
148148
bufferTooSmall: /^RangeError: buffer too small$/,
149149
};
150150

151+
const max = require('buffer').kMaxLength + 1;
152+
151153
for (const buf of bufs) {
152154
const len = Buffer.byteLength(buf);
153155
assert.strictEqual(len, 10, `Expected byteLength of 10, got ${len}`);
@@ -168,8 +170,6 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
168170
crypto.randomFill(buf, NaN, common.mustNotCall());
169171
}, errMessages.offsetNotNumber);
170172

171-
const max = require('buffer').kMaxLength + 1;
172-
173173
assert.throws(() => {
174174
crypto.randomFillSync(buf, 11);
175175
}, errMessages.offsetOutOfRange);

test/parallel/test-domain-exit-dispose.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
2423
const common = require('../common');
2524
const assert = require('assert');
2625
const domain = require('domain');

0 commit comments

Comments
 (0)