Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-years-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Do not set process.exitCode at all
2 changes: 1 addition & 1 deletion packages/pglite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"test": "pnpm test:basic && pnpm test:node",
"test:basic": "pnpm test:clean && vitest tests/*.test.js tests/*.test.ts tests/**/*.test.js tests/**/*.test.ts",
"test:web": "pnpm test:clean && concurrently -s first --hide 1 --prefix none -k \"sleep 2 && vitest --fileParallelism false tests/targets/web/*.test.web.*\" \"npx http-server --port 3334 ./\"",
"test:bun": "pnpm test:clean && pnpm bun test --timeout 15000 tests/basic.test.js tests/pgvector.test.js tests/live.test.js tests/targets/runtimes/node-fs.test.js",
"test:bun": "pnpm test:clean && bun test --timeout 15000 tests/basic.test.ts tests/live.test.ts tests/targets/runtimes/node-fs.test.js",
"test:deno": "cd tests/targets/deno && deno task test",
"test:node": "pnpm test:clean && pnpm vitest tests/targets/runtimes/node-*.test.js",
"test:runtimes": "pnpm test:bun && pnpm test:node",
Expand Down
11 changes: 2 additions & 9 deletions packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,25 +820,18 @@ export class PGlite
this.#ready = false
this.#running = false

const exitCode = pglUtils.pgliteProc.exitCode
try {
// exit the runtime. since we're using `noExitRuntime: true` on our module,
// we need to do this explicitly
// this sets process.exitCode to 0
this.mod!._emscripten_force_exit(0)
// clear mod to release memory
this.mod = undefined
} catch (e: any) {
this.#log(e)
if (e.status !== 0) {
this.#log('Error when exiting', e.toString())
}
} finally {
try {
pglUtils.pgliteProc.exitCode = exitCode
} catch {
// some envs do not allow setting the exitCode, swallow
}
// clear mod to release memory
this.mod = undefined
}
}

Expand Down
18 changes: 6 additions & 12 deletions packages/pglite/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,12 @@ await testEsmCjsAndDTC(async (importType) => {
expect(process.exitCode).toEqual(origExitCode)
})

it('restores undefined process.exitCode on close', async () => {
expect(process.exitCode).toBeUndefined()
await db.close()
expect(process.exitCode).toBeUndefined()
})

it('restores process.exitCode on close', async () => {
const origExitCode = process.exitCode
process.exitCode = 42
Expand All @@ -812,18 +818,6 @@ await testEsmCjsAndDTC(async (importType) => {
}
})

it('restores undefined process.exitCode on close', async () => {
const origExitCode = process.exitCode
process.exitCode = undefined

try {
await db.close()
expect(process.exitCode).toEqual(undefined)
} finally {
process.exitCode = origExitCode
}
})

it("arrays with NULL elements should return null, not string 'NULL'", async () => {
const pg = await PGlite.create()

Expand Down
2 changes: 1 addition & 1 deletion postgres-pglite