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

[ENHANCEMENT] - Migrate from Rollup to TypeScript-Driven Module Build for Improved Compatibility and Simplicity #4

Open
DaevMithran opened this issue Nov 16, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@DaevMithran
Copy link

DaevMithran commented Nov 16, 2024

Description

I was able to integrate lit-protocol natively within the sp-sdk, and here are my findings.

Background

Currently, SDK depends on Rollup as the bundler of choice to generate both CJS and ESM outputs. Since such an approach seemed good enough for past use cases, this indeed creates many problems and compatibility issues.

Proposed Solution: Direct TypeScript Compilation Approach

This proposal ensures that a move to a modern "exports"-based configuration would better solve module resolution, compatibility, and maintainability issues. The summary of the approach is given below.

Changes in Build:

  • Use tsc to directly produce ESM (build/esm) and CJS (build/cjs) outputs.
  • Use tsc to generate a types folder, and remember to add in your exports map type definitions, such as "types": "./build/types/index.d.ts".
  • Explicit exports in package.json

Example:

{
  "exports": {
    ".": {
      "import": "./build/esm/index.js",
      "require": "./build/cjs/index.js"
    },
    "./IndexingService": {
      "import": "./build/esm/IndexingService.js",
      "require": "./build/cjs/IndexingService.js"
    },
    "./utils": {
      "import": "./build/esm/utils/index.js",
      "require": "./build/cjs/utils/index.js"
    }
  },
  "scripts": {
    "build": "rm -rf build && npm run build:types && npm run build:esm",
    "build:types": "tsc -p tsconfig.types.json",
    "build:esm": "tsc -p tsconfig.esm.json",
    "build:cjs": "tsc -p tsconfig.cjs.json"
 }
}

Other Suggestions

  • Also, I noticed the sdk depends on react, vocs, etc. which are gonna cause compatibility issue during switching mobile and browser envs.
  • Clearly separating concerns between the SDK's core functionality and UI-related features.

Advantages

  • Better Compatibility
  • Quicker Installation times: Observed first installation times reduced from 53s to 16s
  • Smaller bundle sizes, with changes suggested below I was able to cut down the build size from 4.9mb to 1.9mb

Codebase URL

https://github.com/DaevMithran/SignxLit
@daevm/ethsign-sp-sdk

Reproduction steps

  1. Install '@lit-protocol/lit-node-client'
  2. Import the dependency in index.js and publish it
  3. Using the sdk now in nodejs envs will throw a window is undefined error with a lot of .css in the trace
  4. See error
ReferenceError: window is not defined
    at Object.<anonymous> (/node_modules/@ethsign/sp-sdk/dist/index.cjs:376452:1
@DaevMithran DaevMithran added the bug Something isn't working label Nov 16, 2024
@DaevMithran DaevMithran changed the title [BUG] - Sign Protocol SDK Tooling and Design Changes [ENHANCEMENT] - Migrate from Rollup to TypeScript-Driven Module Build for Improved Compatibility and Simplicity Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants