Skip to content

Commit 507ee0d

Browse files
committed
feat: improve modules support
1 parent eb1cf0d commit 507ee0d

Some content is hidden

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

49 files changed

+2627
-829
lines changed

.eslintignore

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

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ module.exports = {
1919
'@typescript-eslint/no-object-literal-type-assertion': 'off',
2020
'no-console': 'error',
2121
},
22+
overrides: [
23+
{
24+
files: ['config/*.js'],
25+
rules: { '@typescript-eslint/no-var-requires': 'off' },
26+
},
27+
],
2228
};

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: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
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',
3+
testEnvironment: 'node',
114
restoreMocks: true,
12-
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
5+
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
136
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
14-
moduleFileExtensions: ['ts', 'tsx', 'js'],
7+
moduleNameMapper: {
8+
'^@hookform/resolvers$': '<rootDir>/src',
9+
},
1510
};

joi.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

joi.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

joi/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "joi",
3+
"amdName": "hookformResolversJoi",
4+
"version": "1.0.0",
5+
"private": true,
6+
"description": "React Hook Form validation resolver: joi",
7+
"main": "dist/joi.js",
8+
"module": "dist/joi.module.js",
9+
"umd:main": "dist/joi.umd.js",
10+
"source": "src/index.ts",
11+
"types": "dist/index.d.ts",
12+
"license": "MIT",
13+
"peerDependencies": {
14+
"react-hook-form": ">=6.6.0",
15+
"@hookform/resolvers": "^1.0.0"
16+
}
17+
}
File renamed without changes.

src/joi.test.ts renamed to joi/src/__tests__/joi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Joi from 'joi';
2-
import { joiResolver } from './joi';
2+
import { joiResolver } from '..';
33

44
const schema = Joi.object({
55
username: Joi.string().alphanum().min(3).max(30).required(),

joi/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './joi';

0 commit comments

Comments
 (0)