Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate SDK package to TypeScript "Project References" #5894

Closed
kraenhansen opened this issue Jun 16, 2023 · 0 comments
Closed

Migrate SDK package to TypeScript "Project References" #5894

kraenhansen opened this issue Jun 16, 2023 · 0 comments
Assignees

Comments

@kraenhansen
Copy link
Member

kraenhansen commented Jun 16, 2023

In an effort to lower complexity of our build / bundle process for the realm SDK package we'd like to explore migrating from using a bundler (we're currently using Rollup) into a pure TypeScript project (leveraging TypeScript Project References).

The immediate benefits that we expect this will bring:

  • Simpler tooling:
    • One less tool to learn when approaching the project as a new developer.
    • Less components to depend on (which all have their limitations and bugs that we sometimes need to work around).
  • Because of a bug in rollup-plugin-dts we need to use type aliases when reexporting types through the Realm namespace.
  • Because we're bundling .d.ts with rollup-plugin-dts we need to co-locate the declaration of the Realm namespace with the Realm class and cannot move this to a separate file and leverage TypeScript "Module Augmentation".
  • Transpiling to individual files instead of a bundle would:
    • Enable end-users bundlers to more easily shake unused code and
    • We'll have source-maps and declaration maps (enabling "go to definition" to jump straight to source code) enabled by default.
    • Enable us to export internal entry-points to
      • simplify our testing by moving unit tests into our "integration tests" and run these tests of internal primitives of the SDK on all supported platforms.
      • allow end-users to inject their own platform specific helpers (such as using the window.fetch in an Electron renderer process, etc.)
      • build / publish experimental packages hooking into our internal APIs.

I attempted to do this migration as part of #5853, but hit a couple of issues that I needed to find workarounds for:

  • The Typescript compiler would emit .mjs files even when module was set to commonjs which would break the package upon import. I filed an issue for this, created a PR and found a temporary workaround.
  • Although the Jest issue is closed, I found problems from Jest lacking support of export conditions out of the box and had to implement a custom resolver. I later transitioned into exporting via a separate package in an attempt to work around this.
  • I was planning to rely on bundleDependencies to pull @realm/network-transport (and a new @realm/binding package) into the SDK's .tar.gz before uploading it to NPM. But this is not supported when using NPM workspaces (yet) :meow_sad: [BUG] Workspaces - bundledDependencies missing in tarball after npm pack npm/cli#3466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant