Skip to content

Commit

Permalink
Moved stocked into monorepo (#317)
Browse files Browse the repository at this point in the history
* Moved stocked into monorepo

* Fix stocked package build

* Added changeset

* Fixed build

* Update size limit config
  • Loading branch information
ArtiomTr authored Oct 29, 2024
1 parent afd8d8a commit 363bb0e
Show file tree
Hide file tree
Showing 83 changed files with 6,730 additions and 525 deletions.
8 changes: 8 additions & 0 deletions .changeset/red-gifts-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'stocked': patch
'@reactive-forms/core': patch
'pxth': patch
'@reactive-forms/dom': patch
---

Moved stocked into monorepo
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
},
"size-limit": [
{
"path": "packages/core/dist/core.cjs.production.min.js",
"path": "packages/core/dist/index.js",
"limit": "30 KB"
},
{
"path": "packages/core/dist/core.esm.js",
"path": "packages/core/dist/index.mjs",
"limit": "30 KB"
}
]
Expand Down
15 changes: 0 additions & 15 deletions packages/autosave/aqu.config.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/autosave/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import baseConfig from '@reactive-tools/eslint-config';

export default [
{
ignores: ['**/dist', '**/node_modules', '**/*.config.js'],
ignores: ['**/dist', '**/node_modules', '**/*.config.js', '**/.tsup'],
},
...baseConfig,
];
31 changes: 22 additions & 9 deletions packages/autosave/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
"name": "@reactive-forms/autosave",
"description": "> TODO: description",
"version": "0.11.1",
"main": "dist/index.js",
"module": "dist/autosave.esm.js",
"types": "dist/autosave.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": {
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js"
}
},
"homepage": "https://github.com/fracht/reactive-forms#readme",
"repository": "fracht/reactive-forms.git",
"author": "ReactiveForms team",
Expand All @@ -15,10 +25,10 @@
"directory": "prepared-package"
},
"scripts": {
"build": "aqu build && rimraf ./prepared-package && clean-publish",
"dev": "aqu watch",
"lint": "eslint .",
"lint:fix": "npm run lint --fix",
"build": "tsup && rimraf ./prepared-package && clean-publish",
"dev": "tsup --watch",
"lint": "eslint . && attw --pack .",
"lint:fix": "eslint . --fix",
"test": "jest --passWithNoTests",
"test:log-coverage": "jest --passWithNoTests --coverage --silent --ci --coverageReporters=text",
"test:watch": "jest --passWithNoTests --watch"
Expand All @@ -28,16 +38,19 @@
"tiny-invariant": "1.2.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.16.4",
"@babel/core": "7.19.6",
"@microsoft/api-extractor": "^7.47.11",
"@reactive-forms/core": "workspace:*",
"@reactive-tools/eslint-config": "workspace:*",
"@types/react": "18.0.23",
"@types/react": "18.3.12",
"aqu": "0.4.3",
"eslint": "^9.13.0",
"jest": "29.2.2",
"react": "18.2.0",
"react": "18.3.1",
"rimraf": "3.0.2",
"tslib": "2.3.1",
"tsup": "^8.3.5",
"typescript": "4.8.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/autosave/src/localSaveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AutoSaveService } from './AutoSaveService';

const prefix = 'reactiveForms.';

const isServer = () => typeof global.window === 'undefined';
const isServer = () => !(typeof window !== 'undefined' && window.document);

export const localSaveService: AutoSaveService<unknown> = {
save: (key, value) => {
Expand Down
13 changes: 13 additions & 0 deletions packages/autosave/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['./src/index.ts'],
experimentalDts: true,
bundle: true,
format: ['cjs', 'esm'],
treeshake: 'smallest',
tsconfig: './tsconfig.json',
define: {
'import.meta.vitest': 'undefined',
},
});
12 changes: 0 additions & 12 deletions packages/core/aqu.config.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import baseConfig from '@reactive-tools/eslint-config';

export default [
{
ignores: ['**/dist', '**/node_modules', '**/*.config.js'],
ignores: ['**/dist', '**/node_modules', '**/*.config.js', '**/prepared-package', '**/.tsup'],
},
...baseConfig,
{
Expand Down
41 changes: 27 additions & 14 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,64 @@
"name": "@reactive-forms/core",
"description": "Core package of Reactive Forms framework",
"version": "0.11.1",
"main": "dist/index.js",
"module": "dist/core.esm.js",
"types": "dist/core.d.ts",
"type": "commonjs",
"bugs": "https://github.com/fracht/reactive-forms/issues",
"homepage": "https://github.com/fracht/reactive-forms#readme",
"repository": "fracht/reactive-forms.git",
"author": "ReactiveForms team",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": {
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js"
}
},
"publishConfig": {
"access": "public",
"directory": "prepared-package"
},
"scripts": {
"build": "aqu build && rimraf ./prepared-package && clean-publish",
"dev": "aqu watch --no-cleanup",
"lint": "eslint .",
"lint:fix": "npm run lint --fix",
"build": "tsup && rimraf ./prepared-package && clean-publish",
"dev": "tsup --watch",
"lint": "eslint . && attw --pack .",
"lint:fix": "eslint . --fix",
"test": "jest --passWithNoTests",
"test:log-coverage": "jest --passWithNoTests --coverage --silent --ci --coverageReporters=text",
"test:watch": "jest --passWithNoTests --watch"
},
"dependencies": {
"lodash": "4.17.21",
"lodash-es": "4.17.15",
"pxth": "0.7.0",
"stocked": "1.0.0-beta.33",
"pxth": "workspace:*",
"stocked": "workspace:*",
"tiny-invariant": "1.2.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.16.4",
"@babel/core": "7.19.6",
"@microsoft/api-extractor": "^7.47.11",
"@reactive-tools/eslint-config": "workspace:*",
"@testing-library/react": "13.4.0",
"@types/jest": "26.0.24",
"@types/lodash": "4.14.161",
"@types/node": "^18.11.18",
"@types/react": "18.0.23",
"@types/react": "18.3.12",
"aqu": "0.4.3",
"eslint": "^9.13.0",
"jest": "29.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"rimraf": "3.0.2",
"ts-jest": "29.0.3",
"tslib": "2.3.1",
"tsup": "^8.3.5",
"typescript": "4.8.4",
"yup": "0.32.9"
},
Expand All @@ -54,6 +68,5 @@
},
"files": [
"dist"
],
"source": "src/index.ts"
]
}
6 changes: 3 additions & 3 deletions packages/core/src/components/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import React, { Fragment, ReactNode } from 'react';

import { FieldConfig, useField } from '../hooks/useField';
import { FieldContext } from '../typings/FieldContext';

export type FieldProps<V> = FieldConfig<V> & {
children: (ctx: FieldContext<V>) => React.ReactNode;
children: (ctx: FieldContext<V>) => ReactNode;
};

export const Field = <V,>({ children, ...config }: FieldProps<V>) => {
const bag = useField(config);

return <React.Fragment>{children(bag)}</React.Fragment>;
return <Fragment>{children(bag)}</Fragment>;
};
4 changes: 2 additions & 2 deletions packages/core/src/hooks/useFieldValidator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react';
import merge from 'lodash/merge';
import { Pxth } from 'pxth';
import type { Schema } from 'yup';
import type { BaseSchema } from 'yup';

import { useFormContext } from './useFormContext';
import { FieldValidator } from '../typings/FieldValidator';
Expand All @@ -12,7 +12,7 @@ export type UseFieldValidatorConfig<V> = FieldValidationProps<V> & { name: Pxth<

export type FieldValidationProps<V> = {
validator?: FieldValidator<V>;
schema?: Schema<Partial<V> | V | undefined>;
schema?: BaseSchema<Partial<V> | V | undefined>;
};

export const useFieldValidator = <V>({ name, validator: validatorFn, schema }: UseFieldValidatorConfig<V>) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/hooks/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mergeWith from 'lodash/mergeWith';
import { createPxth, deepGet, deepSet, Pxth } from 'pxth';
import { BatchUpdate } from 'stocked';
import invariant from 'tiny-invariant';
import type { Schema } from 'yup';
import type { BaseSchema } from 'yup';

import { useFormControl } from './useFormControl';
import { usePluginBagDecorators, usePluginConfigDecorators } from './usePlugins';
Expand Down Expand Up @@ -34,7 +34,7 @@ export type InitialFormStateConfig<Values extends object> = {
};

export interface ExtendableFormConfig<Values extends object> {
schema?: Schema<Partial<Values> | undefined>;
schema?: BaseSchema<Partial<Values> | undefined>;
onSubmit?: SubmitAction<Values>;
validateForm?: FieldValidator<Values>;
onValidationFailed?: (errors: FieldError<Values>) => void;
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/utils/runYupSchema.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Schema, ValidateOptions } from 'yup';
import type { BaseSchema } from 'yup';
import { ValidateOptions } from 'yup/lib/types';

import { isYupError } from './isYupError';
import { yupToFormErrors } from './yupToFormErrors';
import { FieldError } from '../typings/FieldError';

export const runYupSchema = async <V>(
schema: Schema<Partial<V> | undefined>,
schema: BaseSchema<Partial<V> | undefined>,
value: V,
options?: ValidateOptions,
): Promise<FieldError<V> | undefined> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/utils/runYupSchema.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { array, number, object, Schema, string } from 'yup';
import { array, BaseSchema, number, object, string } from 'yup';

import { runYupSchema } from '../../src/utils/runYupSchema';

Expand Down Expand Up @@ -101,7 +101,7 @@ describe('array schema', () => {

describe('throw not yup error', () => {
it('should throw unexpected error', async () => {
await expect(() => runYupSchema(null as unknown as Schema<string>, 'a')).rejects.toBeTruthy();
await expect(() => runYupSchema(null as unknown as BaseSchema<string>, 'a')).rejects.toBeTruthy();
});
});

Expand Down
28 changes: 5 additions & 23 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "esnext",
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"jsx": "react",
"sourceMap": true,
"declaration": true,
"esModuleInterop": true,
"noImplicitReturns": false,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"strict": true,
"importHelpers": true,
"skipLibCheck": true
},
"include": ["src", "tests"]
}
"references": [
{ "path": "./tsconfig.lib.json" },
{ "path": "./tsconfig.test.json" }
]
}
25 changes: 25 additions & 0 deletions packages/core/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "esnext",
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"jsx": "react",
"sourceMap": true,
"declaration": true,
"esModuleInterop": true,
"noImplicitReturns": false,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"strict": true,
"importHelpers": true,
"skipLibCheck": true,
"composite": true
},
"include": ["src"]
}
7 changes: 5 additions & 2 deletions packages/core/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"alwaysStrict": false,
"jsx": "react",
"esModuleInterop": true,
"skipLibCheck": true
}
"skipLibCheck": true,
"composite": true
},
"include": ["tests"],
"references": [{ "path": "./tsconfig.lib.json" }]
}
Loading

0 comments on commit 363bb0e

Please sign in to comment.