-
Notifications
You must be signed in to change notification settings - Fork 42
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
Making js-waku adaptive and modular (+ ESM migration) #802
Comments
Work towards first release: #891 |
Note regarding the usage of For now, I am exporting the different modules via the Once we have a release of js-waku that works and makes sense (meaning that all functionality are re-exposed and usable from a consumer pov) then we can more the repo to multi-repo, extract the various |
Migration to monorepo has started: |
|
Next steps:
|
Problem
protons
is ESM only, and generate code that expect to be used in an ESM package, meaning that if one were to use dynamic imports, they would need to post-process code generated byprotons
.It would also be possible to not migrate to ESM and:
ts-proto
instead ofprotons
.However, we have already identified reasons to move away from
ts-proto
: #335Also, the dynamic import solution is cumbersome to use as imports needs to be wrapped in async functions, making the code less maintainable.
Finally, ESM is the only module management system adopted by browsers, which are the target audience for js-waku.
Solution
Migrate js-waku to ESM.
Limitations
Only modern browsers support ESM
js-waku's usage is already limited to modern browser due to the usage of
BigInt
operations (**
, cannot be polyfiled) by@noble
dependencies (cryptographic libraries). We recently migrated to said dependencies as they are better for the browser: #599.Only latest NodeJS version (>16) support ESM
js-waku is already limited to running in NodeJS >16.
Tooling support of ESM is experimental
This is correct. However, as the ecosystem is moving to ESM then we can expect the tooling to get better.
Also note that the alternative of not migrating to ESM in the first section.
Other Benefits
Migration from Webpack to Rollup
As we need to re-configure bundling tools for
"type": "module"
, we will take this opportunity to move from Webpack to Rollup.Rollup is easier to use than Webpack, with zero-conf plugins to handle bundling to several formats, polyfilling, etc.
Make js-waku adaptive and modular
The current js-waku codebase is not as modular as it could be:
if then
statement used for bootstrapping).The js-libp2p libraries have gone through a massive refactor:
@libp2p/interface-*
) and function (@libp2p/*
) has been madepubsub
config).Note that we have a number of new cryptography-based protocols to be implemented in js-waku:
These protocols will come with their own set of new dependencies, possibly using WASM code.
They may introduce incompatibilities with some browser or NodeJS version, or polyfilling.
They may possibly need custom building and bundling.
Maybe some of the new crypto dependencies will have no/poor tree-shakeable support, etc.
Ideally these implementations should live in their own repo/package, separated from js-waku core library.
For this to happen, we need a proven way to enable a modular usage of protocol a la js-libp2p, by having current available protocols already separated from the core js-waku package.
However, we want Waku to remain an easy to use, with a great out of the box experience, and it is why we will aim to maintain good defaults while providing increased modularity.
Also note, it is not possible to use js-waku in React Native due to
@noble/secp256k1
.This library is only used by ENR and Waku Message version 1.
One should be able to easily use js-waku without these protocols or with custom React Native implementations of them.
An more modular architecture will also enable this use case.
Draft Roadmap
js-waku
to@waku/core
, publish first version of@waku/core
@libp2p/interface-peer-discovery
forjs-waku/boostrap
, DNS Discovery, extract it from@waku/core
We might be able to reach a stage where
@waku/core
only provides good defaults but anyone could use Waku Relay, Store, Message, js-implementations directly withlibp2p
by passing them tocreateLibp2p
.Definition of Done
JS-Waku is
"type": "module"
and usable:<script>
tagTasks
<script>
tag: js-libp2p cannot be bundled with Rollup due to the usage of node's cluster, this is fixed by the latest js-libp2p release Upgrade to latest libp2p libraries #803@waku/core
Remove dupeRemove dupeCreateOptions
interfacesCreateOptions
interfaces #1000See if producing a CJS build is possible and useful.CJS is only useful for older NodeJS versions that we already do not support.@waku/core
, introduce a NodeJS example (see status-im/waku-tests).DecryptionParams
may be passed when usingqueryHistory
instead of just keys. #927console.log
files refactor: remove console.log usage #926The text was updated successfully, but these errors were encountered: