diff --git a/lib/os.js b/lib/os.js index 078dba3fcc..0973e14788 100644 --- a/lib/os.js +++ b/lib/os.js @@ -140,7 +140,6 @@ function networkInterfaces() { module.exports = exports = { arch, cpus, - EOL: isWindows ? '\r\n' : '\n', endianness, freemem: getFreeMem, homedir: getHomeDirectory, @@ -162,8 +161,17 @@ module.exports = exports = { tmpDir: deprecate(tmpdir, tmpDirDeprecationMsg, 'DEP0022') }; -Object.defineProperty(module.exports, 'constants', { - configurable: false, - enumerable: true, - value: constants +Object.defineProperties(module.exports, { + constants: { + configurable: false, + enumerable: true, + value: constants + }, + + EOL: { + configurable: true, + enumerable: true, + writable: false, + value: isWindows ? '\r\n' : '\n' + } }); diff --git a/test/parallel/test-os-eol.js b/test/parallel/test-os-eol.js new file mode 100644 index 0000000000..7a7a300717 --- /dev/null +++ b/test/parallel/test-os-eol.js @@ -0,0 +1,27 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const os = require('os'); + +const eol = common.isWindows ? '\r\n' : '\n'; + +assert.strictEqual(os.EOL, eol); + +common.expectsError(function() { + os.EOL = 123; +}, { + type: TypeError, + message: /^Cannot assign to read only property 'EOL' of object '#'$/ +}); + +const foo = 'foo'; +Object.defineProperties(os, { + EOL: { + configurable: true, + enumerable: true, + writable: false, + value: foo + } +}); +assert.strictEqual(os.EOL, foo);