@palettelab/cli 0.3.41 → 0.3.42
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/lib/commands/publish.js +115 -2
- package/package.json +1 -1
package/lib/commands/publish.js
CHANGED
|
@@ -23,6 +23,114 @@ function sha256(buf) {
|
|
|
23
23
|
return crypto.createHash("sha256").update(buf).digest("hex")
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function formatBytes(bytes) {
|
|
27
|
+
if (!Number.isFinite(bytes)) return null
|
|
28
|
+
const units = ["bytes", "KiB", "MiB", "GiB"]
|
|
29
|
+
let value = bytes
|
|
30
|
+
let unit = 0
|
|
31
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
32
|
+
value /= 1024
|
|
33
|
+
unit += 1
|
|
34
|
+
}
|
|
35
|
+
const fixed = unit === 0 ? String(value) : value.toFixed(value >= 10 ? 1 : 2)
|
|
36
|
+
const formatted = fixed.replace(/\.0+$|(\.\d*[1-9])0+$/, "$1")
|
|
37
|
+
return `${formatted} ${units[unit]}`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function plural(count, singular, pluralForm = `${singular}s`) {
|
|
41
|
+
return count === 1 ? singular : pluralForm
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function routeLabel(route) {
|
|
45
|
+
if (!route?.path) return null
|
|
46
|
+
const methods = Array.isArray(route.methods) && route.methods.length ? route.methods.join(", ") : "ANY"
|
|
47
|
+
return `${methods} ${route.path}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function extractMigrationHint(message) {
|
|
51
|
+
const match = String(message || "").match(
|
|
52
|
+
/^([^:]+): create_table\("([^"]+)"\) is missing ensure_org_rls\(op, "([^"]+)"\)/,
|
|
53
|
+
)
|
|
54
|
+
if (!match) return null
|
|
55
|
+
return { file: match[1], table: match[2] }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function explainPreflightFailure(result) {
|
|
59
|
+
const message = String(result?.message || "preflight check failed")
|
|
60
|
+
const fix = result?.fix ? String(result.fix) : null
|
|
61
|
+
|
|
62
|
+
if (result?.bytes && result?.limit && /bundle exceeds size limit/.test(message)) {
|
|
63
|
+
const kind = message.startsWith("frontend") ? "Frontend" : "Backend"
|
|
64
|
+
return {
|
|
65
|
+
title: `${kind} bundle is too large`,
|
|
66
|
+
details: [
|
|
67
|
+
`Current bundle: ${formatBytes(result.bytes)} (${result.bytes} bytes)`,
|
|
68
|
+
`Allowed limit: ${formatBytes(result.limit)} (${result.limit} bytes)`,
|
|
69
|
+
],
|
|
70
|
+
fix,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (result?.route && /has no require_permission\(\)/.test(message)) {
|
|
75
|
+
const label = routeLabel(result.route)
|
|
76
|
+
return {
|
|
77
|
+
title: "Backend route is missing a permission gate",
|
|
78
|
+
details: label ? [`Route: ${label}`] : [],
|
|
79
|
+
fix,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const migration = extractMigrationHint(message)
|
|
84
|
+
if (migration) {
|
|
85
|
+
return {
|
|
86
|
+
title: "Database migration is missing organization RLS",
|
|
87
|
+
details: [`File: ${migration.file}`, `Table: ${migration.table}`],
|
|
88
|
+
fix:
|
|
89
|
+
fix ||
|
|
90
|
+
`Call ensure_org_rls(op, "${migration.table}") after create_table, or add # palette:rls-ok only if the table is intentionally global.`,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
title: message,
|
|
96
|
+
details: [],
|
|
97
|
+
fix,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function printPreflightFailure(payload, fallbackOutput) {
|
|
102
|
+
const results = Array.isArray(payload?.results) ? payload.results : []
|
|
103
|
+
const failures = results.filter((result) => result?.status === "fail")
|
|
104
|
+
const warnings = results.filter((result) => result?.status === "warn")
|
|
105
|
+
const passed = results.filter((result) => result?.status === "ok").length
|
|
106
|
+
|
|
107
|
+
console.error("[pltt] preflight checks failed; publish cancelled before upload.")
|
|
108
|
+
if (!failures.length) {
|
|
109
|
+
if (fallbackOutput) console.error(fallbackOutput)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.error(
|
|
114
|
+
`[pltt] ${failures.length} blocking ${plural(failures.length, "issue")} found. ` +
|
|
115
|
+
"Fix these and rerun the command.\n",
|
|
116
|
+
)
|
|
117
|
+
failures.forEach((failure, index) => {
|
|
118
|
+
const issue = explainPreflightFailure(failure)
|
|
119
|
+
console.error(`${index + 1}. ${issue.title}`)
|
|
120
|
+
for (const detail of issue.details) console.error(` ${detail}`)
|
|
121
|
+
if (issue.fix) console.error(` Fix: ${issue.fix}`)
|
|
122
|
+
console.error("")
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
if (passed > 0) {
|
|
126
|
+
console.error(`[pltt] ${passed} ${plural(passed, "check")} passed before the publish was blocked.`)
|
|
127
|
+
}
|
|
128
|
+
if (warnings.length) {
|
|
129
|
+
console.error(`[pltt] ${warnings.length} ${plural(warnings.length, "warning", "warnings")} were also reported by preflight.`)
|
|
130
|
+
}
|
|
131
|
+
console.error("[pltt] Need machine-readable details? Run `pltt test --json`.")
|
|
132
|
+
}
|
|
133
|
+
|
|
26
134
|
function runPreflight(cwd, json) {
|
|
27
135
|
const cliBin = path.resolve(__dirname, "..", "..", "bin", "pltt.js")
|
|
28
136
|
const res = spawnSync(process.execPath, [cliBin, "test", "--json"], {
|
|
@@ -46,8 +154,13 @@ function runPreflight(cwd, json) {
|
|
|
46
154
|
}
|
|
47
155
|
console.log(JSON.stringify({ ok: false, stage: "preflight", test: payload }, null, 2))
|
|
48
156
|
} else {
|
|
49
|
-
|
|
50
|
-
|
|
157
|
+
let payload = null
|
|
158
|
+
try {
|
|
159
|
+
payload = JSON.parse(res.stdout)
|
|
160
|
+
} catch {
|
|
161
|
+
payload = null
|
|
162
|
+
}
|
|
163
|
+
printPreflightFailure(payload, output)
|
|
51
164
|
}
|
|
52
165
|
process.exit(res.status || 1)
|
|
53
166
|
}
|