@sdxc/kit 0.0.0-pre.1 → 0.0.0-stage
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 +2 -92
- package/package.json +5 -44
- package/LICENSE.md +0 -21
- package/config.schema.json +0 -89
- package/dist/bin.d.ts +0 -9
- package/dist/bin.js +0 -10
- package/dist/cli.d.ts +0 -33
- package/dist/cli.js +0 -58
- package/dist/commands/create.d.ts +0 -20
- package/dist/commands/create.js +0 -164
- package/dist/commands/init.d.ts +0 -16
- package/dist/commands/init.js +0 -27
- package/dist/commands/make.d.ts +0 -335
- package/dist/commands/make.js +0 -152
- package/dist/commands/run.d.ts +0 -23
- package/dist/commands/run.js +0 -51
- package/dist/commands/ui/add.d.ts +0 -23
- package/dist/commands/ui/add.js +0 -50
- package/dist/commands/ui/diff.d.ts +0 -20
- package/dist/commands/ui/diff.js +0 -28
- package/dist/commands/ui/list.d.ts +0 -24
- package/dist/commands/ui/list.js +0 -45
- package/dist/commands/ui/remove.d.ts +0 -22
- package/dist/commands/ui/remove.js +0 -48
- package/dist/commands/ui/update.d.ts +0 -23
- package/dist/commands/ui/update.js +0 -37
- package/dist/commands/upgrade.d.ts +0 -30
- package/dist/commands/upgrade.js +0 -184
- package/dist/config.d.ts +0 -81
- package/dist/config.js +0 -157
- package/dist/contract.d.ts +0 -161
- package/dist/contract.js +0 -308
- package/dist/create/github.d.ts +0 -63
- package/dist/create/github.js +0 -172
- package/dist/create/target.d.ts +0 -31
- package/dist/create/target.js +0 -56
- package/dist/create/templates.d.ts +0 -62
- package/dist/create/templates.js +0 -228
- package/dist/dependencies.d.ts +0 -34
- package/dist/dependencies.js +0 -76
- package/dist/diff.d.ts +0 -14
- package/dist/diff.js +0 -103
- package/dist/format.d.ts +0 -21
- package/dist/format.js +0 -40
- package/dist/init.d.ts +0 -38
- package/dist/init.js +0 -92
- package/dist/lock.d.ts +0 -74
- package/dist/lock.js +0 -214
- package/dist/make/declare.d.ts +0 -54
- package/dist/make/declare.js +0 -495
- package/dist/make/generate.d.ts +0 -56
- package/dist/make/generate.js +0 -139
- package/dist/make/imports.d.ts +0 -43
- package/dist/make/imports.js +0 -104
- package/dist/make/index.d.ts +0 -43
- package/dist/make/index.js +0 -136
- package/dist/make/kinds.d.ts +0 -39
- package/dist/make/kinds.js +0 -95
- package/dist/make/migrations.d.ts +0 -21
- package/dist/make/migrations.js +0 -48
- package/dist/make/names.d.ts +0 -31
- package/dist/make/names.js +0 -47
- package/dist/make/stubs.d.ts +0 -44
- package/dist/make/stubs.js +0 -89
- package/dist/middleware.d.ts +0 -44
- package/dist/middleware.js +0 -49
- package/dist/package-manager.d.ts +0 -41
- package/dist/package-manager.js +0 -80
- package/dist/project.d.ts +0 -19
- package/dist/project.js +0 -42
- package/dist/releases.d.ts +0 -40
- package/dist/releases.js +0 -110
- package/dist/testing.d.ts +0 -47
- package/dist/testing.js +0 -126
- package/dist/ui/commands.d.ts +0 -114
- package/dist/ui/commands.js +0 -432
- package/dist/ui/imports.d.ts +0 -46
- package/dist/ui/imports.js +0 -160
- package/dist/ui/layout.d.ts +0 -48
- package/dist/ui/layout.js +0 -138
- package/dist/ui/registry.d.ts +0 -58
- package/dist/ui/registry.js +0 -82
- package/dist/upgrade/changelog.d.ts +0 -50
- package/dist/upgrade/changelog.js +0 -69
- package/dist/upgrade/project.d.ts +0 -62
- package/dist/upgrade/project.js +0 -132
- package/dist/upgrade/prompt.d.ts +0 -51
- package/dist/upgrade/prompt.js +0 -227
- package/dist/upgrade/registry.d.ts +0 -33
- package/dist/upgrade/registry.js +0 -50
- package/lock.schema.json +0 -60
- package/stubs/command.stub +0 -12
- package/stubs/command.test.stub +0 -18
- package/stubs/controller.form.stub +0 -33
- package/stubs/controller.stub +0 -17
- package/stubs/controller.test.stub +0 -15
- package/stubs/email.stub +0 -44
- package/stubs/email.test.stub +0 -16
- package/stubs/factory.stub +0 -10
- package/stubs/initializer.stub +0 -7
- package/stubs/initializer.test.stub +0 -13
- package/stubs/job.cron.stub +0 -12
- package/stubs/job.stub +0 -11
- package/stubs/job.test.stub +0 -15
- package/stubs/mcp.resource.stub +0 -12
- package/stubs/mcp.stub +0 -10
- package/stubs/mcp.test.stub +0 -15
- package/stubs/middleware.stub +0 -11
- package/stubs/middleware.test.stub +0 -13
- package/stubs/migration.stub +0 -1
- package/stubs/model.stub +0 -24
- package/stubs/model.test.stub +0 -15
- package/stubs/policy.stub +0 -13
- package/stubs/policy.test.stub +0 -17
- package/stubs/service.stub +0 -13
- package/stubs/service.test.stub +0 -14
- package/stubs/validator.stub +0 -14
- package/stubs/validator.test.stub +0 -22
- package/templates/app/README.md +0 -57
- package/templates/app/app/commands/about.test.ts +0 -29
- package/templates/app/app/commands/about.ts +0 -34
- package/templates/app/app/commands/index.ts +0 -15
- package/templates/app/app/http/controllers/home.tsx +0 -22
- package/templates/app/app/http/controllers/not-found.tsx +0 -25
- package/templates/app/app/initializers/assets.ts +0 -11
- package/templates/app/app/initializers/cli.ts +0 -35
- package/templates/app/app/initializers/dispatcher.ts +0 -18
- package/templates/app/app/initializers/logger.ts +0 -10
- package/templates/app/app/initializers/mcp.ts +0 -16
- package/templates/app/app/initializers/router.tsx +0 -65
- package/templates/app/app/jobs/index.ts +0 -10
- package/templates/app/app/mcp/resources/index.ts +0 -9
- package/templates/app/app/mcp/tools/index.ts +0 -10
- package/templates/app/bootstrap/browser.ts +0 -27
- package/templates/app/bootstrap/cli.ts +0 -9
- package/templates/app/bootstrap/worker.ts +0 -31
- package/templates/app/cloudflare.config.ts +0 -28
- package/templates/app/config/router-context.d.ts +0 -20
- package/templates/app/gitignore +0 -9
- package/templates/app/package.json +0 -38
- package/templates/app/resources/layouts/document.tsx +0 -58
- package/templates/app/routes/web.ts +0 -12
- package/templates/app/tsconfig.json +0 -40
- package/templates/app/vite.config.ts +0 -40
package/dist/commands/ui/diff.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui diff` handler: prints how a copy differs from the installed version as a unified
|
|
3
|
-
* diff, or says that it matches.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
import { createCommand, success } from "@sdxc/cli";
|
|
9
|
-
import { isFailure } from "@sdxc/result";
|
|
10
|
-
import { SDXC_COMMANDS } from "../../contract.js";
|
|
11
|
-
import { packageRoot, project } from "../../middleware.js";
|
|
12
|
-
import { diffComponent, loadContext } from "../../ui/commands.js";
|
|
13
|
-
/** Writes the diff, from the installed file to the local one, to stdout. */
|
|
14
|
-
export default createCommand(SDXC_COMMANDS.ui.diff, {
|
|
15
|
-
middleware: [project(), packageRoot()],
|
|
16
|
-
/** Exits 1 for a component that is not copied or no longer shipped. */
|
|
17
|
-
async handler(ctx) {
|
|
18
|
-
let context = await loadContext(ctx.project, ctx.packageRoot);
|
|
19
|
-
if (isFailure(context))
|
|
20
|
-
return context;
|
|
21
|
-
let name = ctx.arguments.component;
|
|
22
|
-
let diff = await diffComponent(context.data, name);
|
|
23
|
-
if (isFailure(diff))
|
|
24
|
-
return diff;
|
|
25
|
-
ctx.stdout(diff.data === "" ? `${name} matches release ${context.data.registry.release}\n` : diff.data);
|
|
26
|
-
return success();
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui list` handler: one line per component in the installed release and per copy
|
|
3
|
-
* the release no longer ships, marking each copy's release and whether it is edited or behind.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
import type { ListRow } from "../../ui/commands.js";
|
|
9
|
-
/** Prints every component, sorted by name. */
|
|
10
|
-
declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<Readonly<Record<string, import("@sdxc/cli").Argument<unknown>>>, Readonly<Record<string, import("@sdxc/cli").Flag<unknown>>>>, readonly [import("@sdxc/cli").CommandMiddleware<{
|
|
11
|
-
key: typeof import("../../middleware.js").CurrentProject;
|
|
12
|
-
value: import("../../middleware.js").Project;
|
|
13
|
-
property: "project";
|
|
14
|
-
}>, import("@sdxc/cli").CommandMiddleware<{
|
|
15
|
-
key: typeof import("../../middleware.js").PackageRoot;
|
|
16
|
-
value: string;
|
|
17
|
-
property: "packageRoot";
|
|
18
|
-
}>]>;
|
|
19
|
-
export default _default;
|
|
20
|
-
/**
|
|
21
|
-
* The `list` output: one line per component, its name padded to a column, then whether it is
|
|
22
|
-
* copied, from which release, and whether the copy is edited or behind.
|
|
23
|
-
*/
|
|
24
|
-
export declare function formatList(rows: readonly ListRow[]): string;
|
package/dist/commands/ui/list.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui list` handler: one line per component in the installed release and per copy
|
|
3
|
-
* the release no longer ships, marking each copy's release and whether it is edited or behind.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
import { createCommand, success } from "@sdxc/cli";
|
|
9
|
-
import { isFailure } from "@sdxc/result";
|
|
10
|
-
import { SDXC_COMMANDS } from "../../contract.js";
|
|
11
|
-
import { packageRoot, project } from "../../middleware.js";
|
|
12
|
-
import { listComponents, loadContext } from "../../ui/commands.js";
|
|
13
|
-
/** Prints every component, sorted by name. */
|
|
14
|
-
export default createCommand(SDXC_COMMANDS.ui.list, {
|
|
15
|
-
middleware: [project(), packageRoot()],
|
|
16
|
-
/** Writes the table to stdout. */
|
|
17
|
-
async handler(ctx) {
|
|
18
|
-
let context = await loadContext(ctx.project, ctx.packageRoot);
|
|
19
|
-
if (isFailure(context))
|
|
20
|
-
return context;
|
|
21
|
-
ctx.stdout(formatList(await listComponents(context.data)));
|
|
22
|
-
return success();
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* The `list` output: one line per component, its name padded to a column, then whether it is
|
|
27
|
-
* copied, from which release, and whether the copy is edited or behind.
|
|
28
|
-
*/
|
|
29
|
-
export function formatList(rows) {
|
|
30
|
-
let width = Math.max(0, ...rows.map((row) => row.name.length));
|
|
31
|
-
return rows
|
|
32
|
-
.map((row) => {
|
|
33
|
-
if (row.copy === null)
|
|
34
|
-
return `${row.name}\n`;
|
|
35
|
-
let state = [`copied from ${row.copy.release}`];
|
|
36
|
-
if (row.copy.edited)
|
|
37
|
-
state.push("edited");
|
|
38
|
-
if (row.changedIn === null)
|
|
39
|
-
state.push("no longer shipped");
|
|
40
|
-
else if (row.copy.behind)
|
|
41
|
-
state.push(`behind, changed in ${row.changedIn}`);
|
|
42
|
-
return `${row.name.padEnd(width)} ${state.join(", ")}\n`;
|
|
43
|
-
})
|
|
44
|
-
.join("");
|
|
45
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui remove` handler: deletes copies and points imports back at `@sdxc/ui/<name>`.
|
|
3
|
-
* Without names, a terminal picks from the copies the lock file lists.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
/** Removes the named copies, or the ones picked on a terminal, and prints what it did. */
|
|
9
|
-
declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
10
|
-
readonly components: import("@sdxc/cli").Argument<string[]>;
|
|
11
|
-
}, {
|
|
12
|
-
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
13
|
-
}>, readonly [import("@sdxc/cli").CommandMiddleware<{
|
|
14
|
-
key: typeof import("../../middleware.js").CurrentProject;
|
|
15
|
-
value: import("../../middleware.js").Project;
|
|
16
|
-
property: "project";
|
|
17
|
-
}>, import("@sdxc/cli").CommandMiddleware<{
|
|
18
|
-
key: typeof import("../../middleware.js").PackageRoot;
|
|
19
|
-
value: string;
|
|
20
|
-
property: "packageRoot";
|
|
21
|
-
}>]>;
|
|
22
|
-
export default _default;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui remove` handler: deletes copies and points imports back at `@sdxc/ui/<name>`.
|
|
3
|
-
* Without names, a terminal picks from the copies the lock file lists.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
import { createCommand, success, usage } from "@sdxc/cli";
|
|
9
|
-
import { failure, isFailure } from "@sdxc/result";
|
|
10
|
-
import { SDXC_COMMANDS } from "../../contract.js";
|
|
11
|
-
import { uiEntries } from "../../lock.js";
|
|
12
|
-
import { packageRoot, project } from "../../middleware.js";
|
|
13
|
-
import { finishPlan, loadContext, planRemove } from "../../ui/commands.js";
|
|
14
|
-
/** Removes the named copies, or the ones picked on a terminal, and prints what it did. */
|
|
15
|
-
export default createCommand(SDXC_COMMANDS.ui.remove, {
|
|
16
|
-
middleware: [project(), packageRoot()],
|
|
17
|
-
/** Exits 1 when nothing is copied, and 2 when no copy is named and none is picked. */
|
|
18
|
-
async handler(ctx) {
|
|
19
|
-
let context = await loadContext(ctx.project, ctx.packageRoot);
|
|
20
|
-
if (isFailure(context))
|
|
21
|
-
return context;
|
|
22
|
-
let names = ctx.arguments.components;
|
|
23
|
-
if (names.length === 0) {
|
|
24
|
-
let copies = uiEntries(context.data.lock).map((entry) => entry.name);
|
|
25
|
-
if (copies.length === 0) {
|
|
26
|
-
return failure(new Error("No component is copied; sdxc ui add copies one"));
|
|
27
|
-
}
|
|
28
|
-
let picked = await ctx.prompt.multiselect({
|
|
29
|
-
message: "Remove which copies?",
|
|
30
|
-
options: copies.sort(),
|
|
31
|
-
default: [],
|
|
32
|
-
name: "components",
|
|
33
|
-
});
|
|
34
|
-
if (isFailure(picked))
|
|
35
|
-
return picked;
|
|
36
|
-
names = picked.data;
|
|
37
|
-
}
|
|
38
|
-
if (names.length === 0)
|
|
39
|
-
return usage("Name at least one component to remove");
|
|
40
|
-
let plan = await planRemove(context.data, names);
|
|
41
|
-
if (isFailure(plan))
|
|
42
|
-
return plan;
|
|
43
|
-
let finished = await finishPlan(ctx, context.data, plan.data, ctx.flags.dryRun);
|
|
44
|
-
if (isFailure(finished))
|
|
45
|
-
return finished;
|
|
46
|
-
return success();
|
|
47
|
-
},
|
|
48
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui update` handler: replaces copied files with the installed version. A file the
|
|
3
|
-
* project edited is replaced only with `--force`, or when the user says yes on a terminal.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
/** Updates the named copies and prints what it replaced and what it left. */
|
|
9
|
-
declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
10
|
-
readonly components: import("@sdxc/cli").Argument<[string, ...string[]]>;
|
|
11
|
-
}, {
|
|
12
|
-
readonly force: import("@sdxc/cli").Flag<boolean>;
|
|
13
|
-
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
14
|
-
}>, readonly [import("@sdxc/cli").CommandMiddleware<{
|
|
15
|
-
key: typeof import("../../middleware.js").CurrentProject;
|
|
16
|
-
value: import("../../middleware.js").Project;
|
|
17
|
-
property: "project";
|
|
18
|
-
}>, import("@sdxc/cli").CommandMiddleware<{
|
|
19
|
-
key: typeof import("../../middleware.js").PackageRoot;
|
|
20
|
-
value: string;
|
|
21
|
-
property: "packageRoot";
|
|
22
|
-
}>]>;
|
|
23
|
-
export default _default;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc ui update` handler: replaces copied files with the installed version. A file the
|
|
3
|
-
* project edited is replaced only with `--force`, or when the user says yes on a terminal.
|
|
4
|
-
*
|
|
5
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
-
* @copyright Sergio Xalambrí 2026
|
|
7
|
-
*/
|
|
8
|
-
import { createCommand, success } from "@sdxc/cli";
|
|
9
|
-
import { isFailure, success as succeed } from "@sdxc/result";
|
|
10
|
-
import { SDXC_COMMANDS } from "../../contract.js";
|
|
11
|
-
import { packageRoot, project } from "../../middleware.js";
|
|
12
|
-
import { finishPlan, loadContext, planUpdate } from "../../ui/commands.js";
|
|
13
|
-
/** Updates the named copies and prints what it replaced and what it left. */
|
|
14
|
-
export default createCommand(SDXC_COMMANDS.ui.update, {
|
|
15
|
-
middleware: [project(), packageRoot()],
|
|
16
|
-
/** Without a terminal and without `--force`, every edited file is left as it is. */
|
|
17
|
-
async handler(ctx) {
|
|
18
|
-
let context = await loadContext(ctx.project, ctx.packageRoot);
|
|
19
|
-
if (isFailure(context))
|
|
20
|
-
return context;
|
|
21
|
-
let plan = await planUpdate(context.data, ctx.arguments.components, {
|
|
22
|
-
overwrite: (path) => ctx.flags.force
|
|
23
|
-
? Promise.resolve(succeed(true))
|
|
24
|
-
: ctx.prompt.confirm({
|
|
25
|
-
message: `${path} is edited; replace it with the installed version?`,
|
|
26
|
-
default: false,
|
|
27
|
-
name: "overwrite",
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
if (isFailure(plan))
|
|
31
|
-
return plan;
|
|
32
|
-
let finished = await finishPlan(ctx, context.data, plan.data, ctx.flags.dryRun);
|
|
33
|
-
if (isFailure(finished))
|
|
34
|
-
return finished;
|
|
35
|
-
return success();
|
|
36
|
-
},
|
|
37
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc upgrade` handler: moves every `@sdxc/*` package the project lists to another
|
|
3
|
-
* release, `remix` following the peer it pins, installs, and hands off to that release's
|
|
4
|
-
* `@sdxc/kit` for the prompt, so the prompt comes from the target's own changelog and registry.
|
|
5
|
-
*
|
|
6
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
-
* @copyright Sergio Xalambrí 2026
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Exits 0 when done or already up to date, 1 when the upgrade failed or the target is older.
|
|
11
|
-
* Progress goes to stderr; stdout carries only the prompt.
|
|
12
|
-
*/
|
|
13
|
-
declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
14
|
-
readonly version: import("@sdxc/cli").Argument<string | undefined>;
|
|
15
|
-
}, {
|
|
16
|
-
readonly install: import("@sdxc/cli").Flag<boolean>;
|
|
17
|
-
readonly output: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
18
|
-
readonly prompt: import("@sdxc/cli").Flag<boolean>;
|
|
19
|
-
readonly from: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
20
|
-
readonly remixFrom: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
21
|
-
}>, readonly [import("@sdxc/cli").CommandMiddleware<{
|
|
22
|
-
key: typeof import("../middleware.js").CurrentProject;
|
|
23
|
-
value: import("../middleware.js").Project;
|
|
24
|
-
property: "project";
|
|
25
|
-
}>, import("@sdxc/cli").CommandMiddleware<{
|
|
26
|
-
key: typeof import("../middleware.js").PackageRoot;
|
|
27
|
-
value: string;
|
|
28
|
-
property: "packageRoot";
|
|
29
|
-
}>]>;
|
|
30
|
-
export default _default;
|
package/dist/commands/upgrade.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc upgrade` handler: moves every `@sdxc/*` package the project lists to another
|
|
3
|
-
* release, `remix` following the peer it pins, installs, and hands off to that release's
|
|
4
|
-
* `@sdxc/kit` for the prompt, so the prompt comes from the target's own changelog and registry.
|
|
5
|
-
*
|
|
6
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
-
* @copyright Sergio Xalambrí 2026
|
|
8
|
-
*/
|
|
9
|
-
import { writeFile } from "node:fs/promises";
|
|
10
|
-
import { resolve } from "node:path";
|
|
11
|
-
import { createCommand, success, usage } from "@sdxc/cli";
|
|
12
|
-
import { failure, isFailure, isSuccess, wrap } from "@sdxc/result";
|
|
13
|
-
import { compare } from "@sdxc/semver";
|
|
14
|
-
import { SDXC_COMMANDS } from "../contract.js";
|
|
15
|
-
import { packageRoot, project } from "../middleware.js";
|
|
16
|
-
import { lockFileAtOrAbove, packageManager } from "../package-manager.js";
|
|
17
|
-
import { resolveRelease, scopedPackageOf } from "../releases.js";
|
|
18
|
-
import { entriesBetween } from "../upgrade/changelog.js";
|
|
19
|
-
import { bumpManifest, currentRelease, listedScopedPackages, lists, projectImports, readManifest, } from "../upgrade/project.js";
|
|
20
|
-
import { buildPrompt } from "../upgrade/prompt.js";
|
|
21
|
-
import { fetchChangelog, fetchRelease, RELEASE_PACKAGE } from "../upgrade/registry.js";
|
|
22
|
-
/** The middleware `upgrade` runs behind. */
|
|
23
|
-
const UPGRADE_MIDDLEWARE = [project(), packageRoot()];
|
|
24
|
-
/**
|
|
25
|
-
* Exits 0 when done or already up to date, 1 when the upgrade failed or the target is older.
|
|
26
|
-
* Progress goes to stderr; stdout carries only the prompt.
|
|
27
|
-
*/
|
|
28
|
-
export default createCommand(SDXC_COMMANDS.upgrade, {
|
|
29
|
-
middleware: UPGRADE_MIDDLEWARE,
|
|
30
|
-
/** Prints the prompt with `--prompt`, and otherwise bumps, installs and hands off. */
|
|
31
|
-
async handler(ctx) {
|
|
32
|
-
let output = ctx.flags.output === undefined ? null : resolve(ctx.cwd, ctx.flags.output);
|
|
33
|
-
if (ctx.flags.prompt) {
|
|
34
|
-
if (ctx.flags.from === undefined || ctx.arguments.version !== undefined) {
|
|
35
|
-
return usage("sdxc upgrade --prompt takes --from <version> and no version");
|
|
36
|
-
}
|
|
37
|
-
return printPrompt(ctx, ctx.flags.from, output);
|
|
38
|
-
}
|
|
39
|
-
let root = ctx.project.root;
|
|
40
|
-
let read = await readManifest(root);
|
|
41
|
-
if (isFailure(read))
|
|
42
|
-
return read;
|
|
43
|
-
let { manifest, text } = read.data;
|
|
44
|
-
let scoped = listedScopedPackages(manifest);
|
|
45
|
-
if (scoped.length === 0) {
|
|
46
|
-
return failure(new Error("package.json lists no @sdxc/* package to upgrade"));
|
|
47
|
-
}
|
|
48
|
-
let current = currentRelease(manifest);
|
|
49
|
-
if (current === null) {
|
|
50
|
-
return failure(new Error("package.json pins no @sdxc/* package to an exact release"));
|
|
51
|
-
}
|
|
52
|
-
let found = await lookUp(ctx, ctx.arguments.version ?? null, current);
|
|
53
|
-
if (isFailure(found))
|
|
54
|
-
return found;
|
|
55
|
-
let { release, changelog } = found.data;
|
|
56
|
-
let order = compare(release.version, current);
|
|
57
|
-
if (order < 0) {
|
|
58
|
-
return failure(new Error(`Release ${release.version} is older than the project's ${current}; upgrade only moves forward`));
|
|
59
|
-
}
|
|
60
|
-
if (order === 0) {
|
|
61
|
-
ctx.stderr(`The @sdxc packages are up to date at ${current}\n`);
|
|
62
|
-
return success();
|
|
63
|
-
}
|
|
64
|
-
let imports = await projectImports(root);
|
|
65
|
-
if (changelog !== null) {
|
|
66
|
-
let proceed = await confirmBreaking(ctx, changelog, current, release.version, imports);
|
|
67
|
-
if (isFailure(proceed))
|
|
68
|
-
return proceed;
|
|
69
|
-
if (!proceed.data) {
|
|
70
|
-
ctx.stderr(`Kept the @sdxc packages at ${current}; package.json is unchanged\n`);
|
|
71
|
-
return success();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
let pins = await ctx.task(`Resolving ${scoped.length} @sdxc packages at ${release.version}`, (task) => resolveRelease(scoped, release.version, task.signal));
|
|
75
|
-
if (isFailure(pins))
|
|
76
|
-
return pins;
|
|
77
|
-
let versions = Object.fromEntries(pins.data);
|
|
78
|
-
if (release.remix !== null && lists(manifest, "remix"))
|
|
79
|
-
versions.remix = release.remix;
|
|
80
|
-
let bumped = bumpManifest(text, versions);
|
|
81
|
-
let written = await wrap(() => writeFile(resolve(root, "package.json"), bumped.text));
|
|
82
|
-
if (isFailure(written))
|
|
83
|
-
return written;
|
|
84
|
-
for (let bump of bumped.bumps) {
|
|
85
|
-
ctx.stderr(`package.json: ${bump.name} ${bump.from} -> ${bump.to}\n`);
|
|
86
|
-
}
|
|
87
|
-
let manager = await packageManager({
|
|
88
|
-
declared: manifest.packageManager,
|
|
89
|
-
findLockFile: lockFileAtOrAbove(root),
|
|
90
|
-
});
|
|
91
|
-
let remixFrom = bumped.bumps.find((bump) => bump.name === "remix")?.from ?? null;
|
|
92
|
-
let promptCommand = [
|
|
93
|
-
...manager.dlx,
|
|
94
|
-
`${RELEASE_PACKAGE}@${release.version}`,
|
|
95
|
-
"upgrade",
|
|
96
|
-
"--prompt",
|
|
97
|
-
"--from",
|
|
98
|
-
current,
|
|
99
|
-
...(remixFrom === null ? [] : ["--remix-from", remixFrom]),
|
|
100
|
-
...(output === null ? [] : ["--output", output]),
|
|
101
|
-
];
|
|
102
|
-
if (!ctx.flags.install) {
|
|
103
|
-
ctx.stderr(`Run \`${manager.install.join(" ")}\`, then \`${promptCommand.join(" ")}\` for the upgrade prompt.\n`);
|
|
104
|
-
return success();
|
|
105
|
-
}
|
|
106
|
-
let installed = await ctx.task(`Installing with ${manager.name}`, (task) => ctx.exec(manager.install, { cwd: root, stdio: "stderr", signal: task.signal }));
|
|
107
|
-
if (isFailure(installed)) {
|
|
108
|
-
return failure(new Error(`${installed.error.message}\nFix the install and run it again, then \`${promptCommand.join(" ")}\` for the upgrade prompt.`));
|
|
109
|
-
}
|
|
110
|
-
let prompted = await ctx.exec(promptCommand, { cwd: root, stdio: "inherit" });
|
|
111
|
-
if (isFailure(prompted))
|
|
112
|
-
return prompted;
|
|
113
|
-
return success();
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
/** Prints the prompt for this kit's release, or writes it to `output`. */
|
|
117
|
-
async function printPrompt(ctx, from, output) {
|
|
118
|
-
let prompt = await buildPrompt({
|
|
119
|
-
root: ctx.project.root,
|
|
120
|
-
packageRoot: ctx.packageRoot,
|
|
121
|
-
from,
|
|
122
|
-
remixFrom: ctx.flags.remixFrom ?? null,
|
|
123
|
-
});
|
|
124
|
-
if (isFailure(prompt))
|
|
125
|
-
return prompt;
|
|
126
|
-
if (output === null) {
|
|
127
|
-
ctx.stdout(prompt.data);
|
|
128
|
-
return success();
|
|
129
|
-
}
|
|
130
|
-
let text = prompt.data;
|
|
131
|
-
let written = await wrap(() => writeFile(output, text));
|
|
132
|
-
if (isFailure(written))
|
|
133
|
-
return written;
|
|
134
|
-
ctx.stderr(`Wrote the upgrade prompt to ${output}\n`);
|
|
135
|
-
return success();
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Finds the release `version` names on npm, and, when it is newer than `current`, the
|
|
139
|
-
* changelog it ships. A changelog the CDN cannot serve is `null`, which skips the question
|
|
140
|
-
* about breaking changes rather than the upgrade.
|
|
141
|
-
*/
|
|
142
|
-
async function lookUp(ctx, version, current) {
|
|
143
|
-
return ctx.task(`Looking up release ${version ?? "latest"}`, async (task) => {
|
|
144
|
-
let release = await fetchRelease(version, task.signal);
|
|
145
|
-
if (isFailure(release))
|
|
146
|
-
return release;
|
|
147
|
-
task.update(`Found release ${release.data.version}`);
|
|
148
|
-
if (compare(release.data.version, current) <= 0) {
|
|
149
|
-
return success({ release: release.data, changelog: null });
|
|
150
|
-
}
|
|
151
|
-
let changelog = await fetchChangelog(release.data.version, task.signal);
|
|
152
|
-
return success({
|
|
153
|
-
release: release.data,
|
|
154
|
-
changelog: isSuccess(changelog) ? changelog.data : null,
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Lists the breaking changes between `from` and `to` in packages the project imports and asks
|
|
160
|
-
* whether to go on. Without a terminal the upgrade goes on; with none to list nothing is asked.
|
|
161
|
-
*
|
|
162
|
-
* @returns Whether to bump `package.json`
|
|
163
|
-
*/
|
|
164
|
-
async function confirmBreaking(ctx, changelog, from, to, imports) {
|
|
165
|
-
let imported = new Set();
|
|
166
|
-
for (let specifier of imports.keys()) {
|
|
167
|
-
let name = scopedPackageOf(specifier);
|
|
168
|
-
if (name !== null)
|
|
169
|
-
imported.add(name);
|
|
170
|
-
}
|
|
171
|
-
let breaking = entriesBetween(changelog, from, to).filter((entry) => entry.breaking && imported.has(entry.package));
|
|
172
|
-
if (breaking.length === 0)
|
|
173
|
-
return success(true);
|
|
174
|
-
let count = breaking.length === 1 ? "1 breaking change" : `${breaking.length} breaking changes`;
|
|
175
|
-
ctx.stderr(`Release ${to} brings ${count} to packages this project imports:\n`);
|
|
176
|
-
for (let entry of breaking) {
|
|
177
|
-
ctx.stderr(` ${entry.release} ${entry.package}: ${entry.title}\n`);
|
|
178
|
-
}
|
|
179
|
-
return ctx.prompt.confirm({
|
|
180
|
-
message: `Upgrade to release ${to}?`,
|
|
181
|
-
default: true,
|
|
182
|
-
name: "breaking",
|
|
183
|
-
});
|
|
184
|
-
}
|
package/dist/config.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `sdxc` project configuration: one schema holds every key with its default and its
|
|
3
|
-
* description, so validating a project's file, rendering `sdxc init`'s output and emitting
|
|
4
|
-
* `config.schema.json` for editors all read the same definition.
|
|
5
|
-
*
|
|
6
|
-
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
-
* @copyright Sergio Xalambrí 2026
|
|
8
|
-
*/
|
|
9
|
-
import type { Result } from "@sdxc/result";
|
|
10
|
-
import * as s from "@sdxc/json-schema";
|
|
11
|
-
/** Where the CLI looks for the configuration, relative to the project root, in lookup order. */
|
|
12
|
-
export declare const CONFIG_LOCATIONS: readonly [".config/sdxc.jsonc", "sdxc.jsonc"];
|
|
13
|
-
/**
|
|
14
|
-
* Every configuration key. Each leaf carries its default, or an example when it has none, and
|
|
15
|
-
* a description that becomes its comment in `sdxc init`'s output; an unknown key is an error, so
|
|
16
|
-
* a misspelt key is reported instead of silently ignored.
|
|
17
|
-
*/
|
|
18
|
-
export declare const CONFIG_SCHEMA: s.Schema<{
|
|
19
|
-
$schema?: string | undefined;
|
|
20
|
-
format?: string[] | undefined;
|
|
21
|
-
ui?: {
|
|
22
|
-
directory?: string | undefined;
|
|
23
|
-
alias?: string | undefined;
|
|
24
|
-
tests?: boolean | undefined;
|
|
25
|
-
} | undefined;
|
|
26
|
-
make?: {
|
|
27
|
-
tests?: boolean | undefined;
|
|
28
|
-
routes?: string | undefined;
|
|
29
|
-
migrations?: Record<string, string> | undefined;
|
|
30
|
-
stubs?: string | undefined;
|
|
31
|
-
} | undefined;
|
|
32
|
-
lock?: string | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
ui: {
|
|
35
|
-
directory: string;
|
|
36
|
-
tests: boolean;
|
|
37
|
-
alias?: string | undefined;
|
|
38
|
-
};
|
|
39
|
-
make: {
|
|
40
|
-
tests: boolean;
|
|
41
|
-
routes: string;
|
|
42
|
-
migrations: Record<string, string>;
|
|
43
|
-
stubs: string;
|
|
44
|
-
};
|
|
45
|
-
lock: string;
|
|
46
|
-
$schema?: string | undefined;
|
|
47
|
-
format?: string[] | undefined;
|
|
48
|
-
}>;
|
|
49
|
-
/** A validated configuration with every default filled in. */
|
|
50
|
-
export type Config = s.InferOutput<typeof CONFIG_SCHEMA>;
|
|
51
|
-
/** The configuration a command runs with, and the file it came from when the project has one. */
|
|
52
|
-
export interface LoadedConfig {
|
|
53
|
-
/** Path relative to the project root, or `null` when the defaults apply. */
|
|
54
|
-
path: string | null;
|
|
55
|
-
config: Config;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The configuration schema as a JSON Schema 2020-12 document, which `config.schema.json`
|
|
59
|
-
* ships and `sdxc init` renders.
|
|
60
|
-
*/
|
|
61
|
-
export declare function configJSONSchema(): Result<s.JSONSchema, Error>;
|
|
62
|
-
/**
|
|
63
|
-
* The configuration file of the project at `root`, relative to it, or `null` when there is
|
|
64
|
-
* none. A file at both locations is a failure naming them, since either could be the one meant.
|
|
65
|
-
*/
|
|
66
|
-
export declare function findConfigFile(root: string): Promise<Result<string | null, Error>>;
|
|
67
|
-
/**
|
|
68
|
-
* Reads, validates and completes the configuration of the project at `root`. Every failing key
|
|
69
|
-
* is reported on its own line with its path, and every configured path must stay inside the
|
|
70
|
-
* project; a project without a file runs with the defaults.
|
|
71
|
-
*/
|
|
72
|
-
export declare function loadConfig(root: string): Promise<Result<LoadedConfig, Error>>;
|
|
73
|
-
/**
|
|
74
|
-
* Validates an already parsed configuration value against {@link CONFIG_SCHEMA} and the project
|
|
75
|
-
* boundary. Messages read `<file>: <key path>: <problem>`, one per line.
|
|
76
|
-
*
|
|
77
|
-
* @param value - The parsed file, or `{}` for a project without one.
|
|
78
|
-
* @param root - The project root every configured path resolves against.
|
|
79
|
-
* @param location - The file the value came from, named in every message.
|
|
80
|
-
*/
|
|
81
|
-
export declare function parseConfig(value: unknown, root: string, location: string | null): Result<LoadedConfig, Error>;
|