node-postgres
node-postgres copied to clipboard
Improve Deno compatibility: config-first and safe env access
This PR introduces three changes to make the pg package more compatible with Deno while keeping full Node.js functionality:
-
Default user value
- Replace
user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER
withuser: 'postgres'in defaults. - Avoids requiring environment variables in Deno.
- Replace
-
Config-first parameter resolution
- Update
val()in connection-parameters.js to returnconfig[key]first, before checking environment variables. - Prevents Deno errors when
--allow-envis not granted.
- Update
-
Safe NODE_PG_FORCE_NATIVE check
- Wrap the
NODE_PG_FORCE_NATIVEcheck in atry/catch. - Ensures
process.envaccess in Deno doesn’t throw, while preserving Node.js behavior.
- Wrap the
These changes maintain Node.js compatibility, preserve the lazy-loading of the native module,
and allow using the package in Deno without requiring --allow-env.