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

Better exports #1241

Open
wighawag opened this issue Oct 4, 2024 · 3 comments
Open

Better exports #1241

wighawag opened this issue Oct 4, 2024 · 3 comments
Labels
Type: feature New feature or request

Comments

@wighawag
Copy link

wighawag commented Oct 4, 2024

Is your feature request related to a problem? Please describe.
Currently starknet.js export many of its utilities as object, which prevent best dead code elimination

Describe the solution you'd like
It would be better to expose the utils via package.json exports field

so if you were to export num utils this way in your package.json:

{
  "name": "starknet",
   ...
  "exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.ts",
        "default": "./dist/index.js"
      }
    },
    "./utils": {
      "import": {
        "types": "./dist/utils/index.d.ts",
        "default": "./dist/utils/index.js"
      }
    },
    "./utils/num": {
      "import": {
        "types": "./dist/utils/num.d.ts",
        "default": "./dist/utils/num.js"
      }
    },
  },
...
}

we would then be able to import it this way and benefit from dead code elimination if we were to only use part of the num exports:

import {toBigInt} from 'starknet/utils/num';

Also another bonus is that it will let us access types defined there too

@wighawag wighawag added the Type: feature New feature or request label Oct 4, 2024
@od-hunter
Copy link

od-hunter commented Oct 10, 2024

Hi @wighawag , can I be assigned this please?
I’m ready to work

@Benjtalkshow
Copy link

Benjtalkshow commented Oct 10, 2024

hello @wighawag
Can i be assigned to this task?
I propose restructuring Starknet.js to export utilities more modularly by utilizing the package.json exports field. This change will allow for better dead code elimination and enhance the ability to import only the needed utilities.

The benefit of doing this are:

  1. By exposing individual utilities through the exports field, unused code can be excluded from the final bundle, resulting in smaller and more optimized builds.
  2. Type-Safe Imports: Developers will be able to directly access types from each utility, improving code clarity and the developer experience, especially in TypeScript environments.

@0xdevcollins
Copy link

0xdevcollins commented Oct 10, 2024

@wighawag can I be assigned this task? I'll deliver as soon as possible

To tackle this task, I’d start by updating the package.json to configure exports for modular access. This involves restructuring the exports field so that individual utility functions, like those in utils and specifically num, are accessible as separate entry points. This setup will allow for better dead code elimination by letting users import only the utilities they need, such as toBigInt from starknet/utils/num, which reduces bundle size and improves performance. After setting up the exports, I’d test the changes by importing functions selectively in a test environment to confirm that only the required code is included in the output bundle. Additionally, I’d verify that type declarations are correctly accessible to ensure a seamless developer experience.

@starknet-io starknet-io deleted a comment Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants