Skip to content

Commit 28d00a1

Browse files
BridgeARMylesBorins
authored andcommitted
os: lazy loaded
PR-URL: #20567 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 3eb38de commit 28d00a1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const { codes: {
3333
const { AssertionError, errorCache } = require('internal/assert');
3434
const { openSync, closeSync, readSync } = require('fs');
3535
const { inspect, types: { isPromise, isRegExp } } = require('util');
36-
const { EOL } = require('os');
36+
const { EOL } = require('internal/constants');
3737
const { NativeModule } = require('internal/bootstrap/loaders');
3838

3939
// Escape control characters but not \n and \t to keep the line breaks and

lib/internal/constants.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const isWindows = process.platform === 'win32';
4+
35
module.exports = {
46
// Alphabet chars.
57
CHAR_UPPERCASE_A: 65, /* A */
@@ -45,4 +47,6 @@ module.exports = {
4547
// Digits
4648
CHAR_0: 48, /* 0 */
4749
CHAR_9: 57, /* 9 */
50+
51+
EOL: isWindows ? '\r\n' : '\n'
4852
};

lib/internal/tty.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
'use strict';
2424

25-
const { release } = require('os');
26-
27-
const OSRelease = release().split('.');
25+
let OSRelease;
2826

2927
const COLORS_2 = 1;
3028
const COLORS_16 = 4;
@@ -75,6 +73,11 @@ function getColorDepth(env = process.env) {
7573
}
7674

7775
if (process.platform === 'win32') {
76+
// Lazy load for startup performance.
77+
if (OSRelease === undefined) {
78+
const { release } = require('os');
79+
OSRelease = release().split('.');
80+
}
7881
// Windows 10 build 10586 is the first Windows release that supports 256
7982
// colors. Windows 10 build 14931 is the first release that supports
8083
// 16m/TrueColor.

0 commit comments

Comments
 (0)