Repository navigation
Make morphology parsers safe to bundle in browser/React Native - #53
Merged
willwade merged 3 commits intoOct 13, 2026
Merged
Conversation
Grid3VerbsParser statically imported Node's `path` and `adm-zip`, and TDSnapLexiconParser statically required `better-sqlite3`. Metro cannot resolve those builtins/Node-only packages for native (and they rely on Node shims on web), so importing the `browser` or `metrics` entry points failed with "Unable to resolve module path"/"fs". - Resolve `join`/`dirname`/`basename` via the existing FileAdapter (defaultFileAdapter), which loads `path` lazily. - Load `adm-zip` and `fs` through getNodeRequire() instead of static `import`/`require`, mirroring utils/zip.ts and utils/io.ts. - Use the existing requireBetterSqlite3() helper in TDSnapLexiconParser. The Node-only code paths keep working; the modules can now be bundled for web and native.
Collaborator
|
Merged — thanks Chris, this is exactly the right approach (routing through the FileAdapter/ZipAdapter abstractions rather than platform conditionals). Released as 0.4.0 since |
willwade
marked this pull request as ready for review
October 13, 2026 11:44
Contributor
Author
|
Thanks. I've not added support for sqlite based formats yet but when I do I'll probably use a similar adapter approach so that I can use my own adapter that wraps Expo SQLite |
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 update uses the file and zip adapters in
Grid3VerbsParserandTDSnapLexiconParserso that it can compile for React Native. However, it makesMetricsCalculator.analyzeasync which is a breaking change.AI summary
Problem
Importing the
browserormetricsentry points fails to bundle under Metro (Expo / React Native) with:Grid3VerbsParserstatically imported Node'spathandadm-zip, andTDSnapLexiconParserstatically requiredbetter-sqlite3.adm-zipandbetter-sqlite3themselves pull in Node builtins (path,fs), so Metro failson the next module as soon as one is fixed.
Import stack for reference:
Fix
Route all I/O through the library's existing
FileAdapter/ZipAdapterabstractions (
src/utils/io.ts,src/utils/zip.ts,src/utils/sqlite.ts)instead of touching Node modules directly:
Grid3VerbsParsernow takes aFileAdapter(defaultdefaultFileAdapter).getZipAdapter(...)—adm-zipon Node,jszipin thebrowser.
FileAdapter.TDSnapLexiconParsertakes aFileAdapterand opens databases viaopenSqliteDatabase(...)—better-sqlite3on Node,sql.jsin the browser.Breaking change
Because the adapters are asynchronous, these methods now return promises:
Grid3VerbsParser.parseXmlFileDetailed/parseZip/parseZipDetailed/parseCustomDirectory,TDSnapLexiconParser.parseDb,WordFormGenerator.generateFromPos, andMetricsCalculator.analyze.Call sites in the CLI and tests have been updated accordingly.
Verification
npm run type-check(bothtsconfig.jsonandtsconfig.test.json) — passnpm run lint— 0 errorsnpm run test:ci— 92 suites, 847 passed, 1 skipped@willwade/aac-processors@0.3.7, anExpo SDK 57 iOS production bundle builds successfully (it previously failed
with
Unable to resolve module path).