Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Make codebase Deno-first #136

Merged
merged 56 commits into from
Jan 12, 2022
Merged

Make codebase Deno-first #136

merged 56 commits into from
Jan 12, 2022

Conversation

sgwilym
Copy link
Contributor

@sgwilym sgwilym commented Jan 12, 2022

This changes the codebase so that Deno is the primary runtime for building, bundling, typechecking, and running tests.

Motivation

I had two motivations for doing this work:

  • Making it easier to produce many distributions (NPM, Deno, web bundle) from a single codebase, while also catering to their differences
  • Making the experience of working with this codebase as simple and fast as possible.

Producing many distributions

We have a unique problem in that we want Earthstar to not only run only different platforms, but also take advantage of different platforms’ capabilities, e.g. offering ways to persist data to SQLite in environments that offer it.

In this codebase this mostly takes the form of storage and cryptography drivers. For us to develop these ergonomically we need type-checking and tests. The tests should also preferably be run against many different environments.

My attempts to change the node-centric codebase to provide this always had significant tradeoffs and added a lot of userland glue.

In a nutshell:

  • Deriving a Deno and web module distribution from a codebase meant for NPM was difficult.
  • But deriving a NPM distribution from a codebase meant for Deno and web modules is many times simpler.

Part of this is to do with Deno's position as underdog: there are far more actively developed tools for compatibility with the NPM ecosystem.

One of these is dnt, a tool for creating NPM packages from Deno codebases. dnt produces a NPM package for us, type-checks the output, and it also runs all the tests we have against the outputted code.

This gives us both a first-class NPM package and Deno distribution. We are also to very easily build a bundle meant for the browser.

Codebase ergonomics

Maintaining a codebase like this requires a lot of tooling for things like building, type-checking, bundling, formatting, testing. Previously we were using many different tools created by many different providers: tsc for building and type-checking, tap for testing, esbuild for bundling, etc. Sometimes it can be a lot of work to make these tools coordinate with each other.

This branch puts all these responsibilities with Deno. Deno handles type-checking, bundling, testing, and formatting the code. Because all these responsibilities are in one place, it's easier to coordinate certain things (for example, running Deno tests against the NPM-ified version of the code). It also makes certain tasks much faster: running the test suites currently takes 10.5 seconds, but in this branch it takes 4 seconds.

There are also fewer things to configure: no tsconfig.json, no package.json.

I think the story of getting a user to experiment with Earthstar is much easier this way: once the user has Deno installed they can make a single .ts file, import Earthstar via URL, and deno run ./my_earthstar_script.ts. Without npm / yarn, node_modules, tsc, tsconfig.json.

Concessions

Some things got lost in the move.

  • Testing in browsers. But I think we may be able to do this with the NPM-ified tests and browserify + browser-run. Down the road this will be something we can do directly with Deno.
  • The yarn print-platform-support command.

More

  • Added Github workflows for Deno testing, NPM package testing, and seeing if the web bundle runs without errors.
  • CryptoDriverTweetNacl was removed.
  • Everything has been formatted by Deno. Sorry about the diff.

Todo

  • Update README
  • Use external Superbus, SuperbusMap
  • Port benchmarking code

sgwilym and others added 30 commits January 4, 2022 10:22
Adjust GitHub CI setup for node & deno; drop node 12 and 14 for now since they don't work yet
cinnamon-bun and others added 23 commits January 7, 2022 14:04
[Deno] inline noble-ed25519 & make it use std/node/crypto in Deno
Use external noble/ed25519, fix coverage, remove config
pin noble-ed25519 version from raw.github so it's stable
@cinnamon-bun
Copy link
Member

Hooray! Thanks for all this work, let's merge it.

@sgwilym sgwilym merged commit 0798e15 into main Jan 12, 2022
@sgwilym sgwilym deleted the esm-first branch January 12, 2022 16:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants