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

ES Module Support for Lumos #528

Open
6 of 18 tasks
homura opened this issue Jun 27, 2023 · 1 comment · May be fixed by #543
Open
6 of 18 tasks

ES Module Support for Lumos #528

homura opened this issue Jun 27, 2023 · 1 comment · May be fixed by #543

Comments

@homura
Copy link
Collaborator

homura commented Jun 27, 2023

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:

  • native support for ES module to use the 1k+ very common modules without transpilation in Lumos
  • work well with code splitting and tree shaking
    • import only the required code
    • improve the cold start time
  • avoid users using non-exported APIs
    • the exports field in package.json to specify the entry point of the package

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;
Loading
  • Add a build script to build both CJS and ESM output
  • @ckb-lumos/bi
  • @ckb-lumos/codec
  • @ckb-lumos/toolkit
  • @ckb-lumos/base
  • @ckb-lumos/rpc
  • @ckb-lumos/crypto
  • @ckb-lumos/config-manager
  • @ckb-lumos/helpers
  • @ckb-lumos/hd
  • @ckb-lumos/ckb-indexer
  • @ckb-lumos/light-client
  • @ckb-lumos/transaction-manager
  • @ckb-lumos/common-scripts
  • Re-design the @ckb-lumos/lumos package
  • Documentation
    • Migration guide
  • Release and announcement

Breaking

  • Importing the non-exported API like import {} from '@ckb-lumos/base/lib/...' will be broken

Notes for Contributors

/*#__PURE__*/ annotation for tree shaking

how to

@homura
Copy link
Collaborator Author

homura commented Jun 27, 2023

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

@homura homura linked a pull request Jul 24, 2023 that will close this issue
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 a pull request may close this issue.

1 participant