fix(pg-cloudflare): use conditional export to support bundlers that d… #3482
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.
close #3452
Conditional export was chosen as the fix to align with the previous solution #2978, however this does require the consumers to explicitly resolve the condition to
cloudflare
in their bundler's config with some extra setup, which might be considered as a breaking change.A private package
pg-bundler-test
is also created to test the bundling case. It will be run throughyarn test
and testwebpack
,vite
(usesrollup
underneath),rollup
andesbuild
to bundle the code that importspg-cloudflare
.webpack
,vite
androllup
are all having problems bundlingcloudflare:sockets
if not specifically exclude/ignore it, whileesbuild
works fine. These are the top bundlers on my head, other examples and tests could be added later.I didn't update
docs
as I searched forcloudflare
on node-postgres.com and didn't find anything, so I am not sure where is the right place. Hopefully the README of pg-cloudflare is good enough, and feel free to add more docs if necessary.Note: Vite 5+ requires Node 18+, so the Vite bundler test is skipped on Node 16, see the
vite
script in thepackage.json
for the details.