Skip to content

fix: lazy-load SqliteProvider to avoid node:sqlite ExperimentalWarning#16

Open
robertsLando wants to merge 1 commit intoplatformatic:mainfrom
robertsLando:fix/lazy-sqlite-provider
Open

fix: lazy-load SqliteProvider to avoid node:sqlite ExperimentalWarning#16
robertsLando wants to merge 1 commit intoplatformatic:mainfrom
robertsLando:fix/lazy-sqlite-provider

Conversation

@robertsLando
Copy link
Copy Markdown
Contributor

Summary

  • Make SqliteProvider a lazy getter on module.exports so node:sqlite is only required when a consumer actually reads vfs.SqliteProvider.
  • Eliminates the process-wide ExperimentalWarning: SQLite is an experimental feature that was emitted on every require('@platformatic/vfs'), even for consumers that only use MemoryProvider / RealFSProvider.

Why

index.js eagerly required ./lib/providers/sqlite.js, which in turn imports node:sqlite at the top of the module. node:sqlite emits an ExperimentalWarning the first time it is loaded in a process. That meant:

  • Any app using @platformatic/vfs printed the warning on startup, regardless of whether SQLite was used.
  • The noise was especially visible in SEA / pkg binaries where @platformatic/vfs is loaded unconditionally during bootstrap.

The alternative fixes were weaker:

  • Suppressing the warning at the consumer layer (e.g. in pkg's sea-bootstrap.js) hides it but keeps the eager load — users still pay the node:sqlite startup cost, and non-SEA consumers still see the warning.
  • Splitting into a subpath export (@platformatic/vfs/sqlite) is cleaner long-term but a breaking API change.

The lazy getter is zero API break: the export shape (typeof vfs.SqliteProvider === 'function', enumerable on the object) is preserved, and the value is memoized on first access.

Test plan

  • node --test test/sqlite.test.js — all 90 sqlite tests pass.
  • Manual repro:
    • require('./index.js') without touching SqliteProvider → no ExperimentalWarning.
    • Reading vfs.SqliteProvider → warning fires exactly once, as expected.
  • eslint index.js clean.

Eagerly requiring ./lib/providers/sqlite.js pulled in node:sqlite at
module load time, emitting `ExperimentalWarning: SQLite is an
experimental feature` for every consumer — even those who only use
MemoryProvider or RealFSProvider. The warning was especially noisy in
SEA/pkg binaries where vfs is loaded unconditionally.

Expose SqliteProvider via a lazy getter on module.exports. The first
access resolves the module and memoizes the value, so behavior and API
shape are preserved; node:sqlite (and its warning) is only loaded when
a consumer actually touches vfs.SqliteProvider.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant