Skip to content

Commit

Permalink
feat: flat bundles and size reductions
Browse files Browse the repository at this point in the history
Use rollup to produce flat bundles of yup.
  • Loading branch information
jquense committed Jan 3, 2022
1 parent dde11ca commit 753abdf
Show file tree
Hide file tree
Showing 30 changed files with 1,990 additions and 2,379 deletions.
5 changes: 1 addition & 4 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
module.exports = (api) => ({
presets: [
[
'babel-preset-jason/esm',
'babel-preset-env-modules',
api.env() !== 'test'
? {
ignoreBrowserslistConfig: true,
modules: api.env() === 'esm' ? false : 'commonjs',
}
: {
target: 'node',

// debug: true,
targets: { node: 'current' },
},
],
['@babel/preset-typescript', { allowDeclareFields: true }],
],
plugins: ['@babel/plugin-proposal-logical-assignment-operators'],
});
8 changes: 3 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"env": {
"browser": true
},
"parserOptions": {
"requireConfigFile": false
},
"rules": {
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-empty-interface": "off"
Expand All @@ -14,18 +17,13 @@
"env": {
"jest/globals": true
},
"globals": {
"TestHelpers": false,
"sinon": true
},
"rules": {
"global-require": "off",
"no-await-in-loop": "off",
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "off",
"@typescript-eslint/no-empty-function": "off"
}
}
Expand Down
113 changes: 57 additions & 56 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# Users Environment Variables
.lock-wscript

# =========================
# Operating System Files
# =========================

# OSX
# =========================

# Logs
logs
*.log
dts/
# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# Users Environment Variables
.lock-wscript

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon
Icon


# Thumbnails
._*
Expand All @@ -54,25 +55,25 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Ignore build files
lib/
Expand Down
64 changes: 31 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0-beta.0",
"description": "Dead simple Object schema validation",
"main": "lib/index.js",
"module": "es/index.js",
"module": "lib/index.esm.js",
"runkitExampleFilename": "./runkit-example.js",
"scripts": {
"test": "yarn lint && yarn test-all --runInBand",
Expand All @@ -15,13 +15,10 @@
"precommit": "lint-staged",
"toc": "doctoc README.md --github",
"release": "rollout",
"build": "yarn 4c build && yarn toc",
"build:dts": "yarn tsc --emitDeclarationOnly -p . --outDir dts",
"build": "rm -rf dts && yarn build:dts && yarn rollup -c rollup.config.js && yarn toc",
"prepublishOnly": "yarn build"
},
"files": [
"es",
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/jquense/yup.git"
Expand All @@ -35,7 +32,8 @@
},
"homepage": "https://github.com/jquense/yup",
"release": {
"conventionalCommits": true
"conventionalCommits": true,
"publishDir": "lib"
},
"prettier": {
"singleQuote": true,
Expand Down Expand Up @@ -69,41 +67,41 @@
"@4c/cli": "^3.0.1",
"@4c/rollout": "^3.0.1",
"@4c/tsconfig": "^0.4.0",
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.8",
"@babel/plugin-proposal-logical-assignment-operators": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.2.5",
"babel-plugin-transform-rename-import": "^2.3.0",
"babel-preset-jason": "^6.3.0",
"doctoc": "^2.0.1",
"eslint": "^7.12.0",
"eslint-config-jason": "^8.1.1",
"@babel/cli": "^7.16.7",
"@babel/core": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^13.1.2",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"babel-jest": "^27.4.5",
"babel-preset-env-modules": "^1.0.1",
"doctoc": "^2.1.0",
"dts-bundle-generator": "^6.3.0",
"eslint": "^8.6.0",
"eslint-config-jason": "^8.2.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^25.0.1",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-ts-expect": "^2.0.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-ts-expect": "^2.1.0",
"eslint-plugin-typescript": "^0.14.0",
"hookem": "^2.0.1",
"jest": "^27.2.5",
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"rollup": "^2.58.0",
"jest": "^27.4.5",
"lint-staged": "^12.1.5",
"prettier": "^2.5.1",
"rollup": "^2.62.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-dts": "^4.1.0",
"rollup-plugin-filesize": "^9.1.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-size-snapshot": "^0.12.0",
"synchronous-promise": "^2.0.15",
"typescript": "^4.4.3"
"typescript": "^4.5.4"
},
"dependencies": {
"nanoclone": "^0.2.1",
"nanoclone": "^1.0.0",
"property-expr": "^2.0.4",
"tiny-case": "^1.0.2",
"toposort": "^2.0.2"
Expand Down
25 changes: 16 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
const nodeResolve = require('rollup-plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const filesize = require('rollup-plugin-filesize');
import nodeResolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import dts from 'rollup-plugin-dts';
import filesize from 'rollup-plugin-filesize';

const base = {
input: './src/index.js',
input: './src/index.ts',
plugins: [
nodeResolve(),
nodeResolve({ extensions: ['.js', '.ts'] }),
babel({
babelrc: false,
presets: [['jason', { modules: false, runtime: false }]],
babelrc: true,
envName: 'esm',
extensions: ['.js', '.ts'],
}),
],
external: ['tiny-case', 'toposort', 'fn-name', 'property-expr'],
};

module.exports = [
{
input: './dts/index.d.ts',
output: [{ file: 'lib/index.d.ts', format: 'es' }],
plugins: [dts()],
},
{
...base,
output: [
{
file: 'dist/yup.js',
file: 'lib/index.js',
format: 'cjs',
},
{
file: 'dist/yup.esm.js',
file: 'lib/index.esm.js',
format: 'es',
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/Condition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isSchema from './util/isSchema';
import Reference from './Reference';
import type { ISchema } from './util/types';
import type { ISchema } from './types';

export type ConditionBuilder<
T extends ISchema<any, any>,
Expand Down
4 changes: 2 additions & 2 deletions src/Lazy.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import isSchema from './util/isSchema';
import type { AnyObject, ValidateOptions } from './types';
import type { AnyObject, ISchema, ValidateOptions } from './types';
import type { ResolveOptions } from './Condition';

import type {
CastOptions,
SchemaFieldDescription,
SchemaLazyDescription,
} from './schema';
import { Flags, ISchema } from './util/types';
import { Flags } from './util/types';
import { Schema } from '.';

export type LazyBuilder<
Expand Down
19 changes: 7 additions & 12 deletions src/array.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import isAbsent from './util/isAbsent';
import isSchema from './util/isSchema';
import printValue from './util/printValue';
import parseJson from './util/parseJson';
import { array as locale } from './locale';
import type {
AnyObject,
InternalOptions,
Message,
Maybe,
Optionals,
} from './types';
import type { AnyObject, InternalOptions, Message, ISchema } from './types';
import type Reference from './Reference';
import {
import type {
Defined,
Flags,
NotNull,
SetFlag,
Thunk,
Maybe,
Optionals,
ToggleDefault,
ISchema,
UnsetFlag,
Concat,
} from './util/types';
Expand All @@ -26,9 +22,8 @@ import Schema, {
SchemaInnerTypeDescription,
SchemaSpec,
} from './schema';
import { ResolveOptions } from './Condition';
import parseJson from 'parse-json';
import { ValidationError } from '.';
import type { ResolveOptions } from './Condition';
import type ValidationError from './ValidationError';

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

Expand Down
Loading

0 comments on commit 753abdf

Please sign in to comment.