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

[BREAKING] switch package to module type #1472

Merged
merged 6 commits into from
Dec 19, 2023
Merged

[BREAKING] switch package to module type #1472

merged 6 commits into from
Dec 19, 2023

Conversation

xobotyi
Copy link
Contributor

@xobotyi xobotyi commented Dec 17, 2023

As part of migration to react 18 and docosaurus - i made a decision to switch package to "type": "module".

By itself it leads to following BREAKING CHANGES:

  • Hooks are now distrubutes as JS built form TS with target ESNext and ESM module resolution. There is no more sense to distribute CJS version as package is ESM-only.

  • Consequent of above - no more esm and cjs subfolders - hooks are importable from index.js or its own directory which don't have a prefix anymore, thanks to exports directive. All of below examples will lead to same result, choose any on your taste:

    • import { useFirstMountState } from '@react-hookz/web';
    • import { useFirstMountState } from '@react-hookz/web/';
    • import { useFirstMountState } from '@react-hookz/web/useFirstMountState/';
    • import { useFirstMountState } from '@react-hookz/web/useFirstMountState/index.js';

    Thought is seems not to have subfolder, it is only due to exports directive, in real it is
    @react-hookz/web/dist/useFirstMountState/index.js.

  • Pakage uses imports directive to define path alias #root - it stays so even in distributed code, thus, some may be affected in case their bundler configured to somehow handle such alias. Those developer shoud configure import rewriter not to handle node_modules or @react-hookz/web package exclusively.

Side-effect for current PR - documentation is broken, as storybook 6 is not working within ESM packages and Im planning to switch to docosaurus anyways.

BREAKING CHANGE: the package is of ESM type now (`"type": "module"`).
Distributed code compiled with `ESNext` target. `cjs` and `esm` folders
are not existent anymore.
BREAKING CHANGE: all hooks now can be imported several different ways
that will lead to same result:
- `import { useFirstMountState } from '@react-hookz/web';`
- `import { useFirstMountState } from '@react-hookz/web/';`
- `import { useFirstMountState } from '@react-hookz/web/useFirstMountState/';`
- `import { useFirstMountState } from
'@react-hookz/web/useFirstMountState/index.js';`
@xobotyi xobotyi added the ✨ enhancement New feature or request label Dec 17, 2023
@xobotyi xobotyi self-assigned this Dec 17, 2023
Copy link

codecov bot commented Dec 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8634836) 99.62% compared to head (0577c1f) 99.62%.
Report is 37 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1472   +/-   ##
=======================================
  Coverage   99.62%   99.62%           
=======================================
  Files          62       62           
  Lines        1072     1074    +2     
  Branches      169      171    +2     
=======================================
+ Hits         1068     1070    +2     
  Misses          2        2           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xobotyi xobotyi merged commit 50921ef into master Dec 19, 2023
8 checks passed
@xobotyi xobotyi deleted the ESM branch December 19, 2023 19:25
github-actions bot pushed a commit that referenced this pull request Dec 20, 2023
# [24.0.0](v23.1.0...v24.0.0) (2023-12-20)

### Features

* switch package to module type ([#1472](#1472)) ([50921ef](50921ef))

### BREAKING CHANGES

* Hooks are now distrubutes as JS built form TS with target ESNext and ESM module resolution. There is no more sense to distribute CJS version as package is ESM-only.

Consequent of above - no more esm and cjs subfolders - hooks are importable from index.js or its own directory which don't have a prefix anymore, thanks to exports directive. All of below examples will lead to same result, choose any on your taste:

import { useFirstMountState } from '@react-hookz/web';
import { useFirstMountState } from '@react-hookz/web/';
import { useFirstMountState } from '@react-hookz/web/useFirstMountState/';
import { useFirstMountState } from '@react-hookz/web/useFirstMountState/index.js';
Thought is seems not to have subfolder, it is only due to exports directive, in real it is
@react-hookz/web/dist/useFirstMountState/index.js.

Pakage uses imports directive to define path alias #root - it stays so even in distributed code, thus, some may be affected in case their bundler configured to somehow handle such alias. Those developer shoud configure import rewriter not to handle node_modules or @react-hookz/web package exclusively.

Side-effect for current PR - documentation is broken, as storybook 6 is not working within ESM packages and I'm planning to switch to another domenting engine anyway.
@xobotyi
Copy link
Contributor Author

xobotyi commented Dec 20, 2023

🎉 This PR is included in version 24.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Comment on lines +38 to +40
"engines": {
"node": ">=20.0.0"
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the rationale behind requiring node 20+ now? node 18 is still in LTS and will be in widespread use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason except lockfile differs if being built with 18 and 20 versions.
As i understand it forces users to have node20+ - ill lower requirement to node18 (as it is lowest for ESM packages)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i understand it forces users to have node20+

yes this is the trouble we are having while trying to upgrade

ill lower requirement to node18

much appreciated, thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24.0.2 is live

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request released
Development

Successfully merging this pull request may close these issues.

None yet

2 participants