@prenta/cli 1.3.3 → 1.5.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.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +67 -53
- package/CHANGELOG.md +48 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +86 -31
- package/dist/commands/doctor.js.map +1 -1
- package/dist/deployment/diagnostics.d.ts +67 -2
- package/dist/deployment/diagnostics.d.ts.map +1 -1
- package/dist/deployment/diagnostics.js +500 -90
- package/dist/deployment/diagnostics.js.map +1 -1
- package/dist/deployment/health-check.d.ts +15 -0
- package/dist/deployment/health-check.d.ts.map +1 -0
- package/dist/deployment/health-check.js +85 -0
- package/dist/deployment/health-check.js.map +1 -0
- package/dist/deployment/layout.d.ts +19 -0
- package/dist/deployment/layout.d.ts.map +1 -0
- package/dist/deployment/layout.js +67 -0
- package/dist/deployment/layout.js.map +1 -0
- package/dist/vercel/env-matrix.d.ts +11 -1
- package/dist/vercel/env-matrix.d.ts.map +1 -1
- package/dist/vercel/env-matrix.js +6 -1
- package/dist/vercel/env-matrix.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/deployment-diagnostics.test.ts +1 -1
- package/src/__tests__/doctor-astro-split.test.ts +376 -0
- package/src/__tests__/doctor-env-shape-fallback.test.ts +44 -0
- package/src/__tests__/rate-limit-backend.test.ts +259 -0
- package/src/__tests__/vercel-cron-plan.test.ts +71 -0
- package/src/commands/doctor.ts +104 -29
- package/src/deployment/diagnostics.ts +569 -95
- package/src/deployment/health-check.ts +114 -0
- package/src/deployment/layout.ts +90 -0
- package/src/vercel/env-matrix.ts +22 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1262: Vercel Hobby allows crons at most once a day and fails the deployment
|
|
3
|
+
* for anything more frequent. `prenta doctor` / `deploy:check` warn about such
|
|
4
|
+
* crons in the CMS host's vercel.json.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { createDiagnosticReport, cronRunsMoreThanDaily } from '../deployment/diagnostics.js'
|
|
9
|
+
|
|
10
|
+
describe('cronRunsMoreThanDaily', () => {
|
|
11
|
+
it.each(['*/5 * * * *', '0 * * * *', '*/30 * * * *', '0 0,12 * * *', '0 1-3 * * *', '* 1 * * *'])(
|
|
12
|
+
'flags %s, which Hobby rejects',
|
|
13
|
+
(schedule) => {
|
|
14
|
+
expect(cronRunsMoreThanDaily(schedule)).toBe(true)
|
|
15
|
+
},
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
it.each(['0 1 * * *', '30 2 * * *', '0 4 * * 1', '0 6 1 * *', '0 0 */2 * *'])(
|
|
19
|
+
'accepts %s, which runs at most once a day',
|
|
20
|
+
(schedule) => {
|
|
21
|
+
expect(cronRunsMoreThanDaily(schedule)).toBe(false)
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
it('treats a malformed expression as sub-daily rather than passing it', () => {
|
|
26
|
+
expect(cronRunsMoreThanDaily('daily')).toBe(true)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
function cronCheck(vercelJson: string | undefined) {
|
|
31
|
+
const report = createDiagnosticReport({
|
|
32
|
+
schemaModels: new Set(),
|
|
33
|
+
env: {},
|
|
34
|
+
packageManager: 'pnpm',
|
|
35
|
+
schemaPath: 'prisma/schema.prisma',
|
|
36
|
+
mode: 'deploy',
|
|
37
|
+
projectFiles: { vercelJson },
|
|
38
|
+
})
|
|
39
|
+
return report.checks.find((c) => c.id === 'vercel-cron-plan')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('vercel-cron-plan check', () => {
|
|
43
|
+
it('warns about the old 5-minute publish cron and names it', () => {
|
|
44
|
+
const check = cronCheck(
|
|
45
|
+
JSON.stringify({
|
|
46
|
+
crons: [
|
|
47
|
+
{ path: '/api/cms/cron/publish', schedule: '*/5 * * * *' },
|
|
48
|
+
{ path: '/api/cms/cron/cleanup', schedule: '0 3 * * *' },
|
|
49
|
+
],
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
expect(check?.status).toBe('warn')
|
|
53
|
+
expect(check?.message).toContain('/api/cms/cron/publish (*/5 * * * *)')
|
|
54
|
+
expect(check?.message).not.toContain('cleanup')
|
|
55
|
+
expect(check?.message).toContain('Hobby')
|
|
56
|
+
expect(check?.fix).toContain('0 1 * * *')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('passes a Hobby-safe vercel.json', () => {
|
|
60
|
+
const check = cronCheck(
|
|
61
|
+
JSON.stringify({ crons: [{ path: '/api/cms/cron/publish', schedule: '0 1 * * *' }] }),
|
|
62
|
+
)
|
|
63
|
+
expect(check?.status).toBe('pass')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('says nothing without a vercel.json, or one without crons or valid JSON', () => {
|
|
67
|
+
expect(cronCheck(undefined)).toBeUndefined()
|
|
68
|
+
expect(cronCheck(JSON.stringify({ framework: 'nextjs' }))).toBeUndefined()
|
|
69
|
+
expect(cronCheck('{ not json')).toBeUndefined()
|
|
70
|
+
})
|
|
71
|
+
})
|
package/src/commands/doctor.ts
CHANGED
|
@@ -10,8 +10,12 @@ import {
|
|
|
10
10
|
type ProjectFileSignals,
|
|
11
11
|
VERCEL_MATRIX_OPTIONAL,
|
|
12
12
|
VERCEL_MATRIX_REQUIRED,
|
|
13
|
+
VERCEL_MATRIX_REQUIRED_ONE_OF,
|
|
13
14
|
type DiagnosticReport,
|
|
15
|
+
type EnvShapeSummary,
|
|
14
16
|
} from '../deployment/diagnostics.js'
|
|
17
|
+
import { resolveProjectLayout, type ProjectLayout } from '../deployment/layout.js'
|
|
18
|
+
import { checkHealthResponse } from '../deployment/health-check.js'
|
|
15
19
|
import {
|
|
16
20
|
createVercelClient,
|
|
17
21
|
readVercelLink,
|
|
@@ -63,7 +67,10 @@ async function readFirstExistingFile(cwd: string, candidates: string[]): Promise
|
|
|
63
67
|
return ''
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
async function readProjectFileSignals(
|
|
70
|
+
async function readProjectFileSignals(layout: ProjectLayout): Promise<ProjectFileSignals> {
|
|
71
|
+
const cms = layout.cmsRoot
|
|
72
|
+
const site = layout.siteRoot
|
|
73
|
+
const fromSite = (relative: string) => (site ? readOptionalFile(resolve(site, relative)) : '')
|
|
67
74
|
const [
|
|
68
75
|
catchAllPage,
|
|
69
76
|
cmsLib,
|
|
@@ -78,24 +85,29 @@ async function readProjectFileSignals(cwd: string): Promise<ProjectFileSignals>
|
|
|
78
85
|
astroConfigMjs,
|
|
79
86
|
astroConfigTs,
|
|
80
87
|
backupWorkflowPresent,
|
|
88
|
+
vercelJson,
|
|
89
|
+
siteVercelJson,
|
|
90
|
+
siteEnv,
|
|
81
91
|
] = await Promise.all([
|
|
82
|
-
readFirstExistingFile(
|
|
83
|
-
readOptionalFile(resolve(
|
|
84
|
-
readOptionalFile(resolve(
|
|
85
|
-
readFirstExistingFile(
|
|
86
|
-
readOptionalFile(resolve(
|
|
87
|
-
readOptionalFile(resolve(
|
|
88
|
-
readOptionalFile(resolve(
|
|
89
|
-
readOptionalFile(resolve(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
readOptionalFile(resolve(cwd, 'site/astro.config.ts')),
|
|
92
|
+
readFirstExistingFile(cms, ['app/(site)/[[...path]]/page.tsx', 'app/[[...path]]/page.tsx']),
|
|
93
|
+
readOptionalFile(resolve(cms, 'lib/cms.ts')),
|
|
94
|
+
readOptionalFile(resolve(cms, 'app/api/cms/[[...cms]]/route.ts')),
|
|
95
|
+
readFirstExistingFile(cms, ['next.config.ts', 'next.config.mjs', 'next.config.js']),
|
|
96
|
+
readOptionalFile(resolve(cms, 'app/llms.txt/route.ts')),
|
|
97
|
+
readOptionalFile(resolve(cms, 'app/robots.txt/route.ts')),
|
|
98
|
+
readOptionalFile(resolve(cms, 'app/sitemap.xml/route.ts')),
|
|
99
|
+
readOptionalFile(resolve(cms, 'prenta.seed.json')),
|
|
100
|
+
fromSite('src/lib/cms.ts'),
|
|
101
|
+
site
|
|
102
|
+
? readFirstExistingFile(site, ['src/pages/[...path].astro', 'src/pages/[...slug].astro'])
|
|
103
|
+
: '',
|
|
104
|
+
fromSite('astro.config.mjs'),
|
|
105
|
+
fromSite('astro.config.ts'),
|
|
97
106
|
// Workflows live at the git top-level, not next to the CMS app (apps/cms).
|
|
98
|
-
fileExists(resolve(findRepoRoot(
|
|
107
|
+
fileExists(resolve(findRepoRoot(cms), DB_BACKUP_WORKFLOW_PATH)),
|
|
108
|
+
readOptionalFile(resolve(cms, 'vercel.json')),
|
|
109
|
+
fromSite('vercel.json'),
|
|
110
|
+
site ? readSiteEnv(site) : undefined,
|
|
99
111
|
])
|
|
100
112
|
|
|
101
113
|
return {
|
|
@@ -109,8 +121,43 @@ async function readProjectFileSignals(cwd: string): Promise<ProjectFileSignals>
|
|
|
109
121
|
seedFile,
|
|
110
122
|
astroCmsLib,
|
|
111
123
|
astroCatchAll,
|
|
112
|
-
astroConfigPresent: Boolean(astroConfigMjs || astroConfigTs),
|
|
124
|
+
astroConfigPresent: Boolean(astroConfigMjs || astroConfigTs || site),
|
|
113
125
|
backupWorkflowPresent,
|
|
126
|
+
vercelJson,
|
|
127
|
+
siteLabel: layout.siteLabel,
|
|
128
|
+
siteVercelJson,
|
|
129
|
+
siteEnv,
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The Astro site's local env files only (no process.env): `undefined` when it
|
|
135
|
+
* has none, since its deployed env then lives only on its own Vercel project.
|
|
136
|
+
*/
|
|
137
|
+
async function readSiteEnv(
|
|
138
|
+
siteRoot: string,
|
|
139
|
+
): Promise<Record<string, string | undefined> | undefined> {
|
|
140
|
+
const present = (
|
|
141
|
+
await Promise.all(['.env', '.env.local'].map((f) => fileExists(resolve(siteRoot, f))))
|
|
142
|
+
).some(Boolean)
|
|
143
|
+
return present ? loadProjectEnv(siteRoot, {}) : undefined
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* `validateEnvShape` from `@prenta/core/diagnostics`, the same rules /health
|
|
148
|
+
* applies. Older cores lack the entry; doctor then falls back to presence checks.
|
|
149
|
+
*/
|
|
150
|
+
async function readEnvShape(
|
|
151
|
+
env: Record<string, string | undefined>,
|
|
152
|
+
): Promise<EnvShapeSummary | null> {
|
|
153
|
+
try {
|
|
154
|
+
const mod = (await import('@prenta/core/diagnostics')) as {
|
|
155
|
+
validateEnvShape?: (source: { get(name: string): string | undefined }) => EnvShapeSummary
|
|
156
|
+
}
|
|
157
|
+
if (typeof mod.validateEnvShape !== 'function') return null
|
|
158
|
+
return mod.validateEnvShape({ get: (name) => env[name] })
|
|
159
|
+
} catch {
|
|
160
|
+
return null
|
|
114
161
|
}
|
|
115
162
|
}
|
|
116
163
|
|
|
@@ -129,7 +176,9 @@ function printReport(title: string, report: DiagnosticReport): void {
|
|
|
129
176
|
? chalk.green('PASS')
|
|
130
177
|
: check.status === 'warn'
|
|
131
178
|
? chalk.yellow('WARN')
|
|
132
|
-
:
|
|
179
|
+
: check.status === 'skip'
|
|
180
|
+
? chalk.dim('SKIP')
|
|
181
|
+
: chalk.red('FAIL')
|
|
133
182
|
console.log(`${icon} ${check.label}: ${check.message}`)
|
|
134
183
|
if (check.fix) console.log(chalk.dim(` Fix: ${check.fix}`))
|
|
135
184
|
if (check.docs) console.log(chalk.dim(` Docs: ${check.docs}`))
|
|
@@ -144,19 +193,27 @@ async function buildReport(
|
|
|
144
193
|
configPath: string,
|
|
145
194
|
mode: 'doctor' | 'deploy' = 'doctor',
|
|
146
195
|
) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
196
|
+
const layout = await resolveProjectLayout(process.cwd())
|
|
197
|
+
// A path that exists from the current folder is taken as given (an explicit
|
|
198
|
+
// `--schema apps/cms/prisma/schema.prisma` from the root); otherwise it is
|
|
199
|
+
// relative to the CMS, which from an astro-split root is apps/cms.
|
|
200
|
+
const fromCwdOrCms = async (path: string) =>
|
|
201
|
+
(await fileExists(resolve(process.cwd(), path)))
|
|
202
|
+
? resolve(process.cwd(), path)
|
|
203
|
+
: resolve(layout.cmsRoot, path)
|
|
204
|
+
const resolvedSchema = await fromCwdOrCms(schemaPath)
|
|
205
|
+
const resolvedConfig = await fromCwdOrCms(configPath)
|
|
150
206
|
const [schemaModels, schemaContent, configContent, packageManager, projectFiles] =
|
|
151
207
|
await Promise.all([
|
|
152
208
|
readSchemaModels(resolvedSchema),
|
|
153
209
|
readSchemaContent(resolvedSchema),
|
|
154
210
|
readOptionalFile(resolvedConfig),
|
|
155
211
|
detectProjectPackageManager(),
|
|
156
|
-
readProjectFileSignals(
|
|
212
|
+
readProjectFileSignals(layout),
|
|
157
213
|
])
|
|
158
214
|
|
|
159
|
-
const env = await loadProjectEnv(
|
|
215
|
+
const env = await loadProjectEnv(layout.cmsRoot)
|
|
216
|
+
const envShape = await readEnvShape(env)
|
|
160
217
|
|
|
161
218
|
return createDiagnosticReport({
|
|
162
219
|
schemaModels,
|
|
@@ -167,6 +224,7 @@ async function buildReport(
|
|
|
167
224
|
schemaPath,
|
|
168
225
|
mode,
|
|
169
226
|
projectFiles,
|
|
227
|
+
envShape,
|
|
170
228
|
})
|
|
171
229
|
}
|
|
172
230
|
|
|
@@ -231,7 +289,12 @@ async function runVercelMatrix(opts: {
|
|
|
231
289
|
const client = createVercelClient({ token, teamId: link.orgId ?? opts.org })
|
|
232
290
|
try {
|
|
233
291
|
const envVars = await client.listProjectEnv(link.projectId)
|
|
234
|
-
const matrix = buildEnvMatrix(
|
|
292
|
+
const matrix = buildEnvMatrix(
|
|
293
|
+
envVars,
|
|
294
|
+
VERCEL_MATRIX_REQUIRED,
|
|
295
|
+
VERCEL_MATRIX_OPTIONAL,
|
|
296
|
+
VERCEL_MATRIX_REQUIRED_ONE_OF,
|
|
297
|
+
)
|
|
235
298
|
if (!opts.json) {
|
|
236
299
|
printEnvMatrix(matrix)
|
|
237
300
|
if (matrix.missingCritical.length > 0) {
|
|
@@ -336,10 +399,22 @@ export function registerVerifyCommand(program: Command): void {
|
|
|
336
399
|
const adminUrl = `${origin}${manifest.routes.adminDefault}`
|
|
337
400
|
let failed = false
|
|
338
401
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
402
|
+
try {
|
|
403
|
+
const health = await checkHealthResponse(
|
|
404
|
+
await fetch(healthUrl, { method: 'GET' }),
|
|
405
|
+
healthUrl,
|
|
406
|
+
)
|
|
407
|
+
if (health.verdict === 'fail') failed = true
|
|
408
|
+
const [summary, ...details] = health.lines
|
|
409
|
+
console.log(`${health.verdict.toUpperCase()} ${summary}`)
|
|
410
|
+
for (const line of details) console.log(chalk.dim(` ${line}`))
|
|
411
|
+
} catch (error) {
|
|
412
|
+
failed = true
|
|
413
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
414
|
+
console.log(`FAIL Health route could not be reached at ${healthUrl}: ${message}`)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
for (const [label, url] of [['Admin', adminUrl]] as const) {
|
|
343
418
|
try {
|
|
344
419
|
const response = await fetch(url, { method: 'GET' })
|
|
345
420
|
if (response.ok || response.status === 302 || response.status === 401) {
|