Implement Typescript and ESM, and add Parcel for builds #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #15
What is changed
I've implemented a typescript for each package except
yivi-console
,yivi-dummy
andyivi-css
.Typescript is implemented with the weakest setting
strict: false
in thetsconfig.json
, meaning that there is almost no "type safety", but that can be improved later to keep this PR as minimal as possible.Typescript with
strict: false
is almost the same as ESM.To support different environments, like NodeJS and bundlers like Vite a bundler is needed to output script for each environment. I've added Parcel, which is a super simple bundler, that uses the
package.json
entry paths (module
,main
,browser
,source
, etc) to configure the bundle configuration.In
yivi-frontend
I've replaced the package imports with relative paths since the bundler doesn't like "external" packages to be built in, It is possible but costs some effort to make that work. And since these packages are "DEV" only and bundled in using relative paths, they are bit easier. An alternative strategy is to make them "external", but then it is required to mark them as "dependencies" inpackage.json
.Future improvements
NPM workspaces
I would recommend switching this repo to NPM Workspaces, which is designed and made for frontend mono repo. For example, makes installing the package much easier, for example running
npm install
from the root.Typescript typing
After this PR there are a lot of types of "any" which is not benefit from the power of typescript. Making things strictly typed will help prevent bugs in the future
Testing
I would recommend starting with writing some tests for these packages to make sure everything is working correctly in the future. You may not realizing that this library will grow in the coming years, since Yivi is getting some attention lately.