Add Bun-first SQLite runtime adapter for Node-targeted bundles#5
Open
Copilot wants to merge 5 commits into
Open
Add Bun-first SQLite runtime adapter for Node-targeted bundles#5Copilot wants to merge 5 commits into
Copilot wants to merge 5 commits into
Conversation
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix npm CLIs failing due to bun:sqlite import
Add Bun-first SQLite runtime adapter for Node-targeted bundles
Mar 17, 2026
There was a problem hiding this comment.
Pull request overview
Adds a runtime-selected SQLite adapter so @wgtechlabs/secrets-engine can be bundled for (and executed on) Node without a hard bun:sqlite import at module init time, while keeping Bun as the preferred runtime.
Changes:
- Replace static
bun:sqliteimport with a lazy runtime adapter that prefers Bun and falls back tonode:sqlite. - Make
SecretStore.open()async and update engine call sites to await store initialization. - Update packaging/metadata + docs, and add a regression test that bundles a Node-targeted consumer and runs it under Node.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/engine.test.ts | Adds a bundle-level regression test that builds for target: "node" and executes via node |
| src/store.ts | Introduces runtime-selected SQLite opener (Bun-first, Node fallback) and makes SecretStore.open() async |
| src/engine.ts | Awaits async store initialization in engine open + detached-store cleanup |
| package.json | Builds dist with --target node and declares engines.node >= 22.5.0 |
| README.md | Documents Bun-first / Node-compatible behavior and Node’s built-in sqlite requirement |
Member
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/wgtechlabs/secrets-engine/sessions/ad0bce68-0b43-426f-a545-c2bab590bcba Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Contributor
Author
Applied the thread feedback in 58939a9. The Node-targeted bundle regression now skips when the local |
Comment on lines
+70
to
+71
| const nodeSqliteRuntimeTest = supportsNodeSqliteRuntime() ? test : test.skip; | ||
|
|
Comment on lines
+97
to
+126
| const bundlePath = join(testDir, "dist", "consumer.js"); | ||
| const nodeStorePath = join(testDir, "node-store"); | ||
| const sourceImport = relative(testDir, join(process.cwd(), "src/index.ts")).replaceAll( | ||
| "\\", | ||
| "/", | ||
| ); | ||
|
|
||
| await writeFile( | ||
| consumerEntry, | ||
| ` | ||
| import { SecretsEngine } from ${JSON.stringify(sourceImport)}; | ||
|
|
||
| const secrets = await SecretsEngine.open({ path: ${JSON.stringify(nodeStorePath)} }); | ||
| await secrets.set("cli.version", "1.0.0"); | ||
| console.log(await secrets.get("cli.version")); | ||
| await secrets.close(); | ||
| `, | ||
| ); | ||
|
|
||
| const buildResult = await Bun.build({ | ||
| entrypoints: [consumerEntry], | ||
| outfile: bundlePath, | ||
| target: "node", | ||
| }); | ||
|
|
||
| expect(buildResult.success).toBe(true); | ||
|
|
||
| const result = spawnSync("node", [bundlePath], { | ||
| encoding: "utf-8", | ||
| }); |
Member
|
@copilot apply code review as necessary as possible. |
Agent-Logs-Url: https://github.com/wgtechlabs/secrets-engine/sessions/ada469b0-2d80-4373-be8b-f7106b172483 Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Node-targeted consumers could still fail at runtime because the package statically imported
bun:sqlite, which survives bundling into Node CLI artifacts. This change keeps Bun as the primary runtime while allowing Node consumers to load the package without pulling inbun:*imports at module initialization.Runtime backend selection
bun:sqliteimport with a runtime-selected SQLite adapter.bun:sqliteon Bun.node:sqliteon supported Node runtimes.Engine/store lifecycle
SecretStore.open()asynchronous so the backend can be resolved lazily.SecretsEngineAPI.Packaging and runtime expectations
bun:sqlitedependency.Regression coverage
ERR_UNSUPPORTED_ESM_URL_SCHEME.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.