Skip to content

Commit

Permalink
os: lazy loaded
Browse files Browse the repository at this point in the history
PR-URL: #20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed May 22, 2018
1 parent 3eb38de commit 28d00a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const { codes: {
const { AssertionError, errorCache } = require('internal/assert');
const { openSync, closeSync, readSync } = require('fs');
const { inspect, types: { isPromise, isRegExp } } = require('util');
const { EOL } = require('os');
const { EOL } = require('internal/constants');
const { NativeModule } = require('internal/bootstrap/loaders');

// Escape control characters but not \n and \t to keep the line breaks and
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const isWindows = process.platform === 'win32';

module.exports = {
// Alphabet chars.
CHAR_UPPERCASE_A: 65, /* A */
Expand Down Expand Up @@ -45,4 +47,6 @@ module.exports = {
// Digits
CHAR_0: 48, /* 0 */
CHAR_9: 57, /* 9 */

EOL: isWindows ? '\r\n' : '\n'
};
9 changes: 6 additions & 3 deletions lib/internal/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

'use strict';

const { release } = require('os');

const OSRelease = release().split('.');
let OSRelease;

const COLORS_2 = 1;
const COLORS_16 = 4;
Expand Down Expand Up @@ -75,6 +73,11 @@ function getColorDepth(env = process.env) {
}

if (process.platform === 'win32') {
// Lazy load for startup performance.
if (OSRelease === undefined) {
const { release } = require('os');
OSRelease = release().split('.');
}
// Windows 10 build 10586 is the first Windows release that supports 256
// colors. Windows 10 build 14931 is the first release that supports
// 16m/TrueColor.
Expand Down

0 comments on commit 28d00a1

Please sign in to comment.