ckb-js / lumos

A full featured dapp framework for Nervos CKB
https://lumos-website.vercel.app/
MIT License
67 stars 54 forks source link

ES Module Support for Lumos #528

Open homura opened 1 year ago

homura commented 1 year ago

ES Module Support for Lumos

Motivation

ES module is the modern standard for JavaScript module system. It is supported by all major browsers and Node.js. It is also the default module system for TypeScript. However, Lumos currently only supports CommonJS module system. Supporting ES module will bring the following benefits:

How to

To keep the backward compatibility, we will keep the CommonJS module system as the default, thanks to the conditional exports feature in Node.js, we'll use the exports field in package.json to specify the entry point of the package.

graph TD
    bi-->base;
    codec-->base;
    toolkit-->base;
    base-->ckb-indexer;
    bi-->ckb-indexer;
    codec-->ckb-indexer;
    rpc-->ckb-indexer;
    toolkit-->ckb-indexer;
    testkit-->ckb-indexer;
    bi-->codec;
    base-->common-scripts;
    bi-->common-scripts;
    codec-->common-scripts;
    config-manager-->common-scripts;
    helpers-->common-scripts;
    rpc-->common-scripts;
    toolkit-->common-scripts;
    debugger-->common-scripts;
    hd-->common-scripts;
    base-->config-manager;
    bi-->config-manager;
    codec-->config-manager;
    base-->debugger;
    bi-->debugger;
    codec-->debugger;
    config-manager-->debugger;
    helpers-->debugger;
    rpc-->debugger;
    common-scripts-->debugger;
    experiment-tx-assembler-->debugger;
    hd-->debugger;
    base-->e2e-test;
    bi-->e2e-test;
    ckb-indexer-->e2e-test;
    codec-->e2e-test;
    common-scripts-->e2e-test;
    config-manager-->e2e-test;
    hd-->e2e-test;
    helpers-->e2e-test;
    light-client-->e2e-test;
    rpc-->e2e-test;
    runner-->e2e-test;
    toolkit-->e2e-test;
    utils-->e2e-test;
    testkit-->e2e-test;
    base-->experiment-tx-assembler;
    bi-->experiment-tx-assembler;
    config-manager-->experiment-tx-assembler;
    helpers-->experiment-tx-assembler;
    toolkit-->experiment-tx-assembler;
    base-->hd;
    bi-->hd;
    codec-->hd;
    crypto-->hd;
    base-->hd-cache;
    bi-->hd-cache;
    ckb-indexer-->hd-cache;
    config-manager-->hd-cache;
    hd-->hd-cache;
    rpc-->hd-cache;
    base-->helpers;
    bi-->helpers;
    codec-->helpers;
    config-manager-->helpers;
    toolkit-->helpers;
    base-->light-client;
    ckb-indexer-->light-client;
    rpc-->light-client;
    testkit-->light-client;
    base-->lumos;
    bi-->lumos;
    ckb-indexer-->lumos;
    common-scripts-->lumos;
    config-manager-->lumos;
    hd-->lumos;
    helpers-->lumos;
    rpc-->lumos;
    toolkit-->lumos;
    bi-->molecule;
    codec-->molecule;
    base-->molecule;
    base-->rpc;
    bi-->rpc;
    utils-->runner;
    base-->testkit;
    bi-->testkit;
    codec-->testkit;
    base-->transaction-manager;
    codec-->transaction-manager;
    ckb-indexer-->transaction-manager;
    rpc-->transaction-manager;
    toolkit-->transaction-manager;

Breaking

Notes for Contributors

/*#__PURE__*/ annotation for tree shaking

how to

homura commented 1 year ago

Can be tracked at https://github.com/homura/lumos/tree/esm

The @ckb-lumos/bi is easy to start working, so I first supported the ES module for @ckb-lumos/bi, and it also acts as a good & simple example