Packages RFC #722
Replies: 3 comments 4 replies
-
I'm on board. This package layout would really simplify development and the build tooling. Would the |
Beta Was this translation helpful? Give feedback.
-
One thought that I'll add to the conversation is about possibly hiding the details of the genetic interface behind the common use cases. To the end user, they don't care that add or any of the other api functions are generic. Once they have chosen a number type, I expect they will use only the one. A tighter coupling between the calculator and api functions would simplify the usage for the end user. I suggest that each number type, supported by the library, export a set of api functions already initialized with the correct calculator. The documentation could be focused on the simplest use case and wouldn't even need to discuss TAmount or generics until explaining more advanced usage. IMHO I think it would be more accessible to general JavaScript developer and remove a possible hurdle to learning the library. |
Beta Was this translation helpful? Give feedback.
-
I've really been diving into This is the directory structure I suggest: packages/
# maintains same structure, though the api tests are moved to this package
core/
# `@dinero.js/big.js`, I figure this might as well be added, its already implemented and tested
big.js/
# `@dinero.js/bigint`
bigint/
# `dinero.js` is the the `number` type implementation
dinero.js/ All of the implementation packages share this directory structure: src/
api/ # This could just be a re-export of the `@dinero.js/core` api functions, or tailored to the specific number type.
calculator/
currencies/ A user of the library only installs one package and that packages depends on |
Beta Was this translation helpful? Give feedback.
-
This RFC outlines how to divide Dinero.js v2 into one or more npm packages for optimal developer and user experience.
It builds upon the existing package breakdown of the v2 alpha.
Motivation
The current v2 alpha is broken down between multiple packages:
Not all these packages are relevant:
dinero.js
and@dinero.js/currencies
@dinero.js/core
and@dinero.js/calculator-number
aredinero.js
dependency and have no use on their ownHaving more packages than necessary hurts developer experience. For example, it's easy to have mismatched versions, and it makes users break their flow to install more packages.
Goals
Proposal
This solution exposes a single package:
dinero.js
.All existing
@dinero.js/*
packages are deprecated, and moved to the single package.Rationale
When installing a package, you should be able to forget about it. Having to constantly think about what package contains what API, or whether you still need that package you added a few commits ago, creates friction that distracts users from what matters.
Separate packages should have unambiguously distinct concerns.
For example, a Vue and a React integration of a library should be in separate packages because they will never be used together in the same app.
Another example, an ESLint plugin for a library should be in a separate package. Although it’s designed to be used together when using the library, it’s a fully separate project and doesn’t share any code. Also, unlike the library, it’s a dev dependency. In back-end projects, it shouldn’t be installed at runtime.
Summary
The
dinero.js
package becomes the universal entry point to access everything in one place—core API and currencies.The core API is accessible from the root of the package. Currencies are available from the
/currencies
path to avoid potential name clashes. It also keeps imports organized.This lets users use the library without having to figure out how packages are broken down. Users who need the currencies have everything available from the first install—they don’t have to interrupt their flow, check the documentation, and install a separate package. If they realize they no longer need them, they don’t have to uninstall.
Users who don’t need currencies can just not use them. They can use the ESM bundle and tree-shake their app to get rid of unused code. If they use the UMD bundle, they can use separate endpoints.
Type implementations
Currently, the
@dinero.js/calculator-bigint
exposes abigint
calculator for users to use with thecreateDinero
to make abigint
implementation themselves.With this proposal, this separate package would go away. The previously exposed
bigint
calculator would be replaced by a ready to usebigint
implementation. The package would also providebigint
currencies.Type implementations are exposed via the
/bigint
path.UMD
When using the UMD bundle, users can pick separate endpoints to avoid bundling more code than they need.
They can load each endpoint in one request either by bundling them on their own with a build step, or using jsDelivr’s combine endpoint.
UMD users who aren’t concerned about bundle size can still access everything from the main endpoint.
Usage
Working with
number
ESM
With pinned currencies:
UMD
With pinned currencies:
Working with
bigint
ESM
With pinned currencies:
UMD
With pinned currencies:
3 votes ·
Beta Was this translation helpful? Give feedback.
All reactions