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

V2 🚀 #108

Merged
merged 26 commits into from
Apr 2, 2021
Merged

V2 🚀 #108

merged 26 commits into from
Apr 2, 2021

Conversation

jorisre
Copy link
Member

@jorisre jorisre commented Jan 5, 2021

Resolvers V2 🚀

Root branch for V2 work.

Update to react-hook-form v7 - #118

Breaking changes: yes 🟥

  • Require react-hook-form >= 7

Global improvements

Breaking changes: no 🟩


Improve bundle output format: CJS, ESM & UMD - #104

First of all, huge thank to the preact hard work. This PR is heavily inspired of their modules structure.

Breaking changes: no 🟩

Related: #71 & #100

  • Remove IE11 support
  • Move resolvers into separate folders
  • Use microbundle to generate bundles
  • Multiple bundles per resolver: CJS, ESM, UMD (modern coming later)
  • Add exports map in package.json + support node 13 (thank to preact)

Support sync/async validation

Breaking changes: no 🟩

Related to #88
Resolver get a third optional param. Async mode is set by default.

Before:

useForm({
    resolver: zodResolver(schema, schemaOptions)
})

After:

useForm({
    resolver: zodResolver(schema, schemaOptions, { mode: 'async' | 'sync' })
})

Pass down Joi context - #124

Breaking changes: no 🟩

Related to #121


Zod resolver: add union errors + reduce bundle size by ~23% - #126

Breaking changes: no 🟩

Related to #119


Add error's reference - #127

Breaking changes: no 🟩

Related to #77


Reduce resolvers's size

Breaking changes: no 🟩

BREAKING CHANGE: there will be some breaking changes in the next versions
@jorisre jorisre marked this pull request as draft January 8, 2021 12:40
* test: add components test to ensure TypeScript is working as expected

Related to #97

* chore: improve zod resolvers types

* chore(eslint): remove warnings

* test: add severals tests & improve typings

* chore: setup compressed-size

* test: update describe
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2021

Size Change: -9.58 kB (-49%) 🎉

Total Size: 9.98 kB

Filename Size Change
dist/ie11/joi/joi.js 0 B -622 B (removed) 🏆
dist/ie11/superstruct/superstruct.js 0 B -978 B (removed) 🏆
dist/ie11/vest/vest.js 0 B -504 B (removed) 🏆
dist/ie11/yup/yup.js 0 B -708 B (removed) 🏆
dist/ie11/zod/zod.js 0 B -1.03 kB (removed) 🏆
dist/resolvers.js 190 B +21 B (+12%) ⚠️
dist/resolvers.modern.js 195 B +18 B (+10%) ⚠️
dist/resolvers.module.js 197 B +15 B (+8%) 🔍
dist/resolvers.umd.js 292 B +32 B (+12%) ⚠️
joi/dist/joi.js 525 B -87 B (-14%) 👏
joi/dist/joi.modern.js 419 B -91 B (-18%) 👏
joi/dist/joi.module.js 540 B -84 B (-13%) 👏
joi/dist/joi.umd.js 630 B -82 B (-12%) 👏
superstruct/dist/superstruct.js 269 B -698 B (-72%) 🏆
superstruct/dist/superstruct.modern.js 274 B -651 B (-70%) 🏆
superstruct/dist/superstruct.module.js 282 B -697 B (-71%) 🏆
superstruct/dist/superstruct.umd.js 367 B -696 B (-65%) 🏆
vest/dist/vest.js 419 B -73 B (-15%) 👏
vest/dist/vest.modern.js 335 B -105 B (-24%) 🎉
vest/dist/vest.module.js 389 B -114 B (-23%) 🎉
vest/dist/vest.umd.js 508 B -82 B (-14%) 👏
yup/dist/yup.js 541 B -154 B (-22%) 🎉
yup/dist/yup.modern.js 471 B -131 B (-22%) 🎉
yup/dist/yup.module.js 553 B -151 B (-21%) 🎉
yup/dist/yup.umd.js 642 B -149 B (-19%) 👏
zod/dist/zod.js 470 B -553 B (-54%) 🏆
zod/dist/zod.modern.js 408 B -138 B (-25%) 🎉
zod/dist/zod.module.js 485 B -551 B (-53%) 🏆
zod/dist/zod.umd.js 578 B -534 B (-48%) 🎉

compressed-size-action

@bluebill1049
Copy link
Member

bluebill1049 commented Jan 19, 2021

Can we remove transformToNestObject import from react-hook-form?

// Todo: to be removed
import set from '../utils/set';
import isKey from '../utils/isKey';
import { FieldValues } from '../types';

export default (data: FieldValues, value: Record<string, any> = {}): any => {
  for (const key in data) {
    !isKey(key) ? set(value, key, data[key]) : (value[key] = data[key]);
  }
  return value;
};

I think we can export set function from react-hook-form.

I did a quick test by removed that function transformToNestObject, looks like only vest needs it.
Screen Shot 2021-01-19 at 7 27 07 pm

@jorisre
Copy link
Member Author

jorisre commented Jan 19, 2021

Can we remove transformToNestObject import from react-hook-form?

// Todo: to be removed
import set from '../utils/set';
import isKey from '../utils/isKey';
import { FieldValues } from '../types';

export default (data: FieldValues, value: Record<string, any> = {}): any => {
  for (const key in data) {
    !isKey(key) ? set(value, key, data[key]) : (value[key] = data[key]);
  }
  return value;
};

I think we can export set function from react-hook-form.

I did a quick test by removed that function transformToNestObject, looks like only vest needs it.
Screen Shot 2021-01-19 at 7 27 07 pm

Yes you can replace this function

* feat: add Joi sync validation

* fix(joi): sync error

* test: add validateAllCriteria test

* test(joi): update test description
* feat: add Yup sync validation

* test(zod): add tests

* test(zod): update tests

* test(yup): add validateAllCriteria test
BREAKING CHANGE: Require react-hook-form >= 7
* chore: update deps

* chore: fix TypeScript error
* test: extract fixtures

* fix: zod resolver union error + reduce resolver size
* feat: add error's ref

* test: add error's ref + extract fixtures

* test: add nested test

* refactor: rename toNestObject to toNestError
* test: extract test's fixtures

* test: jest fixtures config

* perf: reduce superstruct resolver size

* feat: add error's ref

* test: add error's ref + extract fixtures

* test: add nested test

* refactor: rename toNestObject to toNestError

* refactor: remove duplicate line

* chore: update superstruct peer dep
* test: extract test's fixtures

* test: jest fixtures config

* perf: reduce superstruct resolver size

* feat: add error's ref

* test: add error's ref + extract fixtures

* test: add nested test

* refactor: rename toNestObject to toNestError

* refactor: remove duplicate line

* perf: recude vest resolver bundle size
@bluebill1049
Copy link
Member

Screen Shot 2021-02-08 at 2 25 57 pm

Hey @jorisre,

More of a question, Do we need to include the src folders? cause i didn't include src in react-hook-form.

@jorisre
Copy link
Member Author

jorisre commented Feb 8, 2021

Hey @bluebill1049
I'm not sure to understand, what's your needs ?

@bluebill1049
Copy link
Member

It's minor don't worry about it @jorisre. I was referring to the src folder been generated inside of dist during the build.

@nierennakker
Copy link

nierennakker commented Feb 23, 2021

I noticed that the superstruct types are missing from the root of the package. Is that normal? (2.0.0-rc.1)
Turns out that rc.1 is a 5 month old version, but NPM updates to it automatically. Oops :p

@jorisre jorisre marked this pull request as ready for review March 31, 2021 20:03
@jorisre jorisre merged commit fe53179 into master Apr 2, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2021

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jorisre jorisre deleted the beta branch April 8, 2021 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants