Skip to content

fix: decouple gram/WASM from @relateby/pattern, add browser export condition - #88

Merged
akollegger merged 2 commits into
mainfrom
fix/decouple-gram-from-pattern
Jun 14, 2026
Merged

fix: decouple gram/WASM from @relateby/pattern, add browser export condition#88
akollegger merged 2 commits into
mainfrom
fix/decouple-gram-from-pattern

Conversation

@akollegger

Copy link
Copy Markdown
Contributor

Summary

Closes #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 PR completes it.

What changed

@relateby/gram now owns the full implementation:

  • gram.ts, wasm-types.d.ts, wasm/, wasm-node/ moved here from @relateby/pattern
  • New gram-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 condition
  • package.json: wasm build scripts and @types/node moved here; "browser" export condition added
  • gram-errors and gram-parity tests migrated from pattern

@relateby/pattern is now pure TypeScript:

  • export { Gram } removed from src/index.ts
  • gram.ts, wasm-types.d.ts deleted; wasm/ and wasm-node/ dirs removed
  • Build simplified to tsc only — no wasm-pack steps
  • Public-API tests updated to reflect removed Gram export

Why two separate fixes

  1. Moving Gram to @relateby/gram solves the reported issue — consumers of @relateby/pattern can't accidentally pull in WASM because there's nothing to pull.
  2. The browser export condition on @relateby/gram solves the follow-on issue — consumers who do import Gram from @relateby/gram and bundle for a browser target get an entry point with no import("module")/import("url")/import("path") calls, which is what Turbopack and similar bundlers require.

Breaking change

Consumers importing Gram from @relateby/pattern must update to:

import { Gram } from "@relateby/gram"

Test plan

  • @relateby/pattern tests: 85 passed (all gram tests removed/migrated)
  • @relateby/gram tests: 23 passed (gram-errors, gram-parity, public-api)
  • @relateby/pattern public-API type check: clean
  • dist/gram-browser.js confirmed to contain no Node.js built-in imports

akollegger and others added 2 commits June 14, 2026 21:11
…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Gram from @relateby/pattern’s public barrel exports and simplify its build to TypeScript-only (tsc).
  • Move Gram implementation/tests into @relateby/gram, add index-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).

@akollegger
akollegger merged commit cd72596 into main Jun 14, 2026
14 checks passed
@akollegger akollegger mentioned this pull request Jun 14, 2026
4 tasks
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.

Client bundlers (Turbopack) pull in gram.js/wasm via barrel export even when Gram is not used

2 participants