GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add esm exports by brianc · Pull Request #3423 · brianc/node-postgres Conversation
|
There was an error while loading. Please reload this page.
|
Still adding more tests, but wanted to open the PR to see how it runs in CI. edit: yay - tests are passing. now I'll add some more. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Deploying node-postgres with
|
| Latest commit: |
8162202
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2ed736ef.node-postgres.pages.dev |
| Branch Preview URL: | https://bmc-add-esm-exports.node-postgres.pages.dev |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
todo:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR adds ECMAScript Module (ESM) export wrappers for several pg-related packages to improve compatibility with ESM environments. Key changes include:
Copilot reviewed 21 out of 28 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/pg-protocol/esm/index.js | Adds ESM exports for pg-protocol re-exporting from the dist build |
| packages/pg-pool/esm/index.mjs | Provides an ESM wrapper for pg-pool with default export |
| packages/pg-native/esm/index.mjs | Provides an ESM wrapper for pg-native with default export |
| packages/pg-esm-test/pg.test.js | Introduces tests for exported Client, Pool, and default export from pg |
| packages/pg-esm-test/pg-query-stream.test.js | Verifies the default export for pg-query-stream |
| packages/pg-esm-test/pg-pool.test.js | Validates the Pool constructor export for pg-pool |
| packages/pg-esm-test/pg-native.test.js | Validates the Client constructor export for pg-native |
| packages/pg-esm-test/pg-cursor.test.js | Verifies the default export for pg-cursor |
| packages/pg-esm-test/pg-connection-string.test.js | Confirms the parsing functions export from pg-connection-string |
| packages/pg-esm-test/pg-cloudflare.test.js | Tests the CloudflareSocket export, though the test description mismatches |
| packages/pg-cursor/index.js | Refactors pg-cursor to import Result and utils from the pg module |
| packages/pg-cursor/esm/index.mjs | Provides an ESM wrapper for pg-cursor with default export |
| packages/pg-connection-string/esm/index.mjs | Exposes the parse, toClientConfig, and parseIntoClientConfig functions via ESM |
packages/pg-esm-test/pg-cloudflare.test.js:5
describe('pg-pool', () => {
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This feels breaking, since now you are disallowing the imports for import TypeOverrides from 'pg/lib/type-overrides'; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@B4nan importing from undocumented paths is debatable wether it's breaking or not. To my understanding, in an ESM environment this (your snippet) will get tricky since the source code is mostly CJS, and ESM only has single wrapper index files. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Fair enough, but how can we do this properly if this was the wrong way? i believe that class is supposed to be used in downstream. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@B4nan I guess the best way is to make sure that class is also exported as part of the esm-facing index file. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Btw I learned about this trick ages ago from this issue, maybe there is another way to override type mapping per connection? There is an old PR that was exposing the class in root exports but it never got merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@B4nan I did what i could by adding a voice: #2369 (comment) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pg-protocol is the only package from brianc#3423 whose ESM wrapper is a .js file in a package without "type": "module". Node loads it as ESM only through module syntax detection. Without detection (Node 18, or --no-experimental-detect-module), `import { parse } from 'pg-protocol'` fails with "Named export 'parse' not found". Rename it to esm/index.mjs, like pg, pg-pool, pg-cursor and the other packages.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.