Files
payloadcms/packages/payload/bundle.js
Alessio Gravili e83eb99436 feat: remove joi schema validation (#7226)
We do not really need runtime joi schema validation - this is what TypeScript is for. If people are ignoring TypeScript errors in your schema, or JavaScript errors, that is their fault and does not warrant an extra dependency (joi), lots of code to maintain, as well as slower startups.

If we wanna keep runtime schema validation, we should switch to zod so that we can generate TypeScript types based on the schema and do not have to manually maintain config properties in 2 different places (types & schema).

**joi PROs:**
- Safety for JavaScript-only evangelists messing up their schema
- Safety for people putting @ts-expect-error or `as any` everywhere in their code

**joi CONs:**
- Larger bundle size
- More Modules
- Slower Compilation Speed in dev. Worse DX
- Slower Startup (it needs to validate) in dev. Worse DX
- More code to maintain. For every schema change we'll have to change the types AND the joi schema
- TypeScript already throws proper errors if you mess up your schema. Why have runtime errors?
- The errors are bad. They might tell you what field has an issue, but they do not tell you what exactly is wrong. You have probably seen those "Field XY, value is incorrect" errors - and value could mean anything. Worse DX
- Having extra properties in your schema, even if they are useless, doesn't cause any harm

Cons outweigh the pros
2024-07-22 13:22:54 -04:00

66 lines
1.6 KiB
JavaScript

import * as esbuild from 'esbuild'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
async function build() {
const resultIndex = await esbuild.build({
entryPoints: ['src/exports/index.ts'],
bundle: true,
platform: 'node',
format: 'esm',
outfile: 'dist/exports/index.js',
splitting: false,
external: [
'lodash',
'*.scss',
'*.css',
'@payloadcms/translations',
'memoizee',
'pino-pretty',
'pino',
//'ajv',
//'image-size',
],
minify: true,
metafile: true,
tsconfig: path.resolve(dirname, './tsconfig.json'),
// plugins: [commonjs()],
sourcemap: true,
})
console.log('payload server bundled successfully')
const resultShared = await esbuild.build({
entryPoints: ['src/exports/shared.ts'],
bundle: true,
platform: 'node',
format: 'esm',
outfile: 'dist/exports/shared.js',
splitting: false,
external: [
'lodash',
'*.scss',
'*.css',
'@payloadcms/translations',
'memoizee',
'pino-pretty',
'pino',
//'ajv',
//'image-size',
],
minify: true,
metafile: true,
tsconfig: path.resolve(dirname, './tsconfig.json'),
// plugins: [commonjs()],
sourcemap: true,
})
console.log('payload shared bundled successfully')
fs.writeFileSync('meta_index.json', JSON.stringify(resultIndex.metafile))
fs.writeFileSync('meta_shared.json', JSON.stringify(resultShared.metafile))
}
await build()