Skip to content

Commit

Permalink
Fetch os.username() optimistically - fixes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Apr 6, 2020
1 parent 7a4ef4b commit a519e18
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function parseOptions(a, b) {
port,
path : o.path || host.indexOf('/') > -1 && host + '/.s.PGSQL.' + port,
database : o.database || o.db || (url.pathname || '').slice(1) || env.PGDATABASE || 'postgres',
user : o.user || o.username || auth[0] || env.PGUSERNAME || env.PGUSER || os.userInfo().username,
user : o.user || o.username || auth[0] || env.PGUSERNAME || env.PGUSER || osUsername(),
pass : o.pass || o.password || auth[1] || env.PGPASSWORD || '',
max : o.max || url.query.max || Math.max(1, os.cpus().length),
types : o.types || {},
Expand All @@ -505,3 +505,11 @@ function parseOptions(a, b) {
mergeUserTypes(o.types)
)
}

function osUsername() {
try {
return require('os').userInfo().username // eslint-disable-line
} catch (_) {
return
}
}

0 comments on commit a519e18

Please sign in to comment.