Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dev dependencies, clean up repository #7

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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
37 changes: 14 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
name: Create Relase & Publish Package
name: Test Package

on:
push:
tags:
- 'v*'
on: push

env:
NODE_VERSION: 20
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
test:
runs-on: ubuntu-22.04
timeout-minutes: 5
timeout-minutes: 15
strategy:
matrix:
node_version: [16, 18, 20]
steps:
- uses: actions/checkout@v4
- uses: actions/github-script@v7
with:
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ github.ref }}',
name: 'Release ${{ github.ref_name }}'
})
- uses: aboutbits/github-actions-node/setup-and-install@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
node-version: ${{ matrix.node_version }}
- run: npm run lint
- run: npm run typecheck
- run: npm run test
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Create Relase & Publish Package

on:
push:
tags:
- 'v*'

env:
NODE_VERSION: 20

jobs:
build:
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/github-script@v7
with:
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ github.ref }}',
name: 'Release ${{ github.ref_name }}'
})
- uses: aboutbits/github-actions-node/setup-and-install@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 0 additions & 18 deletions .github/workflows/test.yml

This file was deleted.

7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,8 +7,11 @@

# Project
/node_modules
/dist
/translations-template.json

# ESLint
# Build
/dist
*.tsbuildinfo

# Cache
.eslintcache
7,523 changes: 4,534 additions & 2,989 deletions package-lock.json

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@
"name": "@aboutbits/zod-locales-formatjs",
"version": "0.0.6",
"description": "Custom Zod locales for FormatJS",
"author": "AboutBits",
"license": "MIT",
"homepage": "https://github.com/aboutbits/zod-locales-formatjs",
"repository": {
"type": "git",
"url": "git+https://github.com/aboutbits/zod-locales-formatjs.git"
},
"bugs": {
"url": "https://github.com/aboutbits/zod-locales-formatjs/issues"
},
"keywords": [
"zod",
"formatjs",
@@ -10,12 +20,22 @@
"language",
"languages"
],
"author": "AboutBits",
"license": "MIT",
"private": false,
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/cjs/index.d.ts",
"files": [
"dist/",
"react-intl/"
],
"engines": {
"npm": ">=8",
"node": ">=16"
},
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.build.cjs.json",
@@ -31,29 +51,30 @@
"version": "npm run test && npm run lint && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aboutbits/zod-locales-formatjs.git"
},
"files": [
"dist/",
"react-intl/"
],
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/aboutbits/zod-locales-formatjs/issues"
},
"homepage": "https://github.com/aboutbits/zod-locales-formatjs#readme",
"engines": {
"npm": ">=8",
"node": ">=16"
},
"dependencies": {
"@formatjs/intl": "^2.6.5",
"zod": "^3.20.6"
"zod": "^3.22.4"
},
"devDependencies": {
"@formatjs/cli": "^6.2.8",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.26",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"babel-jest": "^29.7.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-formatjs": "^4.12.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"jest": "^29.7.0",
"json-diff": "^1.0.6",
"prettier": "^3.2.5",
"react-intl": "^6.6.3",
"typescript": "^5.4.3"
},
"peerDependencies": {
"react-intl": "^6.2.8"
@@ -62,26 +83,5 @@
"react-intl": {
"optional": true
}
},
"devDependencies": {
"@formatjs/cli": "^6.0.1",
"@types/jest": "^29.4.0",
"@types/node": "^16.18.12",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"babel-jest": "^29.4.2",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-formatjs": "^4.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"jest": "^29.4.2",
"json-diff": "^1.0.2",
"prettier": "^2.8.4",
"react-intl": "^6.2.8",
"typescript": "^4.9.5"
}
}
18 changes: 13 additions & 5 deletions src/zod/makeZodErrorMap.ts
Original file line number Diff line number Diff line change
@@ -5,23 +5,23 @@ import { errorMessages } from './errorMessages'
// Docs https://zod.dev/ERROR_HANDLING?id=error-map-priority
export function makeZodErrorMap<T>(
issue: z.ZodIssueOptionalMessage,
intl: IntlShape<T>
intl: IntlShape<T>,
) {
const descriptorItem = getDescriptorItem<T>(issue, intl)

return descriptorItem.key in errorMessages
? {
message: intl.formatMessage(
errorMessages[descriptorItem.key as keyof typeof errorMessages],
descriptorItem.values
descriptorItem.values,
),
}
: { message: intl.formatMessage(errorMessages['default']) }
}

export function getDescriptorItem<T>(
issue: z.ZodIssueOptionalMessage,
intl: IntlShape<T>
intl: IntlShape<T>,
): {
key: string
values?: Record<string, string | number>
@@ -58,8 +58,16 @@ export function getDescriptorItem<T>(
issue.code === z.ZodIssueCode.too_small
? issue.minimum
: issue.code === z.ZodIssueCode.too_big
? issue.maximum
: '-'
? issue.maximum
: '-'

/**
* The intl.formatMessage function does not support bigint values to be passed as values. That's why we have to
* handle these values and format them already here.
*/
if (typeof value === 'bigint') {
value = intl.formatNumber(value)
}

if (issue.type === 'date') {
const date = new Date(value)