Skip to content

Commit

Permalink
fix: make util standalone from form
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed May 28, 2024
1 parent 5088546 commit 33999c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
"preset": "ts-jest/presets/js-with-ts",
"testPathIgnorePatterns": [
"__tests__/components"
]
],
"moduleNameMapper": {
"jotai-form": "<rootDir>/src"
}
},
"keywords": [
"jotai",
Expand Down
24 changes: 18 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ module.exports = function config() {
builder.buildESM('./src/react/index.ts', 'dist/react'),

// utils - zod
builder.buildUMD('./src/utils/zod.ts', 'jotai-form-zod', 'dist/utils/zod'),
builder.buildESM('./src/utils/zod.ts', 'dist/utils/zod'),
builder.buildUMD('./src/utils/zod.ts', 'jotai-form-zod', 'dist/utils/zod', {
external: [/^jotai\//, 'jotai-form', 'zod'],
}),
builder.buildESM('./src/utils/zod.ts', 'dist/utils/zod', {
external: [/^jotai\//, 'jotai-form', 'zod'],
}),
);
};

Expand Down Expand Up @@ -61,8 +65,10 @@ function configBuilder({ env } = {}) {
merge(...configs) {
return [].concat(configs).flat(1);
},
/** @returns {import("rollup").RollupOptions[]} */
buildESM(input, output) {
/**
* @param {import("rollup").RollupOptions} options
* @returns {import("rollup").RollupOptions[]} */
buildESM(input, output, options = {}) {
const plugins = getCommonPlugins(input, output);

return [
Expand All @@ -77,6 +83,7 @@ function configBuilder({ env } = {}) {
entryFileNames: '[name].modern.js',
},
plugins: [...plugins],
...options,
},
{
input,
Expand All @@ -89,11 +96,15 @@ function configBuilder({ env } = {}) {
entryFileNames: '[name].modern.mjs',
},
plugins: [...plugins],
...options,
},
];
},
/** @returns {import("rollup").RollupOptions[]} */
buildUMD(input, name, output) {

/**
* @param {import("rollup").RollupOptions} options
* @returns {import("rollup").RollupOptions[]} */
buildUMD(input, name, output, options = {}) {
const plugins = getCommonPlugins(input, output);
return [
{
Expand All @@ -108,6 +119,7 @@ function configBuilder({ env } = {}) {
entryFileNames: '[name].umd.js',
},
plugins: [...plugins],
...options,
},
];
},
Expand Down
9 changes: 6 additions & 3 deletions src/utils/zod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {
AtomWithValidation,
Options,
atomWithFormControls,
atomWithValidate,
} from 'jotai-form';
import { ZodDefault, ZodObject, ZodType } from 'zod';
import { Options, atomWithFormControls } from '../atomWithFormControls';
import { atomWithValidate } from '../atomWithValidate';
import { AtomWithValidation } from '../validateAtoms';

const INSTANCE_DEFAULT_MAP = {
string: 'defaultemail',
Expand Down

0 comments on commit 33999c9

Please sign in to comment.