/usr/lib/nodejs/osenv.js is in node-osenv 0.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | var isWindows = process.platform === 'win32'
var windir = isWindows ? process.env.windir || 'C:\\Windows' : null
var path = require('path')
var exec = require('child_process').exec
// looking up envs is a bit costly.
// Also, sometimes we want to have a fallback
// Pass in a callback to wait for the fallback on failures
// After the first lookup, always returns the same thing.
function memo (key, lookup, fallback) {
var fell = false
var falling = false
exports[key] = function (cb) {
var val = lookup()
if (!val && !fell && !falling && fallback) {
fell = true
falling = true
exec(fallback, function (er, output, stderr) {
falling = false
if (er) return // oh well, we tried
val = output.trim()
})
}
exports[key] = function (cb) {
if (cb) process.nextTick(cb.bind(null, null, val))
return val
}
if (cb && !falling) process.nextTick(cb.bind(null, null, val))
return val
}
}
memo('user', function () {
return ( isWindows
? process.env.USERDOMAIN + '\\' + process.env.USERNAME
: process.env.USER
)
}, 'whoami')
memo('prompt', function () {
return isWindows ? process.env.PROMPT : process.env.PS1
})
memo('hostname', function () {
return isWindows ? process.env.COMPUTERNAME : process.env.HOSTNAME
}, 'hostname')
memo('tmpdir', function () {
var t = isWindows ? 'temp' : 'tmp'
return process.env.TMPDIR ||
process.env.TMP ||
process.env.TEMP ||
( exports.home() ? path.resolve(exports.home(), t)
: isWindows ? path.resolve(windir, t)
: '/tmp'
)
})
memo('home', function () {
return ( isWindows ? process.env.USERPROFILE
: process.env.HOME
)
})
memo('path', function () {
return (process.env.PATH ||
process.env.Path ||
process.env.path).split(isWindows ? ';' : ':')
})
memo('editor', function () {
return process.env.EDITOR ||
process.env.VISUAL ||
(isWindows ? 'notepad.exe' : 'vi')
})
memo('shell', function () {
return isWindows ? process.env.ComSpec || 'cmd'
: process.env.SHELL || 'bash'
})
|