Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ module.exports = {
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'no-console': 'error',
},
overrides: [
{
files: ['config/*.js'],
rules: { '@typescript-eslint/no-var-requires': 'off' },
},
],
};
26 changes: 26 additions & 0 deletions config/node-13-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Original source: https://github.com/preactjs/preact/blob/master/config/node-13-exports.js
const fs = require('fs');

const subRepositories = ['zod', 'joi', 'vest', 'yup', 'superstruct'];
const snakeCaseToCamelCase = (str) =>
str.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace('-', ''));

const copySrc = () => {
// Copy .module.js --> .mjs for Node 13 compat.
fs.writeFileSync(
`${process.cwd()}/dist/resolvers.mjs`,
fs.readFileSync(`${process.cwd()}/dist/resolvers.module.js`),
);
};

const copy = (name) => {
// Copy .module.js --> .mjs for Node 13 compat.
const filename = name.includes('-') ? snakeCaseToCamelCase(name) : name;
fs.writeFileSync(
`${process.cwd()}/${name}/dist/${filename}.mjs`,
fs.readFileSync(`${process.cwd()}/${name}/dist/${filename}.module.js`),
);
};

copySrc();
subRepositories.forEach(copy);
17 changes: 6 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
module.exports = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
globals: {
'ts-jest': {
tsconfig: 'tsconfig.jest.json',
},
},
preset: 'ts-jest',
testEnvironment: 'node',
restoreMocks: true,
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
moduleNameMapper: {
'^@hookform/resolvers$': '<rootDir>/src',
},
};
1 change: 0 additions & 1 deletion joi.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion joi.js

This file was deleted.

17 changes: 17 additions & 0 deletions joi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "joi",
"amdName": "hookformResolversJoi",
"version": "1.0.0",
"private": true,
"description": "React Hook Form validation resolver: joi",
"main": "dist/joi.js",
"module": "dist/joi.module.js",
"umd:main": "dist/joi.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": ">=6.6.0",
"@hookform/resolvers": "^1.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

dependent itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, to import convertArrayToPathName, inspiration from preact

Copy link
Member

Choose a reason for hiding this comment

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

oh cool! 👍

}
}
2 changes: 1 addition & 1 deletion src/joi.test.ts → joi/src/__tests__/joi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Joi from 'joi';
import { joiResolver } from './joi';
import { joiResolver } from '..';

const schema = Joi.object({
username: Joi.string().alphanum().min(3).max(30).required(),
Expand Down
1 change: 1 addition & 0 deletions joi/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './joi';
3 changes: 2 additions & 1 deletion src/joi.ts → joi/src/joi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
FieldValues,
} from 'react-hook-form';
import * as Joi from 'joi';
import convertArrayToPathName from './utils/convertArrayToPathName';
// @ts-expect-error maybe fixed after the first publish ?
import { convertArrayToPathName } from '@hookform/resolvers';

const parseErrorSchema = (
error: Joi.ValidationError,
Expand Down
129 changes: 86 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,89 @@
{
"name": "@hookform/resolvers",
"amdName": "hookformResolvers",
"version": "1.3.1",
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod and etc.",
"umd:main": "umd/index.js",
"unpkg": "umd/index.js",
"jsdelivr": "umd/index.js",
"sideEffects": false,
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest and etc.",
"main": "dist/resolvers.js",
"module": "dist/resolvers.module.js",
"umd:main": "dist/resolvers.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"exports": {
".": {
"browser": "./dist/resolvers.module.js",
"umd": "./dist/resolvers.umd.js",
"import": "./dist/resolvers.mjs",
"require": "./dist/resolvers.js"
},
"./zod": {
"browser": "./zod/dist/zod.module.js",
"umd": "./zod/dist/zod.umd.js",
"import": "./zod/dist/zod.mjs",
"require": "./zod/dist/zod.js"
},
"./yup": {
"browser": "./yup/dist/yup.module.js",
"umd": "./yup/dist/yup.umd.js",
"import": "./yup/dist/yup.mjs",
"require": "./yup/dist/yup.js"
},
"./joi": {
"browser": "./joi/dist/joi.module.js",
"umd": "./joi/dist/joi.umd.js",
"import": "./joi/dist/joi.mjs",
"require": "./joi/dist/joi.js"
},
"./vest": {
"browser": "./vest/dist/vest.module.js",
"umd": "./vest/dist/vest.umd.js",
"import": "./vest/dist/vest.mjs",
"require": "./vest/dist/vest.js"
},
"./superstruct": {
"browser": "./superstruct/dist/superstruct.module.js",
"umd": "./superstruct/dist/superstruct.umd.js",
"import": "./superstruct/dist/superstruct.mjs",
"require": "./superstruct/dist/superstruct.js"
},
Copy link
Member

Choose a reason for hiding this comment

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

nice!

"./package.json": "./package.json",
"./": "./"
},
"files": [
"dist",
"yup.js",
"yup.d.ts",
"joi.js",
"joi.d.ts",
"superstruct.js",
"superstruct.d.ts",
"zod.js",
"zod.d.ts",
"vest.js",
"vest.d.ts"
"yup/package.json",
"yup/src",
"yup/dist",
"zod/package.json",
"zod/src",
"zod/dist",
"vest/package.json",
"vest/src",
"vest/dist",
"joi/package.json",
"joi/src",
"joi/dist",
"superstruct/package.json",
"superstruct/src",
"superstruct/dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "rimraf dist",
"prebuild": "yarn clean",
"build": "tsc && rollup -c",
"lint": "eslint '**/*.{js,ts}'",
"lint:fix": "yarn lint -- --fix",
"lint:types": "tsc --noEmit",
"test": "jest --runInBand",
"test:watch": "yarn test --watchAll --coverage"
"prepare": "run-s build && check-export-map",
"build": "npm-run-all --parallel build:*",
"build:src": "microbundle build",
"build:zod": "microbundle --cwd zod --globals '@hookform/resolvers=hookformResolvers'",
Copy link
Member

Choose a reason for hiding this comment

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

That's new to me, --globals

Copy link
Member Author

Choose a reason for hiding this comment

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

It specify variable name for external imports in umd/iife bundles

"build:yup": "microbundle --cwd yup",
"build:joi": "microbundle --cwd joi --globals '@hookform/resolvers=hookformResolvers'",
"build:superstruct": "microbundle --cwd superstruct --globals '@hookform/resolvers=hookformResolvers'",
"build:vest": "microbundle --cwd vest",
"postbuild": "node ./config/node-13-exports.js",
"lint": "eslint . --ext .ts,.js --ignore-path .gitignore",
"lint:types": "tsc",
"test": "jest",
"test:watch": "yarn test --watchAll --coverage --runInBand",
"check:all": "npm-run-all --parallel lint:* test"
},
"keywords": [
"scheme",
Expand All @@ -40,9 +93,10 @@
"react-hook-form",
"yup",
"joi",
"sperstruct",
"superstruct",
"typescript",
"zod"
"zod",
"vest"
],
"repository": {
"type": "git",
Expand All @@ -55,28 +109,22 @@
},
"homepage": "https://react-hook-form.com",
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@types/jest": "^26.0.19",
"@types/yup": "^0.29.11",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"eslint": "^7.16.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"check-export-map": "^1.0.1",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-prettier": "^3.3.0",
"husky": "^4.3.6",
"jest": "^26.6.3",
"joi": "^17.3.0",
"lint-staged": "^10.5.3",
"matched": "^5.0.1",
"microbundle": "^0.13.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react-hook-form": "^6.13.1",
"rimraf": "^3.0.2",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"react-hook-form": "^6.14.0",
"semantic-release": "^17.3.1",
"superstruct": "^0.13.1",
"ts-jest": "^26.4.4",
Expand All @@ -88,19 +136,14 @@
"peerDependencies": {
"react-hook-form": ">=6.6.0"
},
"release": {
"branches": [
"master"
]
},
"husky": {
"hooks": {
"pre-commit": "yarn lint:types && lint-staged"
}
},
"lint-staged": {
"*.{js,ts}": [
"yarn lint:fix"
"yarn lint --fix"
],
"*.{md,json,yml}": [
"prettier --write"
Expand Down
4 changes: 0 additions & 4 deletions rollup.config.js

This file was deleted.

39 changes: 0 additions & 39 deletions rollup/cjs.ie11.js

This file was deleted.

26 changes: 0 additions & 26 deletions rollup/merge-config.js

This file was deleted.

28 changes: 0 additions & 28 deletions rollup/umd.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import convertArrayToPathName from './convertArrayToPathName';
import { convertArrayToPathName } from '..';

describe('convertArrayToPathName', () => {
it('should convert into path name', () => {
Expand Down
Loading