@prenta/cli 1.4.0 → 1.5.1
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 +41 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +68 -25
- package/dist/commands/doctor.js.map +1 -1
- package/dist/deployment/diagnostics.d.ts +41 -1
- package/dist/deployment/diagnostics.d.ts.map +1 -1
- package/dist/deployment/diagnostics.js +422 -88
- package/dist/deployment/diagnostics.js.map +1 -1
- 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/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__/vercel-cron-plan.test.ts +71 -0
- package/src/commands/doctor.ts +80 -24
- package/src/deployment/diagnostics.ts +474 -93
- package/src/deployment/layout.ts +90 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1263: the CLI peers @prenta/core >=8.10, and only newer cores ship
|
|
3
|
+
* `@prenta/core/diagnostics`. With an older core, doctor must still run and
|
|
4
|
+
* report the value check as skipped, not crash.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
7
|
+
import { tmpdir } from 'node:os'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import { Command } from 'commander'
|
|
10
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
11
|
+
|
|
12
|
+
vi.mock('@prenta/core/diagnostics', () => {
|
|
13
|
+
throw new Error('Package subpath "./diagnostics" is not defined by "exports"')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const { registerDoctorCommand } = await import('../commands/doctor.js')
|
|
17
|
+
|
|
18
|
+
const originalCwd = process.cwd()
|
|
19
|
+
let root: string | undefined
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
process.chdir(originalCwd)
|
|
23
|
+
vi.restoreAllMocks()
|
|
24
|
+
process.exitCode = undefined
|
|
25
|
+
if (root) await rm(root, { recursive: true, force: true })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('skips the env value check when the installed core has no diagnostics entry', async () => {
|
|
29
|
+
root = await mkdtemp(path.join(tmpdir(), 'prenta-doctor-oldcore-'))
|
|
30
|
+
await writeFile(path.join(root, 'prenta.config.ts'), 'export default {}')
|
|
31
|
+
const out: string[] = []
|
|
32
|
+
vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
|
|
33
|
+
out.push(args.join(' '))
|
|
34
|
+
})
|
|
35
|
+
process.chdir(root)
|
|
36
|
+
const program = new Command()
|
|
37
|
+
program.exitOverride()
|
|
38
|
+
registerDoctorCommand(program)
|
|
39
|
+
await program.parseAsync(['node', 'prenta', 'doctor', '--json'])
|
|
40
|
+
vi.restoreAllMocks()
|
|
41
|
+
|
|
42
|
+
const report = JSON.parse(out.join('\n')) as { checks: Array<{ id: string; status: string }> }
|
|
43
|
+
expect(report.checks.find((c) => c.id === 'env-shape')).toMatchObject({ status: 'skip' })
|
|
44
|
+
})
|
|
@@ -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
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
VERCEL_MATRIX_REQUIRED,
|
|
13
13
|
VERCEL_MATRIX_REQUIRED_ONE_OF,
|
|
14
14
|
type DiagnosticReport,
|
|
15
|
+
type EnvShapeSummary,
|
|
15
16
|
} from '../deployment/diagnostics.js'
|
|
17
|
+
import { resolveProjectLayout, type ProjectLayout } from '../deployment/layout.js'
|
|
16
18
|
import { checkHealthResponse } from '../deployment/health-check.js'
|
|
17
19
|
import {
|
|
18
20
|
createVercelClient,
|
|
@@ -65,7 +67,10 @@ async function readFirstExistingFile(cwd: string, candidates: string[]): Promise
|
|
|
65
67
|
return ''
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
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)) : '')
|
|
69
74
|
const [
|
|
70
75
|
catchAllPage,
|
|
71
76
|
cmsLib,
|
|
@@ -80,24 +85,29 @@ async function readProjectFileSignals(cwd: string): Promise<ProjectFileSignals>
|
|
|
80
85
|
astroConfigMjs,
|
|
81
86
|
astroConfigTs,
|
|
82
87
|
backupWorkflowPresent,
|
|
88
|
+
vercelJson,
|
|
89
|
+
siteVercelJson,
|
|
90
|
+
siteEnv,
|
|
83
91
|
] = await Promise.all([
|
|
84
|
-
readFirstExistingFile(
|
|
85
|
-
readOptionalFile(resolve(
|
|
86
|
-
readOptionalFile(resolve(
|
|
87
|
-
readFirstExistingFile(
|
|
88
|
-
readOptionalFile(resolve(
|
|
89
|
-
readOptionalFile(resolve(
|
|
90
|
-
readOptionalFile(resolve(
|
|
91
|
-
readOptionalFile(resolve(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
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'),
|
|
99
106
|
// Workflows live at the git top-level, not next to the CMS app (apps/cms).
|
|
100
|
-
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,
|
|
101
111
|
])
|
|
102
112
|
|
|
103
113
|
return {
|
|
@@ -111,8 +121,43 @@ async function readProjectFileSignals(cwd: string): Promise<ProjectFileSignals>
|
|
|
111
121
|
seedFile,
|
|
112
122
|
astroCmsLib,
|
|
113
123
|
astroCatchAll,
|
|
114
|
-
astroConfigPresent: Boolean(astroConfigMjs || astroConfigTs),
|
|
124
|
+
astroConfigPresent: Boolean(astroConfigMjs || astroConfigTs || site),
|
|
115
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
|
|
116
161
|
}
|
|
117
162
|
}
|
|
118
163
|
|
|
@@ -131,7 +176,9 @@ function printReport(title: string, report: DiagnosticReport): void {
|
|
|
131
176
|
? chalk.green('PASS')
|
|
132
177
|
: check.status === 'warn'
|
|
133
178
|
? chalk.yellow('WARN')
|
|
134
|
-
:
|
|
179
|
+
: check.status === 'skip'
|
|
180
|
+
? chalk.dim('SKIP')
|
|
181
|
+
: chalk.red('FAIL')
|
|
135
182
|
console.log(`${icon} ${check.label}: ${check.message}`)
|
|
136
183
|
if (check.fix) console.log(chalk.dim(` Fix: ${check.fix}`))
|
|
137
184
|
if (check.docs) console.log(chalk.dim(` Docs: ${check.docs}`))
|
|
@@ -146,19 +193,27 @@ async function buildReport(
|
|
|
146
193
|
configPath: string,
|
|
147
194
|
mode: 'doctor' | 'deploy' = 'doctor',
|
|
148
195
|
) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
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)
|
|
152
206
|
const [schemaModels, schemaContent, configContent, packageManager, projectFiles] =
|
|
153
207
|
await Promise.all([
|
|
154
208
|
readSchemaModels(resolvedSchema),
|
|
155
209
|
readSchemaContent(resolvedSchema),
|
|
156
210
|
readOptionalFile(resolvedConfig),
|
|
157
211
|
detectProjectPackageManager(),
|
|
158
|
-
readProjectFileSignals(
|
|
212
|
+
readProjectFileSignals(layout),
|
|
159
213
|
])
|
|
160
214
|
|
|
161
|
-
const env = await loadProjectEnv(
|
|
215
|
+
const env = await loadProjectEnv(layout.cmsRoot)
|
|
216
|
+
const envShape = await readEnvShape(env)
|
|
162
217
|
|
|
163
218
|
return createDiagnosticReport({
|
|
164
219
|
schemaModels,
|
|
@@ -169,6 +224,7 @@ async function buildReport(
|
|
|
169
224
|
schemaPath,
|
|
170
225
|
mode,
|
|
171
226
|
projectFiles,
|
|
227
|
+
envShape,
|
|
172
228
|
})
|
|
173
229
|
}
|
|
174
230
|
|