@sdxc/kit 2026.10.17 → 2026.10.20
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/README.md +390 -20
- package/changelog.jsonl +1160 -1092
- package/config.schema.json +47 -1
- package/dist/cli.js +12 -0
- package/dist/commands/deploy.d.ts +23 -0
- package/dist/commands/deploy.js +167 -0
- package/dist/commands/destroy.d.ts +22 -0
- package/dist/commands/destroy.js +92 -0
- package/dist/commands/doctor.d.ts +26 -0
- package/dist/commands/doctor.js +65 -0
- package/dist/commands/initializers.d.ts +16 -0
- package/dist/commands/initializers.js +23 -0
- package/dist/commands/make.d.ts +72 -6
- package/dist/commands/make.js +127 -19
- package/dist/commands/middleware.d.ts +16 -0
- package/dist/commands/middleware.js +21 -0
- package/dist/commands/models.d.ts +18 -0
- package/dist/commands/models.js +29 -0
- package/dist/commands/notes.d.ts +17 -0
- package/dist/commands/notes.js +27 -0
- package/dist/commands/routes.d.ts +25 -0
- package/dist/commands/routes.js +50 -0
- package/dist/commands/run.d.ts +16 -0
- package/dist/commands/run.js +32 -11
- package/dist/commands/scaffold.d.ts +29 -0
- package/dist/commands/scaffold.js +33 -0
- package/dist/commands/schedule.d.ts +16 -0
- package/dist/commands/schedule.js +21 -0
- package/dist/commands/stats.d.ts +16 -0
- package/dist/commands/stats.js +21 -0
- package/dist/commands/ui/update.d.ts +6 -3
- package/dist/commands/ui/update.js +24 -7
- package/dist/commands/upgrade.d.ts +3 -1
- package/dist/commands/upgrade.js +88 -23
- package/dist/config.d.ts +18 -0
- package/dist/config.js +28 -1
- package/dist/contract.d.ts +97 -3
- package/dist/contract.js +360 -26
- package/dist/create/templates.js +3 -2
- package/dist/dependencies.d.ts +4 -1
- package/dist/dependencies.js +13 -1
- package/dist/deploy/plan.d.ts +49 -0
- package/dist/deploy/plan.js +68 -0
- package/dist/destroy.d.ts +40 -0
- package/dist/destroy.js +311 -0
- package/dist/doctor/check.d.ts +71 -0
- package/dist/doctor/check.js +53 -0
- package/dist/doctor/checks.d.ts +23 -0
- package/dist/doctor/checks.js +68 -0
- package/dist/doctor/define.d.ts +59 -0
- package/dist/doctor/define.js +16 -0
- package/dist/doctor/emails.d.ts +18 -0
- package/dist/doctor/emails.js +243 -0
- package/dist/doctor/env.d.ts +26 -0
- package/dist/doctor/env.js +88 -0
- package/dist/doctor/files.d.ts +14 -0
- package/dist/doctor/files.js +34 -0
- package/dist/doctor/fixture.d.ts +23 -0
- package/dist/doctor/fixture.js +46 -0
- package/dist/doctor/install.d.ts +17 -0
- package/dist/doctor/install.js +37 -0
- package/dist/doctor/installed.d.ts +11 -0
- package/dist/doctor/installed.js +79 -0
- package/dist/doctor/layout.d.ts +23 -0
- package/dist/doctor/layout.js +83 -0
- package/dist/doctor/migrations.d.ts +16 -0
- package/dist/doctor/migrations.js +96 -0
- package/dist/doctor/models.d.ts +13 -0
- package/dist/doctor/models.js +69 -0
- package/dist/doctor/pins.d.ts +15 -0
- package/dist/doctor/pins.js +79 -0
- package/dist/doctor/project.d.ts +58 -0
- package/dist/doctor/project.js +261 -0
- package/dist/doctor/remix.d.ts +14 -0
- package/dist/doctor/remix.js +44 -0
- package/dist/doctor/routes.d.ts +11 -0
- package/dist/doctor/routes.js +49 -0
- package/dist/doctor/typegen.d.ts +13 -0
- package/dist/doctor/typegen.js +57 -0
- package/dist/doctor/ui.d.ts +14 -0
- package/dist/doctor/ui.js +51 -0
- package/dist/initializers.d.ts +25 -0
- package/dist/initializers.js +89 -0
- package/dist/lock.d.ts +2 -2
- package/dist/make/actions.d.ts +23 -0
- package/dist/make/actions.js +82 -0
- package/dist/make/declare.d.ts +31 -3
- package/dist/make/declare.js +284 -9
- package/dist/make/email.d.ts +23 -0
- package/dist/make/email.js +111 -0
- package/dist/make/from-fields.d.ts +30 -0
- package/dist/make/from-fields.js +162 -0
- package/dist/make/from-model.d.ts +39 -0
- package/dist/make/from-model.js +161 -0
- package/dist/make/generate.d.ts +16 -5
- package/dist/make/generate.js +38 -15
- package/dist/make/guard.d.ts +35 -0
- package/dist/make/guard.js +73 -0
- package/dist/make/imports.d.ts +6 -0
- package/dist/make/imports.js +19 -0
- package/dist/make/index.d.ts +47 -4
- package/dist/make/index.js +287 -29
- package/dist/make/kinds.d.ts +29 -2
- package/dist/make/kinds.js +79 -7
- package/dist/make/mount.d.ts +25 -0
- package/dist/make/mount.js +135 -0
- package/dist/make/schema-diff.d.ts +58 -0
- package/dist/make/schema-diff.js +609 -0
- package/dist/make/schema.d.ts +76 -0
- package/dist/make/schema.js +206 -0
- package/dist/make/stubs.d.ts +7 -5
- package/dist/make/stubs.js +16 -5
- package/dist/make/test.d.ts +43 -0
- package/dist/make/test.js +149 -0
- package/dist/make/trigger.d.ts +31 -0
- package/dist/make/trigger.js +163 -0
- package/dist/models.d.ts +42 -0
- package/dist/models.js +149 -0
- package/dist/notes.d.ts +28 -0
- package/dist/notes.js +66 -0
- package/dist/reference.d.ts +27 -0
- package/dist/reference.js +103 -0
- package/dist/releases.d.ts +9 -0
- package/dist/releases.js +29 -8
- package/dist/routes/chains.d.ts +34 -0
- package/dist/routes/chains.js +95 -0
- package/dist/routes/filter.d.ts +53 -0
- package/dist/routes/filter.js +147 -0
- package/dist/routes/format.d.ts +23 -0
- package/dist/routes/format.js +123 -0
- package/dist/routes/helpers.d.ts +21 -0
- package/dist/routes/helpers.js +165 -0
- package/dist/routes/index.d.ts +56 -0
- package/dist/routes/index.js +167 -0
- package/dist/routes/modules.d.ts +116 -0
- package/dist/routes/modules.js +235 -0
- package/dist/routes/parse.d.ts +161 -0
- package/dist/routes/parse.js +621 -0
- package/dist/routes/routers.d.ts +69 -0
- package/dist/routes/routers.js +327 -0
- package/dist/scaffold/fields.d.ts +129 -0
- package/dist/scaffold/fields.js +421 -0
- package/dist/scaffold/index.d.ts +37 -0
- package/dist/scaffold/index.js +613 -0
- package/dist/scaffold/render.d.ts +51 -0
- package/dist/scaffold/render.js +332 -0
- package/dist/schedule.d.ts +45 -0
- package/dist/schedule.js +124 -0
- package/dist/stats.d.ts +37 -0
- package/dist/stats.js +126 -0
- package/dist/ui/commands.d.ts +10 -3
- package/dist/ui/commands.js +85 -15
- package/dist/ui/registry.d.ts +8 -8
- package/dist/upgrade/agents.d.ts +49 -0
- package/dist/upgrade/agents.js +110 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +4 -0
- package/dist/upgrade/project.js +11 -1
- package/dist/upgrade/prompt.d.ts +11 -0
- package/dist/upgrade/prompt.js +50 -7
- package/package.json +6 -4
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/color-picker.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/file-trigger.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/message-scroller.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/resizable.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.form.stub +2 -2
- package/stubs/controller.form.test.stub +2 -2
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/email.stub +9 -14
- package/stubs/email.test.stub +9 -9
- package/stubs/factory.stub +1 -1
- package/stubs/model.stub +3 -3
- package/stubs/policy.test.stub +34 -8
- package/stubs/scaffold.api.create.stub +34 -0
- package/stubs/scaffold.api.create.test.stub +37 -0
- package/stubs/scaffold.api.destroy.stub +34 -0
- package/stubs/scaffold.api.destroy.test.stub +44 -0
- package/stubs/scaffold.api.index.stub +23 -0
- package/stubs/scaffold.api.index.test.stub +31 -0
- package/stubs/scaffold.api.show.stub +27 -0
- package/stubs/scaffold.api.show.test.stub +41 -0
- package/stubs/scaffold.api.update.stub +44 -0
- package/stubs/scaffold.api.update.test.stub +46 -0
- package/stubs/scaffold.command.create.stub +22 -0
- package/stubs/scaffold.command.create.test.stub +30 -0
- package/stubs/scaffold.command.delete.stub +20 -0
- package/stubs/scaffold.command.delete.test.stub +39 -0
- package/stubs/scaffold.command.list.stub +18 -0
- package/stubs/scaffold.command.list.test.stub +31 -0
- package/stubs/scaffold.command.show.stub +19 -0
- package/stubs/scaffold.command.show.test.stub +37 -0
- package/stubs/scaffold.controller.destroy.stub +35 -0
- package/stubs/scaffold.controller.destroy.test.stub +65 -0
- package/stubs/scaffold.controller.edit.stub +97 -0
- package/stubs/scaffold.controller.edit.test.stub +91 -0
- package/stubs/scaffold.controller.index.stub +55 -0
- package/stubs/scaffold.controller.index.test.stub +32 -0
- package/stubs/scaffold.controller.new.stub +70 -0
- package/stubs/scaffold.controller.new.test.stub +81 -0
- package/stubs/scaffold.controller.show.stub +59 -0
- package/stubs/scaffold.controller.show.test.stub +43 -0
- package/stubs/scaffold.factory.stub +16 -0
- package/stubs/scaffold.form.stub +75 -0
- package/stubs/scaffold.mcp.create.stub +24 -0
- package/stubs/scaffold.mcp.create.test.stub +36 -0
- package/stubs/scaffold.mcp.delete.stub +31 -0
- package/stubs/scaffold.mcp.delete.test.stub +43 -0
- package/stubs/scaffold.mcp.get.stub +21 -0
- package/stubs/scaffold.mcp.get.test.stub +31 -0
- package/stubs/scaffold.mcp.list.stub +23 -0
- package/stubs/scaffold.mcp.list.test.stub +25 -0
- package/stubs/scaffold.mcp.update.stub +37 -0
- package/stubs/scaffold.mcp.update.test.stub +40 -0
- package/stubs/scaffold.migration.stub +2 -0
- package/stubs/scaffold.model.stub +35 -0
- package/stubs/scaffold.model.test.stub +25 -0
- package/stubs/scaffold.test-database.stub +33 -0
- package/stubs/scaffold.test-mcp.stub +92 -0
- package/stubs/scaffold.validator.stub +18 -0
- package/stubs/scaffold.validator.test.stub +26 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +28 -13
- package/templates/app/app/commands/console.test.ts +26 -0
- package/templates/app/app/commands/console.ts +19 -0
- package/templates/app/app/commands/db/fresh.test.ts +57 -0
- package/templates/app/app/commands/db/fresh.ts +37 -0
- package/templates/app/app/commands/db/migrate.test.ts +17 -1
- package/templates/app/app/commands/db/migrate.ts +51 -18
- package/templates/app/app/commands/db/prepare.test.ts +39 -0
- package/templates/app/app/commands/db/prepare.ts +35 -0
- package/templates/app/app/commands/db/seed.test.ts +38 -0
- package/templates/app/app/commands/db/seed.ts +26 -0
- package/templates/app/app/commands/deploy.test.ts +34 -0
- package/templates/app/app/commands/deploy.ts +18 -0
- package/templates/app/app/commands/emails/preview.test.tsx +63 -0
- package/templates/app/app/commands/emails/preview.ts +24 -0
- package/templates/app/app/commands/index.ts +57 -2
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/middleware/access.test.ts +43 -0
- package/templates/app/app/http/middleware/access.ts +41 -0
- package/templates/app/app/http/middleware/api.ts +12 -3
- package/templates/app/app/http/middleware/page.test.ts +4 -1
- package/templates/app/app/http/middleware/page.ts +7 -5
- package/templates/app/app/initializers/cli.ts +28 -2
- package/templates/app/app/initializers/dispatcher.ts +9 -1
- package/templates/app/app/initializers/mail-transport.test.ts +27 -0
- package/templates/app/app/initializers/mail-transport.ts +26 -0
- package/templates/app/app/initializers/mail.test.ts +17 -17
- package/templates/app/app/initializers/mail.ts +15 -7
- package/templates/app/app/initializers/router.test.ts +7 -0
- package/templates/app/app/initializers/router.tsx +13 -3
- package/templates/app/app/jobs/email.test.tsx +70 -0
- package/templates/app/app/jobs/email.ts +16 -0
- package/templates/app/app/jobs/index.ts +6 -2
- package/templates/app/app/policies/abilities.ts +13 -0
- package/templates/app/app/policies/policy.test.ts +15 -0
- package/templates/app/app/policies/policy.ts +30 -0
- package/templates/app/app/services/commands.ts +30 -0
- package/templates/app/app/services/migrations.test.ts +48 -1
- package/templates/app/app/services/migrations.ts +66 -9
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/cloudflare.config.ts +3 -3
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +2 -1
- package/stubs/policy.stub +0 -16
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `sdxc deploy` shows before it touches production and says when a step fails: the steps
|
|
3
|
+
* it runs, the migrations the app's own `db migrate --remote --pending` lists, and where
|
|
4
|
+
* production stands after a failure, worded from what already ran.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { ExecError } from "@sdxc/cli";
|
|
10
|
+
/** The steps `sdxc deploy` runs, in order; `--skip` names any of them. */
|
|
11
|
+
export const DEPLOY_STEPS = ["build", "migrate", "deploy"];
|
|
12
|
+
/** The migration names `db migrate --pending` printed, one per line, in the order it applies them. */
|
|
13
|
+
export function parsePending(stdout) {
|
|
14
|
+
return stdout
|
|
15
|
+
.split("\n")
|
|
16
|
+
.map((line) => line.trim())
|
|
17
|
+
.filter((line) => line !== "");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether the app's command line ended with the usage error its parser prints for `kind`, such
|
|
21
|
+
* as `Unknown command "deploy" for blog` or `Unknown flag --pending`.
|
|
22
|
+
*
|
|
23
|
+
* @param error - The failure of a run whose stderr was collected
|
|
24
|
+
* @param kind - The word the message starts with
|
|
25
|
+
*/
|
|
26
|
+
export function isUnknown(error, kind) {
|
|
27
|
+
return (error instanceof ExecError &&
|
|
28
|
+
error.code === 2 &&
|
|
29
|
+
error.stderr.includes(kind === "command" ? "Unknown command" : "Unknown flag"));
|
|
30
|
+
}
|
|
31
|
+
/** Whether the migration step applies anything once the plan is confirmed. */
|
|
32
|
+
export function migrates(step) {
|
|
33
|
+
return step.status === "unlisted" || (step.status === "pending" && step.names.length > 0);
|
|
34
|
+
}
|
|
35
|
+
/** The plan as the terminal shows it, one fact per line and one line per pending migration. */
|
|
36
|
+
export function formatPlan(plan) {
|
|
37
|
+
let lines = [
|
|
38
|
+
`App: ${plan.app}`,
|
|
39
|
+
`Build: ${plan.build ? "built just now" : "the existing build output (--skip build)"}`,
|
|
40
|
+
];
|
|
41
|
+
let migrations = plan.migrations;
|
|
42
|
+
if (migrations.status === "skipped") {
|
|
43
|
+
lines.push(`Migrations: none to apply (${migrations.reason})`);
|
|
44
|
+
}
|
|
45
|
+
else if (migrations.status === "unlisted") {
|
|
46
|
+
lines.push("Migrations: db migrate --remote runs; the app's db migrate has no --pending to list them");
|
|
47
|
+
}
|
|
48
|
+
else if (migrations.names.length === 0) {
|
|
49
|
+
lines.push("Migrations: none pending");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
lines.push(`Migrations: ${migrations.names.length} pending`);
|
|
53
|
+
for (let name of migrations.names)
|
|
54
|
+
lines.push(` ${name}`);
|
|
55
|
+
}
|
|
56
|
+
lines.push(`Deploy: ${plan.deploy ? "the app's deploy command" : "skipped (--skip deploy)"}`);
|
|
57
|
+
return `${lines.join("\n")}\n`;
|
|
58
|
+
}
|
|
59
|
+
/** Where production stands when the app's `deploy` fails after the migration step. */
|
|
60
|
+
export function deployFailure(step) {
|
|
61
|
+
if (step.status === "unlisted") {
|
|
62
|
+
return "Deploy failed after db migrate --remote ran, so production may run the previous version on a newer schema";
|
|
63
|
+
}
|
|
64
|
+
if (step.status === "pending" && step.names.length > 0) {
|
|
65
|
+
return `Deploy failed; migrations ${step.names.join(", ")} were applied, so production runs the previous version on the new schema`;
|
|
66
|
+
}
|
|
67
|
+
return "Deploy failed; no migrations were applied, and production still runs the previous version";
|
|
68
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc destroy <kind> <name>`: the reverse of `sdxc make`. It removes the file, its test and,
|
|
3
|
+
* for a model, its factory, then the mapping that loads the file, the declaration that mapping
|
|
4
|
+
* names and the Worker trigger of a schedule no other job runs on. Every other reference is
|
|
5
|
+
* listed for the user to remove.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { Result } from "@sdxc/result";
|
|
11
|
+
import type { FileEdit } from "./make/declare.js";
|
|
12
|
+
import type { DestroyKind } from "./make/kinds.js";
|
|
13
|
+
/** What one `destroy` would do. */
|
|
14
|
+
export interface DestroyPlan {
|
|
15
|
+
/** The files it deletes, relative to the project root. */
|
|
16
|
+
remove: string[];
|
|
17
|
+
edits: FileEdit[];
|
|
18
|
+
/** Each line of the project's code that still names the file or its declaration. */
|
|
19
|
+
references: string[];
|
|
20
|
+
/** What the user should know beside the edits, such as the migration a model keeps. */
|
|
21
|
+
notes: string[];
|
|
22
|
+
}
|
|
23
|
+
/** What `destroy` was asked for. */
|
|
24
|
+
export interface DestroyInput {
|
|
25
|
+
kind: DestroyKind;
|
|
26
|
+
name: string;
|
|
27
|
+
/** `mcp`: a resource in `app/mcp/resources/` instead of a tool. */
|
|
28
|
+
resource: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* `after` without the import bindings whose last use the edit removed: a binding used outside
|
|
32
|
+
* imports in `before` and nowhere in `after` is dropped, and a declaration left with none goes
|
|
33
|
+
* too, so an import `sdxc make` added for a mapping leaves with it. Every other import stays.
|
|
34
|
+
*/
|
|
35
|
+
export declare function pruneImports(filename: string, before: string, after: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Plans what `sdxc destroy` does for `input` in the project at `root`, writing nothing. A file
|
|
38
|
+
* that does not exist is a failure, so a typo never edits declarations.
|
|
39
|
+
*/
|
|
40
|
+
export declare function planDestroy(root: string, input: DestroyInput): Promise<Result<DestroyPlan, Error>>;
|
package/dist/destroy.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc destroy <kind> <name>`: the reverse of `sdxc make`. It removes the file, its test and,
|
|
3
|
+
* for a model, its factory, then the mapping that loads the file, the declaration that mapping
|
|
4
|
+
* names and the Worker trigger of a schedule no other job runs on. Every other reference is
|
|
5
|
+
* listed for the user to remove.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { readFile, stat } from "node:fs/promises";
|
|
11
|
+
import { join, posix } from "node:path";
|
|
12
|
+
import { findStatements, removeProperty, removeStatements, tokenize } from "@sdxc/codemod";
|
|
13
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
14
|
+
import { listFiles } from "./doctor/files.js";
|
|
15
|
+
import { exists, folderOf } from "./make/generate.js";
|
|
16
|
+
import { KINDS } from "./make/kinds.js";
|
|
17
|
+
import { parseName } from "./make/names.js";
|
|
18
|
+
import { planUntrigger } from "./make/trigger.js";
|
|
19
|
+
import { declaredJobs, normalized } from "./schedule.js";
|
|
20
|
+
/** The builder call each declared kind's declarations module passes its object to. */
|
|
21
|
+
const DECLARATION_CALLS = {
|
|
22
|
+
controller: "route",
|
|
23
|
+
job: "jobs",
|
|
24
|
+
command: "commands",
|
|
25
|
+
email: "emails",
|
|
26
|
+
};
|
|
27
|
+
/** The folders whose code may still reference a destroyed file. */
|
|
28
|
+
const REFERENCING_FOLDERS = ["app", "bootstrap", "config", "database", "resources", "routes"];
|
|
29
|
+
/** Every spelling a module of the project may import `file` by, from the module `from`. */
|
|
30
|
+
function specifiers(file, from) {
|
|
31
|
+
let bare = file.replace(/\.[cm]?[jt]sx?$/, "");
|
|
32
|
+
let relative = posix.relative(posix.dirname(from), bare);
|
|
33
|
+
let local = relative.startsWith(".") ? relative : `./${relative}`;
|
|
34
|
+
let extension = file.slice(bare.length);
|
|
35
|
+
return [`~/${bare}`, `~/${file}`, `~/${bare}.js`, local, `${local}${extension}`, `${local}.js`];
|
|
36
|
+
}
|
|
37
|
+
/** The project file a specifier written in `from` names, or `null` for a package. */
|
|
38
|
+
async function resolveModule(root, from, specifier) {
|
|
39
|
+
let base = specifier.startsWith("~/")
|
|
40
|
+
? specifier.slice(2)
|
|
41
|
+
: specifier.startsWith(".")
|
|
42
|
+
? posix.normalize(posix.join(posix.dirname(from), specifier))
|
|
43
|
+
: null;
|
|
44
|
+
if (base === null)
|
|
45
|
+
return null;
|
|
46
|
+
let bare = base.replace(/\.[cm]?js$/, "");
|
|
47
|
+
for (let candidate of [base, `${bare}.ts`, `${bare}.tsx`, `${bare}/index.ts`]) {
|
|
48
|
+
let found = await wrap(() => stat(join(root, candidate)));
|
|
49
|
+
if (!isFailure(found) && found.data.isFile())
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/** The text of `path`: from `edits` when an earlier step changed it, from disk otherwise. */
|
|
55
|
+
async function current(root, edits, path) {
|
|
56
|
+
let edited = edits.find((edit) => edit.path === path);
|
|
57
|
+
if (edited !== undefined)
|
|
58
|
+
return edited.after;
|
|
59
|
+
let read = await wrap(() => readFile(join(root, path), "utf8"));
|
|
60
|
+
return isFailure(read) ? null : read.data;
|
|
61
|
+
}
|
|
62
|
+
/** Records `after` as the new text of `path`, merging with an earlier edit of the same file. */
|
|
63
|
+
async function record(root, edits, path, after) {
|
|
64
|
+
let index = edits.findIndex((edit) => edit.path === path);
|
|
65
|
+
if (index !== -1) {
|
|
66
|
+
edits[index] = { ...edits[index], after };
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let before = await wrap(() => readFile(join(root, path), "utf8"));
|
|
70
|
+
if (!isFailure(before))
|
|
71
|
+
edits.push({ path, before: before.data, after });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Removes the mapping of `file` from every initializer and, for a declared kind, the
|
|
75
|
+
* declaration the mapping names; answers the declaration's dotted path, or `null`.
|
|
76
|
+
*/
|
|
77
|
+
async function unmap(root, kind, file, resource, edits, notes) {
|
|
78
|
+
let declared = null;
|
|
79
|
+
for (let initializer of await listFiles(root, "app/initializers")) {
|
|
80
|
+
let source = await current(root, edits, initializer);
|
|
81
|
+
if (source === null)
|
|
82
|
+
continue;
|
|
83
|
+
for (let specifier of specifiers(file, initializer)) {
|
|
84
|
+
let found = findStatements(initializer, source, { specifier });
|
|
85
|
+
if (isFailure(found) || found.data.length === 0)
|
|
86
|
+
continue;
|
|
87
|
+
for (let statement of found.data) {
|
|
88
|
+
let member = /\.map\(\s*([A-Za-z_$][\w$]*)((?:\s*\.\s*[A-Za-z_$][\w$]*|\s*\[\s*"[^"]+"\s*\])+)/.exec(statement.text);
|
|
89
|
+
if (member === null)
|
|
90
|
+
continue;
|
|
91
|
+
let local = member[1];
|
|
92
|
+
let path = [
|
|
93
|
+
...(member[2] ?? "").matchAll(/\.\s*([A-Za-z_$][\w$]*)|\[\s*"([^"]+)"\s*\]/g),
|
|
94
|
+
].map((part) => (part[1] ?? part[2]));
|
|
95
|
+
declared = [local, ...path].join(".");
|
|
96
|
+
let imported = new RegExp(`import\\s+${local}\\s+from\\s+"([^"]+)"`).exec(source)?.[1];
|
|
97
|
+
let module = imported === undefined ? null : await resolveModule(root, initializer, imported);
|
|
98
|
+
let call = kind === "mcp" ? (resource ? "resources" : "tools") : DECLARATION_CALLS[kind];
|
|
99
|
+
if (module === null || call === undefined || path.length === 0)
|
|
100
|
+
continue;
|
|
101
|
+
let declarations = await current(root, edits, module);
|
|
102
|
+
if (declarations === null)
|
|
103
|
+
continue;
|
|
104
|
+
let removed = { ok: false, source: declarations };
|
|
105
|
+
for (let argument of [0, 1]) {
|
|
106
|
+
let attempt = removeProperty(module, declarations, {
|
|
107
|
+
call,
|
|
108
|
+
argument,
|
|
109
|
+
path: path.slice(0, -1),
|
|
110
|
+
key: path.at(-1),
|
|
111
|
+
});
|
|
112
|
+
if (!isFailure(attempt)) {
|
|
113
|
+
removed = { ok: true, source: attempt.data.source };
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (removed.ok)
|
|
118
|
+
await record(root, edits, module, removed.source);
|
|
119
|
+
else
|
|
120
|
+
notes.push(`Remove ${path.join(".")} from ${module} by hand; sdxc destroy could not find it\n`);
|
|
121
|
+
if (kind === "controller")
|
|
122
|
+
await undecideSitemap(root, path, edits);
|
|
123
|
+
}
|
|
124
|
+
let unmapped = removeStatements(initializer, source, { specifier });
|
|
125
|
+
if (!isFailure(unmapped) && unmapped.data.changed) {
|
|
126
|
+
source = unmapped.data.source;
|
|
127
|
+
await record(root, edits, initializer, source);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return declared;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Removes the sitemap decision `sdxc make controller` added for the route at `path` from every
|
|
135
|
+
* controller that builds a sitemap with `fromRoutes(routes, origin, { … })`.
|
|
136
|
+
*/
|
|
137
|
+
async function undecideSitemap(root, path, edits) {
|
|
138
|
+
for (let file of await listFiles(root, "app/http/controllers")) {
|
|
139
|
+
if (!/\.tsx?$/.test(file) || /\.test\.tsx?$/.test(file))
|
|
140
|
+
continue;
|
|
141
|
+
let source = await current(root, edits, file);
|
|
142
|
+
if (source === null || !source.includes("fromRoutes("))
|
|
143
|
+
continue;
|
|
144
|
+
let removed = removeProperty(file, source, {
|
|
145
|
+
call: "fromRoutes",
|
|
146
|
+
argument: 2,
|
|
147
|
+
path: path.slice(0, -1),
|
|
148
|
+
key: path.at(-1),
|
|
149
|
+
});
|
|
150
|
+
if (!isFailure(removed))
|
|
151
|
+
await record(root, edits, file, removed.data.source);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** `text` matched literally inside a regular expression, every syntax character escaped. */
|
|
155
|
+
function escapeRegExp(text) {
|
|
156
|
+
return text.replace(/[\\^$.*+?()[\]{}|/-]/g, "\\$&");
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether `name` is used in the code of `source` outside its import declarations: as an
|
|
160
|
+
* identifier that is no property name, or in JSX markup. Comments and strings never count, and a
|
|
161
|
+
* file that does not scan counts every name as used, so nothing of it is pruned.
|
|
162
|
+
*/
|
|
163
|
+
function usedOutsideImports(filename, source, name) {
|
|
164
|
+
let tokens = tokenize(filename, source);
|
|
165
|
+
if (isFailure(tokens))
|
|
166
|
+
return true;
|
|
167
|
+
let code = tokens.data.filter((token) => token.type !== "comment");
|
|
168
|
+
let markup = new RegExp(`(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
169
|
+
for (let index = 0; index < code.length; index += 1) {
|
|
170
|
+
let token = code[index];
|
|
171
|
+
let previous = code[index - 1];
|
|
172
|
+
let next = code[index + 1];
|
|
173
|
+
let statementStart = previous === undefined ||
|
|
174
|
+
token.newlineBefore ||
|
|
175
|
+
(previous.type === "punctuator" && previous.value === ";");
|
|
176
|
+
if (token.type === "identifier" && token.value === "import" && statementStart) {
|
|
177
|
+
if (next?.type === "punctuator" && next.value === "(")
|
|
178
|
+
continue;
|
|
179
|
+
while (index < code.length && code[index]?.type !== "string")
|
|
180
|
+
index += 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (token.type === "jsx" && markup.test(token.value))
|
|
184
|
+
return true;
|
|
185
|
+
let member = previous?.type === "punctuator" && previous.value === ".";
|
|
186
|
+
if (token.type === "identifier" && token.value === name && !member)
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* `after` without the import bindings whose last use the edit removed: a binding used outside
|
|
193
|
+
* imports in `before` and nowhere in `after` is dropped, and a declaration left with none goes
|
|
194
|
+
* too, so an import `sdxc make` added for a mapping leaves with it. Every other import stays.
|
|
195
|
+
*/
|
|
196
|
+
export function pruneImports(filename, before, after) {
|
|
197
|
+
let gone = (local) => usedOutsideImports(filename, before, local) && !usedOutsideImports(filename, after, local);
|
|
198
|
+
return after.replace(/^import\s+(?!type\b)([^;"]*?)\s+from\s*("[^"]+");?[ \t]*\r?\n/gm, (statement, clause, specifier) => {
|
|
199
|
+
let named = /\{([^}]*)\}/.exec(clause);
|
|
200
|
+
let leading = clause
|
|
201
|
+
.replace(/\{[^}]*\}/, "")
|
|
202
|
+
.replace(/,/g, "")
|
|
203
|
+
.trim();
|
|
204
|
+
let keepLeading = leading !== "" && !gone(leading.replace(/^\*\s*as\s+/, ""));
|
|
205
|
+
let names = (named?.[1] ?? "")
|
|
206
|
+
.split(",")
|
|
207
|
+
.map((part) => part.trim())
|
|
208
|
+
.filter((part) => part !== "");
|
|
209
|
+
let kept = names.filter((part) => {
|
|
210
|
+
let local = part.split(/\s+as\s+/).at(-1) ?? part;
|
|
211
|
+
return !gone(local.replace(/^type\s+/, "").trim());
|
|
212
|
+
});
|
|
213
|
+
if ((leading === "" || keepLeading) && kept.length === names.length)
|
|
214
|
+
return statement;
|
|
215
|
+
if (!keepLeading && kept.length === 0)
|
|
216
|
+
return "";
|
|
217
|
+
let parts = [
|
|
218
|
+
...(keepLeading ? [leading] : []),
|
|
219
|
+
...(kept.length === 0 ? [] : [`{ ${kept.join(", ")} }`]),
|
|
220
|
+
];
|
|
221
|
+
return `import ${parts.join(", ")} from ${specifier};\n`;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/** Removes the model's entry from `app/models/index.ts`, found by the import its value holds. */
|
|
225
|
+
async function unregisterModel(root, file, edits) {
|
|
226
|
+
let registry = "app/models/index.ts";
|
|
227
|
+
let source = await current(root, edits, registry);
|
|
228
|
+
if (source === null)
|
|
229
|
+
return;
|
|
230
|
+
for (let specifier of specifiers(file, registry)) {
|
|
231
|
+
let escaped = specifier.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
232
|
+
let entry = new RegExp(`([A-Za-z_$][\\w$]*|"[^"]+")\\s*:\\s*\\(\\)\\s*=>\\s*import\\(\\s*"${escaped}"\\s*\\)`).exec(source);
|
|
233
|
+
if (entry === null)
|
|
234
|
+
continue;
|
|
235
|
+
let key = entry[1].replace(/^"|"$/g, "");
|
|
236
|
+
let removed = removeProperty(registry, source, { call: "createModels", key });
|
|
237
|
+
if (!isFailure(removed))
|
|
238
|
+
await record(root, edits, registry, removed.data.source);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Plans what `sdxc destroy` does for `input` in the project at `root`, writing nothing. A file
|
|
244
|
+
* that does not exist is a failure, so a typo never edits declarations.
|
|
245
|
+
*/
|
|
246
|
+
export async function planDestroy(root, input) {
|
|
247
|
+
let name = parseName(input.name);
|
|
248
|
+
if (isFailure(name))
|
|
249
|
+
return name;
|
|
250
|
+
let kind = KINDS[input.kind];
|
|
251
|
+
let variant = input.kind === "mcp" && input.resource ? "resource" : null;
|
|
252
|
+
let base = `${folderOf(input.kind, variant)}/${name.data.segments.join("/")}`;
|
|
253
|
+
let file = `${base}${kind.extension}`;
|
|
254
|
+
if (!(await exists(root, file))) {
|
|
255
|
+
return failure(new Error(`${file} does not exist; sdxc destroy removes what sdxc make wrote`));
|
|
256
|
+
}
|
|
257
|
+
let candidates = [file, `${base}.test${kind.extension}`];
|
|
258
|
+
if (input.kind === "model")
|
|
259
|
+
candidates.push(`database/factories/${name.data.segments.join("/")}.ts`);
|
|
260
|
+
let remove = [];
|
|
261
|
+
for (let candidate of candidates)
|
|
262
|
+
if (await exists(root, candidate))
|
|
263
|
+
remove.push(candidate);
|
|
264
|
+
let edits = [];
|
|
265
|
+
let notes = [];
|
|
266
|
+
let scheduled = input.kind === "job" ? await declaredJobs(root) : [];
|
|
267
|
+
let declared = await unmap(root, input.kind, file, input.resource, edits, notes);
|
|
268
|
+
let job = declared?.split(".").slice(1).join(".");
|
|
269
|
+
let cron = scheduled.find((entry) => entry.job === job)?.cron;
|
|
270
|
+
let shared = scheduled.some((entry) => entry.job !== job && cron !== undefined && normalized(entry.cron) === normalized(cron));
|
|
271
|
+
if (cron !== undefined && !shared) {
|
|
272
|
+
let untrigger = await planUntrigger(root, cron);
|
|
273
|
+
if (untrigger.edit !== null)
|
|
274
|
+
edits.push(untrigger.edit);
|
|
275
|
+
if (untrigger.note !== null)
|
|
276
|
+
notes.push(untrigger.note);
|
|
277
|
+
}
|
|
278
|
+
if (input.kind === "model") {
|
|
279
|
+
await unregisterModel(root, file, edits);
|
|
280
|
+
notes.push(`The migrations that create its table stay, since a database may have applied them; write one that drops the table with sdxc make migration\n`);
|
|
281
|
+
}
|
|
282
|
+
for (let edit of edits)
|
|
283
|
+
edit.after = pruneImports(edit.path, edit.before, edit.after);
|
|
284
|
+
let references = [];
|
|
285
|
+
let removing = new Set([...remove, ...edits.map((edit) => edit.path)]);
|
|
286
|
+
for (let folder of REFERENCING_FOLDERS) {
|
|
287
|
+
for (let path of await listFiles(root, folder)) {
|
|
288
|
+
if (removing.has(path) || !/\.[cm]?[jt]sx?$/.test(path))
|
|
289
|
+
continue;
|
|
290
|
+
let source = await current(root, edits, path);
|
|
291
|
+
if (source === null)
|
|
292
|
+
continue;
|
|
293
|
+
let names = specifiers(file, path).map((specifier) => `"${specifier}"`);
|
|
294
|
+
let member = declared === null ? null : new RegExp(`\\b${declared.replaceAll(".", "\\.")}\\b`);
|
|
295
|
+
source.split("\n").forEach((line, index) => {
|
|
296
|
+
if (names.some((quoted) => line.includes(quoted)) || (member?.test(line) ?? false)) {
|
|
297
|
+
references.push(`${path}:${index + 1}: ${line.trim()}`);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
for (let edit of edits) {
|
|
303
|
+
let names = specifiers(file, edit.path).map((specifier) => `"${specifier}"`);
|
|
304
|
+
edit.after.split("\n").forEach((line, index) => {
|
|
305
|
+
if (names.some((quoted) => line.includes(quoted))) {
|
|
306
|
+
references.push(`${edit.path}:${index + 1}: ${line.trim()}`);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
return success({ remove, edits, references, notes });
|
|
311
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every `sdxc doctor` check shares: the result it answers, the project context it reads,
|
|
3
|
+
* and the run that takes a list of checks in order. A new check is one more entry in the list,
|
|
4
|
+
* reading the same memoized manifest and registry documents as the others.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Result } from "@sdxc/result";
|
|
10
|
+
import type { Config } from "../config.js";
|
|
11
|
+
import type { PackageManager } from "../package-manager.js";
|
|
12
|
+
import type { Packument } from "../releases.js";
|
|
13
|
+
import type { Manifest } from "../upgrade/project.js";
|
|
14
|
+
/** How a check came out; only `fail` makes the run exit 1. */
|
|
15
|
+
export type CheckStatus = "pass" | "warn" | "fail" | "skip";
|
|
16
|
+
/** What one check found. */
|
|
17
|
+
export interface CheckResult {
|
|
18
|
+
status: CheckStatus;
|
|
19
|
+
/** One sentence summing up what the check found, or why it was skipped. */
|
|
20
|
+
message: string;
|
|
21
|
+
/** Each package or key the check flagged, in the order it read them. */
|
|
22
|
+
findings: string[];
|
|
23
|
+
/** The command or edit that clears a warning or failure, `null` when there is none to make. */
|
|
24
|
+
fix: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** A named check, run against the project once per `sdxc doctor`. */
|
|
27
|
+
export interface Check {
|
|
28
|
+
/** The check's name in the report, one lowercase word. */
|
|
29
|
+
name: string;
|
|
30
|
+
run(context: DoctorContext): Promise<CheckResult>;
|
|
31
|
+
}
|
|
32
|
+
/** A check's result under its name, as the report prints it. */
|
|
33
|
+
export interface CheckReport extends CheckResult {
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
/** The project every check reads, loaded once per run. */
|
|
37
|
+
export interface DoctorContext {
|
|
38
|
+
root: string;
|
|
39
|
+
manifest: Manifest;
|
|
40
|
+
config: Config;
|
|
41
|
+
manager: PackageManager;
|
|
42
|
+
/** The `@sdxc/kit` package whose component registry the copies are compared with. */
|
|
43
|
+
packageRoot: string;
|
|
44
|
+
/**
|
|
45
|
+
* The registry document for `name`, fetched at most once per run, so checks that read the
|
|
46
|
+
* same package share a request and agree on what the registry answered.
|
|
47
|
+
*/
|
|
48
|
+
packument(name: string): Promise<Result<Packument, Error>>;
|
|
49
|
+
}
|
|
50
|
+
/** What `createDoctorContext` needs to build a context. */
|
|
51
|
+
export interface DoctorContextOptions {
|
|
52
|
+
root: string;
|
|
53
|
+
manifest: Manifest;
|
|
54
|
+
config: Config;
|
|
55
|
+
manager: PackageManager;
|
|
56
|
+
packageRoot: string;
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}
|
|
59
|
+
/** A context whose registry reads are memoized by package name. */
|
|
60
|
+
export declare function createDoctorContext(options: DoctorContextOptions): DoctorContext;
|
|
61
|
+
/** Runs `checks` one after another, so the report keeps their order. */
|
|
62
|
+
export declare function runChecks(checks: readonly Check[], context: DoctorContext): Promise<CheckReport[]>;
|
|
63
|
+
/**
|
|
64
|
+
* The range `package.json` gives `name`, read from its dependency sections in the order an
|
|
65
|
+
* install resolves them, or an empty string when none lists it.
|
|
66
|
+
*/
|
|
67
|
+
export declare function rangeOf(manifest: Manifest, name: string): string;
|
|
68
|
+
/** A result with no findings and no fix. */
|
|
69
|
+
export declare function passed(message: string): CheckResult;
|
|
70
|
+
/** A result for a check that could not judge the project, saying why. */
|
|
71
|
+
export declare function skipped(message: string): CheckResult;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every `sdxc doctor` check shares: the result it answers, the project context it reads,
|
|
3
|
+
* and the run that takes a list of checks in order. A new check is one more entry in the list,
|
|
4
|
+
* reading the same memoized manifest and registry documents as the others.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { fetchPackument } from "../releases.js";
|
|
10
|
+
/** A context whose registry reads are memoized by package name. */
|
|
11
|
+
export function createDoctorContext(options) {
|
|
12
|
+
let fetched = new Map();
|
|
13
|
+
return {
|
|
14
|
+
root: options.root,
|
|
15
|
+
manifest: options.manifest,
|
|
16
|
+
config: options.config,
|
|
17
|
+
manager: options.manager,
|
|
18
|
+
packageRoot: options.packageRoot,
|
|
19
|
+
packument(name) {
|
|
20
|
+
let pending = fetched.get(name);
|
|
21
|
+
if (pending === undefined) {
|
|
22
|
+
pending = fetchPackument(name, options.signal);
|
|
23
|
+
fetched.set(name, pending);
|
|
24
|
+
}
|
|
25
|
+
return pending;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Runs `checks` one after another, so the report keeps their order. */
|
|
30
|
+
export async function runChecks(checks, context) {
|
|
31
|
+
let reports = [];
|
|
32
|
+
for (let check of checks)
|
|
33
|
+
reports.push({ name: check.name, ...(await check.run(context)) });
|
|
34
|
+
return reports;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The range `package.json` gives `name`, read from its dependency sections in the order an
|
|
38
|
+
* install resolves them, or an empty string when none lists it.
|
|
39
|
+
*/
|
|
40
|
+
export function rangeOf(manifest, name) {
|
|
41
|
+
return (manifest.dependencies?.[name] ??
|
|
42
|
+
manifest.devDependencies?.[name] ??
|
|
43
|
+
manifest.optionalDependencies?.[name] ??
|
|
44
|
+
"");
|
|
45
|
+
}
|
|
46
|
+
/** A result with no findings and no fix. */
|
|
47
|
+
export function passed(message) {
|
|
48
|
+
return { status: "pass", message, findings: [], fix: null };
|
|
49
|
+
}
|
|
50
|
+
/** A result for a check that could not judge the project, saying why. */
|
|
51
|
+
export function skipped(message) {
|
|
52
|
+
return { status: "skip", message, findings: [], fix: null };
|
|
53
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checks `sdxc doctor` runs, in report order, and the two forms the report takes: one line
|
|
3
|
+
* per check for a person and one JSON document for an agent. Adding a check means adding it to
|
|
4
|
+
* `CHECKS`; both forms print it without further changes.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check, CheckReport } from "./check.js";
|
|
10
|
+
/**
|
|
11
|
+
* Every built-in check: release drift, the install and the `remix` peer first, then the
|
|
12
|
+
* Worker's secrets and types, then the app's own code, layout to copied components.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CHECKS: readonly Check[];
|
|
15
|
+
/** Whether any check failed, which makes `sdxc doctor` exit 1. */
|
|
16
|
+
export declare function hasFailure(reports: readonly CheckReport[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* One line per check: its status and name in aligned columns, what it found with each finding
|
|
19
|
+
* after a colon, and the fix after it, so a line reads whole when copied on its own.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatText(reports: readonly CheckReport[]): string;
|
|
22
|
+
/** The report as one JSON document, `ok` false exactly when the run exits 1. */
|
|
23
|
+
export declare function formatJSON(reports: readonly CheckReport[]): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checks `sdxc doctor` runs, in report order, and the two forms the report takes: one line
|
|
3
|
+
* per check for a person and one JSON document for an agent. Adding a check means adding it to
|
|
4
|
+
* `CHECKS`; both forms print it without further changes.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { emailsCheck } from "./emails.js";
|
|
10
|
+
import { envCheck } from "./env.js";
|
|
11
|
+
import { installedCheck } from "./installed.js";
|
|
12
|
+
import { layoutCheck } from "./layout.js";
|
|
13
|
+
import { migrationsCheck } from "./migrations.js";
|
|
14
|
+
import { modelsCheck } from "./models.js";
|
|
15
|
+
import { pinsCheck } from "./pins.js";
|
|
16
|
+
import { remixCheck } from "./remix.js";
|
|
17
|
+
import { routesCheck } from "./routes.js";
|
|
18
|
+
import { typegenCheck } from "./typegen.js";
|
|
19
|
+
import { uiCheck } from "./ui.js";
|
|
20
|
+
/**
|
|
21
|
+
* Every built-in check: release drift, the install and the `remix` peer first, then the
|
|
22
|
+
* Worker's secrets and types, then the app's own code, layout to copied components.
|
|
23
|
+
*/
|
|
24
|
+
export const CHECKS = [
|
|
25
|
+
pinsCheck,
|
|
26
|
+
installedCheck,
|
|
27
|
+
remixCheck,
|
|
28
|
+
envCheck,
|
|
29
|
+
typegenCheck,
|
|
30
|
+
migrationsCheck,
|
|
31
|
+
layoutCheck,
|
|
32
|
+
routesCheck,
|
|
33
|
+
modelsCheck,
|
|
34
|
+
emailsCheck,
|
|
35
|
+
uiCheck,
|
|
36
|
+
];
|
|
37
|
+
/** Whether any check failed, which makes `sdxc doctor` exit 1. */
|
|
38
|
+
export function hasFailure(reports) {
|
|
39
|
+
return reports.some((report) => report.status === "fail");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One line per check: its status and name in aligned columns, what it found with each finding
|
|
43
|
+
* after a colon, and the fix after it, so a line reads whole when copied on its own.
|
|
44
|
+
*/
|
|
45
|
+
export function formatText(reports) {
|
|
46
|
+
let width = Math.max(0, ...reports.map((report) => report.name.length));
|
|
47
|
+
return reports
|
|
48
|
+
.map((report) => {
|
|
49
|
+
let line = `${report.status.padEnd(4)} ${report.name.padEnd(width)} ${report.message}`;
|
|
50
|
+
if (report.findings.length > 0)
|
|
51
|
+
line += `: ${report.findings.join("; ")}`;
|
|
52
|
+
if (report.fix !== null)
|
|
53
|
+
line += `. Fix: ${report.fix}`;
|
|
54
|
+
return `${line}\n`;
|
|
55
|
+
})
|
|
56
|
+
.join("");
|
|
57
|
+
}
|
|
58
|
+
/** The report as one JSON document, `ok` false exactly when the run exits 1. */
|
|
59
|
+
export function formatJSON(reports) {
|
|
60
|
+
let checks = reports.map(({ name, status, message, findings, fix }) => ({
|
|
61
|
+
name,
|
|
62
|
+
status,
|
|
63
|
+
message,
|
|
64
|
+
findings,
|
|
65
|
+
fix,
|
|
66
|
+
}));
|
|
67
|
+
return `${JSON.stringify({ ok: !hasFailure(reports), checks }, null, 2)}\n`;
|
|
68
|
+
}
|