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

Fix internal library export hygiene #544

Open
4 tasks
m0ar opened this issue Oct 4, 2024 · 0 comments
Open
4 tasks

Fix internal library export hygiene #544

m0ar opened this issue Oct 4, 2024 · 0 comments
Assignees

Comments

@m0ar
Copy link
Contributor

m0ar commented Oct 4, 2024

There are some best-practices we should be following in our internal libraries:

  1. No reliance on barrel files (prevents tree-shaking)
  2. Pick one export methodology to replace the barrel file:
    • actual API in index.ts (more verbose, singular namespace, less dependent on module structure)
    • package.json export maps (less verbose, isolated namespace, more responsibility on module structure)
    • combination (see notes below)
  3. Ideally set sideEffects: false in package.json (tells bundlers that the import is pure)
  4. Explicitly export type where possible
  5. Only named exports (no export default, which can break bundler analysis in certain cases)
  6. No dynamic imports (don't think we have this in any lib atm)

Checklist:

  • @desci-labs/nodes-lib
  • @desci-labs/desci-codex-lib
  • @desci-labs/desci-contracts:
    • Can we drop entirely from webapp?
  • @desci-labs/desci-models

Notes on export methodologies:

  • Explicitly preventing import of "package-private" internals directly from /dist requires we use export maps
  • We can use a hybrid approach, by putting most common API items in a root-exported index.ts, and use export maps to expose module internals
@m0ar m0ar self-assigned this Oct 4, 2024
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

No branches or pull requests

1 participant