Skip to content

Commit ce10ba8

Browse files
committed
Merge branch 'master' into 1.x
2 parents 97cf291 + 5672e65 commit ce10ba8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2757
-234
lines changed

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,20 @@ module.exports = {
1818
'@typescript-eslint/explicit-function-return-type': 'off',
1919
'@typescript-eslint/no-object-literal-type-assertion': 'off',
2020
'no-console': 'error',
21+
'@typescript-eslint/no-unused-vars': [
22+
'error',
23+
{
24+
argsIgnorePattern: '^_',
25+
},
26+
],
2127
},
28+
overrides: [
29+
{
30+
files: ['config/*.js'],
31+
rules: {
32+
'@typescript-eslint/no-var-requires': 'off',
33+
'no-console': 'off',
34+
},
35+
},
36+
],
2237
};

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ coverage
1010

1111
# Dependency directories
1212
node_modules/
13-
app/node_modules/
14-
example/node_modules/
15-
example/build/
1613

1714
# Optional npm cache directory
1815
.npm
@@ -27,11 +24,8 @@ example/build/
2724
.yarn-integrity
2825

2926
.DS_Store
30-
/lib
31-
/dist
27+
dist
3228
.idea/
3329
.rpt2_cache
3430
.coveralls.yml
35-
package-lock.json
36-
/cypress/videos
37-
/cypress/screenshots
31+
package-lock.json

CHANGELOG.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const App = () => {
6565
</form>
6666
);
6767
};
68+
69+
export default App;
6870
```
6971

7072
### [Zod](https://github.com/vriad/zod)
@@ -115,11 +117,11 @@ A simple and composable way to validate data in JavaScript (or TypeScript).
115117
import React from 'react';
116118
import { useForm } from 'react-hook-form';
117119
import { superstructResolver } from '@hookform/resolvers/superstruct';
118-
import { struct } from 'superstruct';
120+
import { object, string, number } from 'superstruct';
119121

120-
const schema = struct({
121-
name: 'string',
122-
age: 'number',
122+
const schema = object({
123+
name: string(),
124+
age: number(),
123125
});
124126

125127
const App = () => {
@@ -130,11 +132,13 @@ const App = () => {
130132
return (
131133
<form onSubmit={handleSubmit((d) => console.log(d))}>
132134
<input name="name" ref={register} />
133-
<input name="age" type="number" ref={register} />
135+
<input name="age" type="number" ref={register({ valueAsNumber: true })} />
134136
<input type="submit" />
135137
</form>
136138
);
137139
};
140+
141+
export default App;
138142
```
139143

140144
### [Joi](https://github.com/sideway/joi)
@@ -166,6 +170,8 @@ const App = () => {
166170
</form>
167171
);
168172
};
173+
174+
export default App;
169175
```
170176

171177
### [Vest](https://github.com/ealush/vest)
@@ -219,6 +225,8 @@ const App = () => {
219225
</form>
220226
);
221227
};
228+
229+
export default App;
222230
```
223231

224232
## Backers

config/build-ie11.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const { move } = require('fs-extra');
4+
const microbundle = require('microbundle');
5+
const getResolversName = require('./get-resolvers-name');
6+
7+
const IE11_PATH = 'ie11';
8+
const OUTPUT = 'dist';
9+
10+
(async () => {
11+
console.log(`Build IE11 resolvers to ${OUTPUT}`);
12+
const resolvers = getResolversName();
13+
14+
for await (let resolver of resolvers) {
15+
console.log(`> Build ${resolver}`);
16+
const filePath = path.join(resolver, 'package.json');
17+
18+
const resolverPkg = JSON.parse(fs.readFileSync(filePath));
19+
const resolverPkgCopy = Object.assign({}, resolverPkg);
20+
21+
// Temporary update `types` field
22+
resolverPkg.types = `${IE11_PATH}/index.d.ts`;
23+
24+
await fs.writeFileSync(filePath, JSON.stringify(resolverPkg, null, 2));
25+
26+
try {
27+
await microbundle({
28+
cwd: resolver,
29+
output: IE11_PATH,
30+
globals: '@hookform/resolvers=hookformResolvers',
31+
format: 'cjs',
32+
alias: 'react-hook-form=react-hook-form/dist/index.ie11',
33+
});
34+
35+
// Move `./{resolver}/ie11` -> `./dist/ie11/{resolver}`
36+
await move(
37+
`${resolver}/${IE11_PATH}`,
38+
`${OUTPUT}/${IE11_PATH}/${resolver}`,
39+
{
40+
overwrite: true,
41+
},
42+
);
43+
} catch (error) {
44+
console.error(error);
45+
process.exit(1);
46+
} finally {
47+
// Revert back changes on `{resolver}/package.json`
48+
await fs.writeFileSync(
49+
filePath,
50+
JSON.stringify(resolverPkgCopy, null, 2),
51+
);
52+
}
53+
}
54+
})();

config/check-ie11.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const fs = require('fs');
2+
const getResolversName = require('./get-resolvers-name');
3+
4+
(async () => {
5+
console.log('Checking IE11 bundles...');
6+
const resolvers = getResolversName();
7+
8+
for await (const resolver of resolvers) {
9+
console.log(`> Checking ${resolver} IE11 bundle`);
10+
const file = fs.readFileSync(`dist/ie11/${resolver}/${resolver}.js`);
11+
12+
if (!file.includes('react-hook-form/dist/index.ie11')) {
13+
throw new Error(
14+
'IE11 bundle should require `react-hook-form/dist/index.ie11`',
15+
);
16+
}
17+
}
18+
})();

config/get-resolvers-name.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const pkg = require('../package.json');
2+
3+
module.exports = function () {
4+
return Object.keys(pkg.exports)
5+
.map((e) => e.replace(/(\.\/|\.)/, '').replace(/package.*/, ''))
6+
.filter(Boolean);
7+
};

config/node-13-exports.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Original source: https://github.com/preactjs/preact/blob/master/config/node-13-exports.js
2+
const fs = require('fs');
3+
4+
const subRepositories = ['zod', 'joi', 'vest', 'yup', 'superstruct'];
5+
const snakeCaseToCamelCase = (str) =>
6+
str.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace('-', ''));
7+
8+
const copySrc = () => {
9+
// Copy .module.js --> .mjs for Node 13 compat.
10+
fs.writeFileSync(
11+
`${process.cwd()}/dist/resolvers.mjs`,
12+
fs.readFileSync(`${process.cwd()}/dist/resolvers.module.js`),
13+
);
14+
};
15+
16+
const copy = (name) => {
17+
// Copy .module.js --> .mjs for Node 13 compat.
18+
const filename = name.includes('-') ? snakeCaseToCamelCase(name) : name;
19+
fs.writeFileSync(
20+
`${process.cwd()}/${name}/dist/${filename}.mjs`,
21+
fs.readFileSync(`${process.cwd()}/${name}/dist/${filename}.module.js`),
22+
);
23+
};
24+
25+
copySrc();
26+
subRepositories.forEach(copy);

jest.config.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
module.exports = {
2-
roots: ['<rootDir>/src'],
3-
transform: {
4-
'^.+\\.tsx?$': 'ts-jest',
5-
},
6-
globals: {
7-
'ts-jest': {
8-
tsconfig: 'tsconfig.jest.json',
9-
},
10-
},
2+
preset: 'ts-jest',
113
restoreMocks: true,
12-
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
4+
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
135
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
14-
moduleFileExtensions: ['ts', 'tsx', 'js'],
6+
moduleNameMapper: {
7+
'^@hookform/resolvers$': '<rootDir>/src',
8+
},
159
};

0 commit comments

Comments
 (0)