@kerf-js/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +554 -2
  3. package/bin/kerf.mjs +15 -0
  4. package/docs/async.md +50 -0
  5. package/docs/browser.md +53 -0
  6. package/docs/config.md +127 -0
  7. package/docs/core.md +30 -0
  8. package/docs/deploy.md +108 -0
  9. package/docs/design.md +106 -0
  10. package/docs/entrypoints.md +83 -0
  11. package/docs/fonts.md +118 -0
  12. package/docs/icons.md +108 -0
  13. package/docs/lists.md +25 -0
  14. package/docs/meta.md +92 -0
  15. package/docs/plugins.md +166 -0
  16. package/docs/props.md +88 -0
  17. package/docs/reactivity.md +26 -0
  18. package/docs/rules.md +39 -0
  19. package/docs/rust.md +253 -0
  20. package/docs/start-short.md +10 -0
  21. package/docs/start.md +642 -0
  22. package/docs/state.md +122 -0
  23. package/docs/style.md +82 -0
  24. package/docs/surface.md +158 -0
  25. package/docs/testing.md +81 -0
  26. package/docs/theme.md +263 -0
  27. package/docs/ui-state.md +105 -0
  28. package/docs/verify.md +61 -0
  29. package/package.json +47 -3
  30. package/src/add/config.mjs +93 -0
  31. package/src/add/errors.mjs +2 -0
  32. package/src/add/setup.mjs +88 -0
  33. package/src/add-rust.mjs +178 -0
  34. package/src/add.mjs +392 -0
  35. package/src/agents-md.mjs +240 -0
  36. package/src/alias.mjs +70 -0
  37. package/src/audit/page.mjs +313 -0
  38. package/src/audit/report.mjs +69 -0
  39. package/src/audit/utils.mjs +5 -0
  40. package/src/audit.mjs +319 -0
  41. package/src/browser/cli.mjs +53 -0
  42. package/src/browser/client.mjs +299 -0
  43. package/src/browser/commands.mjs +258 -0
  44. package/src/capture.mjs +21 -0
  45. package/src/catalog/audit.mjs +129 -0
  46. package/src/catalog/auth.mjs +40 -0
  47. package/src/catalog/compiler.mjs +337 -0
  48. package/src/catalog/contracts.mjs +18 -0
  49. package/src/catalog/database.mjs +52 -0
  50. package/src/catalog/deploy.mjs +117 -0
  51. package/src/catalog/design.mjs +159 -0
  52. package/src/catalog/forms.mjs +25 -0
  53. package/src/catalog/hydration.mjs +29 -0
  54. package/src/catalog/icons.mjs +24 -0
  55. package/src/catalog/media.mjs +163 -0
  56. package/src/catalog/metadata.mjs +116 -0
  57. package/src/catalog/plugins.mjs +228 -0
  58. package/src/catalog/realtime.mjs +195 -0
  59. package/src/catalog/rust.mjs +75 -0
  60. package/src/catalog/server-functions.mjs +100 -0
  61. package/src/catalog/state.mjs +39 -0
  62. package/src/catalog/style-groups.mjs +54 -0
  63. package/src/catalog/tests.mjs +127 -0
  64. package/src/catalog/text.mjs +200 -0
  65. package/src/catalog/ui-state.mjs +42 -0
  66. package/src/catalog.mjs +103 -0
  67. package/src/check/runtime.mjs +280 -0
  68. package/src/check.mjs +321 -0
  69. package/src/cli/authoring.mjs +213 -0
  70. package/src/cli/project.mjs +302 -0
  71. package/src/cli.mjs +340 -0
  72. package/src/config.d.ts +1 -0
  73. package/src/config.mjs +5 -0
  74. package/src/contributions.mjs +119 -0
  75. package/src/db-layer.mjs +41 -0
  76. package/src/deploy/cdn.mjs +142 -0
  77. package/src/deploy/files.mjs +266 -0
  78. package/src/deploy/fit.mjs +166 -0
  79. package/src/deploy/hosts.mjs +126 -0
  80. package/src/deploy/index/cli.mjs +20 -0
  81. package/src/deploy/index/environment.mjs +69 -0
  82. package/src/deploy/index/steps.mjs +87 -0
  83. package/src/deploy/index.mjs +387 -0
  84. package/src/deploy/needs.mjs +149 -0
  85. package/src/design-checks/accessible-names.mjs +62 -0
  86. package/src/design-checks/contrast.mjs +43 -0
  87. package/src/design-checks/csp.mjs +60 -0
  88. package/src/design-checks/files.mjs +59 -0
  89. package/src/design-checks/heading-links.mjs +61 -0
  90. package/src/design-checks/interaction.mjs +65 -0
  91. package/src/design-checks/jsx.mjs +67 -0
  92. package/src/design-checks/layout-values.mjs +68 -0
  93. package/src/design-checks/native-controls.mjs +48 -0
  94. package/src/design-checks/outline.mjs +39 -0
  95. package/src/design-checks/reporter.mjs +37 -0
  96. package/src/design-checks/rules.mjs +274 -0
  97. package/src/design-checks/values.mjs +262 -0
  98. package/src/design-checks.mjs +49 -0
  99. package/src/diag.mjs +98 -0
  100. package/src/docs.mjs +228 -0
  101. package/src/doctor.mjs +42 -0
  102. package/src/files.mjs +60 -0
  103. package/src/fix.mjs +48 -0
  104. package/src/gate/after.mjs +40 -0
  105. package/src/gate/before.mjs +54 -0
  106. package/src/gate/classify.mjs +72 -0
  107. package/src/gate/mutation.mjs +209 -0
  108. package/src/gate/resolve-cases.mjs +22 -0
  109. package/src/gate/result.mjs +63 -0
  110. package/src/gate/run.mjs +75 -0
  111. package/src/gate.mjs +178 -0
  112. package/src/index.mjs +9 -0
  113. package/src/infer/box-props.cjs +140 -0
  114. package/src/infer/core-boxes.cjs +46 -0
  115. package/src/infer/derived-writes.cjs +95 -0
  116. package/src/infer/engine/checks.cjs +193 -0
  117. package/src/infer/engine/flow.cjs +293 -0
  118. package/src/infer/engine/report.cjs +158 -0
  119. package/src/infer/engine/utils.cjs +15 -0
  120. package/src/infer/engine.cjs +265 -0
  121. package/src/infer/facts/sites.cjs +114 -0
  122. package/src/infer/facts.cjs +345 -0
  123. package/src/infer/hosts.cjs +161 -0
  124. package/src/infer/lsp.mjs +240 -0
  125. package/src/infer/session.cjs +161 -0
  126. package/src/infer/shadow.cjs +54 -0
  127. package/src/infer/worker.cjs +145 -0
  128. package/src/jsx-scan.mjs +128 -0
  129. package/src/kerf.mjs +98 -0
  130. package/src/load-config/schema.mjs +300 -0
  131. package/src/load-config.mjs +302 -0
  132. package/src/map.mjs +177 -0
  133. package/src/mcp/browser-tools.mjs +155 -0
  134. package/src/mcp.mjs +273 -0
  135. package/src/meta-table.mjs +63 -0
  136. package/src/mutate.mjs +224 -0
  137. package/src/plugin-checks.mjs +118 -0
  138. package/src/plugins.mjs +258 -0
  139. package/src/project.mjs +310 -0
  140. package/src/props-checks.mjs +64 -0
  141. package/src/props-listener.mjs +56 -0
  142. package/src/react-checks.mjs +67 -0
  143. package/src/server-state-checks.mjs +34 -0
  144. package/src/share-checks.mjs +158 -0
  145. package/src/site.mjs +46 -0
  146. package/src/slots.mjs +181 -0
  147. package/src/start/build.mjs +116 -0
  148. package/src/start/routes.mjs +38 -0
  149. package/src/start.mjs +394 -0
  150. package/src/state-checks/core-state.mjs +223 -0
  151. package/src/state-checks/modules.mjs +17 -0
  152. package/src/state-checks/scan.mjs +232 -0
  153. package/src/state-checks/server-graph.mjs +65 -0
  154. package/src/state-checks.mjs +189 -0
  155. package/src/style/find.mjs +121 -0
  156. package/src/style.mjs +327 -0
  157. package/src/surface-checks.mjs +384 -0
  158. package/src/tailwind.mjs +23 -0
  159. package/src/tasks.mjs +261 -0
  160. package/src/test-rules/context.mjs +109 -0
  161. package/src/test-rules/file-rules.mjs +279 -0
  162. package/src/test-rules/rule-helpers.mjs +244 -0
  163. package/src/test-rules/syntax.mjs +223 -0
  164. package/src/test-rules/test-rules.mjs +127 -0
  165. package/src/testdiff.mjs +219 -0
  166. package/src/tests.mjs +120 -0
  167. package/src/text-checks.mjs +332 -0
  168. package/src/tokens.mjs +33 -0
  169. package/src/trust/scan.mjs +95 -0
  170. package/src/trust.mjs +394 -0
  171. package/src/workspace.mjs +182 -0
  172. package/ts-plugin/context.js +57 -0
  173. package/ts-plugin/index.js +17 -0
  174. package/ts-plugin/mapping.js +65 -0
  175. package/ts-plugin/package.json +1 -0
  176. package/ts-plugin/proxy.js +144 -0
@@ -0,0 +1,128 @@
1
+ // A small JSX view of one .tsx/.jsx file (research 26 §2.5, §7), shared by the X-code pass and plugin `check` hooks:
2
+ // imports, every element with its attributes and ancestors, and the file's function bodies by name. TypeScript's
3
+ // parser only, no type checking.
4
+
5
+ import ts from 'typescript'
6
+
7
+ /**
8
+ * @typedef {{ name: string, kind: 'string' | 'expr' | 'bool' | 'spread', value?: string, expr?: string, start: number, end: number, valueStart?: number, valueEnd?: number }} Attr
9
+ * @typedef {{ name: string, attrs: Attr[], attr: (n: string) => Attr | undefined, ancestors: string[], start: number, end: number, tagEnd: number, children: string }} Element
10
+ * @typedef {{ local: string, imported?: string, source: string, start: number, end: number }} Import
11
+ */
12
+
13
+ /**
14
+ * @param {string} text
15
+ * @param {string} [file]
16
+ * @returns {{ imports: Import[], elements: Element[], functions: Map<string, string> }}
17
+ */
18
+ export function scanJsx(text, file = 'file.tsx') {
19
+ const sf = ts.createSourceFile(
20
+ file,
21
+ text,
22
+ ts.ScriptTarget.Latest,
23
+ true,
24
+ file.endsWith('.jsx') ? ts.ScriptKind.JSX : ts.ScriptKind.TSX,
25
+ )
26
+ const imports = []
27
+ const elements = []
28
+ const functions = new Map()
29
+ const stack = []
30
+
31
+ const record = (open, node) => {
32
+ const attrs = attrsOf(sf, open.attributes)
33
+ const el = {
34
+ name: open.tagName.getText(sf),
35
+ attrs,
36
+ attr: (n) => attrs.find((a) => a.name === n),
37
+ ancestors: [...stack],
38
+ start: node.getStart(sf),
39
+ end: node.end,
40
+ tagEnd: open.tagName.end,
41
+ children: ts.isJsxElement(node) ? node.children.map((c) => c.getText(sf)).join('') : '',
42
+ }
43
+ elements.push(el)
44
+ return el
45
+ }
46
+
47
+ const visit = (node) => {
48
+ if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
49
+ const source = node.moduleSpecifier.text
50
+ const c = node.importClause
51
+ const at = { source, start: node.getStart(sf), end: node.end }
52
+ if (c?.name) imports.push({ local: c.name.text, ...at })
53
+ if (c?.namedBindings && ts.isNamedImports(c.namedBindings))
54
+ for (const s of c.namedBindings.elements)
55
+ imports.push({ local: s.name.text, imported: s.propertyName?.text ?? s.name.text, ...at })
56
+ if (!c) imports.push({ local: '', ...at })
57
+ }
58
+ if (ts.isFunctionDeclaration(node) && node.name && node.body)
59
+ functions.set(node.name.text, node.body.getText(sf))
60
+ if (
61
+ ts.isVariableDeclaration(node) &&
62
+ ts.isIdentifier(node.name) &&
63
+ node.initializer &&
64
+ (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))
65
+ ) {
66
+ functions.set(node.name.text, node.initializer.body.getText(sf))
67
+ }
68
+ if (ts.isJsxSelfClosingElement(node)) {
69
+ record(node, node)
70
+ } else if (ts.isJsxElement(node)) {
71
+ const el = record(node.openingElement, node)
72
+ // attribute expressions (a `pending={<X />}`) see this element as an ancestor too
73
+ stack.push(el.name)
74
+ ts.forEachChild(node, visit)
75
+ stack.pop()
76
+ return
77
+ }
78
+ ts.forEachChild(node, visit)
79
+ }
80
+ visit(sf)
81
+ return { imports, elements, functions }
82
+ }
83
+
84
+ /** The import an identifier in an expression (`{hero}`, `{hero.src}`) comes from, or undefined. */
85
+ export function importOf(scan, expr) {
86
+ const id = /^\s*([A-Za-z_$][\w$]*)/.exec(expr ?? '')?.[1]
87
+ return id ? scan.imports.find((i) => i.local === id) : undefined
88
+ }
89
+
90
+ function attrsOf(sf, attributes) {
91
+ return attributes.properties.map((p) => {
92
+ if (ts.isJsxSpreadAttribute(p))
93
+ return {
94
+ name: '...',
95
+ kind: 'spread',
96
+ expr: p.expression.getText(sf),
97
+ start: p.getStart(sf),
98
+ end: p.end,
99
+ }
100
+ const name = p.name.getText(sf)
101
+ const base = { name, start: p.getStart(sf), end: p.end }
102
+ if (!p.initializer) return { ...base, kind: 'bool' }
103
+ if (ts.isStringLiteral(p.initializer))
104
+ return {
105
+ ...base,
106
+ kind: 'string',
107
+ value: p.initializer.text,
108
+ valueStart: p.initializer.getStart(sf),
109
+ valueEnd: p.initializer.end,
110
+ }
111
+ const e = p.initializer.expression
112
+ if (e && (ts.isStringLiteral(e) || ts.isNoSubstitutionTemplateLiteral(e)))
113
+ return {
114
+ ...base,
115
+ kind: 'string',
116
+ value: e.text,
117
+ valueStart: e.getStart(sf),
118
+ valueEnd: e.end,
119
+ }
120
+ return {
121
+ ...base,
122
+ kind: 'expr',
123
+ expr: e ? e.getText(sf) : '',
124
+ valueStart: e?.getStart(sf),
125
+ valueEnd: e?.end,
126
+ }
127
+ })
128
+ }
package/src/kerf.mjs ADDED
@@ -0,0 +1,98 @@
1
+ // The installed kerf: its compiler (only through the public `@kerf-js/core/compiler` transform()), version and exports.
2
+
3
+ import { existsSync, readFileSync } from 'node:fs'
4
+ import { createRequire } from 'node:module'
5
+ import { dirname, join } from 'node:path'
6
+ import ts from 'typescript'
7
+
8
+ const own = createRequire(import.meta.url)
9
+
10
+ /** The project's own kerf wins; the CLI's kerf (its dev/peer dependency) is the fallback. */
11
+ export function resolveKerf(root) {
12
+ const tries = [
13
+ () => createRequire(join(root, 'package.json')).resolve('@kerf-js/core/compiler'),
14
+ () => own.resolve('@kerf-js/core/compiler'),
15
+ ]
16
+ for (const [i, attempt] of tries.entries()) {
17
+ let path
18
+ try {
19
+ path = attempt()
20
+ } catch {
21
+ continue
22
+ }
23
+ let dir = dirname(path)
24
+ while (!existsSync(join(dir, 'package.json')) && dirname(dir) !== dir) dir = dirname(dir)
25
+ const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
26
+ return { from: i === 0 ? 'project' : 'cli', dir, version: pkg.version, pkg, compilerPath: path }
27
+ }
28
+ throw Object.assign(
29
+ new Error(
30
+ 'kerf is not installed: `@kerf-js/core/compiler` resolves neither from the project nor from @kerf-js/cli',
31
+ ),
32
+ { code: 'E_NO_KERF' },
33
+ )
34
+ }
35
+
36
+ const compilers = new Map()
37
+
38
+ /** @returns {{ transform(source: string, options?: object): { code: string | null, diagnostics: any[] } }} */
39
+ export function loadCompiler(kerf) {
40
+ if (!compilers.has(kerf.compilerPath)) compilers.set(kerf.compilerPath, own(kerf.compilerPath))
41
+ return compilers.get(kerf.compilerPath)
42
+ }
43
+
44
+ /** Exported names per public subpath, read from the installed package's entry files (no execution). */
45
+ export function exportsOf(
46
+ kerf,
47
+ subpaths = [
48
+ '.',
49
+ './dom',
50
+ './ssr',
51
+ './test',
52
+ './browser',
53
+ './interaction',
54
+ './style',
55
+ './surface',
56
+ ],
57
+ ) {
58
+ const out = {}
59
+ for (const sub of subpaths) {
60
+ const target = kerf.pkg.exports?.[sub]
61
+ const file = typeof target === 'string' ? join(kerf.dir, target) : null
62
+ if (!file || !/\.[mc]?[jt]sx?$/.test(file) || !existsSync(file)) continue
63
+ /** @type {Set<string>} */
64
+ const names = new Set()
65
+ const read = (path) => {
66
+ const sf = ts.createSourceFile(path, readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true)
67
+ for (const node of sf.statements) {
68
+ const exported =
69
+ ts.canHaveModifiers(node) &&
70
+ ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)
71
+ if (ts.isExportDeclaration(node) && !node.exportClause && !node.isTypeOnly) {
72
+ // `export * from './index'`: the `kerf` entry is a thin one over the runtime.
73
+ const next = join(dirname(path), `${node.moduleSpecifier.text}.ts`)
74
+ if (existsSync(next)) read(next)
75
+ } else if (
76
+ ts.isExportDeclaration(node) &&
77
+ node.exportClause &&
78
+ ts.isNamedExports(node.exportClause)
79
+ ) {
80
+ if (!node.isTypeOnly)
81
+ for (const el of node.exportClause.elements) if (!el.isTypeOnly) names.add(el.name.text)
82
+ } else if (
83
+ exported &&
84
+ (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) &&
85
+ node.name
86
+ ) {
87
+ names.add(node.name.text)
88
+ } else if (exported && ts.isVariableStatement(node)) {
89
+ for (const d of node.declarationList.declarations)
90
+ if (ts.isIdentifier(d.name)) names.add(d.name.text)
91
+ }
92
+ }
93
+ }
94
+ read(file)
95
+ out[sub === '.' ? '@kerf-js/core' : `@kerf-js/core/${sub.slice(2)}`] = [...names].sort()
96
+ }
97
+ return out
98
+ }
@@ -0,0 +1,300 @@
1
+ /** `site.limits` and `site.security`: what Start's server does with requests and responses. */
2
+ function serverSite(z) {
3
+ return {
4
+ limits: z
5
+ .strictObject({
6
+ body: z.int().positive().optional(),
7
+ upload: z.int().positive().optional(),
8
+ })
9
+ .optional(),
10
+ security: z
11
+ .union([z.literal(false), z.record(z.string(), z.union([z.string(), z.literal(false)]))])
12
+ .optional(),
13
+ trustProxy: z.union([z.boolean(), z.int().positive()]).optional(),
14
+ log: z.enum(['text', 'json']).optional(),
15
+ }
16
+ }
17
+
18
+ function baseSchemas(z) {
19
+ const zodSchema = z.custom(
20
+ (v) => v != null && typeof v === 'object' && ('_zod' in v || '~standard' in v),
21
+ )
22
+ const globs = z.array(z.string())
23
+
24
+ const task = z.strictObject({
25
+ run: z.string().min(1),
26
+ description: z.string().optional(),
27
+ sideEffects: z.array(z.string()).optional(),
28
+ env: z.array(z.string()).optional(),
29
+ args: z.union([zodSchema, z.record(z.string(), z.unknown())]).optional(),
30
+ })
31
+
32
+ const pluginEntry = z.looseObject({
33
+ name: z.string().min(1),
34
+ version: z.string().optional(),
35
+ provides: z
36
+ .array(z.union([z.string(), z.strictObject({ slot: z.string(), key: z.string() })]))
37
+ .optional(),
38
+ })
39
+
40
+ const image = z.strictObject({
41
+ url: z.string().min(1),
42
+ width: z.int().positive().optional(),
43
+ height: z.int().positive().optional(),
44
+ alt: z.string().optional(),
45
+ })
46
+
47
+ const hex = z.string().regex(/^#[0-9a-fA-F]{6}$/, { error: 'must be #rrggbb' })
48
+ const colors = {
49
+ background: hex.optional(),
50
+ text: hex.optional(),
51
+ subtle: hex.optional(),
52
+ accent: hex.optional(),
53
+ }
54
+ const cardFont = z.strictObject({
55
+ family: z.string().regex(/^[\w -]+$/, { error: 'must be a font family name' }),
56
+ src: z.string().min(1),
57
+ weight: z.number().optional(),
58
+ })
59
+ const card = z.strictObject({
60
+ ...colors,
61
+ scheme: z.enum(['dark', 'light']).optional(),
62
+ dark: z.strictObject(colors).optional(),
63
+ light: z.strictObject(colors).optional(),
64
+ fonts: z.strictObject({ display: cardFont.optional(), body: cardFont.optional() }).optional(),
65
+ })
66
+
67
+ const site = z.strictObject({
68
+ headers: z.record(z.string(), z.record(z.string(), z.string())).optional(),
69
+ name: z.string().min(1).optional(),
70
+ url: z.url({ protocol: /^https?$/, error: 'must be an absolute http(s) URL' }).optional(),
71
+ title: z.string().includes('%s', { error: 'must contain `%s` (the page title)' }).optional(),
72
+ description: z.string().optional(),
73
+ locale: z
74
+ .string()
75
+ .regex(/^[a-z]{2,3}(_[A-Z]{2})?$/, { error: 'must look like `en_US`' })
76
+ .optional(),
77
+ inlineCss: z.boolean().optional(),
78
+ criticalCss: z.boolean().optional(),
79
+ criticalKeep: z.array(z.string()).optional(),
80
+ csp: z.literal('strict').optional(),
81
+ ...serverSite(z),
82
+ image: z.union([z.literal('auto'), z.literal(false), z.string().min(1), image]).optional(),
83
+ card: card.optional(),
84
+ head: z.string().optional(),
85
+ twitter: z
86
+ .strictObject({
87
+ card: z.enum(['summary', 'summary_large_image', 'app', 'player']).optional(),
88
+ site: z.string().optional(),
89
+ creator: z.string().optional(),
90
+ })
91
+ .optional(),
92
+ })
93
+
94
+ return { globs, task, pluginEntry, site }
95
+ }
96
+
97
+ function mainProperties(z, { globs, task, pluginEntry, site }) {
98
+ return {
99
+ scope: z
100
+ .strictObject({ write: globs.optional(), read: globs.optional(), forbid: globs.optional() })
101
+ .optional(),
102
+ tasks: z.record(z.string(), task).optional(),
103
+ environments: z.record(z.string(), z.looseObject({ url: z.string().optional() })).optional(),
104
+ test: z
105
+ .strictObject({
106
+ include: globs.optional(),
107
+ lanes: z.array(z.enum(['fast', 'browser', 'e2e'])).optional(),
108
+ gate: z
109
+ .strictObject({
110
+ mutationBudgetSec: z.number().positive().optional(),
111
+ maxMutants: z.number().int().positive().optional(),
112
+ })
113
+ .optional(),
114
+ })
115
+ .optional(),
116
+ build: z
117
+ .strictObject({
118
+ audit: z
119
+ .union([
120
+ z.boolean(),
121
+ z.strictObject({
122
+ routes: z.array(z.string()).optional(),
123
+ all: z.boolean().optional(),
124
+ max: z.number().int().positive().optional(),
125
+ indexing: z.enum(['auto', 'public', 'private']).optional(),
126
+ }),
127
+ ])
128
+ .optional(),
129
+ unsafeAllow: z
130
+ .record(
131
+ z.string().regex(/^(all|[A-Z]|[A-Z]+\d{3})$/, 'a code (R002), a family (L) or all'),
132
+ z.string().min(1, 'say why'),
133
+ )
134
+ .optional(),
135
+ })
136
+ .optional(),
137
+ check: z
138
+ .strictObject({
139
+ include: globs.optional(),
140
+ exclude: globs.optional(),
141
+ design: z.boolean().optional(),
142
+ routes: z.boolean().optional(),
143
+ props: z.union([z.boolean(), z.literal('manual')]).optional(),
144
+ })
145
+ .optional(),
146
+ plugins: z.array(pluginEntry).optional(),
147
+ slots: z.record(z.string(), z.union([z.string(), z.record(z.string(), z.string())])).optional(),
148
+ site: site.optional(),
149
+ runtime: z.enum(['node', 'bun', 'deno']).optional(),
150
+ hydration: z.enum(['lazy', 'partial', 'full']).optional(),
151
+ rust: z
152
+ .strictObject({
153
+ unions: z.literal('allow').optional(),
154
+ services: z
155
+ .record(
156
+ z.string(),
157
+ z.strictObject({
158
+ crate: z.string().optional(),
159
+ external: z.boolean().optional(),
160
+ wasm: z.literal(false).optional(),
161
+ }),
162
+ )
163
+ .optional(),
164
+ })
165
+ .optional(),
166
+ }
167
+ }
168
+
169
+ function deployFirst(z) {
170
+ return {
171
+ target: z.enum(['netlify', 'vercel', 'cloudflare', 'fly', 'render']).optional(),
172
+ netlify: z.strictObject({ site: z.string().min(1).optional() }).optional(),
173
+ vercel: z
174
+ .strictObject({
175
+ project: z
176
+ .string()
177
+ .regex(/^[a-z0-9][a-z0-9-]{0,62}$/i, 'a name: letters, digits and dashes')
178
+ .optional(),
179
+ })
180
+ .optional(),
181
+ cloudflare: z
182
+ .strictObject({
183
+ name: z
184
+ .string()
185
+ .regex(/^[a-z0-9][a-z0-9-]{0,62}$/i, 'a name: letters, digits and dashes')
186
+ .optional(),
187
+ })
188
+ .optional(),
189
+ }
190
+ }
191
+
192
+ function deployFly(z) {
193
+ return {
194
+ fly: z
195
+ .strictObject({
196
+ app: z
197
+ .string()
198
+ .regex(/^[a-z0-9][a-z0-9-]{0,62}$/i, 'a name: letters, digits and dashes')
199
+ .optional(),
200
+ region: z
201
+ .string()
202
+ .regex(/^[a-z]{3}$/, 'a Fly region code, like `iad`')
203
+ .optional(),
204
+ memory: z
205
+ .string()
206
+ .regex(/^\d+(mb|gb)$/, 'like `512mb`')
207
+ .optional(),
208
+ volume: z
209
+ .strictObject({
210
+ name: z
211
+ .string()
212
+ .regex(/^[a-z0-9_]+$/, 'lowercase letters, digits and underscores')
213
+ .optional(),
214
+ path: z.string().startsWith('/').optional(),
215
+ sizeGb: z.number().int().positive().optional(),
216
+ })
217
+ .optional(),
218
+ })
219
+ .optional(),
220
+ }
221
+ }
222
+
223
+ function deployRest(z) {
224
+ return {
225
+ render: z
226
+ .strictObject({
227
+ service: z
228
+ .string()
229
+ .regex(/^[a-z0-9][a-z0-9-]{0,62}$/i, 'a name: letters, digits and dashes')
230
+ .optional(),
231
+ plan: z.string().optional(),
232
+ region: z.string().optional(),
233
+ disk: z
234
+ .strictObject({
235
+ path: z.string().startsWith('/').optional(),
236
+ sizeGb: z.number().int().positive().optional(),
237
+ })
238
+ .optional(),
239
+ })
240
+ .optional(),
241
+ ci: z.union([z.literal('github'), z.literal(false)]).optional(),
242
+ branch: z.string().min(1).optional(),
243
+ cdn: z
244
+ .strictObject({
245
+ proxy: z.literal('cloudflare').optional(),
246
+ images: z
247
+ .strictObject({
248
+ provider: z.literal('cloudinary'),
249
+ cloud: z
250
+ .string()
251
+ .regex(/^[\w-]+$/, "the cloud's name, not its URL")
252
+ .optional(),
253
+ })
254
+ .optional(),
255
+ })
256
+ .optional(),
257
+ }
258
+ }
259
+
260
+ function deploySchema(z) {
261
+ return z.strictObject({ ...deployFirst(z), ...deployFly(z), ...deployRest(z) }).optional()
262
+ }
263
+
264
+ function remainingProperties(z) {
265
+ return {
266
+ /** Named targets for a query's `live: { verify: 'staging' }`. `db` is an env var's name. */
267
+ live: z
268
+ .strictObject({
269
+ targets: z
270
+ .record(
271
+ z.string(),
272
+ z.strictObject({
273
+ url: z.string().optional(),
274
+ db: z.string().optional(),
275
+ production: z.boolean().optional(),
276
+ }),
277
+ )
278
+ .optional(),
279
+ })
280
+ .optional(),
281
+ trust: z.enum(['enforce', 'warn']).optional(),
282
+ }
283
+ }
284
+
285
+ export function createSchemas(z) {
286
+ const base = baseSchemas(z)
287
+ const configSchema = z.strictObject({
288
+ ...mainProperties(z, base),
289
+ deploy: deploySchema(z),
290
+ ...remainingProperties(z),
291
+ })
292
+ const { pluginEntry } = base
293
+ const dataSchema = configSchema.extend({
294
+ $schema: z.string().optional(),
295
+ plugins: z
296
+ .array(z.union([z.string(), z.tuple([z.string(), z.unknown()]), pluginEntry]))
297
+ .optional(),
298
+ })
299
+ return { configSchema, dataSchema }
300
+ }