@sdxc/kit 2026.10.16 → 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 +391 -20
- package/changelog.jsonl +1160 -1035
- package/config.schema.json +47 -1
- package/dist/author.d.ts +36 -0
- package/dist/author.js +107 -0
- package/dist/cli.js +12 -0
- package/dist/commands/create.js +9 -4
- 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 +18 -2
- package/dist/commands/run.js +35 -12
- 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.d.ts +8 -1
- package/dist/create/templates.js +26 -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/init.d.ts +5 -3
- package/dist/init.js +15 -7
- 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 +32 -4
- package/dist/make/declare.js +405 -27
- 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 +43 -14
- 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 -25
- package/dist/make/kinds.d.ts +31 -3
- package/dist/make/kinds.js +82 -9
- 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/testing.d.ts +12 -2
- package/dist/testing.js +22 -3
- 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/command.stub +4 -0
- package/stubs/command.test.stub +3 -0
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.api.stub +21 -0
- package/stubs/controller.api.test.stub +18 -0
- package/stubs/controller.form.stub +40 -10
- package/stubs/controller.form.test.stub +61 -0
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/controller.stub +15 -8
- package/stubs/controller.test.stub +3 -0
- package/stubs/email.stub +15 -38
- package/stubs/email.test.stub +12 -7
- package/stubs/factory.stub +4 -1
- package/stubs/initializer.stub +2 -0
- package/stubs/initializer.test.stub +3 -0
- package/stubs/job.cron.stub +4 -0
- package/stubs/job.stub +4 -0
- package/stubs/job.test.stub +3 -0
- package/stubs/mcp.resource.stub +3 -0
- package/stubs/mcp.stub +3 -0
- package/stubs/mcp.test.stub +3 -0
- package/stubs/middleware.stub +6 -1
- package/stubs/middleware.test.stub +3 -0
- package/stubs/model.stub +12 -3
- package/stubs/model.test.stub +3 -0
- package/stubs/policy.test.stub +36 -7
- 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/stubs/service.stub +4 -0
- package/stubs/service.test.stub +3 -0
- package/stubs/validator.stub +3 -0
- package/stubs/validator.test.stub +3 -0
- package/templates/app/.env.example +16 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +79 -37
- package/templates/app/app/commands/about.test.ts +1 -1
- 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/console.ts +6 -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 +46 -0
- package/templates/app/app/commands/db/migrate.ts +88 -0
- 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 +72 -1
- package/templates/app/app/commands/typegen.test.ts +17 -0
- package/templates/app/app/commands/typegen.ts +16 -0
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/controllers/api/health.tsx +15 -0
- package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
- package/templates/app/app/http/controllers/home.tsx +21 -13
- package/templates/app/app/http/controllers/mcp.tsx +16 -0
- package/templates/app/app/http/controllers/not-found.tsx +23 -18
- package/templates/app/app/http/controllers/robots.test.ts +18 -0
- package/templates/app/app/http/controllers/robots.ts +24 -0
- package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
- package/templates/app/app/http/controllers/sitemap.ts +25 -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 +19 -0
- package/templates/app/app/http/middleware/page.test.ts +43 -0
- package/templates/app/app/http/middleware/page.ts +51 -0
- package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
- package/templates/app/app/http/middleware/server-timing.ts +42 -0
- package/templates/app/app/initializers/assets.ts +1 -1
- package/templates/app/app/initializers/captcha.ts +11 -0
- package/templates/app/app/initializers/cli.ts +68 -2
- package/templates/app/app/initializers/database.test.ts +18 -0
- package/templates/app/app/initializers/database.ts +18 -0
- package/templates/app/app/initializers/dispatcher.ts +26 -0
- package/templates/app/app/initializers/honeypot.ts +11 -0
- package/templates/app/app/initializers/i18n.test.ts +16 -0
- package/templates/app/app/initializers/i18n.ts +28 -0
- package/templates/app/app/initializers/local-database.test.ts +33 -0
- package/templates/app/app/initializers/local-database.ts +53 -0
- 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 +27 -0
- package/templates/app/app/initializers/mail.ts +19 -0
- package/templates/app/app/initializers/mcp.ts +1 -1
- package/templates/app/app/initializers/openapi.ts +21 -0
- package/templates/app/app/initializers/router.test.ts +68 -0
- package/templates/app/app/initializers/router.tsx +81 -25
- package/templates/app/app/initializers/seo.ts +15 -0
- package/templates/app/app/initializers/session.test.ts +34 -0
- package/templates/app/app/initializers/session.ts +29 -0
- package/templates/app/app/initializers/spam.ts +10 -0
- 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/models/index.ts +10 -0
- 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 +92 -0
- package/templates/app/app/services/migrations.ts +117 -0
- package/templates/app/app/test/cloudflare-workers.ts +25 -0
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/cli.ts +1 -1
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/bootstrap/worker.ts +4 -4
- package/templates/app/cloudflare.config.ts +30 -2
- package/templates/app/config/constants.ts +19 -0
- package/templates/app/config/problems.ts +24 -0
- package/templates/app/config/security-policy.ts +34 -0
- package/templates/app/config/security-txt.ts +28 -0
- package/templates/app/database/migrations/.gitkeep +0 -0
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +37 -6
- package/templates/app/resources/layouts/document.tsx +28 -7
- package/templates/app/resources/locales/en.json +10 -0
- package/templates/app/routes/api.ts +29 -0
- package/templates/app/routes/web.ts +6 -4
- package/templates/app/vite.config.ts +4 -0
- package/stubs/policy.stub +0 -13
- package/templates/app/config/router-context.d.ts +0 -20
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The install commands `sdxc doctor` prints as fixes, spelled for the project's package manager:
|
|
3
|
+
* each pins an exact version and keeps a package in the dependency section that lists it, so
|
|
4
|
+
* running the fix changes only the versions the check flagged.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** How each package manager adds an exact version, and the flag that keeps it a dev dependency. */
|
|
10
|
+
const EXACT_ADD = {
|
|
11
|
+
bun: { add: ["bun", "add", "--exact"], dev: "--dev" },
|
|
12
|
+
npm: { add: ["npm", "install", "--save-exact"], dev: "--save-dev" },
|
|
13
|
+
pnpm: { add: ["pnpm", "add", "--save-exact"], dev: "--save-dev" },
|
|
14
|
+
yarn: { add: ["yarn", "add", "--exact"], dev: "--dev" },
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The command that pins each package to its version: one for the packages in `dependencies`
|
|
18
|
+
* and one for those in `devDependencies`, joined with `&&` when both are needed.
|
|
19
|
+
*
|
|
20
|
+
* @param versions - The exact version to pin, by package name
|
|
21
|
+
*/
|
|
22
|
+
export function exactInstallCommand(manager, manifest, versions) {
|
|
23
|
+
let spelling = EXACT_ADD[manager.name];
|
|
24
|
+
let runtime = [];
|
|
25
|
+
let development = [];
|
|
26
|
+
for (let [name, version] of versions) {
|
|
27
|
+
let target = manifest.devDependencies?.[name] === undefined ? runtime : development;
|
|
28
|
+
target.push(`${name}@${version}`);
|
|
29
|
+
}
|
|
30
|
+
let commands = [];
|
|
31
|
+
if (runtime.length > 0)
|
|
32
|
+
commands.push([...spelling.add, ...runtime].join(" "));
|
|
33
|
+
if (development.length > 0) {
|
|
34
|
+
commands.push([...spelling.add, spelling.dev, ...development].join(" "));
|
|
35
|
+
}
|
|
36
|
+
return commands.join(" && ");
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `installed` check: every `@sdxc/*` package and `remix` that `package.json` lists is in
|
|
3
|
+
* `node_modules` at the version it pins, found the way Node resolves it from the project root,
|
|
4
|
+
* so a hoisted workspace install counts and a `package.json` edited without an install does not.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/** Fails on a listed package that is missing or installed at another version than its pin. */
|
|
11
|
+
export declare const installedCheck: Check;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `installed` check: every `@sdxc/*` package and `remix` that `package.json` lists is in
|
|
3
|
+
* `node_modules` at the version it pins, found the way Node resolves it from the project root,
|
|
4
|
+
* so a hoisted workspace install counts and a `package.json` edited without an install does not.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import { isFailure, isSuccess, wrap } from "@sdxc/result";
|
|
12
|
+
import { parse } from "@sdxc/semver";
|
|
13
|
+
import { datedPin } from "../releases.js";
|
|
14
|
+
import { listedScopedPackages, lists } from "../upgrade/project.js";
|
|
15
|
+
import { passed, rangeOf, skipped } from "./check.js";
|
|
16
|
+
/** Fails on a listed package that is missing or installed at another version than its pin. */
|
|
17
|
+
export const installedCheck = {
|
|
18
|
+
name: "installed",
|
|
19
|
+
async run(context) {
|
|
20
|
+
let names = listedScopedPackages(context.manifest);
|
|
21
|
+
if (lists(context.manifest, "remix"))
|
|
22
|
+
names.push("remix");
|
|
23
|
+
if (names.length === 0)
|
|
24
|
+
return skipped("package.json lists no @sdxc package or remix");
|
|
25
|
+
let findings = [];
|
|
26
|
+
for (let name of names) {
|
|
27
|
+
let range = rangeOf(context.manifest, name);
|
|
28
|
+
let installed = await installedVersion(context.root, name);
|
|
29
|
+
if (installed === null) {
|
|
30
|
+
findings.push(`${name} is not installed`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
let pinned = exactVersion(range);
|
|
34
|
+
if (pinned !== null && pinned !== installed) {
|
|
35
|
+
findings.push(`${name} ${installed} is installed, package.json pins ${pinned}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (findings.length === 0) {
|
|
39
|
+
return passed(`${names.length} packages are installed at the versions package.json pins`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: "fail",
|
|
43
|
+
message: "node_modules differs from package.json",
|
|
44
|
+
findings,
|
|
45
|
+
fix: context.manager.install.join(" "),
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The exact version a range pins, `null` for a range that admits several, which any installed
|
|
51
|
+
* version satisfies as far as this check is concerned.
|
|
52
|
+
*/
|
|
53
|
+
function exactVersion(range) {
|
|
54
|
+
let dated = datedPin(range);
|
|
55
|
+
if (dated !== null)
|
|
56
|
+
return dated;
|
|
57
|
+
let bare = range.trim().replace(/^=?v?/, "");
|
|
58
|
+
return isSuccess(parse(bare)) ? bare : null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The version of `name` installed in the nearest `node_modules` at or above `root`, or `null`
|
|
62
|
+
* when no directory up to the filesystem root holds it.
|
|
63
|
+
*/
|
|
64
|
+
async function installedVersion(root, name) {
|
|
65
|
+
let directory = root;
|
|
66
|
+
while (true) {
|
|
67
|
+
let text = await wrap(() => readFile(join(directory, "node_modules", name, "package.json"), "utf8"));
|
|
68
|
+
if (isSuccess(text)) {
|
|
69
|
+
let manifest = wrap(() => JSON.parse(text.data));
|
|
70
|
+
if (isFailure(manifest))
|
|
71
|
+
return null;
|
|
72
|
+
return typeof manifest.data.version === "string" ? manifest.data.version : null;
|
|
73
|
+
}
|
|
74
|
+
let parent = dirname(directory);
|
|
75
|
+
if (parent === directory)
|
|
76
|
+
return null;
|
|
77
|
+
directory = parent;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `layout` check: the app keeps one folder per kind of code under `app/`, and only entry
|
|
3
|
+
* points sit in `bootstrap/`, which nothing outside it imports. A folder outside the layout
|
|
4
|
+
* gives a file two possible homes, and an import of an entry point drags the whole Worker along.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/** The folders `app/` may hold, one per kind of code. */
|
|
11
|
+
export declare const APP_FOLDERS: ReadonlySet<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Warns on each folder in `app/` the layout has no kind for, and on each import of `bootstrap/`
|
|
14
|
+
* from outside it. A file the module scanner cannot read is left to the type checker.
|
|
15
|
+
*/
|
|
16
|
+
export declare const layoutCheck: Check;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `specifier`, written in `file`, reaches into `bootstrap/` through the `~/bootstrap`
|
|
19
|
+
* alias or a relative path.
|
|
20
|
+
*
|
|
21
|
+
* @param file - The importing file, relative to the project root.
|
|
22
|
+
*/
|
|
23
|
+
export declare function reachesBootstrap(specifier: string, file: string): boolean;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `layout` check: the app keeps one folder per kind of code under `app/`, and only entry
|
|
3
|
+
* points sit in `bootstrap/`, which nothing outside it imports. A folder outside the layout
|
|
4
|
+
* gives a file two possible homes, and an import of an entry point drags the whole Worker along.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
10
|
+
import { dirname, join, posix } from "node:path";
|
|
11
|
+
import { findModuleReferences } from "@sdxc/codemod";
|
|
12
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
13
|
+
import { passed, skipped } from "./check.js";
|
|
14
|
+
import { isAppSource, listFiles } from "./files.js";
|
|
15
|
+
/** The folders `app/` may hold, one per kind of code. */
|
|
16
|
+
export const APP_FOLDERS = new Set([
|
|
17
|
+
"commands",
|
|
18
|
+
"emails",
|
|
19
|
+
"http",
|
|
20
|
+
"initializers",
|
|
21
|
+
"jobs",
|
|
22
|
+
"mcp",
|
|
23
|
+
"models",
|
|
24
|
+
"policies",
|
|
25
|
+
"services",
|
|
26
|
+
"test",
|
|
27
|
+
]);
|
|
28
|
+
/** The folders whose modules must reach `bootstrap/` through nothing. */
|
|
29
|
+
const IMPORTING_FOLDERS = ["app", "config", "database", "resources", "routes"];
|
|
30
|
+
/**
|
|
31
|
+
* Warns on each folder in `app/` the layout has no kind for, and on each import of `bootstrap/`
|
|
32
|
+
* from outside it. A file the module scanner cannot read is left to the type checker.
|
|
33
|
+
*/
|
|
34
|
+
export const layoutCheck = {
|
|
35
|
+
name: "layout",
|
|
36
|
+
async run(context) {
|
|
37
|
+
let entries = await wrap(() => readdir(join(context.root, "app"), { withFileTypes: true }));
|
|
38
|
+
if (isFailure(entries))
|
|
39
|
+
return skipped("No app/ folder in the project");
|
|
40
|
+
let findings = entries.data
|
|
41
|
+
.filter((entry) => entry.isDirectory() && !APP_FOLDERS.has(entry.name))
|
|
42
|
+
.map((entry) => entry.name)
|
|
43
|
+
.sort()
|
|
44
|
+
.map((name) => `app/${name}/ is a folder the app layout has no kind for`);
|
|
45
|
+
for (let folder of IMPORTING_FOLDERS) {
|
|
46
|
+
for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
|
|
47
|
+
let source = await wrap(() => readFile(join(context.root, file), "utf8"));
|
|
48
|
+
if (isFailure(source))
|
|
49
|
+
continue;
|
|
50
|
+
let references = findModuleReferences(file, source.data);
|
|
51
|
+
if (isFailure(references))
|
|
52
|
+
continue;
|
|
53
|
+
for (let { specifier } of references.data) {
|
|
54
|
+
if (reachesBootstrap(specifier, file))
|
|
55
|
+
findings.push(`${file} imports ${specifier}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (findings.length === 0) {
|
|
60
|
+
return passed("app/ holds only the layout's folders and nothing imports bootstrap/");
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
status: "warn",
|
|
64
|
+
message: "The project strays from the app layout",
|
|
65
|
+
findings,
|
|
66
|
+
fix: "Move each file to the folder its kind has (sdxc make <kind> shows where), and import a Durable Object from its own module instead of bootstrap/",
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Whether `specifier`, written in `file`, reaches into `bootstrap/` through the `~/bootstrap`
|
|
72
|
+
* alias or a relative path.
|
|
73
|
+
*
|
|
74
|
+
* @param file - The importing file, relative to the project root.
|
|
75
|
+
*/
|
|
76
|
+
export function reachesBootstrap(specifier, file) {
|
|
77
|
+
if (specifier === "~/bootstrap" || specifier.startsWith("~/bootstrap/"))
|
|
78
|
+
return true;
|
|
79
|
+
if (!specifier.startsWith("."))
|
|
80
|
+
return false;
|
|
81
|
+
let target = posix.normalize(posix.join(dirname(file).split("\\").join("/"), specifier));
|
|
82
|
+
return target === "bootstrap" || target.startsWith("bootstrap/");
|
|
83
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `migrations` check: every chain in `make.migrations` replays on an empty database with
|
|
3
|
+
* double-quoted string literals disabled. A new database, a new tenant or a fresh test run
|
|
4
|
+
* replays the whole chain, so a file that only applied on top of old state breaks there first.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/**
|
|
11
|
+
* Fails on each chain whose replay stops, naming the file and SQLite's error. An error that
|
|
12
|
+
* `doctor.migrations.accept` lists is stepped past and reported as a finding, so the rest of the
|
|
13
|
+
* chain is still checked; an entry no error matches any more warns, so the list stays current.
|
|
14
|
+
* The replay code loads `node:sqlite` on first use, so a runtime without it skips this check alone.
|
|
15
|
+
*/
|
|
16
|
+
export declare const migrationsCheck: Check;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `migrations` check: every chain in `make.migrations` replays on an empty database with
|
|
3
|
+
* double-quoted string literals disabled. A new database, a new tenant or a fresh test run
|
|
4
|
+
* replays the whole chain, so a file that only applied on top of old state breaks there first.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { isFailure } from "@sdxc/result";
|
|
10
|
+
import { skipped } from "./check.js";
|
|
11
|
+
/**
|
|
12
|
+
* Fails on each chain whose replay stops, naming the file and SQLite's error. An error that
|
|
13
|
+
* `doctor.migrations.accept` lists is stepped past and reported as a finding, so the rest of the
|
|
14
|
+
* chain is still checked; an entry no error matches any more warns, so the list stays current.
|
|
15
|
+
* The replay code loads `node:sqlite` on first use, so a runtime without it skips this check alone.
|
|
16
|
+
*/
|
|
17
|
+
export const migrationsCheck = {
|
|
18
|
+
name: "migrations",
|
|
19
|
+
async run(context) {
|
|
20
|
+
let loaded = await import("../make/from-model.js").then(async (fromModel) => ({ fromModel, schema: await import("../make/schema-diff.js") }), (error) => (error instanceof Error ? error : new Error(String(error))));
|
|
21
|
+
if (loaded instanceof Error)
|
|
22
|
+
return skipped(`Could not load SQLite: ${loaded.message}`);
|
|
23
|
+
let { fromModel, schema } = loaded;
|
|
24
|
+
let entries = context.config.doctor.migrations.accept;
|
|
25
|
+
let matched = new Set();
|
|
26
|
+
let accepts = (file, message) => {
|
|
27
|
+
let entry = entries.find((item) => item.file === file && namesColumn(message, item.column));
|
|
28
|
+
if (entry === undefined)
|
|
29
|
+
return false;
|
|
30
|
+
matched.add(entry);
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
let findings = [];
|
|
34
|
+
let accepted = [];
|
|
35
|
+
let replayed = [];
|
|
36
|
+
for (let folder of Object.values(context.config.make.migrations)) {
|
|
37
|
+
let chain = await fromModel.readChain(context.root, folder);
|
|
38
|
+
if (isFailure(chain)) {
|
|
39
|
+
findings.push(`${folder}: ${chain.error.message}`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (chain.data.length === 0)
|
|
43
|
+
continue;
|
|
44
|
+
let replay = schema.replayChain(chain.data, { accepts });
|
|
45
|
+
if (isFailure(replay)) {
|
|
46
|
+
findings.push(`${folder}/${replay.error.message}`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
replay.data.db.close();
|
|
50
|
+
for (let failure of replay.data.accepted) {
|
|
51
|
+
accepted.push(`${folder}/${failure.file} accepted: ${failure.message}`);
|
|
52
|
+
}
|
|
53
|
+
replayed.push(folder);
|
|
54
|
+
}
|
|
55
|
+
if (findings.length > 0) {
|
|
56
|
+
return {
|
|
57
|
+
status: "fail",
|
|
58
|
+
message: `${findings.length === 1 ? "A migration chain does" : `${findings.length} migration chains do`} not replay on an empty database`,
|
|
59
|
+
findings,
|
|
60
|
+
fix: "Make the named migration apply to an empty database: quote strings with single quotes, and read a column's old name in a rebuild's SELECT. A migration production already ran goes in doctor.migrations.accept instead",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
let stale = entries
|
|
64
|
+
.filter((entry) => !matched.has(entry))
|
|
65
|
+
.map((entry) => `${entry.file} no longer fails on ${entry.column}`);
|
|
66
|
+
if (stale.length > 0) {
|
|
67
|
+
return {
|
|
68
|
+
status: "warn",
|
|
69
|
+
message: stale.length === 1
|
|
70
|
+
? "An accepted migration failure no longer fails"
|
|
71
|
+
: `${stale.length} accepted migration failures no longer fail`,
|
|
72
|
+
findings: [...stale, ...accepted],
|
|
73
|
+
fix: "Remove each entry named above from doctor.migrations.accept in the sdxc configuration",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (replayed.length === 0)
|
|
77
|
+
return skipped("The project has no migrations");
|
|
78
|
+
let replays = `${replayed.join(", ")} ${replayed.length === 1 ? "replays" : "replay"} on an empty database`;
|
|
79
|
+
return {
|
|
80
|
+
status: "pass",
|
|
81
|
+
message: accepted.length === 0
|
|
82
|
+
? replays
|
|
83
|
+
: `${replays} past ${accepted.length === 1 ? "an accepted failure" : `${accepted.length} accepted failures`}`,
|
|
84
|
+
findings: accepted,
|
|
85
|
+
fix: null,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Whether SQLite's error `message` names `column`, quoted or bare, alone or qualified by its
|
|
91
|
+
* table, so an entry accepts the error it was written for and no other in the same file.
|
|
92
|
+
*/
|
|
93
|
+
function namesColumn(message, column) {
|
|
94
|
+
let named = /column(?: name)?: "?([^"\s]+)"?/.exec(message)?.[1];
|
|
95
|
+
return named === column || named?.endsWith(`.${column}`) === true;
|
|
96
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `models` check: every module in `app/models/` that creates a model is registered in
|
|
3
|
+
* `app/models/index.ts`, since `ctx.models` reaches only what `createModels({ … })` lists and an
|
|
4
|
+
* unregistered model is invisible to every request, job and command.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/** The registry module `sdxc make model` adds each model to. */
|
|
11
|
+
export declare const MODELS_INDEX = "app/models/index.ts";
|
|
12
|
+
/** Warns on each model module the registry imports neither statically nor on first use. */
|
|
13
|
+
export declare const modelsCheck: Check;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `models` check: every module in `app/models/` that creates a model is registered in
|
|
3
|
+
* `app/models/index.ts`, since `ctx.models` reaches only what `createModels({ … })` lists and an
|
|
4
|
+
* unregistered model is invisible to every request, job and command.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join, posix } from "node:path";
|
|
11
|
+
import { findModuleReferences } from "@sdxc/codemod";
|
|
12
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
13
|
+
import { passed, skipped } from "./check.js";
|
|
14
|
+
import { isAppSource, listFiles } from "./files.js";
|
|
15
|
+
/** The registry module `sdxc make model` adds each model to. */
|
|
16
|
+
export const MODELS_INDEX = "app/models/index.ts";
|
|
17
|
+
/** A `createModel(` call, which is what makes a module a model rather than a helper beside one. */
|
|
18
|
+
const CREATES_MODEL = /\bcreateModel\s*\(/;
|
|
19
|
+
/** A module extension a specifier may carry or leave out. */
|
|
20
|
+
const EXTENSION = /\.[cm]?[jt]sx?$/;
|
|
21
|
+
/** Warns on each model module the registry imports neither statically nor on first use. */
|
|
22
|
+
export const modelsCheck = {
|
|
23
|
+
name: "models",
|
|
24
|
+
async run(context) {
|
|
25
|
+
let index = await wrap(() => readFile(join(context.root, MODELS_INDEX), "utf8"));
|
|
26
|
+
if (isFailure(index))
|
|
27
|
+
return skipped(`No ${MODELS_INDEX} in the project`);
|
|
28
|
+
let references = findModuleReferences(MODELS_INDEX, index.data);
|
|
29
|
+
if (isFailure(references))
|
|
30
|
+
return skipped(`${MODELS_INDEX} could not be read`);
|
|
31
|
+
let registered = new Set(references.data.map(({ specifier }) => modulePath(specifier)).filter((path) => path !== null));
|
|
32
|
+
let models = [];
|
|
33
|
+
for (let file of (await listFiles(context.root, "app/models")).filter(isAppSource)) {
|
|
34
|
+
if (file === MODELS_INDEX)
|
|
35
|
+
continue;
|
|
36
|
+
let source = await wrap(() => readFile(join(context.root, file), "utf8"));
|
|
37
|
+
if (isFailure(source) || !CREATES_MODEL.test(source.data))
|
|
38
|
+
continue;
|
|
39
|
+
models.push(file);
|
|
40
|
+
}
|
|
41
|
+
let missing = models.filter((file) => {
|
|
42
|
+
let bare = file.replace(EXTENSION, "");
|
|
43
|
+
return !registered.has(bare) && !registered.has(bare.replace(/\/index$/, ""));
|
|
44
|
+
});
|
|
45
|
+
if (missing.length === 0) {
|
|
46
|
+
return passed(`${MODELS_INDEX} registers every model in app/models/`);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
status: "warn",
|
|
50
|
+
message: `${MODELS_INDEX} leaves out ${missing.length === 1 ? "a model" : `${missing.length} models`}`,
|
|
51
|
+
findings: missing.map((file) => `${file} creates a model ${MODELS_INDEX} does not import`),
|
|
52
|
+
fix: `Register each in createModels({ … }) in ${MODELS_INDEX} as key: () => import("./<file>")`,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The project path, extension removed, that a specifier written in the registry names, through
|
|
58
|
+
* a relative path or the `~/app` alias; `null` for a package.
|
|
59
|
+
*/
|
|
60
|
+
function modulePath(specifier) {
|
|
61
|
+
let path;
|
|
62
|
+
if (specifier.startsWith("~/app/"))
|
|
63
|
+
path = specifier.slice(2);
|
|
64
|
+
else if (specifier.startsWith("."))
|
|
65
|
+
path = posix.join("app/models", specifier);
|
|
66
|
+
else
|
|
67
|
+
return null;
|
|
68
|
+
return posix.normalize(path).replace(EXTENSION, "");
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `pins` check: every `@sdxc/*` pin in `package.json` is the package's version at the
|
|
3
|
+
* project's release, read from the npm registry the way `sdxc upgrade` resolves one, since a
|
|
4
|
+
* daily release republishes only what changed and an older date alone is no drift.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/**
|
|
11
|
+
* Fails on a pin older than the package's version at the project's release, and warns on a pin
|
|
12
|
+
* that names no dated version; the fix is `sdxc upgrade <release>`, which re-pins each one to its
|
|
13
|
+
* version at the release and writes the prompt for the changes it crosses.
|
|
14
|
+
*/
|
|
15
|
+
export declare const pinsCheck: Check;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `pins` check: every `@sdxc/*` pin in `package.json` is the package's version at the
|
|
3
|
+
* project's release, read from the npm registry the way `sdxc upgrade` resolves one, since a
|
|
4
|
+
* daily release republishes only what changed and an older date alone is no drift.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { isFailure } from "@sdxc/result";
|
|
10
|
+
import { compare } from "@sdxc/semver";
|
|
11
|
+
import { datedPin, versionAtRelease } from "../releases.js";
|
|
12
|
+
import { currentRelease, listedScopedPackages } from "../upgrade/project.js";
|
|
13
|
+
import { RELEASE_PACKAGE } from "../upgrade/registry.js";
|
|
14
|
+
import { passed, rangeOf, skipped } from "./check.js";
|
|
15
|
+
/**
|
|
16
|
+
* Fails on a pin older than the package's version at the project's release, and warns on a pin
|
|
17
|
+
* that names no dated version; the fix is `sdxc upgrade <release>`, which re-pins each one to its
|
|
18
|
+
* version at the release and writes the prompt for the changes it crosses.
|
|
19
|
+
*/
|
|
20
|
+
export const pinsCheck = {
|
|
21
|
+
name: "pins",
|
|
22
|
+
async run(context) {
|
|
23
|
+
let scoped = listedScopedPackages(context.manifest);
|
|
24
|
+
if (scoped.length === 0)
|
|
25
|
+
return skipped("package.json lists no @sdxc package");
|
|
26
|
+
let release = currentRelease(context.manifest);
|
|
27
|
+
if (release === null)
|
|
28
|
+
return skipped("package.json pins no @sdxc package to a release");
|
|
29
|
+
let fetched = await Promise.all([RELEASE_PACKAGE, ...scoped].map((name) => context.packument(name)));
|
|
30
|
+
let packuments = new Map();
|
|
31
|
+
for (let packument of fetched) {
|
|
32
|
+
if (isFailure(packument))
|
|
33
|
+
return skipped(packument.error.message);
|
|
34
|
+
packuments.set(packument.data.name, packument.data);
|
|
35
|
+
}
|
|
36
|
+
let latest = packuments.get(RELEASE_PACKAGE)?.latest ?? null;
|
|
37
|
+
let upgradeTo = latest !== null && compare(latest, release) > 0 ? latest : null;
|
|
38
|
+
let findings = [];
|
|
39
|
+
let lagging = 0;
|
|
40
|
+
for (let name of scoped) {
|
|
41
|
+
let packument = packuments.get(name);
|
|
42
|
+
let expected = packument === undefined ? null : versionAtRelease(packument, release);
|
|
43
|
+
if (packument === undefined || expected === null)
|
|
44
|
+
continue;
|
|
45
|
+
let range = rangeOf(context.manifest, name);
|
|
46
|
+
let pinned = datedPin(range);
|
|
47
|
+
if (pinned !== null && compare(pinned, expected) >= 0)
|
|
48
|
+
continue;
|
|
49
|
+
if (pinned !== null)
|
|
50
|
+
lagging += 1;
|
|
51
|
+
let next = upgradeTo === null ? null : versionAtRelease(packument, upgradeTo);
|
|
52
|
+
let upgrade = next === null ? "" : ` (sdxc upgrade moves it to ${next})`;
|
|
53
|
+
findings.push(`${name} ${range} -> ${expected}${upgrade}`);
|
|
54
|
+
}
|
|
55
|
+
if (findings.length === 0) {
|
|
56
|
+
let newer = upgradeTo === null ? "" : `; sdxc upgrade moves them to ${upgradeTo}`;
|
|
57
|
+
return passed(`Every @sdxc package is at release ${release}${newer}`);
|
|
58
|
+
}
|
|
59
|
+
let fix = `sdxc upgrade ${release}`;
|
|
60
|
+
if (lagging === 0) {
|
|
61
|
+
return {
|
|
62
|
+
status: "warn",
|
|
63
|
+
message: `${count(findings.length)} not pinned to a release`,
|
|
64
|
+
findings,
|
|
65
|
+
fix,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
status: "fail",
|
|
70
|
+
message: `${count(findings.length)} behind release ${release}`,
|
|
71
|
+
findings,
|
|
72
|
+
fix,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
/** `1 @sdxc package is` or `2 @sdxc packages are`. */
|
|
77
|
+
function count(total) {
|
|
78
|
+
return total === 1 ? "1 @sdxc package is" : `${total} @sdxc packages are`;
|
|
79
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the checks a project defines in its `doctor.checks` folder. They load in a child process
|
|
3
|
+
* of the project's own runtime, so a check imports what the app imports, and whatever a check
|
|
4
|
+
* does, a throw, a bad export or a hang, comes back as a failed report beside the others.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { AnyCommandContext } from "@sdxc/cli";
|
|
10
|
+
import type { Config } from "../config.js";
|
|
11
|
+
import type { RouteEntry } from "../routes/index.js";
|
|
12
|
+
import type { CheckReport } from "./check.js";
|
|
13
|
+
/** What a project check may be named: lowercase words joined by dashes. */
|
|
14
|
+
export declare const CHECK_NAME: RegExp;
|
|
15
|
+
/** How long one check may run before it is reported as failed. */
|
|
16
|
+
export declare const CHECK_TIMEOUT_MS = 30000;
|
|
17
|
+
/** Which checks a run reports, by name; an empty `only` selects every check. */
|
|
18
|
+
export interface Selection {
|
|
19
|
+
only: readonly string[];
|
|
20
|
+
skip: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
/** Whether `selection` reports the check called `name`. */
|
|
23
|
+
export declare function selects(selection: Selection, name: string): boolean;
|
|
24
|
+
/** What the project checks run with. */
|
|
25
|
+
export interface ProjectChecksOptions {
|
|
26
|
+
root: string;
|
|
27
|
+
/** The runtime `sdxc run` uses for the project, which imports the check modules. */
|
|
28
|
+
runtime: "bun" | "node";
|
|
29
|
+
/** `package.json` as written. */
|
|
30
|
+
manifest: Record<string, unknown>;
|
|
31
|
+
config: Config;
|
|
32
|
+
/** The project's routes, computed once the folder holds a check. */
|
|
33
|
+
routes(): Promise<RouteEntry[]>;
|
|
34
|
+
/** The built-in checks' names, which a project check may not take. */
|
|
35
|
+
builtIn: readonly string[];
|
|
36
|
+
selection: Selection;
|
|
37
|
+
}
|
|
38
|
+
/** What the project checks reported, and the name of every check they define. */
|
|
39
|
+
export interface ProjectChecksRun {
|
|
40
|
+
reports: CheckReport[];
|
|
41
|
+
names: string[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The check modules in `folder`, relative to the project root and sorted; a missing folder
|
|
45
|
+
* holds none.
|
|
46
|
+
*/
|
|
47
|
+
export declare function checkFiles(root: string, folder: string): Promise<string[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Runs every selected check in the project's `doctor.checks` folder. A module that fails to
|
|
50
|
+
* load is reported under its path, a check that throws, hangs or answers no result under its
|
|
51
|
+
* name, and a runner that cannot start under the folder's path, each as `fail`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function runProjectChecks(ctx: Pick<AnyCommandContext, "exec">, options: ProjectChecksOptions): Promise<ProjectChecksRun>;
|
|
54
|
+
/**
|
|
55
|
+
* A check's answer completed with the defaults a project check may leave out, or `null` when it
|
|
56
|
+
* lacks a known status or a message, or carries findings that are not strings.
|
|
57
|
+
*/
|
|
58
|
+
export declare function toResult(value: unknown): Omit<CheckReport, "name"> | null;
|