mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
avoid accessing Node specific requires when not needed
This commit is contained in:
parent
f305419676
commit
2b469d01da
@ -3,7 +3,6 @@
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
var utils = require('./utils')
|
||||
var sasl = require('./sasl')
|
||||
var pgPass = require('pgpass')
|
||||
var TypeOverrides = require('./type-overrides')
|
||||
|
||||
var ConnectionParameters = require('./connection-parameters')
|
||||
@ -225,12 +224,17 @@ class Client extends EventEmitter {
|
||||
} else if (this.password !== null) {
|
||||
cb()
|
||||
} else {
|
||||
pgPass(this.connectionParameters, (pass) => {
|
||||
if (undefined !== pass) {
|
||||
this.connectionParameters.password = this.password = pass
|
||||
}
|
||||
cb()
|
||||
})
|
||||
try {
|
||||
const pgPass = require('pgpass')
|
||||
pgPass(this.connectionParameters, (pass) => {
|
||||
if (undefined !== pass) {
|
||||
this.connectionParameters.password = this.password = pass
|
||||
}
|
||||
cb()
|
||||
})
|
||||
} catch (e) {
|
||||
this.emit('error', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,7 +461,7 @@ class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
// escapeIdentifier and escapeLiteral moved to utility functions & exported
|
||||
// on PG
|
||||
// on PG
|
||||
// re-exported here for backwards compatibility
|
||||
escapeIdentifier(str) {
|
||||
return utils.escapeIdentifier(str)
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
// eslint-disable-next-line
|
||||
var Native = require('pg-native')
|
||||
var Native
|
||||
try {
|
||||
// Wrap this `require()` in a try-catch to avoid upstream bundlers from complaining that this might not be available since it is an optional import
|
||||
Native = require('pg-native')
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
var TypeOverrides = require('../type-overrides')
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
var util = require('util')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user