Do not require pg if it cannot be resolved #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I am trying to use db-meta for postgres, but only via exports.connectToExistingConnection since the pg connection comes from a pool.
In my setup,
pgcannot be resolved so thevar pg=require('pg')line breaks everything.This PR uses require.resolve() in a try/catch block to discover if
pgmodule can be resolved or not.The require is only done if
pgcan be resolved.Note that I used the 2 steps resolve/require in order to not put the require inside the try/catch block since code inside try/catch blocks cannot be optimized by V8.
Hope this helps.
ps: I am sorry I did not write a test for this and understand that this is not a perfect PR according to your standards. My setup uses node v0.11.9 and I could not even do
npm installafter cloning db-meta.