@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,261 @@
|
|
|
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 { readdir } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
12
|
+
/** The prefix of the line the runner prints its reports on, apart from anything a check logs. */
|
|
13
|
+
const MARKER = "sdxc-doctor-checks:";
|
|
14
|
+
/** A check module: TypeScript or JavaScript, its tests and declaration files left out. */
|
|
15
|
+
const CHECK_FILE = /^(?!.*\.test\.[cm]?[jt]s$)(?!.*\.d\.[cm]?ts$).+\.[cm]?[jt]s$/;
|
|
16
|
+
/** What a project check may be named: lowercase words joined by dashes. */
|
|
17
|
+
export const CHECK_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
18
|
+
/** How long one check may run before it is reported as failed. */
|
|
19
|
+
export const CHECK_TIMEOUT_MS = 30_000;
|
|
20
|
+
/** Every status a check may answer. */
|
|
21
|
+
const STATUSES = new Set(["pass", "warn", "fail", "skip"]);
|
|
22
|
+
/**
|
|
23
|
+
* The runner, evaluated by the project's runtime from the project root. It reads its input from
|
|
24
|
+
* stdin, imports each check module, runs every selected check against a read-only context with
|
|
25
|
+
* a time limit, and prints one entry per check, or per module that failed to load, on a marked line.
|
|
26
|
+
*/
|
|
27
|
+
const RUNNER = `
|
|
28
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
29
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
30
|
+
import { pathToFileURL } from "node:url";
|
|
31
|
+
|
|
32
|
+
const chunks = [];
|
|
33
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
34
|
+
const input = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
35
|
+
const root = input.root;
|
|
36
|
+
const inside = (path) => {
|
|
37
|
+
const full = resolve(root, String(path));
|
|
38
|
+
const rel = relative(root, full);
|
|
39
|
+
if (rel.startsWith("..") || isAbsolute(rel)) throw new Error(path + " is outside the project");
|
|
40
|
+
return full;
|
|
41
|
+
};
|
|
42
|
+
const describe = (error) => (error instanceof Error ? error.stack ?? error.message : String(error));
|
|
43
|
+
const context = Object.freeze({
|
|
44
|
+
root,
|
|
45
|
+
manifest: input.manifest,
|
|
46
|
+
config: input.config,
|
|
47
|
+
routes: input.routes,
|
|
48
|
+
async readFile(path) {
|
|
49
|
+
try {
|
|
50
|
+
return await readFile(inside(path), "utf8");
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (error?.code === "ENOENT") return null;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
async exists(path) {
|
|
57
|
+
try {
|
|
58
|
+
await stat(inside(path));
|
|
59
|
+
return true;
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
async files(folder) {
|
|
65
|
+
const base = inside(folder);
|
|
66
|
+
let entries;
|
|
67
|
+
try {
|
|
68
|
+
entries = await readdir(base, { recursive: true, withFileTypes: true });
|
|
69
|
+
} catch {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
return entries
|
|
73
|
+
.filter((entry) => entry.isFile())
|
|
74
|
+
.map((entry) => join(entry.parentPath, entry.name))
|
|
75
|
+
.filter((full) => !relative(base, full).split(sep).some((part) => part === "node_modules" || part.startsWith(".")))
|
|
76
|
+
.map((full) => relative(root, full).split(sep).join("/"))
|
|
77
|
+
.sort();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
const NAME = new RegExp(input.namePattern);
|
|
81
|
+
const taken = new Map(input.builtIn.map((name) => [name, "a built-in check"]));
|
|
82
|
+
const selected = (name) =>
|
|
83
|
+
(input.only.length === 0 || input.only.includes(name)) && !input.skip.includes(name);
|
|
84
|
+
const reports = [];
|
|
85
|
+
for (const file of input.files) {
|
|
86
|
+
let checks;
|
|
87
|
+
try {
|
|
88
|
+
const module = await import(pathToFileURL(join(root, file)).href);
|
|
89
|
+
checks = Array.isArray(module.default) ? module.default : [module.default];
|
|
90
|
+
} catch (error) {
|
|
91
|
+
reports.push({ file, name: null, error: "Could not load " + file + ": " + describe(error) });
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
for (const check of checks) {
|
|
95
|
+
if (check === null || typeof check !== "object" || typeof check.run !== "function") {
|
|
96
|
+
reports.push({ file, name: null, error: file + " default-exports no check; export defineCheck({ name, run }) or a list of them" });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const name = check.name;
|
|
100
|
+
if (typeof name !== "string" || !NAME.test(name)) {
|
|
101
|
+
reports.push({ file, name: null, error: file + " exports a check named " + JSON.stringify(name) + "; a name is lowercase words joined by dashes" });
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (taken.has(name)) {
|
|
105
|
+
reports.push({ file, name, error: "The name " + name + " is taken by " + taken.get(name) });
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
taken.set(name, file);
|
|
109
|
+
if (!selected(name)) {
|
|
110
|
+
reports.push({ file, name, selected: false });
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
let timer;
|
|
114
|
+
try {
|
|
115
|
+
const result = await Promise.race([
|
|
116
|
+
Promise.resolve().then(() => check.run(context)),
|
|
117
|
+
new Promise((_, reject) => {
|
|
118
|
+
timer = setTimeout(() => reject(new Error("Did not finish within " + input.timeout + " ms")), input.timeout);
|
|
119
|
+
}),
|
|
120
|
+
]);
|
|
121
|
+
reports.push({ file, name, result });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
reports.push({ file, name, error: describe(error) });
|
|
124
|
+
} finally {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
process.stdout.write("\\n${MARKER}" + JSON.stringify(reports) + "\\n");
|
|
130
|
+
process.exit(0);
|
|
131
|
+
`;
|
|
132
|
+
/** Whether `selection` reports the check called `name`. */
|
|
133
|
+
export function selects(selection, name) {
|
|
134
|
+
return ((selection.only.length === 0 || selection.only.includes(name)) && !selection.skip.includes(name));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The check modules in `folder`, relative to the project root and sorted; a missing folder
|
|
138
|
+
* holds none.
|
|
139
|
+
*/
|
|
140
|
+
export async function checkFiles(root, folder) {
|
|
141
|
+
let entries = await wrap(() => readdir(join(root, folder), { withFileTypes: true }));
|
|
142
|
+
if (isFailure(entries))
|
|
143
|
+
return [];
|
|
144
|
+
return entries.data
|
|
145
|
+
.filter((entry) => entry.isFile() && CHECK_FILE.test(entry.name))
|
|
146
|
+
.map((entry) => `${folder}/${entry.name}`)
|
|
147
|
+
.sort();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Runs every selected check in the project's `doctor.checks` folder. A module that fails to
|
|
151
|
+
* load is reported under its path, a check that throws, hangs or answers no result under its
|
|
152
|
+
* name, and a runner that cannot start under the folder's path, each as `fail`.
|
|
153
|
+
*/
|
|
154
|
+
export async function runProjectChecks(ctx, options) {
|
|
155
|
+
let folder = options.config.doctor.checks;
|
|
156
|
+
let files = await checkFiles(options.root, folder);
|
|
157
|
+
if (files.length === 0)
|
|
158
|
+
return { reports: [], names: [] };
|
|
159
|
+
let input = JSON.stringify({
|
|
160
|
+
root: options.root,
|
|
161
|
+
manifest: options.manifest,
|
|
162
|
+
config: options.config,
|
|
163
|
+
routes: await options.routes(),
|
|
164
|
+
files,
|
|
165
|
+
builtIn: options.builtIn,
|
|
166
|
+
only: options.selection.only,
|
|
167
|
+
skip: options.selection.skip,
|
|
168
|
+
namePattern: CHECK_NAME.source,
|
|
169
|
+
timeout: CHECK_TIMEOUT_MS,
|
|
170
|
+
});
|
|
171
|
+
let command = options.runtime === "bun"
|
|
172
|
+
? ["bun", "-e", RUNNER]
|
|
173
|
+
: ["node", "--input-type=module", "-e", RUNNER];
|
|
174
|
+
let ran = await ctx.exec(command, { cwd: options.root, stdio: "collect", input });
|
|
175
|
+
let entries = isFailure(ran) ? null : parseEntries(ran.data.stdout);
|
|
176
|
+
if (entries === null) {
|
|
177
|
+
let detail = isFailure(ran)
|
|
178
|
+
? "stderr" in ran.error && ran.error.stderr.trim() !== ""
|
|
179
|
+
? ran.error.stderr.trim()
|
|
180
|
+
: ran.error.message
|
|
181
|
+
: "The runner printed no report";
|
|
182
|
+
return {
|
|
183
|
+
reports: [
|
|
184
|
+
failed(folder, `Could not run the checks in ${folder} with ${options.runtime}`, detail, folder),
|
|
185
|
+
],
|
|
186
|
+
names: [],
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
let reports = [];
|
|
190
|
+
let names = [];
|
|
191
|
+
for (let entry of entries) {
|
|
192
|
+
if (entry.name !== null)
|
|
193
|
+
names.push(entry.name);
|
|
194
|
+
if (entry.selected === false)
|
|
195
|
+
continue;
|
|
196
|
+
let name = entry.name ?? entry.file;
|
|
197
|
+
if (!selects(options.selection, name))
|
|
198
|
+
continue;
|
|
199
|
+
if (entry.error !== undefined) {
|
|
200
|
+
let message = entry.name === null ? `${entry.file} is not a check module` : `${name} failed to run`;
|
|
201
|
+
reports.push(failed(name, message, entry.error, entry.file));
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
let result = toResult(entry.result);
|
|
205
|
+
if (result === null) {
|
|
206
|
+
reports.push(failed(name, `${name} answered no result sdxc doctor reads`, JSON.stringify(entry.result) ?? "undefined", entry.file));
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
reports.push({ name, ...result });
|
|
210
|
+
}
|
|
211
|
+
return { reports, names };
|
|
212
|
+
}
|
|
213
|
+
/** The runner's entries from its output, or `null` when it printed none. */
|
|
214
|
+
function parseEntries(stdout) {
|
|
215
|
+
let line = stdout.split("\n").find((text) => text.startsWith(MARKER));
|
|
216
|
+
if (line === undefined)
|
|
217
|
+
return null;
|
|
218
|
+
let parsed = wrap(() => JSON.parse(line.slice(MARKER.length)));
|
|
219
|
+
if (isFailure(parsed) || !Array.isArray(parsed.data))
|
|
220
|
+
return null;
|
|
221
|
+
return parsed.data;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* A check's answer completed with the defaults a project check may leave out, or `null` when it
|
|
225
|
+
* lacks a known status or a message, or carries findings that are not strings.
|
|
226
|
+
*/
|
|
227
|
+
export function toResult(value) {
|
|
228
|
+
if (value === null || typeof value !== "object")
|
|
229
|
+
return null;
|
|
230
|
+
let answer = value;
|
|
231
|
+
if (typeof answer.status !== "string" || !STATUSES.has(answer.status))
|
|
232
|
+
return null;
|
|
233
|
+
if (typeof answer.message !== "string")
|
|
234
|
+
return null;
|
|
235
|
+
let findings = answer.findings ?? [];
|
|
236
|
+
if (!Array.isArray(findings) || !findings.every((item) => typeof item === "string"))
|
|
237
|
+
return null;
|
|
238
|
+
let fix = answer.fix ?? null;
|
|
239
|
+
if (fix !== null && typeof fix !== "string")
|
|
240
|
+
return null;
|
|
241
|
+
return {
|
|
242
|
+
status: answer.status,
|
|
243
|
+
message: answer.message,
|
|
244
|
+
findings: findings,
|
|
245
|
+
fix,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** A failed report whose single finding is what went wrong, fixed by editing `file`. */
|
|
249
|
+
function failed(name, message, detail, file) {
|
|
250
|
+
return {
|
|
251
|
+
name,
|
|
252
|
+
status: "fail",
|
|
253
|
+
message,
|
|
254
|
+
findings: [firstLine(detail)],
|
|
255
|
+
fix: `Fix ${file}`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/** The first line of `text`, so a stack trace stays one finding. */
|
|
259
|
+
function firstLine(text) {
|
|
260
|
+
return text.split("\n")[0]?.trim() ?? text;
|
|
261
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `remix` check: the project pins `remix` to the peer its release's `@sdxc/*` packages
|
|
3
|
+
* declare, read from that release's `@sdxc/kit` as `sdxc upgrade` reads it, so an install
|
|
4
|
+
* resolves the peer every package pins exactly.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/**
|
|
11
|
+
* Fails when the `remix` pin differs from the release's peer; the fix is `sdxc upgrade <release>`,
|
|
12
|
+
* which pins the peer together with every lagging `@sdxc/*` package in one install.
|
|
13
|
+
*/
|
|
14
|
+
export declare const remixCheck: Check;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `remix` check: the project pins `remix` to the peer its release's `@sdxc/*` packages
|
|
3
|
+
* declare, read from that release's `@sdxc/kit` as `sdxc upgrade` reads it, so an install
|
|
4
|
+
* resolves the peer every package pins exactly.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { isFailure } from "@sdxc/result";
|
|
10
|
+
import { currentRelease, lists } from "../upgrade/project.js";
|
|
11
|
+
import { RELEASE_PACKAGE } from "../upgrade/registry.js";
|
|
12
|
+
import { passed, rangeOf, skipped } from "./check.js";
|
|
13
|
+
/**
|
|
14
|
+
* Fails when the `remix` pin differs from the release's peer; the fix is `sdxc upgrade <release>`,
|
|
15
|
+
* which pins the peer together with every lagging `@sdxc/*` package in one install.
|
|
16
|
+
*/
|
|
17
|
+
export const remixCheck = {
|
|
18
|
+
name: "remix",
|
|
19
|
+
async run(context) {
|
|
20
|
+
if (!lists(context.manifest, "remix"))
|
|
21
|
+
return skipped("package.json lists no remix");
|
|
22
|
+
let release = currentRelease(context.manifest);
|
|
23
|
+
if (release === null)
|
|
24
|
+
return skipped("package.json pins no @sdxc package to a release");
|
|
25
|
+
let kit = await context.packument(RELEASE_PACKAGE);
|
|
26
|
+
if (isFailure(kit))
|
|
27
|
+
return skipped(kit.error.message);
|
|
28
|
+
let peers = kit.data.versions.get(release);
|
|
29
|
+
if (peers === undefined)
|
|
30
|
+
return skipped(`Release ${release} is not published on npm`);
|
|
31
|
+
let peer = peers.remix;
|
|
32
|
+
if (peer === undefined)
|
|
33
|
+
return skipped(`Release ${release} declares no remix peer`);
|
|
34
|
+
let pinned = rangeOf(context.manifest, "remix");
|
|
35
|
+
if (pinned === peer)
|
|
36
|
+
return passed(`remix ${peer} is the peer release ${release} declares`);
|
|
37
|
+
return {
|
|
38
|
+
status: "fail",
|
|
39
|
+
message: `remix ${pinned} differs from the ${peer} release ${release} declares`,
|
|
40
|
+
findings: [`remix ${pinned} -> ${peer}`],
|
|
41
|
+
fix: `sdxc upgrade ${release}`,
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `routes` check: every route a contract declares is mapped by a router, through `lazy()`.
|
|
3
|
+
* An unmapped route answers 404 while its links type check, and a controller mapped without
|
|
4
|
+
* `lazy()` loads with the router, so every request imports it.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/** Warns on each declared route no router maps, and on each mapping written without `lazy()`. */
|
|
11
|
+
export declare const routesCheck: Check;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `routes` check: every route a contract declares is mapped by a router, through `lazy()`.
|
|
3
|
+
* An unmapped route answers 404 while its links type check, and a controller mapped without
|
|
4
|
+
* `lazy()` loads with the router, so every request imports it.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { stat } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
12
|
+
import { listRoutes } from "../routes/index.js";
|
|
13
|
+
import { passed, skipped } from "./check.js";
|
|
14
|
+
/** Warns on each declared route no router maps, and on each mapping written without `lazy()`. */
|
|
15
|
+
export const routesCheck = {
|
|
16
|
+
name: "routes",
|
|
17
|
+
async run(context) {
|
|
18
|
+
let folder = await wrap(() => stat(join(context.root, "routes")));
|
|
19
|
+
if (isFailure(folder) || !folder.data.isDirectory()) {
|
|
20
|
+
return skipped("No routes/ folder in the project");
|
|
21
|
+
}
|
|
22
|
+
let listing = await listRoutes(context.root);
|
|
23
|
+
let unmapped = listing.routes
|
|
24
|
+
.filter((route) => route.router === null)
|
|
25
|
+
.map((route) => `${route.method} ${route.pattern} (${route.contract} ${route.name}) is mapped by no router`);
|
|
26
|
+
let eager = listing.routers.flatMap((router) => router.eager.map((mapping) => `${router.file} maps ${mapping} without lazy()`));
|
|
27
|
+
if (unmapped.length === 0 && eager.length === 0) {
|
|
28
|
+
return passed(`${listing.routes.length} routes are mapped through lazy()`);
|
|
29
|
+
}
|
|
30
|
+
let problems = [
|
|
31
|
+
unmapped.length === 0
|
|
32
|
+
? null
|
|
33
|
+
: plural(unmapped.length, "route no router maps", "routes no router maps"),
|
|
34
|
+
eager.length === 0
|
|
35
|
+
? null
|
|
36
|
+
: plural(eager.length, "mapping without lazy()", "mappings without lazy()"),
|
|
37
|
+
].filter((problem) => problem !== null);
|
|
38
|
+
return {
|
|
39
|
+
status: "warn",
|
|
40
|
+
message: `Found ${problems.join(" and ")}`,
|
|
41
|
+
findings: [...unmapped, ...eager],
|
|
42
|
+
fix: "Map each route in its router initializer as router.map(route, lazy(() => import(…))); sdxc make controller writes and maps one",
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
/** `count` with the singular or plural noun phrase it takes. */
|
|
47
|
+
function plural(count, one, many) {
|
|
48
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `typegen` check: the Worker's generated `env` types are newer than every file they are
|
|
3
|
+
* generated from. `sdxc run typegen` writes them from `cloudflare.config.ts` and `.dev.vars`, so
|
|
4
|
+
* a binding added since types as missing until it runs again.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/** Where `sdxc run typegen` writes the Worker's types, the file the app's tsconfig includes. */
|
|
11
|
+
export declare const TYPES_FILE = ".cloudflare/types/index.d.ts";
|
|
12
|
+
/** Warns when the types were never generated, or when a source file changed after they were. */
|
|
13
|
+
export declare const typegenCheck: Check;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `typegen` check: the Worker's generated `env` types are newer than every file they are
|
|
3
|
+
* generated from. `sdxc run typegen` writes them from `cloudflare.config.ts` and `.dev.vars`, so
|
|
4
|
+
* a binding added since types as missing until it runs again.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { stat } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
12
|
+
import { passed, skipped } from "./check.js";
|
|
13
|
+
import { CONFIG_FILE, ENV_EXAMPLE_FILE } from "./env.js";
|
|
14
|
+
/** Where `sdxc run typegen` writes the Worker's types, the file the app's tsconfig includes. */
|
|
15
|
+
export const TYPES_FILE = ".cloudflare/types/index.d.ts";
|
|
16
|
+
/** The files the types are generated from: the config, and the local and committed variables. */
|
|
17
|
+
const SOURCES = [CONFIG_FILE, ".dev.vars", ENV_EXAMPLE_FILE];
|
|
18
|
+
/** The command that regenerates the types. */
|
|
19
|
+
const FIX = "sdxc run typegen";
|
|
20
|
+
/** Warns when the types were never generated, or when a source file changed after they were. */
|
|
21
|
+
export const typegenCheck = {
|
|
22
|
+
name: "typegen",
|
|
23
|
+
async run(context) {
|
|
24
|
+
let config = await modified(context.root, CONFIG_FILE);
|
|
25
|
+
if (config === null)
|
|
26
|
+
return skipped(`No ${CONFIG_FILE} in the project`);
|
|
27
|
+
let types = await modified(context.root, TYPES_FILE);
|
|
28
|
+
if (types === null) {
|
|
29
|
+
return {
|
|
30
|
+
status: "warn",
|
|
31
|
+
message: `The Worker's env types were never generated; ${TYPES_FILE} is missing`,
|
|
32
|
+
findings: [],
|
|
33
|
+
fix: FIX,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let newer = [];
|
|
37
|
+
for (let source of SOURCES) {
|
|
38
|
+
let time = await modified(context.root, source);
|
|
39
|
+
if (time !== null && time > types)
|
|
40
|
+
newer.push(`${source} changed after the types were generated`);
|
|
41
|
+
}
|
|
42
|
+
if (newer.length > 0) {
|
|
43
|
+
return {
|
|
44
|
+
status: "warn",
|
|
45
|
+
message: `${TYPES_FILE} is older than what it is generated from`,
|
|
46
|
+
findings: newer,
|
|
47
|
+
fix: FIX,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return passed(`${TYPES_FILE} is newer than ${CONFIG_FILE} and the env files`);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
/** When the file at `path` last changed, in milliseconds, or `null` when it does not exist. */
|
|
54
|
+
async function modified(root, path) {
|
|
55
|
+
let found = await wrap(() => stat(join(root, path)));
|
|
56
|
+
return isFailure(found) ? null : found.data.mtimeMs;
|
|
57
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ui` check: every component `sdxc ui add` copied into the project is current with the
|
|
3
|
+
* installed kit's registry. A copy is the project's own code, so a newer component reaches it
|
|
4
|
+
* only through `sdxc ui update`; an edited copy is listed so the update's diff comes as no surprise.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/**
|
|
11
|
+
* Warns on each copy a later release changed, with the update command for all of them; an
|
|
12
|
+
* edited copy is a finding of its own and leaves the status as it is.
|
|
13
|
+
*/
|
|
14
|
+
export declare const uiCheck: Check;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ui` check: every component `sdxc ui add` copied into the project is current with the
|
|
3
|
+
* installed kit's registry. A copy is the project's own code, so a newer component reaches it
|
|
4
|
+
* only through `sdxc ui update`; an edited copy is listed so the update's diff comes as no surprise.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { isFailure } from "@sdxc/result";
|
|
10
|
+
import { readLock, uiEntries } from "../lock.js";
|
|
11
|
+
import { listComponents, loadContext } from "../ui/commands.js";
|
|
12
|
+
import { skipped } from "./check.js";
|
|
13
|
+
/**
|
|
14
|
+
* Warns on each copy a later release changed, with the update command for all of them; an
|
|
15
|
+
* edited copy is a finding of its own and leaves the status as it is.
|
|
16
|
+
*/
|
|
17
|
+
export const uiCheck = {
|
|
18
|
+
name: "ui",
|
|
19
|
+
async run(context) {
|
|
20
|
+
let lock = await readLock(context.root, context.config);
|
|
21
|
+
if (isFailure(lock))
|
|
22
|
+
return skipped(lock.error.message);
|
|
23
|
+
if (uiEntries(lock.data).length === 0)
|
|
24
|
+
return skipped("No @sdxc/ui component is copied");
|
|
25
|
+
let ui = await loadContext(context, context.packageRoot);
|
|
26
|
+
if (isFailure(ui))
|
|
27
|
+
return skipped(ui.error.message);
|
|
28
|
+
let copies = (await listComponents(ui.data)).filter((row) => row.copy !== null);
|
|
29
|
+
let behind = copies.filter((row) => row.copy?.behind === true);
|
|
30
|
+
let edited = copies
|
|
31
|
+
.filter((row) => row.copy?.edited === true)
|
|
32
|
+
.map((row) => `${row.name} is edited; sdxc ui diff ${row.name} shows how`);
|
|
33
|
+
if (behind.length === 0) {
|
|
34
|
+
return {
|
|
35
|
+
status: "pass",
|
|
36
|
+
message: `${copies.length === 1 ? "The copied component is" : `${copies.length} copied components are`} current with release ${ui.data.registry.release}`,
|
|
37
|
+
findings: edited,
|
|
38
|
+
fix: null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: "warn",
|
|
43
|
+
message: `${behind.length === 1 ? "A copied component is" : `${behind.length} copied components are`} behind release ${ui.data.registry.release}`,
|
|
44
|
+
findings: [
|
|
45
|
+
...behind.map((row) => `${row.name} ${row.copy?.release} -> changed in ${row.changedIn}`),
|
|
46
|
+
...edited,
|
|
47
|
+
],
|
|
48
|
+
fix: `sdxc ui update ${behind.map((row) => row.name).join(" ")}`,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
package/dist/init.d.ts
CHANGED
|
@@ -32,7 +32,9 @@ export declare function init(root: string, options: {
|
|
|
32
32
|
}): Promise<Result<InitOutcome, Error>>;
|
|
33
33
|
/**
|
|
34
34
|
* The configuration file `init` writes: `$schema` first, then every key in schema order with
|
|
35
|
-
* its description as a comment. A key
|
|
36
|
-
*
|
|
35
|
+
* its description as a comment. A top-level key in `values` is written with that value, any
|
|
36
|
+
* other key with its default, and a key with neither commented out with its first example.
|
|
37
|
+
*
|
|
38
|
+
* @example renderConfig({ format: ["bunx", "vp", "fmt"] })
|
|
37
39
|
*/
|
|
38
|
-
export declare function renderConfig(): Result<string, Error>;
|
|
40
|
+
export declare function renderConfig(values?: Record<string, unknown>): Result<string, Error>;
|
package/dist/init.js
CHANGED
|
@@ -46,20 +46,25 @@ export async function init(root, options) {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* The configuration file `init` writes: `$schema` first, then every key in schema order with
|
|
49
|
-
* its description as a comment. A key
|
|
50
|
-
*
|
|
49
|
+
* its description as a comment. A top-level key in `values` is written with that value, any
|
|
50
|
+
* other key with its default, and a key with neither commented out with its first example.
|
|
51
|
+
*
|
|
52
|
+
* @example renderConfig({ format: ["bunx", "vp", "fmt"] })
|
|
51
53
|
*/
|
|
52
|
-
export function renderConfig() {
|
|
54
|
+
export function renderConfig(values = {}) {
|
|
53
55
|
let schema = configJSONSchema();
|
|
54
56
|
if (isFailure(schema))
|
|
55
57
|
return schema;
|
|
56
58
|
let lines = ["{", `\t${JSON.stringify("$schema")}: ${JSON.stringify(SCHEMA_REFERENCE)},`];
|
|
57
|
-
renderProperties(schema.data, 1, lines);
|
|
59
|
+
renderProperties(schema.data, 1, lines, values);
|
|
58
60
|
lines.push("}");
|
|
59
61
|
return success(`${lines.join("\n")}\n`);
|
|
60
62
|
}
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Appends one line per key of `schema`'s properties, nesting into a group that has its own;
|
|
65
|
+
* a key in `values` is written with its value there.
|
|
66
|
+
*/
|
|
67
|
+
function renderProperties(schema, depth, lines, values = {}) {
|
|
63
68
|
let indent = "\t".repeat(depth);
|
|
64
69
|
for (let [key, property] of Object.entries(schema.properties ?? {})) {
|
|
65
70
|
if (key === "$schema" || typeof property === "boolean")
|
|
@@ -67,7 +72,10 @@ function renderProperties(schema, depth, lines) {
|
|
|
67
72
|
if (typeof property.description === "string")
|
|
68
73
|
lines.push(`${indent}// ${property.description}`);
|
|
69
74
|
let name = JSON.stringify(key);
|
|
70
|
-
if (
|
|
75
|
+
if (key in values) {
|
|
76
|
+
lines.push(`${indent}${name}: ${inline(values[key])},`);
|
|
77
|
+
}
|
|
78
|
+
else if (property.properties !== undefined) {
|
|
71
79
|
lines.push(`${indent}${name}: {`);
|
|
72
80
|
renderProperties(property, depth + 1, lines);
|
|
73
81
|
lines.push(`${indent}},`);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc initializers`: every module in `app/initializers/`, what it exports and the factories
|
|
3
|
+
* it builds them with, such as `createRouter` from `remix/router`, so where the app's one
|
|
4
|
+
* instance of each thing comes from reads as one table.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** One initializer. */
|
|
10
|
+
export interface Initializer {
|
|
11
|
+
file: string;
|
|
12
|
+
/** Its exported names, `default` for a default export, in source order. */
|
|
13
|
+
exports: string[];
|
|
14
|
+
/** Each imported factory it calls, with the module it comes from. */
|
|
15
|
+
factories: Array<{
|
|
16
|
+
name: string;
|
|
17
|
+
from: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/** The names `source` exports, `default` for its default export, in source order. */
|
|
21
|
+
export declare function exportedNames(source: string): string[];
|
|
22
|
+
/** Reads every initializer of the project at `root`, tests left out. */
|
|
23
|
+
export declare function listInitializers(root: string): Promise<Initializer[]>;
|
|
24
|
+
/** The initializers as a table: file, exports, and the factories that build them. */
|
|
25
|
+
export declare function formatInitializers(initializers: readonly Initializer[]): string;
|