Skip to content

Commit 753abdf

Browse files
committed
feat: flat bundles and size reductions
Use rollup to produce flat bundles of yup.
1 parent dde11ca commit 753abdf

30 files changed

+1990
-2379
lines changed

.babelrc.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
module.exports = (api) => ({
22
presets: [
33
[
4-
'babel-preset-jason/esm',
4+
'babel-preset-env-modules',
55
api.env() !== 'test'
66
? {
77
ignoreBrowserslistConfig: true,
88
modules: api.env() === 'esm' ? false : 'commonjs',
99
}
1010
: {
1111
target: 'node',
12-
13-
// debug: true,
1412
targets: { node: 'current' },
1513
},
1614
],
1715
['@babel/preset-typescript', { allowDeclareFields: true }],
1816
],
19-
plugins: ['@babel/plugin-proposal-logical-assignment-operators'],
2017
});

.eslintrc

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"env": {
44
"browser": true
55
},
6+
"parserOptions": {
7+
"requireConfigFile": false
8+
},
69
"rules": {
710
"@typescript-eslint/no-shadow": "off",
811
"@typescript-eslint/no-empty-interface": "off"
@@ -14,18 +17,13 @@
1417
"env": {
1518
"jest/globals": true
1619
},
17-
"globals": {
18-
"TestHelpers": false,
19-
"sinon": true
20-
},
2120
"rules": {
2221
"global-require": "off",
2322
"no-await-in-loop": "off",
2423
"jest/no-disabled-tests": "warn",
2524
"jest/no-focused-tests": "error",
2625
"jest/no-identical-title": "error",
2726
"jest/prefer-to-have-length": "warn",
28-
"jest/valid-expect": "off",
2927
"@typescript-eslint/no-empty-function": "off"
3028
}
3129
}

.gitignore

+57-56
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
1-
# Logs
2-
logs
3-
*.log
4-
5-
# Runtime data
6-
pids
7-
*.pid
8-
*.seed
9-
10-
# Directory for instrumented libs generated by jscoverage/JSCover
11-
lib-cov
12-
13-
# Coverage directory used by tools like istanbul
14-
coverage
15-
16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17-
.grunt
18-
19-
# Compiled binary addons (http://nodejs.org/api/addons.html)
20-
build/Release
21-
22-
# Dependency directory
23-
# Commenting this out is preferred by some people, see
24-
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
25-
node_modules
26-
27-
# Users Environment Variables
28-
.lock-wscript
29-
30-
# =========================
31-
# Operating System Files
32-
# =========================
33-
34-
# OSX
35-
# =========================
36-
1+
# Logs
2+
logs
3+
*.log
4+
dts/
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# Compiled binary addons (http://nodejs.org/api/addons.html)
20+
build/Release
21+
22+
# Dependency directory
23+
# Commenting this out is preferred by some people, see
24+
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
25+
node_modules
26+
27+
# Users Environment Variables
28+
.lock-wscript
29+
30+
# =========================
31+
# Operating System Files
32+
# =========================
33+
34+
# OSX
35+
# =========================
36+
3737
.DS_Store
3838
.AppleDouble
3939
.LSOverride
4040

4141
# Icon must end with two \r
42-
Icon
42+
Icon
43+
4344

4445
# Thumbnails
4546
._*
@@ -54,25 +55,25 @@ Icon
5455
Network Trash Folder
5556
Temporary Items
5657
.apdisk
57-
58-
# Windows
59-
# =========================
60-
61-
# Windows image file caches
62-
Thumbs.db
63-
ehthumbs.db
64-
65-
# Folder config file
66-
Desktop.ini
67-
68-
# Recycle Bin used on file shares
69-
$RECYCLE.BIN/
70-
71-
# Windows Installer files
72-
*.cab
73-
*.msi
74-
*.msm
75-
*.msp
58+
59+
# Windows
60+
# =========================
61+
62+
# Windows image file caches
63+
Thumbs.db
64+
ehthumbs.db
65+
66+
# Folder config file
67+
Desktop.ini
68+
69+
# Recycle Bin used on file shares
70+
$RECYCLE.BIN/
71+
72+
# Windows Installer files
73+
*.cab
74+
*.msi
75+
*.msm
76+
*.msp
7677

7778
# Ignore build files
7879
lib/

package.json

+31-33
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0-beta.0",
44
"description": "Dead simple Object schema validation",
55
"main": "lib/index.js",
6-
"module": "es/index.js",
6+
"module": "lib/index.esm.js",
77
"runkitExampleFilename": "./runkit-example.js",
88
"scripts": {
99
"test": "yarn lint && yarn test-all --runInBand",
@@ -15,13 +15,10 @@
1515
"precommit": "lint-staged",
1616
"toc": "doctoc README.md --github",
1717
"release": "rollout",
18-
"build": "yarn 4c build && yarn toc",
18+
"build:dts": "yarn tsc --emitDeclarationOnly -p . --outDir dts",
19+
"build": "rm -rf dts && yarn build:dts && yarn rollup -c rollup.config.js && yarn toc",
1920
"prepublishOnly": "yarn build"
2021
},
21-
"files": [
22-
"es",
23-
"lib"
24-
],
2522
"repository": {
2623
"type": "git",
2724
"url": "git+https://github.com/jquense/yup.git"
@@ -35,7 +32,8 @@
3532
},
3633
"homepage": "https://github.com/jquense/yup",
3734
"release": {
38-
"conventionalCommits": true
35+
"conventionalCommits": true,
36+
"publishDir": "lib"
3937
},
4038
"prettier": {
4139
"singleQuote": true,
@@ -69,41 +67,41 @@
6967
"@4c/cli": "^3.0.1",
7068
"@4c/rollout": "^3.0.1",
7169
"@4c/tsconfig": "^0.4.0",
72-
"@babel/cli": "^7.15.7",
73-
"@babel/core": "^7.15.8",
74-
"@babel/plugin-proposal-logical-assignment-operators": "^7.14.5",
75-
"@babel/preset-typescript": "^7.15.0",
76-
"@types/jest": "^27.0.3",
77-
"@typescript-eslint/eslint-plugin": "^4.33.0",
78-
"@typescript-eslint/parser": "^4.33.0",
79-
"babel-eslint": "^10.1.0",
80-
"babel-jest": "^27.2.5",
81-
"babel-plugin-transform-rename-import": "^2.3.0",
82-
"babel-preset-jason": "^6.3.0",
83-
"doctoc": "^2.0.1",
84-
"eslint": "^7.12.0",
85-
"eslint-config-jason": "^8.1.1",
70+
"@babel/cli": "^7.16.7",
71+
"@babel/core": "^7.16.7",
72+
"@babel/preset-typescript": "^7.16.7",
73+
"@rollup/plugin-babel": "^5.3.0",
74+
"@rollup/plugin-node-resolve": "^13.1.2",
75+
"@types/jest": "^27.4.0",
76+
"@typescript-eslint/eslint-plugin": "^5.8.1",
77+
"@typescript-eslint/parser": "^5.8.1",
78+
"babel-jest": "^27.4.5",
79+
"babel-preset-env-modules": "^1.0.1",
80+
"doctoc": "^2.1.0",
81+
"dts-bundle-generator": "^6.3.0",
82+
"eslint": "^8.6.0",
83+
"eslint-config-jason": "^8.2.2",
8684
"eslint-config-prettier": "^8.3.0",
87-
"eslint-plugin-import": "^2.24.2",
88-
"eslint-plugin-jest": "^25.0.1",
89-
"eslint-plugin-react": "^7.26.1",
90-
"eslint-plugin-react-hooks": "^4.2.0",
91-
"eslint-plugin-ts-expect": "^2.0.0",
85+
"eslint-plugin-import": "^2.25.4",
86+
"eslint-plugin-jest": "^25.3.4",
87+
"eslint-plugin-react": "^7.28.0",
88+
"eslint-plugin-react-hooks": "^4.3.0",
89+
"eslint-plugin-ts-expect": "^2.1.0",
9290
"eslint-plugin-typescript": "^0.14.0",
9391
"hookem": "^2.0.1",
94-
"jest": "^27.2.5",
95-
"lint-staged": "^11.2.3",
96-
"prettier": "^2.4.1",
97-
"rollup": "^2.58.0",
92+
"jest": "^27.4.5",
93+
"lint-staged": "^12.1.5",
94+
"prettier": "^2.5.1",
95+
"rollup": "^2.62.0",
9896
"rollup-plugin-babel": "^4.4.0",
97+
"rollup-plugin-dts": "^4.1.0",
9998
"rollup-plugin-filesize": "^9.1.1",
10099
"rollup-plugin-node-resolve": "^5.2.0",
101-
"rollup-plugin-size-snapshot": "^0.12.0",
102100
"synchronous-promise": "^2.0.15",
103-
"typescript": "^4.4.3"
101+
"typescript": "^4.5.4"
104102
},
105103
"dependencies": {
106-
"nanoclone": "^0.2.1",
104+
"nanoclone": "^1.0.0",
107105
"property-expr": "^2.0.4",
108106
"tiny-case": "^1.0.2",
109107
"toposort": "^2.0.2"

rollup.config.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
const nodeResolve = require('rollup-plugin-node-resolve');
2-
const babel = require('rollup-plugin-babel');
3-
const filesize = require('rollup-plugin-filesize');
1+
import nodeResolve from '@rollup/plugin-node-resolve';
2+
import babel from '@rollup/plugin-babel';
3+
import dts from 'rollup-plugin-dts';
4+
import filesize from 'rollup-plugin-filesize';
45

56
const base = {
6-
input: './src/index.js',
7+
input: './src/index.ts',
78
plugins: [
8-
nodeResolve(),
9+
nodeResolve({ extensions: ['.js', '.ts'] }),
910
babel({
10-
babelrc: false,
11-
presets: [['jason', { modules: false, runtime: false }]],
11+
babelrc: true,
12+
envName: 'esm',
13+
extensions: ['.js', '.ts'],
1214
}),
1315
],
1416
external: ['tiny-case', 'toposort', 'fn-name', 'property-expr'],
1517
};
1618

1719
module.exports = [
20+
{
21+
input: './dts/index.d.ts',
22+
output: [{ file: 'lib/index.d.ts', format: 'es' }],
23+
plugins: [dts()],
24+
},
1825
{
1926
...base,
2027
output: [
2128
{
22-
file: 'dist/yup.js',
29+
file: 'lib/index.js',
2330
format: 'cjs',
2431
},
2532
{
26-
file: 'dist/yup.esm.js',
33+
file: 'lib/index.esm.js',
2734
format: 'es',
2835
},
2936
],

src/Condition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isSchema from './util/isSchema';
22
import Reference from './Reference';
3-
import type { ISchema } from './util/types';
3+
import type { ISchema } from './types';
44

55
export type ConditionBuilder<
66
T extends ISchema<any, any>,

src/Lazy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import isSchema from './util/isSchema';
2-
import type { AnyObject, ValidateOptions } from './types';
2+
import type { AnyObject, ISchema, ValidateOptions } from './types';
33
import type { ResolveOptions } from './Condition';
44

55
import type {
66
CastOptions,
77
SchemaFieldDescription,
88
SchemaLazyDescription,
99
} from './schema';
10-
import { Flags, ISchema } from './util/types';
10+
import { Flags } from './util/types';
1111
import { Schema } from '.';
1212

1313
export type LazyBuilder<

src/array.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import isAbsent from './util/isAbsent';
22
import isSchema from './util/isSchema';
33
import printValue from './util/printValue';
4+
import parseJson from './util/parseJson';
45
import { array as locale } from './locale';
5-
import type {
6-
AnyObject,
7-
InternalOptions,
8-
Message,
9-
Maybe,
10-
Optionals,
11-
} from './types';
6+
import type { AnyObject, InternalOptions, Message, ISchema } from './types';
127
import type Reference from './Reference';
13-
import {
8+
import type {
149
Defined,
1510
Flags,
1611
NotNull,
1712
SetFlag,
1813
Thunk,
14+
Maybe,
15+
Optionals,
1916
ToggleDefault,
20-
ISchema,
2117
UnsetFlag,
2218
Concat,
2319
} from './util/types';
@@ -26,9 +22,8 @@ import Schema, {
2622
SchemaInnerTypeDescription,
2723
SchemaSpec,
2824
} from './schema';
29-
import { ResolveOptions } from './Condition';
30-
import parseJson from 'parse-json';
31-
import { ValidationError } from '.';
25+
import type { ResolveOptions } from './Condition';
26+
import type ValidationError from './ValidationError';
3227

3328
type InnerType<T> = T extends Array<infer I> ? I : never;
3429

0 commit comments

Comments
 (0)