grammarly / focal

Program user interfaces the FRP way.
Apache License 2.0
723 stars 34 forks source link

Modernize the package (esm, tree-shaking) #94

Closed Igorbek closed 1 year ago

Igorbek commented 1 year ago

1. Deprecated _esm5 build

The build for _esm5 is pointed in the module of the package.json which corresponds to the native ESM modules loaders. However, the build doesn't produce the modules and almost not distinguishable from CJS.

This PR removes _esm5 altogether and instead uses the _esm2015 build. This build does produce correct ESM modules and has to be references in module entry point.

Also, need to point that es2015 entry point in package.json is non-standard and is not used anywhere (ref: https://stackoverflow.com/questions/43131060/npm-package-json-undocumented-keys)

2. Lens, Prism, Optic namespaces are now modules

For only one reason to merge Lens namespace in lens/base.ts and lens/json.ts the library had side-effects listed in package.json. However, it always does this and no point of this artificial separation.

Now these namespace are moved to separate files (lens.ts, prism.ts, optic.ts) that don;t have namespaces and instead export all of their functions as plain names exports.

then to keep namaspacy-look in public API, they are re-exported as export * as so that they can still be accessed as Lens.blahblah.

Note, that no function code was actually changed, only re-arranged.

Igorbek commented 1 year ago

@oleksiilevzhynskyi I was thinking to add export map (export in package.json) to allow direct imports like import { key } from '@grammarly/focal-atom/lens'. What do you think?