Skip to content

Commit fa81c9b

Browse files
authored
build: drop SWC; use TS for cjs/esm bundles (#8)
* build: drop SWC; use TS for cjs/esm bundles
1 parent e7f6d63 commit fa81c9b

16 files changed

+910
-1172
lines changed

.changeset/tall-fireants-complain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'zod-validation-error': patch
3+
---
4+
5+
Drop SWC; Fix ESM export

.github/workflows/ci.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
pull_request:
55
types: [opened, synchronize, reopened, ready_for_review]
66

7-
# env:
8-
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
9-
107
jobs:
118
block-autosquash:
129
if: github.event.pull_request.draft == false
@@ -24,7 +21,7 @@ jobs:
2421
runs-on: ubuntu-latest
2522
strategy:
2623
matrix:
27-
node-version: [14.x]
24+
node-version: [16.x]
2825

2926
steps:
3027
- uses: actions/checkout@v2
@@ -56,7 +53,7 @@ jobs:
5653
runs-on: ubuntu-latest
5754
strategy:
5855
matrix:
59-
node-version: [14.x]
56+
node-version: [16.x]
6057

6158
steps:
6259
- uses: actions/checkout@v2

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
# This makes action fetch all Git history so that Changesets can generate changelogs with the correct commits
1616
fetch-depth: 0
1717

18-
- name: Use Node.js 14.x
18+
- name: Use Node.js 16.x
1919
uses: actions/setup-node@v1
2020
with:
21-
version: 14.x
21+
version: 16.x
2222

2323
- name: Install Dependencies
2424
run: yarn

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v14.17
1+
v16

config/browser-esm.json

-29
This file was deleted.

config/jest.config.ts

-19
This file was deleted.

config/node-cjs.json

-31
This file was deleted.

config/node-esm.json

-31
This file was deleted.

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
collectCoverageFrom: ['lib/**/*.{js,ts}'],
4+
testRegex: './lib/.*\\.(test|spec)\\.(js|ts)$',
5+
};

lib/ValidationError.spec.ts

+59-46
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as zod from 'zod';
2+
import { ZodError } from 'zod';
23

34
import {
45
fromZodError,
@@ -13,21 +14,23 @@ describe('fromZodError()', () => {
1314
try {
1415
emailSchema.parse('foobar');
1516
} catch (err) {
16-
const validationError = fromZodError(err);
17-
expect(validationError).toBeInstanceOf(ValidationError);
18-
expect(validationError.message).toMatchInlineSnapshot(
19-
`"Validation error: Invalid email"`
20-
);
21-
expect(validationError.details).toMatchInlineSnapshot(`
22-
Array [
23-
Object {
17+
if (err instanceof ZodError) {
18+
const validationError = fromZodError(err);
19+
expect(validationError).toBeInstanceOf(ValidationError);
20+
expect(validationError.message).toMatchInlineSnapshot(
21+
`"Validation error: Invalid email"`
22+
);
23+
expect(validationError.details).toMatchInlineSnapshot(`
24+
[
25+
{
2426
"code": "invalid_string",
2527
"message": "Invalid email",
26-
"path": Array [],
28+
"path": [],
2729
"validation": "email",
2830
},
2931
]
3032
`);
33+
}
3134
}
3235
});
3336

@@ -43,35 +46,39 @@ describe('fromZodError()', () => {
4346
name: 'a',
4447
});
4548
} catch (err) {
46-
const validationError = fromZodError(err);
47-
expect(validationError).toBeInstanceOf(ValidationError);
48-
expect(validationError.message).toMatchInlineSnapshot(
49-
`"Validation error: Number must be greater than 0 at \\"id\\"; String must contain at least 2 character(s) at \\"name\\""`
50-
);
51-
expect(validationError.details).toMatchInlineSnapshot(`
52-
Array [
53-
Object {
49+
if (err instanceof ZodError) {
50+
const validationError = fromZodError(err);
51+
expect(validationError).toBeInstanceOf(ValidationError);
52+
expect(validationError.message).toMatchInlineSnapshot(
53+
`"Validation error: Number must be greater than 0 at "id"; String must contain at least 2 character(s) at "name""`
54+
);
55+
expect(validationError.details).toMatchInlineSnapshot(`
56+
[
57+
{
5458
"code": "too_small",
59+
"exact": false,
5560
"inclusive": false,
5661
"message": "Number must be greater than 0",
5762
"minimum": 0,
58-
"path": Array [
63+
"path": [
5964
"id",
6065
],
6166
"type": "number",
6267
},
63-
Object {
68+
{
6469
"code": "too_small",
70+
"exact": false,
6571
"inclusive": true,
6672
"message": "String must contain at least 2 character(s)",
6773
"minimum": 2,
68-
"path": Array [
74+
"path": [
6975
"name",
7076
],
7177
"type": "string",
7278
},
7379
]
7480
`);
81+
}
7582
}
7683
});
7784

@@ -81,42 +88,44 @@ describe('fromZodError()', () => {
8188
try {
8289
objSchema.parse([1, 'a', true, 1.23]);
8390
} catch (err) {
84-
const validationError = fromZodError(err);
85-
expect(validationError).toBeInstanceOf(ValidationError);
86-
expect(validationError.message).toMatchInlineSnapshot(
87-
`"Validation error: Expected number, received string at \\"[1]\\"; Expected number, received boolean at \\"[2]\\"; Expected integer, received float at \\"[3]\\""`
88-
);
89-
expect(validationError.details).toMatchInlineSnapshot(`
90-
Array [
91-
Object {
91+
if (err instanceof ZodError) {
92+
const validationError = fromZodError(err);
93+
expect(validationError).toBeInstanceOf(ValidationError);
94+
expect(validationError.message).toMatchInlineSnapshot(
95+
`"Validation error: Expected number, received string at "[1]"; Expected number, received boolean at "[2]"; Expected integer, received float at "[3]""`
96+
);
97+
expect(validationError.details).toMatchInlineSnapshot(`
98+
[
99+
{
92100
"code": "invalid_type",
93101
"expected": "number",
94102
"message": "Expected number, received string",
95-
"path": Array [
103+
"path": [
96104
1,
97105
],
98106
"received": "string",
99107
},
100-
Object {
108+
{
101109
"code": "invalid_type",
102110
"expected": "number",
103111
"message": "Expected number, received boolean",
104-
"path": Array [
112+
"path": [
105113
2,
106114
],
107115
"received": "boolean",
108116
},
109-
Object {
117+
{
110118
"code": "invalid_type",
111119
"expected": "integer",
112120
"message": "Expected integer, received float",
113-
"path": Array [
121+
"path": [
114122
3,
115123
],
116124
"received": "float",
117125
},
118126
]
119127
`);
128+
}
120129
}
121130
});
122131

@@ -138,46 +147,50 @@ describe('fromZodError()', () => {
138147
},
139148
});
140149
} catch (err) {
141-
const validationError = fromZodError(err);
142-
expect(validationError).toBeInstanceOf(ValidationError);
143-
expect(validationError.message).toMatchInlineSnapshot(
144-
`"Validation error: Number must be greater than 0 at \\"id\\"; Expected number, received string at \\"arr[1]\\"; String must contain at least 2 character(s) at \\"nestedObj.name\\""`
145-
);
146-
expect(validationError.details).toMatchInlineSnapshot(`
147-
Array [
148-
Object {
150+
if (err instanceof ZodError) {
151+
const validationError = fromZodError(err);
152+
expect(validationError).toBeInstanceOf(ValidationError);
153+
expect(validationError.message).toMatchInlineSnapshot(
154+
`"Validation error: Number must be greater than 0 at "id"; Expected number, received string at "arr[1]"; String must contain at least 2 character(s) at "nestedObj.name""`
155+
);
156+
expect(validationError.details).toMatchInlineSnapshot(`
157+
[
158+
{
149159
"code": "too_small",
160+
"exact": false,
150161
"inclusive": false,
151162
"message": "Number must be greater than 0",
152163
"minimum": 0,
153-
"path": Array [
164+
"path": [
154165
"id",
155166
],
156167
"type": "number",
157168
},
158-
Object {
169+
{
159170
"code": "invalid_type",
160171
"expected": "number",
161172
"message": "Expected number, received string",
162-
"path": Array [
173+
"path": [
163174
"arr",
164175
1,
165176
],
166177
"received": "string",
167178
},
168-
Object {
179+
{
169180
"code": "too_small",
181+
"exact": false,
170182
"inclusive": true,
171183
"message": "String must contain at least 2 character(s)",
172184
"minimum": 2,
173-
"path": Array [
185+
"path": [
174186
"nestedObj",
175187
"name",
176188
],
177189
"type": "string",
178190
},
179191
]
180192
`);
193+
}
181194
}
182195
});
183196
});

0 commit comments

Comments
 (0)