CookieBanner: order, settings="modal", controls="switch", settingsActions, icon and a class slot for every element. Cookie Settings gains eyebrow, title, settingsDescription, alwaysActiveLabel and buttons.close. MaskedField, TestEmailButton and IntegrationStatusBanner import @payloadcms/ui and moved from /client to /admin; with sideEffects in package.json the site bundle no longer ships ~235 KB gz of admin code. A test walks the /client import graph to keep it that way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
64 lines
3.0 KiB
TypeScript
64 lines
3.0 KiB
TypeScript
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { describe, expect, test } from 'vitest'
|
|
|
|
const root = path.resolve(import.meta.dirname, '..')
|
|
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')) as { exports: Record<string, unknown> }
|
|
|
|
function files(dir: string): string[] {
|
|
return readdirSync(dir).flatMap((name) => {
|
|
const p = path.join(dir, name)
|
|
return statSync(p).isDirectory() ? files(p) : /\.(?:md|ts|tsx|mjs)$/.test(name) ? [p] : []
|
|
})
|
|
}
|
|
|
|
describe('package exports', () => {
|
|
test('every @intecion/ipal-kit/<subpath> used in docs and src is exported', () => {
|
|
const used = new Map<string, string>()
|
|
for (const file of [...files(path.join(root, 'docs')), ...files(path.join(root, 'src'))]) {
|
|
for (const m of readFileSync(file, 'utf8').matchAll(/@intecion\/ipal-kit(?<sub>\/[a-z0-9./-]+)?(?=['"#\s`)])/g)) {
|
|
const sub = m.groups?.sub ? `.${m.groups.sub}` : '.'
|
|
// node_modules/@intecion/ipal-kit/dist|docs|package.json — filesystem paths in prose, not imports
|
|
if (/^\.\/(?:dist|docs|package\.json)(?:\/|$)/.test(sub)) {continue}
|
|
if (!used.has(sub)) {used.set(sub, path.relative(root, file))}
|
|
}
|
|
}
|
|
const missing = [...used].filter(([sub]) => !(sub in pkg.exports)).map(([sub, file]) => `${sub} (e.g. ${file})`)
|
|
expect(missing).toEqual([])
|
|
})
|
|
|
|
test('every export points at a file the build produces from src', () => {
|
|
for (const [sub, target] of Object.entries(pkg.exports)) {
|
|
const out = typeof target === 'string' ? target : (target as { import: string }).import
|
|
const src = out.replace('./dist/', 'src/').replace(/\.js$/, '.ts')
|
|
expect(existsSync(path.join(root, src)) || existsSync(path.join(root, src.replace(/\.ts$/, '.tsx'))), `${sub} → ${src}`).toBe(true)
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('client entry', () => {
|
|
// Wszystko, co importuje /client, trafia do bundla strony publicznej — panel (@payloadcms/ui) to ~235 KB gz
|
|
test('does not pull admin UI (@payloadcms/ui, @payloadcms/next) into the site bundle', () => {
|
|
const seen = new Set<string>()
|
|
const offenders: string[] = []
|
|
const resolve = (from: string, spec: string) => {
|
|
const base = path.resolve(path.dirname(from), spec).replace(/\.js$/, '')
|
|
return ['.ts', '.tsx', '/index.ts', '/index.tsx'].map((ext) => base + ext).find((f) => existsSync(f))
|
|
}
|
|
const walk = (file: string) => {
|
|
if (seen.has(file)) {return}
|
|
seen.add(file)
|
|
for (const m of readFileSync(file, 'utf8').matchAll(/(?:import|export)\s[^'"]*?from\s+['"](?<spec>[^'"]+)['"]/g)) {
|
|
const spec = m.groups!.spec
|
|
if (/^@payloadcms\/(?:ui|next)(?:\/|$)/.test(spec)) {offenders.push(`${path.relative(root, file)} → ${spec}`)}
|
|
if (spec.startsWith('.')) {
|
|
const next = resolve(file, spec)
|
|
if (next) {walk(next)}
|
|
}
|
|
}
|
|
}
|
|
walk(path.join(root, 'src/exports/client.ts'))
|
|
expect(offenders).toEqual([])
|
|
})
|
|
})
|