@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
package/dist/testing.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds a project from a built-in template the way a consumer's install would see it, for the
|
|
3
3
|
* tests that type check templates and generated code: dependencies are linked from this
|
|
4
|
-
* workspace instead of installed, and the Worker's types are generated as `
|
|
4
|
+
* workspace instead of installed, and the Worker's types are generated as `sdxc run typegen` does.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
+
import type { Exec } from "@sdxc/cli";
|
|
9
10
|
import type { Result } from "@sdxc/result";
|
|
10
11
|
/** What a spawned command printed and how it exited. */
|
|
11
12
|
export interface Spawned {
|
|
@@ -35,7 +36,9 @@ export declare function linkDependencies(project: string): Promise<Result<void,
|
|
|
35
36
|
export declare function registryDocument(name: string, versions?: readonly string[]): Record<string, unknown>;
|
|
36
37
|
/**
|
|
37
38
|
* Links what `package.json` gained since, generates the Worker's types with the project's own
|
|
38
|
-
* `cf`, then type checks the project
|
|
39
|
+
* `cf`, then type checks the project through its own `vp check`, answering what it printed. That
|
|
40
|
+
* is the checker a consumer's `bun run check` runs, and it reports `vite.config.ts` type errors
|
|
41
|
+
* TypeScript 6's `tsc` passes.
|
|
39
42
|
*/
|
|
40
43
|
export declare function typecheck(project: string): Promise<Spawned>;
|
|
41
44
|
/**
|
|
@@ -48,3 +51,10 @@ export declare function runCommandLine(project: string, argv: string[]): Promise
|
|
|
48
51
|
* `--no-color` so the summary reads as plain text on CI too, where Vite+ colors it otherwise.
|
|
49
52
|
*/
|
|
50
53
|
export declare function testProject(project: string): Promise<Spawned>;
|
|
54
|
+
/**
|
|
55
|
+
* An exec that runs `bunx vp …` with the project's own Vite+, as `bunx` resolves it from an
|
|
56
|
+
* install, so a test runs the `format` command a built-in template configures without a download.
|
|
57
|
+
*/
|
|
58
|
+
export declare function projectExec(project: string): Exec;
|
|
59
|
+
/** Runs the project's own Vite+ formatter in check mode over the whole project, as `vp check` does. */
|
|
60
|
+
export declare function checkFormatting(project: string): Promise<Spawned>;
|
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds a project from a built-in template the way a consumer's install would see it, for the
|
|
3
3
|
* tests that type check templates and generated code: dependencies are linked from this
|
|
4
|
-
* workspace instead of installed, and the Worker's types are generated as `
|
|
4
|
+
* workspace instead of installed, and the Worker's types are generated as `sdxc run typegen` does.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -10,6 +10,7 @@ import { spawn } from "node:child_process";
|
|
|
10
10
|
import { access, lstat, mkdir, mkdtemp, readFile, symlink } from "node:fs/promises";
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { dirname, join } from "node:path";
|
|
13
|
+
import { spawnExec } from "@sdxc/cli";
|
|
13
14
|
import { invoke } from "@sdxc/cli/test";
|
|
14
15
|
import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
|
|
15
16
|
import { createSDXC } from "./cli.js";
|
|
@@ -74,7 +75,9 @@ export function registryDocument(name, versions = ["0.0.1"]) {
|
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
77
|
* Links what `package.json` gained since, generates the Worker's types with the project's own
|
|
77
|
-
* `cf`, then type checks the project
|
|
78
|
+
* `cf`, then type checks the project through its own `vp check`, answering what it printed. That
|
|
79
|
+
* is the checker a consumer's `bun run check` runs, and it reports `vite.config.ts` type errors
|
|
80
|
+
* TypeScript 6's `tsc` passes.
|
|
78
81
|
*/
|
|
79
82
|
export async function typecheck(project) {
|
|
80
83
|
let linked = await linkDependencies(project);
|
|
@@ -83,7 +86,7 @@ export async function typecheck(project) {
|
|
|
83
86
|
let types = await run([join(project, "node_modules/cf/bin/cf"), "workers", "types"], project);
|
|
84
87
|
if (types.code !== 0)
|
|
85
88
|
return types;
|
|
86
|
-
return run([join(project, "node_modules/
|
|
89
|
+
return run([join(project, "node_modules/vite-plus/bin/vp"), "check", "--no-fmt", "--no-lint"], project);
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* Runs the project's own command line, `bootstrap/cli.ts`, under Bun with `argv`, as
|
|
@@ -99,6 +102,22 @@ export function runCommandLine(project, argv) {
|
|
|
99
102
|
export function testProject(project) {
|
|
100
103
|
return run([join(project, "node_modules/vite-plus/bin/vp"), "test", "run", "--no-color"], project);
|
|
101
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* An exec that runs `bunx vp …` with the project's own Vite+, as `bunx` resolves it from an
|
|
107
|
+
* install, so a test runs the `format` command a built-in template configures without a download.
|
|
108
|
+
*/
|
|
109
|
+
export function projectExec(project) {
|
|
110
|
+
return (command, request) => {
|
|
111
|
+
let [runner, binary, ...rest] = command;
|
|
112
|
+
if (runner !== "bunx" || binary !== "vp")
|
|
113
|
+
return spawnExec(command, request);
|
|
114
|
+
return spawnExec([process.execPath, join(project, "node_modules/vite-plus/bin/vp"), ...rest], request);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Runs the project's own Vite+ formatter in check mode over the whole project, as `vp check` does. */
|
|
118
|
+
export function checkFormatting(project) {
|
|
119
|
+
return run([join(project, "node_modules/vite-plus/bin/vp"), "fmt", "--check"], project);
|
|
120
|
+
}
|
|
102
121
|
/** The directory `dependency` is installed at for this package or, failing that, the workspace. */
|
|
103
122
|
async function installed(packageRoot, dependency) {
|
|
104
123
|
let candidates = [
|
package/dist/ui/commands.d.ts
CHANGED
|
@@ -83,14 +83,21 @@ export declare function planAdd(context: UIContext, names: readonly string[], op
|
|
|
83
83
|
* the installed file to the local one, or an empty string when they match.
|
|
84
84
|
*/
|
|
85
85
|
export declare function diffComponent(context: UIContext, name: string): Promise<Result<string, Error>>;
|
|
86
|
+
/** How `planUpdate` treats edited files and the components an update newly reaches. */
|
|
87
|
+
export interface UpdateOptions {
|
|
88
|
+
/** Answers whether to replace an edited file; a `false` leaves it and reports it. */
|
|
89
|
+
overwrite: (path: string) => Promise<Result<boolean, Error>>;
|
|
90
|
+
/** Copies every uncopied component the updated ones reach, as `add --with-deps` does. */
|
|
91
|
+
withDeps: boolean;
|
|
92
|
+
}
|
|
86
93
|
/**
|
|
87
94
|
* Replaces each file of each copy whose hash still matches the lock with the installed version.
|
|
88
95
|
* An edited file is replaced only when `overwrite` answers yes for it, and otherwise left alone
|
|
89
96
|
* and reported; the entry moves to the installed release only when every file was replaced.
|
|
97
|
+
* A component a behind copy now reaches and the project lacks is reported, or copied with
|
|
98
|
+
* `withDeps`, so the new version's imports land on copies whenever the project has them.
|
|
90
99
|
*/
|
|
91
|
-
export declare function planUpdate(context: UIContext, names: readonly string[], options:
|
|
92
|
-
overwrite: (path: string) => Promise<Result<boolean, Error>>;
|
|
93
|
-
}): Promise<Result<Plan, Error>>;
|
|
100
|
+
export declare function planUpdate(context: UIContext, names: readonly string[], options: UpdateOptions): Promise<Result<Plan, Error>>;
|
|
94
101
|
/**
|
|
95
102
|
* Deletes the copies of `names`, drops their lock entries and points every project file's
|
|
96
103
|
* imports of them back at `@sdxc/ui/<name>`, folded into an existing `@sdxc/ui` import.
|
package/dist/ui/commands.js
CHANGED
|
@@ -91,7 +91,17 @@ export async function planAdd(context, names, options) {
|
|
|
91
91
|
}
|
|
92
92
|
added.push(entry);
|
|
93
93
|
}
|
|
94
|
-
let
|
|
94
|
+
let copied = await copyComponents(context, plan, added, copiedComponents(context, added));
|
|
95
|
+
if (isFailure(copied))
|
|
96
|
+
return copied;
|
|
97
|
+
return success(plan);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Adds to `plan` the files and lock entries of `added`, each pointing its imports at `copies`,
|
|
101
|
+
* and points every other project file's imports of `added` at the new copies. A file in the
|
|
102
|
+
* way that the lock does not list stops the plan, so a copy never overwrites the project's own.
|
|
103
|
+
*/
|
|
104
|
+
async function copyComponents(context, plan, added, copies) {
|
|
95
105
|
for (let entry of added) {
|
|
96
106
|
let files = {};
|
|
97
107
|
for (let file of registryFiles(entry, context.config.ui.tests)) {
|
|
@@ -109,10 +119,9 @@ export async function planAdd(context, names, options) {
|
|
|
109
119
|
plan.record.push({ name: entry.name, release: context.registry.release, files });
|
|
110
120
|
plan.report.push(`Copied ${entry.name} to ${copyPath(context.layout, entry.source.path)}`);
|
|
111
121
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return success(plan);
|
|
122
|
+
if (added.length === 0)
|
|
123
|
+
return success(undefined);
|
|
124
|
+
return rewriteProject(context, plan, (file, source) => pointAtCopies(file, source, copiedComponents(context, added, false), context.layout));
|
|
116
125
|
}
|
|
117
126
|
/**
|
|
118
127
|
* The difference between the copy of `name` and the installed version, as a unified diff from
|
|
@@ -142,13 +151,16 @@ export async function diffComponent(context, name) {
|
|
|
142
151
|
* Replaces each file of each copy whose hash still matches the lock with the installed version.
|
|
143
152
|
* An edited file is replaced only when `overwrite` answers yes for it, and otherwise left alone
|
|
144
153
|
* and reported; the entry moves to the installed release only when every file was replaced.
|
|
154
|
+
* A component a behind copy now reaches and the project lacks is reported, or copied with
|
|
155
|
+
* `withDeps`, so the new version's imports land on copies whenever the project has them.
|
|
145
156
|
*/
|
|
146
157
|
export async function planUpdate(context, names, options) {
|
|
147
158
|
let unknown = uncopiedNames(context, names);
|
|
148
159
|
if (unknown !== null)
|
|
149
160
|
return failure(unknown);
|
|
150
161
|
let plan = emptyPlan();
|
|
151
|
-
let
|
|
162
|
+
let planned = [];
|
|
163
|
+
let reaching = [];
|
|
152
164
|
for (let name of new Set(names)) {
|
|
153
165
|
let copied = uiEntry(context.lock, name);
|
|
154
166
|
let entry = context.registry.entries.get(name);
|
|
@@ -159,23 +171,40 @@ export async function planUpdate(context, names, options) {
|
|
|
159
171
|
continue;
|
|
160
172
|
}
|
|
161
173
|
let withTest = context.config.ui.tests || (entry.test !== null && entry.test.path in copied.files);
|
|
162
|
-
let files =
|
|
163
|
-
let skipped = 0;
|
|
164
|
-
let replaced = 0;
|
|
174
|
+
let files = [];
|
|
165
175
|
for (let file of registryFiles(entry, withTest)) {
|
|
166
176
|
let path = copyPath(context.layout, file.path);
|
|
167
177
|
let local = await readProjectFile(context.root, path);
|
|
168
178
|
let recorded = copied.files[file.path];
|
|
169
179
|
let untouched = local === null || (recorded !== undefined && hashContent(local) === recorded);
|
|
180
|
+
let keep = false;
|
|
170
181
|
if (!untouched) {
|
|
171
182
|
let overwrite = await options.overwrite(path);
|
|
172
183
|
if (isFailure(overwrite))
|
|
173
184
|
return overwrite;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
keep = !overwrite.data;
|
|
186
|
+
}
|
|
187
|
+
files.push({ file, path, local, keep });
|
|
188
|
+
}
|
|
189
|
+
planned.push({ name, copied, files });
|
|
190
|
+
let behind = compare(copied.release, entry.changedIn) < 0;
|
|
191
|
+
if (behind && files.some((file) => !file.keep))
|
|
192
|
+
reaching.push(name);
|
|
193
|
+
}
|
|
194
|
+
let lacking = withDependencies(context.registry, reaching).filter((name) => uiEntry(context.lock, name) === undefined);
|
|
195
|
+
let added = options.withDeps
|
|
196
|
+
? lacking.flatMap((name) => context.registry.entries.get(name) ?? [])
|
|
197
|
+
: [];
|
|
198
|
+
let copies = copiedComponents(context, added);
|
|
199
|
+
for (let { name, copied, files: updates } of planned) {
|
|
200
|
+
let files = { ...copied.files };
|
|
201
|
+
let skipped = 0;
|
|
202
|
+
let replaced = 0;
|
|
203
|
+
for (let { file, path, local, keep } of updates) {
|
|
204
|
+
if (keep) {
|
|
205
|
+
skipped += 1;
|
|
206
|
+
plan.report.push(`${path} is edited; left as it is (--force replaces it)`);
|
|
207
|
+
continue;
|
|
179
208
|
}
|
|
180
209
|
let content = pointAtCopies(path, file.content, copies, context.layout);
|
|
181
210
|
if (isFailure(content))
|
|
@@ -194,6 +223,14 @@ export async function planUpdate(context, names, options) {
|
|
|
194
223
|
? `${name} already matches release ${context.registry.release}`
|
|
195
224
|
: `Updated ${replaced} file${replaced === 1 ? "" : "s"} of ${name}`);
|
|
196
225
|
}
|
|
226
|
+
if (!options.withDeps && lacking.length > 0) {
|
|
227
|
+
let one = lacking.length === 1;
|
|
228
|
+
let reachers = reaching.filter((name) => withDependencies(context.registry, [name]).some((reached) => lacking.includes(reached)));
|
|
229
|
+
plan.report.push(`${reachers.join(", ")} now ${reachers.length === 1 ? "reaches" : "reach"} ${lacking.join(", ")} on @sdxc/ui; sdxc ui add ${lacking.join(" ")} copies ${one ? "it" : "them"}, as does --with-deps`);
|
|
230
|
+
}
|
|
231
|
+
let copiedNew = await copyComponents(context, plan, added, copies);
|
|
232
|
+
if (isFailure(copiedNew))
|
|
233
|
+
return copiedNew;
|
|
197
234
|
return success(plan);
|
|
198
235
|
}
|
|
199
236
|
/**
|
|
@@ -362,12 +399,14 @@ async function settleLock(context, plan, read) {
|
|
|
362
399
|
}
|
|
363
400
|
/**
|
|
364
401
|
* Runs `transform` over every project source outside the plan's own files, adding each file it
|
|
365
|
-
* changes to the plan and reporting each import it could not rewrite.
|
|
402
|
+
* changes to the plan and reporting each import it could not rewrite. An untouched copy it
|
|
403
|
+
* rewrites is hashed again once written, so the kit's own edit keeps it reading as untouched.
|
|
366
404
|
*/
|
|
367
405
|
async function rewriteProject(context, plan, transform) {
|
|
368
406
|
let sources = await projectSources(context.root);
|
|
369
407
|
if (isFailure(sources))
|
|
370
408
|
return sources;
|
|
409
|
+
let copies = lockedFiles(context, plan);
|
|
371
410
|
for (let file of sources.data) {
|
|
372
411
|
if (plan.files.has(file))
|
|
373
412
|
continue;
|
|
@@ -379,6 +418,10 @@ async function rewriteProject(context, plan, transform) {
|
|
|
379
418
|
return failure(new Error(`${file}: ${rewritten.error.message}`));
|
|
380
419
|
if (rewritten.data.source !== source) {
|
|
381
420
|
plan.files.set(file, { before: source, after: rewritten.data.source });
|
|
421
|
+
let copy = copies.get(file);
|
|
422
|
+
if (copy !== undefined && copy.entry.files[copy.file] === hashContent(source)) {
|
|
423
|
+
rehash(plan, copy.entry, copy.file);
|
|
424
|
+
}
|
|
382
425
|
}
|
|
383
426
|
for (let location of rewritten.data.unhandled) {
|
|
384
427
|
plan.report.push(`${location} imports @sdxc/ui as a whole; import the copied components' names from their copies by hand`);
|
|
@@ -386,6 +429,33 @@ async function rewriteProject(context, plan, transform) {
|
|
|
386
429
|
}
|
|
387
430
|
return success(undefined);
|
|
388
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Each file of each copy the lock lists and the plan keeps, by its path from the project root,
|
|
434
|
+
* with its entry and its name relative to `ui.directory`.
|
|
435
|
+
*/
|
|
436
|
+
function lockedFiles(context, plan) {
|
|
437
|
+
let files = new Map();
|
|
438
|
+
for (let entry of uiEntries(context.lock)) {
|
|
439
|
+
if (plan.forget.includes(entry.name))
|
|
440
|
+
continue;
|
|
441
|
+
for (let file of Object.keys(entry.files)) {
|
|
442
|
+
files.set(copyPath(context.layout, file), { entry, file });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return files;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Marks `file` of the copy `entry` to be hashed once written, in the plan's pending entry for
|
|
449
|
+
* that copy when it has one, or in a new one at the release the copy came from.
|
|
450
|
+
*/
|
|
451
|
+
function rehash(plan, entry, file) {
|
|
452
|
+
let pending = plan.record.find((record) => record.name === entry.name);
|
|
453
|
+
if (pending === undefined) {
|
|
454
|
+
pending = { name: entry.name, release: entry.release, files: { ...entry.files } };
|
|
455
|
+
plan.record.push(pending);
|
|
456
|
+
}
|
|
457
|
+
pending.files[file] = null;
|
|
458
|
+
}
|
|
389
459
|
/**
|
|
390
460
|
* Every copy the rewrite points imports at: the lock's copies plus `added`, with the names the
|
|
391
461
|
* registry says each exports. `includeLocked: false` answers `added` alone.
|
package/dist/ui/registry.d.ts
CHANGED
|
@@ -14,27 +14,27 @@ export declare const REGISTRY_DIR = "registry/ui";
|
|
|
14
14
|
export declare const REGISTRY_ENTRY: s.Schema<{
|
|
15
15
|
name: string;
|
|
16
16
|
dependencies: string[];
|
|
17
|
-
test: {
|
|
18
|
-
path: string;
|
|
19
|
-
content: string;
|
|
20
|
-
} | null;
|
|
21
17
|
source: {
|
|
22
18
|
path: string;
|
|
23
19
|
content: string;
|
|
24
20
|
};
|
|
21
|
+
test: {
|
|
22
|
+
path: string;
|
|
23
|
+
content: string;
|
|
24
|
+
} | null;
|
|
25
25
|
changedIn: string;
|
|
26
26
|
exports: string[];
|
|
27
27
|
}, {
|
|
28
28
|
name: string;
|
|
29
29
|
dependencies: string[];
|
|
30
|
-
test: {
|
|
31
|
-
path: string;
|
|
32
|
-
content: string;
|
|
33
|
-
} | null;
|
|
34
30
|
source: {
|
|
35
31
|
path: string;
|
|
36
32
|
content: string;
|
|
37
33
|
};
|
|
34
|
+
test: {
|
|
35
|
+
path: string;
|
|
36
|
+
content: string;
|
|
37
|
+
} | null;
|
|
38
38
|
changedIn: string;
|
|
39
39
|
exports: string[];
|
|
40
40
|
}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sdxc section of a project's `AGENTS.md`: the lines between `<!-- sdxc:start … -->` and
|
|
3
|
+
* `<!-- sdxc:end -->`, which `sdxc upgrade` rewrites from the release it installs. Everything
|
|
4
|
+
* outside the markers belongs to the project and is kept byte for byte.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Result } from "@sdxc/result";
|
|
10
|
+
/** The file agents read at the project root. */
|
|
11
|
+
export declare const AGENTS_FILE = "AGENTS.md";
|
|
12
|
+
/** Where a release ships the section, inside its `@sdxc/kit`. */
|
|
13
|
+
export declare const AGENTS_TEMPLATE = "templates/app/AGENTS.md";
|
|
14
|
+
/**
|
|
15
|
+
* Where a project's `AGENTS.md` stands after a refresh: `refreshed` or `current` when it holds
|
|
16
|
+
* one sdxc section, and otherwise why it was left as it is.
|
|
17
|
+
*/
|
|
18
|
+
export type AgentsStatus = "refreshed" | "current" | "missing" | "unmarked" | "unbalanced";
|
|
19
|
+
/** The outcome of replacing the section in one text. */
|
|
20
|
+
export interface Replaced {
|
|
21
|
+
status: Extract<AgentsStatus, "refreshed" | "current" | "unmarked" | "unbalanced">;
|
|
22
|
+
/** The new text, or the given one unchanged when there was nothing to replace. */
|
|
23
|
+
text: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The section in `text`, its start and end lines included, with `\n` line endings. A text
|
|
27
|
+
* without exactly one start line followed by one end line is a failure.
|
|
28
|
+
*/
|
|
29
|
+
export declare function managedSection(text: string): Result<string, Error>;
|
|
30
|
+
/**
|
|
31
|
+
* Replaces the section in `text` with `section`, written with the file's own line endings
|
|
32
|
+
* (CRLF when it has any). Text without one balanced pair of markers comes back unchanged.
|
|
33
|
+
*/
|
|
34
|
+
export declare function replaceSection(text: string, section: string): Replaced;
|
|
35
|
+
/** What refreshing a project's `AGENTS.md` comes to, worked out before anything is written. */
|
|
36
|
+
export interface AgentsPlan {
|
|
37
|
+
status: AgentsStatus;
|
|
38
|
+
/** The file's new text when `status` is `refreshed`, and `null` otherwise. */
|
|
39
|
+
text: string | null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Works out the sdxc section of the `AGENTS.md` at `root` from the template of the `@sdxc/kit`
|
|
43
|
+
* at `packageRoot`, writing nothing, so the caller writes only once the rest of its work holds.
|
|
44
|
+
* A missing, unmarked or unbalanced file is left as it is, since the markers are how a project
|
|
45
|
+
* opts in; a kit that ships no template answers `null`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function planAgentsFile(root: string, packageRoot: string): Promise<Result<AgentsPlan | null, Error>>;
|
|
48
|
+
/** Writes the planned text to the `AGENTS.md` at `root`; a plan without one writes nothing. */
|
|
49
|
+
export declare function writeAgentsFile(root: string, plan: AgentsPlan): Promise<Result<void, Error>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sdxc section of a project's `AGENTS.md`: the lines between `<!-- sdxc:start … -->` and
|
|
3
|
+
* `<!-- sdxc:end -->`, which `sdxc upgrade` rewrites from the release it installs. Everything
|
|
4
|
+
* outside the markers belongs to the project and is kept byte for byte.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
12
|
+
/** The file agents read at the project root. */
|
|
13
|
+
export const AGENTS_FILE = "AGENTS.md";
|
|
14
|
+
/** Where a release ships the section, inside its `@sdxc/kit`. */
|
|
15
|
+
export const AGENTS_TEMPLATE = "templates/app/AGENTS.md";
|
|
16
|
+
/** What a start line begins with; the rest of its comment is the release's wording. */
|
|
17
|
+
const START_MARKER = "<!-- sdxc:start";
|
|
18
|
+
/** The whole end line. */
|
|
19
|
+
const END_MARKER = "<!-- sdxc:end -->";
|
|
20
|
+
/** The line indexes of the one start and end marker, or why the text has no usable pair. */
|
|
21
|
+
function markers(lines) {
|
|
22
|
+
let starts = [];
|
|
23
|
+
let ends = [];
|
|
24
|
+
for (let [index, line] of lines.entries()) {
|
|
25
|
+
let trimmed = line.trim();
|
|
26
|
+
if (trimmed.startsWith(START_MARKER))
|
|
27
|
+
starts.push(index);
|
|
28
|
+
else if (trimmed === END_MARKER)
|
|
29
|
+
ends.push(index);
|
|
30
|
+
}
|
|
31
|
+
if (starts.length === 0 && ends.length === 0)
|
|
32
|
+
return "unmarked";
|
|
33
|
+
let [start] = starts;
|
|
34
|
+
let [end] = ends;
|
|
35
|
+
if (starts.length !== 1 || ends.length !== 1 || start === undefined || end === undefined) {
|
|
36
|
+
return "unbalanced";
|
|
37
|
+
}
|
|
38
|
+
return start < end ? { start, end } : "unbalanced";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The section in `text`, its start and end lines included, with `\n` line endings. A text
|
|
42
|
+
* without exactly one start line followed by one end line is a failure.
|
|
43
|
+
*/
|
|
44
|
+
export function managedSection(text) {
|
|
45
|
+
let lines = text.replaceAll("\r\n", "\n").split("\n");
|
|
46
|
+
let found = markers(lines);
|
|
47
|
+
if (typeof found === "string") {
|
|
48
|
+
return failure(new Error(`${AGENTS_FILE} has no single sdxc section (${found})`));
|
|
49
|
+
}
|
|
50
|
+
return success(lines.slice(found.start, found.end + 1).join("\n"));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Replaces the section in `text` with `section`, written with the file's own line endings
|
|
54
|
+
* (CRLF when it has any). Text without one balanced pair of markers comes back unchanged.
|
|
55
|
+
*/
|
|
56
|
+
export function replaceSection(text, section) {
|
|
57
|
+
let lines = text.split("\n");
|
|
58
|
+
let found = markers(lines);
|
|
59
|
+
if (typeof found === "string")
|
|
60
|
+
return { status: found, text };
|
|
61
|
+
let ending = text.includes("\r\n") ? "\r" : "";
|
|
62
|
+
let replacement = section.split("\n").map((line) => `${line}${ending}`);
|
|
63
|
+
let replaced = [
|
|
64
|
+
...lines.slice(0, found.start),
|
|
65
|
+
...replacement,
|
|
66
|
+
...lines.slice(found.end + 1),
|
|
67
|
+
].join("\n");
|
|
68
|
+
return { status: replaced === text ? "current" : "refreshed", text: replaced };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Works out the sdxc section of the `AGENTS.md` at `root` from the template of the `@sdxc/kit`
|
|
72
|
+
* at `packageRoot`, writing nothing, so the caller writes only once the rest of its work holds.
|
|
73
|
+
* A missing, unmarked or unbalanced file is left as it is, since the markers are how a project
|
|
74
|
+
* opts in; a kit that ships no template answers `null`.
|
|
75
|
+
*/
|
|
76
|
+
export async function planAgentsFile(root, packageRoot) {
|
|
77
|
+
let template = await readOptional(join(packageRoot, AGENTS_TEMPLATE));
|
|
78
|
+
if (isFailure(template))
|
|
79
|
+
return template;
|
|
80
|
+
if (template.data === null)
|
|
81
|
+
return success(null);
|
|
82
|
+
let section = managedSection(template.data);
|
|
83
|
+
if (isFailure(section))
|
|
84
|
+
return section;
|
|
85
|
+
let current = await readOptional(join(root, AGENTS_FILE));
|
|
86
|
+
if (isFailure(current))
|
|
87
|
+
return current;
|
|
88
|
+
if (current.data === null)
|
|
89
|
+
return success({ status: "missing", text: null });
|
|
90
|
+
let replaced = replaceSection(current.data, section.data);
|
|
91
|
+
return success({
|
|
92
|
+
status: replaced.status,
|
|
93
|
+
text: replaced.status === "refreshed" ? replaced.text : null,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Writes the planned text to the `AGENTS.md` at `root`; a plan without one writes nothing. */
|
|
97
|
+
export async function writeAgentsFile(root, plan) {
|
|
98
|
+
let text = plan.text;
|
|
99
|
+
if (text === null)
|
|
100
|
+
return success(undefined);
|
|
101
|
+
return wrap(() => writeFile(join(root, AGENTS_FILE), text));
|
|
102
|
+
}
|
|
103
|
+
/** The file at `path` as text, or `null` when there is none. */
|
|
104
|
+
async function readOptional(path) {
|
|
105
|
+
let read = await wrap(() => readFile(path, "utf8"));
|
|
106
|
+
if (!isFailure(read))
|
|
107
|
+
return read;
|
|
108
|
+
let code = "code" in read.error ? read.error.code : null;
|
|
109
|
+
return code === "ENOENT" ? success(null) : read;
|
|
110
|
+
}
|
|
@@ -14,17 +14,17 @@ export declare const CHANGELOG_FILE = "changelog.jsonl";
|
|
|
14
14
|
declare const ENTRY_SCHEMA: s.Schema<{
|
|
15
15
|
type: string;
|
|
16
16
|
title: string;
|
|
17
|
+
body: string;
|
|
17
18
|
release: string;
|
|
18
19
|
package: string;
|
|
19
20
|
breaking: boolean;
|
|
20
|
-
body: string;
|
|
21
21
|
}, {
|
|
22
22
|
type: string;
|
|
23
23
|
title: string;
|
|
24
|
+
body: string;
|
|
24
25
|
release: string;
|
|
25
26
|
package: string;
|
|
26
27
|
breaking: boolean;
|
|
27
|
-
body: string;
|
|
28
28
|
}>;
|
|
29
29
|
/** One commit's note as it applies to one package in one release. */
|
|
30
30
|
export type ChangelogEntry = s.InferOutput<typeof ENTRY_SCHEMA>;
|
|
@@ -9,12 +9,14 @@ import type { Result } from "@sdxc/result";
|
|
|
9
9
|
import * as s from "@sdxc/json-schema";
|
|
10
10
|
/** The fields of `package.json` the upgrade reads. */
|
|
11
11
|
declare const MANIFEST_SCHEMA: s.Schema<{
|
|
12
|
+
name?: string | undefined;
|
|
12
13
|
dependencies?: Record<string, string> | undefined;
|
|
13
14
|
devDependencies?: Record<string, string> | undefined;
|
|
14
15
|
packageManager?: string | undefined;
|
|
15
16
|
scripts?: Record<string, string> | undefined;
|
|
16
17
|
optionalDependencies?: Record<string, string> | undefined;
|
|
17
18
|
}, {
|
|
19
|
+
name?: string | undefined;
|
|
18
20
|
dependencies?: Record<string, string> | undefined;
|
|
19
21
|
devDependencies?: Record<string, string> | undefined;
|
|
20
22
|
packageManager?: string | undefined;
|
|
@@ -51,6 +53,8 @@ export declare function bumpManifest(text: string, versions: Record<string, stri
|
|
|
51
53
|
};
|
|
52
54
|
/** Whether a dependency section of the manifest lists `name`. */
|
|
53
55
|
export declare function lists(manifest: Manifest, name: string): boolean;
|
|
56
|
+
/** The dated release `name` is pinned to in the first dependency section listing it, or `null`. */
|
|
57
|
+
export declare function pinnedRelease(manifest: Manifest, name: string): string | null;
|
|
54
58
|
/** Every `@sdxc/*` package the manifest lists, which the upgrade moves together. */
|
|
55
59
|
export declare function listedScopedPackages(manifest: Manifest): string[];
|
|
56
60
|
/**
|
package/dist/upgrade/project.js
CHANGED
|
@@ -10,7 +10,7 @@ import { join, relative } from "node:path";
|
|
|
10
10
|
import { findModuleReferences } from "@sdxc/codemod";
|
|
11
11
|
import * as s from "@sdxc/json-schema";
|
|
12
12
|
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
13
|
-
import { projectRelease, scopedPackageOf } from "../releases.js";
|
|
13
|
+
import { datedPin, projectRelease, scopedPackageOf } from "../releases.js";
|
|
14
14
|
/** The `package.json` sections a project's installed versions come from. */
|
|
15
15
|
const DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
16
16
|
/** Files whose imports the upgrade reads. */
|
|
@@ -19,6 +19,7 @@ const SOURCE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
|
19
19
|
const SKIPPED_FOLDERS = new Set(["node_modules", "dist", "build", "coverage"]);
|
|
20
20
|
/** The fields of `package.json` the upgrade reads. */
|
|
21
21
|
const MANIFEST_SCHEMA = s.object({
|
|
22
|
+
name: s.optional(s.string()),
|
|
22
23
|
packageManager: s.optional(s.string()),
|
|
23
24
|
scripts: s.optional(s.record(s.string(), s.string())),
|
|
24
25
|
dependencies: s.optional(s.record(s.string(), s.string())),
|
|
@@ -79,6 +80,15 @@ export function bumpManifest(text, versions) {
|
|
|
79
80
|
export function lists(manifest, name) {
|
|
80
81
|
return DEPENDENCY_FIELDS.some((field) => manifest[field]?.[name] !== undefined);
|
|
81
82
|
}
|
|
83
|
+
/** The dated release `name` is pinned to in the first dependency section listing it, or `null`. */
|
|
84
|
+
export function pinnedRelease(manifest, name) {
|
|
85
|
+
for (let field of DEPENDENCY_FIELDS) {
|
|
86
|
+
let range = manifest[field]?.[name];
|
|
87
|
+
if (range !== undefined)
|
|
88
|
+
return datedPin(range);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
82
92
|
/** Every `@sdxc/*` package the manifest lists, which the upgrade moves together. */
|
|
83
93
|
export function listedScopedPackages(manifest) {
|
|
84
94
|
let names = DEPENDENCY_FIELDS.flatMap((field) => Object.keys(manifest[field] ?? {}));
|
package/dist/upgrade/prompt.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
9
|
import type { Result } from "@sdxc/result";
|
|
10
|
+
import type { AgentsStatus } from "./agents.js";
|
|
10
11
|
import type { ChangelogEntry } from "./changelog.js";
|
|
11
12
|
/** A vendored component whose source changed after the release it was copied from. */
|
|
12
13
|
export interface ChangedComponent {
|
|
@@ -19,6 +20,11 @@ export interface ChangedComponent {
|
|
|
19
20
|
/** Everything the prompt says, already gathered from the project and the installed release. */
|
|
20
21
|
export interface PromptInput {
|
|
21
22
|
from: string;
|
|
23
|
+
/**
|
|
24
|
+
* The release each package lagging behind `from` is pinned to, by name; its notes start
|
|
25
|
+
* there instead of at `from`.
|
|
26
|
+
*/
|
|
27
|
+
since?: ReadonlyMap<string, string>;
|
|
22
28
|
to: string;
|
|
23
29
|
/** The whole changelog of the target release. */
|
|
24
30
|
entries: readonly ChangelogEntry[];
|
|
@@ -31,6 +37,8 @@ export interface PromptInput {
|
|
|
31
37
|
components: readonly ChangedComponent[];
|
|
32
38
|
/** Each verification command, ready to run. */
|
|
33
39
|
verify: readonly string[];
|
|
40
|
+
/** Where the project's `AGENTS.md` stands; a file left as it is gets a note in the prompt. */
|
|
41
|
+
agents?: AgentsStatus;
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
44
|
* The prompt for moving from `input.from` to `input.to`, as Markdown. Only the imported
|
|
@@ -47,5 +55,8 @@ export declare function buildPrompt(options: {
|
|
|
47
55
|
root: string;
|
|
48
56
|
packageRoot: string;
|
|
49
57
|
from: string;
|
|
58
|
+
/** The release each lagging package is pinned to, by name. */
|
|
59
|
+
since?: ReadonlyMap<string, string>;
|
|
50
60
|
remixFrom: string | null;
|
|
61
|
+
agents?: AgentsStatus;
|
|
51
62
|
}): Promise<Result<string, Error>>;
|