feat: remove cjs support, move to esm#24
Merged
Conversation
🦋 Changeset detectedLatest commit: 108883f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
13b0849 to
1af81e7
Compare
Updated sqlite-level version from patch to major due to the removal of CommonJS support and migration to ESM.
1af81e7 to
b47374c
Compare
* _clear was broken — only handled gte via a LIKE prefix match. Rewrote to support all range options (gt, gte, lt, lte) and clear-all with no options, matching the abstract-level contract. * limit: 0 was falsy — if (options.limit) skipped limit: 0, returning everything instead of nothing. Fixed to options.limit != null && options.limit >= 0. * gt/gte/lt/lte falsy checks — empty string or 0 values were silently skipped. Changed to != null checks. Also refactored condition building to use a conditions[] array. * stmt.iterate(params) — changed to stmt.iterate(...params) for explicit spread rather than relying on better-sqlite3 implicit array handling. * async _close — removed misleading async keyword from iterator _close methods since they're synchronous callback-based. * _clear missing readOnly guard — added the same LEVEL_READ_ONLY check that _put, _del, and _batch have. * Dead main/types fields in package.json — removed; redundant with the exports map now that CJS is dropped. Added test coverage Went from 55 → 66 tests. Added: - 7 _clear tests (clear-all, gt, gte, lt, lte, two range combos) - _clear readOnly test - limit: 0 test - Key iterator _close via break - Value iterator _close via break - Updated SQL injection clear tests to match new range semantics Accepted / left as-is UNIQUE constraint migration — major version bump covers it.
3 tasks
Contributor
📦 Tagged Release PublishedYour tagged PR has been published! You can install the packages using their version tags: pnpm add sqlite-level@0.0.0-20260511052325Published Packages:
Commit: |
Contributor
📦 Tagged Release PublishedYour tagged PR has been published! You can install the packages using their version tags: pnpm add sqlite-level@0.0.0-20260511053032Published Packages:
View on npm: Commit: |
JackDevAU
added a commit
to tinacms/tinacms
that referenced
this pull request
May 11, 2026
The prerelease lands the named `SqliteLevel` export from tinacms/sqlite-level#24, so the CJS namespace-import workaround in @tinacms/search can go. The new package is pure ESM (only an `import` export condition), so jest-resolve needs to be in ESM mode to find it — added `extensionsToTreatAsEsm: ['.ts']` to the search package's jest config to flip that switch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
wicksipedia
approved these changes
May 12, 2026
This was referenced May 13, 2026
kulesy
added a commit
to tinacms/tinacms
that referenced
this pull request
May 14, 2026
Closes #6675 Part of #6750 ## Problem TinaCMS v3's CLI bundles `tina/database.ts` with esbuild and dynamically imports the result. Since the December 2025 ESM migration, this is wedged between two failure modes: 1. **Bundling** native modules (`better-sqlite3` via `sqlite-level`) crashes — `bindings` reads `__filename`/`__dirname`, which don't exist in ESM scope. See #6675. 2. **Externalizing** native modules from `os.tmpdir()` doesn't work either — Node's resolver walks up from the importing file's directory and never reaches the project's `node_modules`. ## Fix Two architectural changes plus the API + ergonomics work that comes out of them: ### Build cache moved into the project tree - `loadDatabaseFile` and `loadConfigFile` now write to `<project>/tina/__generated__/.cache/<timestamp>/` instead of `os.tmpdir()`, so Node can resolve `node_modules` from the bundle's location at runtime. - Each load removes its own subdir after the dynamic-import resolves, and `ConfigManager.processConfig()` sweeps `.cache/` on startup to clean up residue from crashed prior runs (Ctrl+C mid-build, OOM kills). - The empty `<timestamp>/` parent is also reaped after both loads complete (using `rmdirSync`, so concurrent in-flight loads don't conflict). - Read-only project mounts (Docker `:ro`, AWS Lambda `/var/task`, sandboxed CI runners) now fail with an actionable error explaining the cause and how to resolve it, instead of a cryptic mid-build `EACCES` from esbuild. ### Externalize curated baseline + user-extensible - `loadDatabaseFile` externalizes `better-sqlite3` so Node loads it as CJS where `__filename` exists. The `sqlite-level` wrapper stays bundled so esbuild handles its CJS named-export interop. - New `defineConfig` field: `build.externalDependencies?: string[]`. Users with custom native adapters outside the baseline can extend the externalize list from their config — discoverable, type-safe, version-controlled. Supersedes the env-var approach proposed in #6683. - The merge logic and baseline live in `external-resolver.ts` with 9 unit tests. ### `tina init` template - New projects (and existing projects without it) get `tina/__generated__` added to `.gitignore`. Belt + suspenders for the cache cleanup. ## Verification Manually verified end-to-end against `examples/next/tina-self-hosted-demo` temporarily reconfigured to use `SqliteLevel`: - Bundle lands in `<project>/tina/__generated__/.cache/<timestamp>/database/database.build.mjs` (not `/tmp/`) - Node loads `bindings.js`'s `__filename`-based path successfully - `better-sqlite3` native binary loads - SqliteLevel instantiates, opens the DB file, and gets through to content indexing - Cache directory is empty after the build The remaining indexing crash is a known SQL-injection bug in sqlite-level **v1**, fixed by [tinacms/sqlite-level#24](tinacms/sqlite-level#24) — tracked as a follow-up in #6848. Not in scope for this PR. The pre-existing mongo demo is unchanged so its CI coverage is preserved. A standalone SQLite example with full CI matrix is filed as #6786. ## Tests - 9 new unit tests on the externalize merge logic (`external-resolver.test.ts`) - All 180 CLI tests pass (was 171 pre-PR — 9 new) - Build clean, type-check clean (via `pnpm types`), format clean ## Follow-ups (filed) - #6786 — Add self-hosted SQLite example + PR-blocking CI matrix - #6787 — Add unit tests for `config-manager.ts` (output location, cache cleanup, watch list, etc.) - #6788 — Adapter compatibility test matrix - #6789 — Promote starter-template smoke subset to PR-blocking - #6847 — Migrate `mongodb-level` to ESM - #6848 — Bump `sqlite-level` to v2.x in `@tinacms/search` - #6849 — Expand the externalize baseline as adapters migrate --------- Co-authored-by: Copilot <copilot@github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JackDevAU <57518417+JackDevAU@users.noreply.github.com> Co-authored-by: kulesy <kulewidak@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Eli Kent [SSW] <69125238+kulesy@users.noreply.github.com> Co-authored-by: JackDevAU <jpr178@live.com.au>
Open
7 tasks
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.
This is a
majorversion changeDescription:
Migrate from cjs to esm, replace Jest with Vitest, fix SQL injection vulnerabilities, improve type safety, and add comprehensive test coverage.
What was Added/Changed:
Package.json
src/index.ts
Tests