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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"precommit": "lint-staged",
"e2e:ui": "playwright test --ui",
"start:app": "turbo run build --filter formik... && yarn --cwd packages/formik link && yarn --cwd ./app link formik && yarn --cwd ./app && yarn --cwd ./app run dev",
"benchmark": "tsx scripts/benchmark.tsx | tee output.txt"
"benchmark": "tsx scripts/benchmark.tsx | tee output.txt",
"custom-build": "turbo run build --force",
"custom-publish": "bash ./scripts/custom-publish.sh"
},
"lint-staged": {
"**/*.{ts,tsx,md,mdx,js,jsx}": [
Expand Down
23 changes: 23 additions & 0 deletions packages/formik/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Formik Fork README

This is a Fork of the original Formik repository. It is intended to be used as a dependency in other projects with minimal changes to address bugs, since the original repository is not actively maintained (as of March 2025).

The `main` branch contains the original Formik codebase, while the `main-dev` branch is the main development branch for this fork.

This Fork has a `custom-publish` script.

```bash
yarn custom-publish
```

This should be called from the `main-dev` branch after making/merging changes to the codebase. The script builds the package and updates a dedicated `custom-build` branch containing only the distributable files. It then commits and force‑pushes these changes to GitHub, allowing you to continuously install the latest build with:

```bash
yarn add git+https://github.com/zduvall/formik.git#custom-build
```

Note that the `custom-publish` script uses the `custom-build` script which forces a build even if there are no detected changes.
---

# Formik Original README

<p align="center">
<img src="https://user-images.githubusercontent.com/4060187/61057426-4e5a4600-a3c3-11e9-9114-630743e05814.png" width="211" height="182" alt="Formik.js" />
</p>
Expand Down
2 changes: 2 additions & 0 deletions packages/formik/src/Formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ export function useFormik<Values extends FormikValues = FormikValues>({

const executeBlur = React.useCallback(
(e: any, path?: string) => {
if (!e) return

if (e.persist) {
e.persist();
}
Expand Down
102 changes: 102 additions & 0 deletions scripts/custom-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
# Exit immediately on error, and treat unset variables as errors.
set -euo pipefail

# Color definitions.
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;34m"
RED="\033[0;31m"
NC="\033[0m" # No Color

# Custom echo function to add newlines before and after the string.
custom_echo() {
echo -e "\n$1\n"
}

# Check that we are in a Git repository.
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
custom_echo "${RED}[ERROR]${NC} Not inside a Git repository. Exiting."
exit 1
fi

# Ensure a clean working directory.
if [ -n "$(git status --porcelain)" ]; then
custom_echo "${RED}[ERROR]${NC} Working directory is not clean. Please commit or stash your changes."
exit 1
fi

# Save the current branch name.
ORIGINAL_BRANCH=$(git symbolic-ref --short HEAD)
custom_echo "${BLUE}[INFO]${NC} Current branch: ${GREEN}${ORIGINAL_BRANCH}${NC}"

# Create a temporary directory for the build output.
TMP_DIR=$(mktemp -d -t custom-build-XXXXXXXX)
custom_echo "${BLUE}[INFO]${NC} Using temporary directory: ${GREEN}$TMP_DIR${NC}"

# Ensure the branch is switched back and the temporary directory is removed on exit.
function cleanup {
CURRENT=$(git symbolic-ref --short HEAD)
if [ "$CURRENT" != "$ORIGINAL_BRANCH" ]; then
custom_echo "${YELLOW}[CLEANUP]${NC} Switching back to original branch: ${GREEN}${ORIGINAL_BRANCH}${NC}..."
git checkout "$ORIGINAL_BRANCH" || custom_echo "${RED}[ERROR]${NC} Failed to switch back to original branch."
else
custom_echo "${YELLOW}[CLEANUP]${NC} Already on the original branch: ${GREEN}${ORIGINAL_BRANCH}${NC}."
fi

custom_echo "${YELLOW}[CLEANUP]${NC} Removing temporary directory..."
rm -rf "$TMP_DIR"
}
trap cleanup EXIT

# Run the build.
custom_echo "${BLUE}[BUILD]${NC} Running build..."
yarn custom-build

# Verify the build output exists.
if [ ! -d "packages/formik/dist" ]; then
custom_echo "${RED}[ERROR]${NC} Build output directory 'packages/formik/dist' does not exist. Exiting."
exit 1
fi

# Copy the built package to the temporary directory.
custom_echo "${BLUE}[BUILD]${NC} Copying built package to temporary directory..."
# copy everything from the built package to the temporary directory
cp -R packages/formik/. "$TMP_DIR/"
# copy the .git-ignore file to the temporary directory
cp .gitignore "$TMP_DIR/"
# delete the node_modules/ and test/ directories in the temporary directory
rm -rf "$TMP_DIR/node_modules" "$TMP_DIR/test"

# Check if the custom-build branch exists. If yes, checkout; if not, create it.
if git rev-parse --verify custom-build >/dev/null 2>&1; then
custom_echo "${BLUE}[BRANCH]${NC} Branch 'custom-build' exists. Checking it out..."
git checkout custom-build
else
custom_echo "${BLUE}[BRANCH]${NC} Branch 'custom-build' does not exist. Creating orphan branch..."
git checkout --orphan custom-build
# add an initial empty commit to the branch
git commit --allow-empty -m "Initial commit"
fi

# Remove all files from the branch.
custom_echo "${BLUE}[BRANCH]${NC} Clearing files from 'custom-build' branch..."
git rm -rf . > /dev/null 2>&1 || true

# Copy the built files into the branch root.
custom_echo "${BLUE}[DEPLOY]${NC} Copying built files to branch root..."
cp -R "$TMP_DIR/." .

# Stage and commit the changes.
custom_echo "${BLUE}[DEPLOY]${NC} Staging files..."
git add .
# Use 'git add -f' to force-add files that are ignored by `.gitignore` -- particularly the `dist` directory
git add -f dist/
custom_echo "${BLUE}[DEPLOY]${NC} Committing build..."
git commit -m "Auto commit -- publish custom build"

# Force-push the branch to origin.
custom_echo "${BLUE}[DEPLOY]${NC} Pushing 'custom-build' branch to origin..."
git push -f origin custom-build

custom_echo "${GREEN}[SUCCESS]${NC} Custom publish completed successfully!"