Skip to content

Commit

Permalink
fix: bundles cjs, esm & umd (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisre committed Mar 26, 2021
1 parent ac2128e commit 09fef30
Show file tree
Hide file tree
Showing 51 changed files with 2,646 additions and 224 deletions.
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'no-console': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
},
],
},
overrides: [
{
files: ['config/*.js'],
rules: { '@typescript-eslint/no-var-requires': 'off' },
},
],
};
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ coverage

# Dependency directories
node_modules/
app/node_modules/
example/node_modules/
example/build/

# Optional npm cache directory
.npm
Expand All @@ -27,11 +24,8 @@ example/build/
.yarn-integrity

.DS_Store
/lib
/dist
dist
.idea/
.rpt2_cache
.coveralls.yml
package-lock.json
/cypress/videos
/cypress/screenshots
package-lock.json
7 changes: 0 additions & 7 deletions CHANGELOG.md

This file was deleted.

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);
16 changes: 5 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
module.exports = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
globals: {
'ts-jest': {
tsconfig: 'tsconfig.jest.json',
},
},
preset: 'ts-jest',
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"
}
}
File renamed without changes.
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';
2 changes: 1 addition & 1 deletion src/joi.ts → joi/src/joi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FieldValues,
} from 'react-hook-form';
import * as Joi from 'joi';
import convertArrayToPathName from './utils/convertArrayToPathName';
import { convertArrayToPathName } from '@hookform/resolvers';

const parseErrorSchema = (
error: Joi.ValidationError,
Expand Down
109 changes: 79 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,90 @@
{
"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,
"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"
},
"./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:src build && check-export-map",
"build": "npm-run-all --parallel build:*",
"build:src": "microbundle build",
"build:zod": "microbundle --cwd zod --globals '@hookform/resolvers=hookformResolvers'",
"build:yup": "microbundle --cwd yup --globals '@hookform/resolvers=hookformResolvers'",
"build:joi": "microbundle --cwd joi --globals '@hookform/resolvers=hookformResolvers'",
"build:superstruct": "microbundle --cwd superstruct --globals '@hookform/resolvers=hookformResolvers'",
"build:vest": "microbundle --cwd vest --globals '@hookform/resolvers=hookformResolvers'",
"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,7 +94,7 @@
"react-hook-form",
"yup",
"joi",
"sperstruct",
"superstruct",
"typescript",
"zod"
],
Expand All @@ -55,28 +109,23 @@
},
"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",
"check-export-map": "^1.0.1",
"eslint": "^7.16.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",
"semantic-release": "^17.3.1",
"superstruct": "^0.13.1",
"ts-jest": "^26.4.4",
Expand All @@ -100,7 +149,7 @@
},
"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.

Loading

0 comments on commit 09fef30

Please sign in to comment.