fix: decouple gram/WASM from @relateby/pattern, add browser export condition - #88
Merged
Conversation
…ssue Resolves #87. Bundlers (Turbopack, webpack) were pulling in gram.js and its WASM+fs dependencies even when Gram was never imported, because @relateby/pattern barrel-exported Gram. The package split already existed in name — @relateby/gram was a hollow re-export shell. This completes it: - Move gram.ts, wasm-types.d.ts, wasm/, wasm-node/ from @relateby/pattern into @relateby/gram, which now owns the full WASM implementation - Remove `export { Gram }` from @relateby/pattern; the package is now pure TypeScript with no WASM files or Node.js built-in imports - Add gram-browser.ts and index-browser.ts: a browser-only entry point with no import("module")/import("url")/import("path") calls, selected via the "browser" export condition in @relateby/gram package.json - Migrate gram-errors and gram-parity tests from pattern to gram; update pattern's public-api tests to reflect removed Gram export Breaking change: consumers importing Gram from @relateby/pattern must change to `import { Gram } from "@relateby/gram"`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The interop test was importing gram.js directly from the pattern package dist, which no longer exists after moving Gram to @relateby/gram. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes the separation of the Gram/WASM implementation from @relateby/pattern into @relateby/gram, and adds a "browser" export condition so browser bundlers can resolve @relateby/gram without pulling in Node.js built-ins.
Changes:
- Remove
Gramfrom@relateby/pattern’s public barrel exports and simplify its build to TypeScript-only (tsc). - Move Gram implementation/tests into
@relateby/gram, addindex-browser.ts+gram-browser.ts, and wire them via the"browser"export condition. - Update interop/tests to import Gram from the new package location.
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| typescript/packages/pattern/tests/public-api/export_inventory.test.ts | Updates expected @relateby/pattern export surface (removes Gram). |
| typescript/packages/pattern/tests/public-api/consumer.ts | Removes Gram usage from pattern public API consumer test. |
| typescript/packages/pattern/tests/pattern.test.ts | Removes Gram/WASM integration tests from @relateby/pattern. |
| typescript/packages/pattern/src/index.ts | Stops re-exporting Gram from @relateby/pattern. |
| typescript/packages/pattern/package.json | Removes wasm build steps; build becomes tsc-only. |
| typescript/packages/gram/tsconfig.json | Adds Node types + excludes generated wasm dirs from TS compilation. |
| typescript/packages/gram/tests/gram-parity.test.ts | Migrates gram parity test; imports shared errors from @relateby/pattern. |
| typescript/packages/gram/tests/gram-errors.test.ts | Migrates gram error tests; imports core types from @relateby/pattern. |
| typescript/packages/gram/src/wasm-types.d.ts | Adds ambient typings for generated wasm modules (currently mismatched to actual exports). |
| typescript/packages/gram/src/index.ts | Makes @relateby/gram the primary Gram entry point and adds an explicit init(). |
| typescript/packages/gram/src/index-browser.ts | New browser-conditioned entrypoint exporting Gram from the browser loader. |
| typescript/packages/gram/src/gram.ts | Node+Vite-capable WASM loader and Promise-based Gram API surface. |
| typescript/packages/gram/src/gram-browser.ts | New browser/bundler-friendly WASM loader with no Node built-in imports. |
| typescript/packages/gram/package.json | Adds "browser" export condition and moves wasm build+assets scripts to @relateby/gram. |
| tests/interop/ts_interop.mjs | Points TS interop test at @relateby/gram’s built Gram module. |
| package-lock.json | Lockfile updates for moved scripts/deps (e.g., @types/node). |
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.
Summary
Closes #87.
Bundlers (Turbopack, webpack) were pulling in
gram.jsand its WASM+fsdependencies even whenGramwas never imported, because@relateby/patternbarrel-exportedGram. The package split already existed in name —@relateby/gramwas a hollow re-export shell. This PR completes it.What changed
@relateby/gramnow owns the full implementation:gram.ts,wasm-types.d.ts,wasm/,wasm-node/moved here from@relateby/patterngram-browser.ts+index-browser.ts: a browser-only WASM loader with zero Node.js built-in imports (module,url,path), selected via the"browser"export conditionpackage.json: wasm build scripts and@types/nodemoved here;"browser"export condition addedgram-errorsandgram-paritytests migrated from pattern@relateby/patternis now pure TypeScript:export { Gram }removed fromsrc/index.tsgram.ts,wasm-types.d.tsdeleted;wasm/andwasm-node/dirs removedtsconly — no wasm-pack stepsGramexportWhy two separate fixes
Gramto@relateby/gramsolves the reported issue — consumers of@relateby/patterncan't accidentally pull in WASM because there's nothing to pull.browserexport condition on@relateby/gramsolves the follow-on issue — consumers who do importGramfrom@relateby/gramand bundle for a browser target get an entry point with noimport("module")/import("url")/import("path")calls, which is what Turbopack and similar bundlers require.Breaking change
Consumers importing
Gramfrom@relateby/patternmust update to:Test plan
@relateby/patterntests: 85 passed (all gram tests removed/migrated)@relateby/gramtests: 23 passed (gram-errors, gram-parity, public-api)@relateby/patternpublic-API type check: cleandist/gram-browser.jsconfirmed to contain no Node.js built-in imports