@sdxc/kit 0.0.0-pre.1
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/LICENSE.md +21 -0
- package/README.md +93 -0
- package/config.schema.json +89 -0
- package/dist/bin.d.ts +9 -0
- package/dist/bin.js +10 -0
- package/dist/cli.d.ts +33 -0
- package/dist/cli.js +58 -0
- package/dist/commands/create.d.ts +20 -0
- package/dist/commands/create.js +164 -0
- package/dist/commands/init.d.ts +16 -0
- package/dist/commands/init.js +27 -0
- package/dist/commands/make.d.ts +335 -0
- package/dist/commands/make.js +152 -0
- package/dist/commands/run.d.ts +23 -0
- package/dist/commands/run.js +51 -0
- package/dist/commands/ui/add.d.ts +23 -0
- package/dist/commands/ui/add.js +50 -0
- package/dist/commands/ui/diff.d.ts +20 -0
- package/dist/commands/ui/diff.js +28 -0
- package/dist/commands/ui/list.d.ts +24 -0
- package/dist/commands/ui/list.js +45 -0
- package/dist/commands/ui/remove.d.ts +22 -0
- package/dist/commands/ui/remove.js +48 -0
- package/dist/commands/ui/update.d.ts +23 -0
- package/dist/commands/ui/update.js +37 -0
- package/dist/commands/upgrade.d.ts +30 -0
- package/dist/commands/upgrade.js +184 -0
- package/dist/config.d.ts +81 -0
- package/dist/config.js +157 -0
- package/dist/contract.d.ts +161 -0
- package/dist/contract.js +308 -0
- package/dist/create/github.d.ts +63 -0
- package/dist/create/github.js +172 -0
- package/dist/create/target.d.ts +31 -0
- package/dist/create/target.js +56 -0
- package/dist/create/templates.d.ts +62 -0
- package/dist/create/templates.js +228 -0
- package/dist/dependencies.d.ts +34 -0
- package/dist/dependencies.js +76 -0
- package/dist/diff.d.ts +14 -0
- package/dist/diff.js +103 -0
- package/dist/format.d.ts +21 -0
- package/dist/format.js +40 -0
- package/dist/init.d.ts +38 -0
- package/dist/init.js +92 -0
- package/dist/lock.d.ts +74 -0
- package/dist/lock.js +214 -0
- package/dist/make/declare.d.ts +54 -0
- package/dist/make/declare.js +495 -0
- package/dist/make/generate.d.ts +56 -0
- package/dist/make/generate.js +139 -0
- package/dist/make/imports.d.ts +43 -0
- package/dist/make/imports.js +104 -0
- package/dist/make/index.d.ts +43 -0
- package/dist/make/index.js +136 -0
- package/dist/make/kinds.d.ts +39 -0
- package/dist/make/kinds.js +95 -0
- package/dist/make/migrations.d.ts +21 -0
- package/dist/make/migrations.js +48 -0
- package/dist/make/names.d.ts +31 -0
- package/dist/make/names.js +47 -0
- package/dist/make/stubs.d.ts +44 -0
- package/dist/make/stubs.js +89 -0
- package/dist/middleware.d.ts +44 -0
- package/dist/middleware.js +49 -0
- package/dist/package-manager.d.ts +41 -0
- package/dist/package-manager.js +80 -0
- package/dist/project.d.ts +19 -0
- package/dist/project.js +42 -0
- package/dist/releases.d.ts +40 -0
- package/dist/releases.js +110 -0
- package/dist/testing.d.ts +47 -0
- package/dist/testing.js +126 -0
- package/dist/ui/commands.d.ts +114 -0
- package/dist/ui/commands.js +432 -0
- package/dist/ui/imports.d.ts +46 -0
- package/dist/ui/imports.js +160 -0
- package/dist/ui/layout.d.ts +48 -0
- package/dist/ui/layout.js +138 -0
- package/dist/ui/registry.d.ts +58 -0
- package/dist/ui/registry.js +82 -0
- package/dist/upgrade/changelog.d.ts +50 -0
- package/dist/upgrade/changelog.js +69 -0
- package/dist/upgrade/project.d.ts +62 -0
- package/dist/upgrade/project.js +132 -0
- package/dist/upgrade/prompt.d.ts +51 -0
- package/dist/upgrade/prompt.js +227 -0
- package/dist/upgrade/registry.d.ts +33 -0
- package/dist/upgrade/registry.js +50 -0
- package/lock.schema.json +60 -0
- package/package.json +45 -0
- package/stubs/command.stub +12 -0
- package/stubs/command.test.stub +18 -0
- package/stubs/controller.form.stub +33 -0
- package/stubs/controller.stub +17 -0
- package/stubs/controller.test.stub +15 -0
- package/stubs/email.stub +44 -0
- package/stubs/email.test.stub +16 -0
- package/stubs/factory.stub +10 -0
- package/stubs/initializer.stub +7 -0
- package/stubs/initializer.test.stub +13 -0
- package/stubs/job.cron.stub +12 -0
- package/stubs/job.stub +11 -0
- package/stubs/job.test.stub +15 -0
- package/stubs/mcp.resource.stub +12 -0
- package/stubs/mcp.stub +10 -0
- package/stubs/mcp.test.stub +15 -0
- package/stubs/middleware.stub +11 -0
- package/stubs/middleware.test.stub +13 -0
- package/stubs/migration.stub +1 -0
- package/stubs/model.stub +24 -0
- package/stubs/model.test.stub +15 -0
- package/stubs/policy.stub +13 -0
- package/stubs/policy.test.stub +17 -0
- package/stubs/service.stub +13 -0
- package/stubs/service.test.stub +14 -0
- package/stubs/validator.stub +14 -0
- package/stubs/validator.test.stub +22 -0
- package/templates/app/README.md +57 -0
- package/templates/app/app/commands/about.test.ts +29 -0
- package/templates/app/app/commands/about.ts +34 -0
- package/templates/app/app/commands/index.ts +15 -0
- package/templates/app/app/http/controllers/home.tsx +22 -0
- package/templates/app/app/http/controllers/not-found.tsx +25 -0
- package/templates/app/app/initializers/assets.ts +11 -0
- package/templates/app/app/initializers/cli.ts +35 -0
- package/templates/app/app/initializers/dispatcher.ts +18 -0
- package/templates/app/app/initializers/logger.ts +10 -0
- package/templates/app/app/initializers/mcp.ts +16 -0
- package/templates/app/app/initializers/router.tsx +65 -0
- package/templates/app/app/jobs/index.ts +10 -0
- package/templates/app/app/mcp/resources/index.ts +9 -0
- package/templates/app/app/mcp/tools/index.ts +10 -0
- package/templates/app/bootstrap/browser.ts +27 -0
- package/templates/app/bootstrap/cli.ts +9 -0
- package/templates/app/bootstrap/worker.ts +31 -0
- package/templates/app/cloudflare.config.ts +28 -0
- package/templates/app/config/router-context.d.ts +20 -0
- package/templates/app/gitignore +9 -0
- package/templates/app/package.json +38 -0
- package/templates/app/resources/layouts/document.tsx +58 -0
- package/templates/app/routes/web.ts +12 -0
- package/templates/app/tsconfig.json +40 -0
- package/templates/app/vite.config.ts +40 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where copied components live and how the project spells an import of one: the folder from
|
|
3
|
+
* `ui.directory`, the prefix from `ui.alias` or the tsconfig `paths` entry covering that folder,
|
|
4
|
+
* and the extension from the tsconfig's module resolution.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
11
|
+
import * as JSONC from "@sdxc/jsonc";
|
|
12
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
13
|
+
/** How deep an `extends` chain is followed before the rest is ignored. */
|
|
14
|
+
const MAX_EXTENDS = 8;
|
|
15
|
+
/** The module resolution modes that require an extension on relative imports. */
|
|
16
|
+
const NODE_RESOLUTION = new Set(["node16", "nodenext"]);
|
|
17
|
+
/**
|
|
18
|
+
* The layout of the project at `root`: `ui.alias` when configured, otherwise inferred from the
|
|
19
|
+
* root `tsconfig.json`. A project without a tsconfig imports copies relatively, without an
|
|
20
|
+
* extension.
|
|
21
|
+
*/
|
|
22
|
+
export async function readLayout(root, config) {
|
|
23
|
+
let directory = posix.normalize(config.ui.directory.split(sep).join("/")).replace(/\/$/, "");
|
|
24
|
+
let options = await readCompilerOptions(join(root, "tsconfig.json"), 0);
|
|
25
|
+
if (isFailure(options))
|
|
26
|
+
return options;
|
|
27
|
+
let resolution = (options.data.moduleResolution ?? options.data.module ?? "").toLowerCase();
|
|
28
|
+
return success({
|
|
29
|
+
directory,
|
|
30
|
+
alias: config.ui.alias?.replace(/\/$/, "") ?? inferAlias(root, directory, options.data),
|
|
31
|
+
extension: NODE_RESOLUTION.has(resolution) ? ".js" : "",
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The import prefix a tsconfig `paths` entry gives `directory`: the `<prefix>/*` entry whose
|
|
36
|
+
* target folder contains it, the deepest such target when several do.
|
|
37
|
+
*/
|
|
38
|
+
export function inferAlias(root, directory, options) {
|
|
39
|
+
let best = null;
|
|
40
|
+
for (let [key, targets] of Object.entries(options.paths ?? {})) {
|
|
41
|
+
if (!key.endsWith("/*"))
|
|
42
|
+
continue;
|
|
43
|
+
for (let target of targets) {
|
|
44
|
+
if (!target.endsWith("*"))
|
|
45
|
+
continue;
|
|
46
|
+
let folder = projectPath(root, options.pathsBase ?? root, target.slice(0, -1));
|
|
47
|
+
if (folder === null)
|
|
48
|
+
continue;
|
|
49
|
+
let rest = null;
|
|
50
|
+
if (folder === directory)
|
|
51
|
+
rest = "";
|
|
52
|
+
else if (folder === "")
|
|
53
|
+
rest = directory;
|
|
54
|
+
else if (directory.startsWith(`${folder}/`))
|
|
55
|
+
rest = directory.slice(folder.length + 1);
|
|
56
|
+
if (rest === null)
|
|
57
|
+
continue;
|
|
58
|
+
let prefix = key.slice(0, -1);
|
|
59
|
+
let alias = rest === "" ? prefix.slice(0, -1) : `${prefix}${rest}`;
|
|
60
|
+
let depth = folder === "" ? 0 : folder.split("/").length;
|
|
61
|
+
if (best === null || depth > best.depth)
|
|
62
|
+
best = { alias, depth };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return best?.alias ?? null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The specifier `file` (relative to the project root) imports the copy of `name` with: relative
|
|
69
|
+
* inside the copies' folder and without an alias, the alias elsewhere.
|
|
70
|
+
*/
|
|
71
|
+
export function copySpecifier(layout, file, name) {
|
|
72
|
+
let from = posix.dirname(file);
|
|
73
|
+
if (layout.alias !== null && from !== layout.directory) {
|
|
74
|
+
return `${layout.alias}/${name}${layout.extension}`;
|
|
75
|
+
}
|
|
76
|
+
let path = posix.relative(from, posix.join(layout.directory, name));
|
|
77
|
+
return `${path.startsWith(".") ? "" : "./"}${path}${layout.extension}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether `specifier`, imported from `file`, names the copy of `name`: through the alias or a
|
|
81
|
+
* relative path, with or without an extension, however the project spelled it.
|
|
82
|
+
*/
|
|
83
|
+
export function namesCopy(layout, file, specifier, name) {
|
|
84
|
+
let bare = specifier.replace(/\.(?:js|jsx|ts|tsx)$/, "");
|
|
85
|
+
if (layout.alias !== null && bare === `${layout.alias}/${name}`)
|
|
86
|
+
return true;
|
|
87
|
+
if (!bare.startsWith("."))
|
|
88
|
+
return false;
|
|
89
|
+
return posix.join(posix.dirname(file), bare) === posix.join(layout.directory, name);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The options of the tsconfig at `path` merged over those it extends, nearest first. Only a
|
|
93
|
+
* relative `extends` is followed, since a package's tsconfig sets no project paths; a missing
|
|
94
|
+
* root file answers no options.
|
|
95
|
+
*/
|
|
96
|
+
async function readCompilerOptions(path, depth) {
|
|
97
|
+
let text = await wrap(() => readFile(path, "utf8"));
|
|
98
|
+
if (isFailure(text))
|
|
99
|
+
return success({});
|
|
100
|
+
let parsed = JSONC.parse(text.data);
|
|
101
|
+
if (isFailure(parsed))
|
|
102
|
+
return failure(new Error(`${path}: ${parsed.error.message}`));
|
|
103
|
+
let config = parsed.data;
|
|
104
|
+
let inherited = {};
|
|
105
|
+
let parents = typeof config.extends === "string" ? [config.extends] : config.extends;
|
|
106
|
+
if (Array.isArray(parents) && depth < MAX_EXTENDS) {
|
|
107
|
+
for (let parent of parents) {
|
|
108
|
+
if (typeof parent !== "string" || !parent.startsWith("."))
|
|
109
|
+
continue;
|
|
110
|
+
let file = resolve(dirname(path), parent.endsWith(".json") ? parent : `${parent}.json`);
|
|
111
|
+
let options = await readCompilerOptions(file, depth + 1);
|
|
112
|
+
if (isFailure(options))
|
|
113
|
+
return options;
|
|
114
|
+
inherited = { ...inherited, ...options.data };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let own = config.compilerOptions ?? {};
|
|
118
|
+
let merged = { ...inherited };
|
|
119
|
+
if (own.moduleResolution !== undefined)
|
|
120
|
+
merged.moduleResolution = own.moduleResolution;
|
|
121
|
+
if (own.module !== undefined)
|
|
122
|
+
merged.module = own.module;
|
|
123
|
+
if (own.paths !== undefined) {
|
|
124
|
+
merged.paths = own.paths;
|
|
125
|
+
merged.pathsBase = resolve(dirname(path), own.baseUrl ?? ".");
|
|
126
|
+
}
|
|
127
|
+
else if (own.baseUrl !== undefined && merged.paths !== undefined) {
|
|
128
|
+
merged.pathsBase = resolve(dirname(path), own.baseUrl);
|
|
129
|
+
}
|
|
130
|
+
return success(merged);
|
|
131
|
+
}
|
|
132
|
+
/** `target` under `base` relative to `root` with `/` separators, or `null` outside the project. */
|
|
133
|
+
function projectPath(root, base, target) {
|
|
134
|
+
let path = relative(root, resolve(base, target)).split(sep).join("/");
|
|
135
|
+
if (path.startsWith(".."))
|
|
136
|
+
return null;
|
|
137
|
+
return path.replace(/\/$/, "");
|
|
138
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component registry the installed `@sdxc/kit` carries in `registry/ui/`, written by its release
|
|
3
|
+
* build: every `@sdxc/ui` component with its source already importing `@sdxc/ui/*`. Reading it from
|
|
4
|
+
* the package itself keeps each copy matched to the helpers installed beside it.
|
|
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 registry sits inside the `@sdxc/kit` package. */
|
|
12
|
+
export declare const REGISTRY_DIR = "registry/ui";
|
|
13
|
+
/** One `registry/ui/<name>.json`. */
|
|
14
|
+
export declare const REGISTRY_ENTRY: s.Schema<{
|
|
15
|
+
name: string;
|
|
16
|
+
dependencies: string[];
|
|
17
|
+
test: {
|
|
18
|
+
path: string;
|
|
19
|
+
content: string;
|
|
20
|
+
} | null;
|
|
21
|
+
source: {
|
|
22
|
+
path: string;
|
|
23
|
+
content: string;
|
|
24
|
+
};
|
|
25
|
+
changedIn: string;
|
|
26
|
+
exports: string[];
|
|
27
|
+
}, {
|
|
28
|
+
name: string;
|
|
29
|
+
dependencies: string[];
|
|
30
|
+
test: {
|
|
31
|
+
path: string;
|
|
32
|
+
content: string;
|
|
33
|
+
} | null;
|
|
34
|
+
source: {
|
|
35
|
+
path: string;
|
|
36
|
+
content: string;
|
|
37
|
+
};
|
|
38
|
+
changedIn: string;
|
|
39
|
+
exports: string[];
|
|
40
|
+
}>;
|
|
41
|
+
/** A component as the installed release ships it. */
|
|
42
|
+
export type RegistryEntry = s.InferOutput<typeof REGISTRY_ENTRY>;
|
|
43
|
+
/** The installed release's components, by name, and the release they belong to. */
|
|
44
|
+
export interface Registry {
|
|
45
|
+
release: string;
|
|
46
|
+
entries: Map<string, RegistryEntry>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The registry of the `@sdxc/kit` package at `packageRoot`, with the version its `package.json`
|
|
50
|
+
* declares. A package without `registry/ui` is a failure: the registry exists only in a
|
|
51
|
+
* published release.
|
|
52
|
+
*/
|
|
53
|
+
export declare function readRegistry(packageRoot: string): Promise<Result<Registry, Error>>;
|
|
54
|
+
/**
|
|
55
|
+
* `names` and every component they reach through other components, transitively, in the order
|
|
56
|
+
* first reached. A name the registry does not hold is skipped here; callers check names first.
|
|
57
|
+
*/
|
|
58
|
+
export declare function withDependencies(registry: Registry, names: readonly string[]): string[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component registry the installed `@sdxc/kit` carries in `registry/ui/`, written by its release
|
|
3
|
+
* build: every `@sdxc/ui` component with its source already importing `@sdxc/ui/*`. Reading it from
|
|
4
|
+
* the package itself keeps each copy matched to the helpers installed beside it.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import * as s from "@sdxc/json-schema";
|
|
12
|
+
import * as checks from "@sdxc/json-schema/checks";
|
|
13
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
14
|
+
/** Where the registry sits inside the `@sdxc/kit` package. */
|
|
15
|
+
export const REGISTRY_DIR = "registry/ui";
|
|
16
|
+
/** A file the registry ships, named as its copy is named in the app: one path segment. */
|
|
17
|
+
const REGISTRY_FILE = s.object({
|
|
18
|
+
path: s.string().pipe(checks.pattern(/^[a-z0-9][a-z0-9-]*(?:\.test)?\.tsx?$/)),
|
|
19
|
+
content: s.string(),
|
|
20
|
+
});
|
|
21
|
+
/** One `registry/ui/<name>.json`. */
|
|
22
|
+
export const REGISTRY_ENTRY = s.object({
|
|
23
|
+
name: s.string().pipe(checks.pattern(/^[a-z0-9][a-z0-9-]*$/)),
|
|
24
|
+
changedIn: s.string(),
|
|
25
|
+
dependencies: s.array(s.string()),
|
|
26
|
+
exports: s.array(s.string()),
|
|
27
|
+
source: REGISTRY_FILE,
|
|
28
|
+
test: s.nullable(REGISTRY_FILE),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* The registry of the `@sdxc/kit` package at `packageRoot`, with the version its `package.json`
|
|
32
|
+
* declares. A package without `registry/ui` is a failure: the registry exists only in a
|
|
33
|
+
* published release.
|
|
34
|
+
*/
|
|
35
|
+
export async function readRegistry(packageRoot) {
|
|
36
|
+
let manifest = await wrap(async () => JSON.parse(await readFile(join(packageRoot, "package.json"), "utf8")));
|
|
37
|
+
if (isFailure(manifest))
|
|
38
|
+
return manifest;
|
|
39
|
+
let release = manifest.data.version;
|
|
40
|
+
if (typeof release !== "string") {
|
|
41
|
+
return failure(new Error(`${join(packageRoot, "package.json")} declares no version`));
|
|
42
|
+
}
|
|
43
|
+
let dir = join(packageRoot, REGISTRY_DIR);
|
|
44
|
+
let files = await wrap(() => readdir(dir));
|
|
45
|
+
if (isFailure(files)) {
|
|
46
|
+
return failure(new Error(`This @sdxc/kit has no component registry at ${dir}; sdxc ui reads it from a published @sdxc/kit release`));
|
|
47
|
+
}
|
|
48
|
+
let entries = new Map();
|
|
49
|
+
for (let file of files.data.filter((name) => name.endsWith(".json")).sort()) {
|
|
50
|
+
let text = await wrap(() => readFile(join(dir, file), "utf8"));
|
|
51
|
+
if (isFailure(text))
|
|
52
|
+
return text;
|
|
53
|
+
let value = wrap(() => JSON.parse(text.data));
|
|
54
|
+
if (isFailure(value))
|
|
55
|
+
return failure(new Error(`${REGISTRY_DIR}/${file}: not valid JSON`));
|
|
56
|
+
let entry = s.parseSafe(REGISTRY_ENTRY, value.data);
|
|
57
|
+
if (!entry.success || `${entry.value.name}.json` !== file) {
|
|
58
|
+
return failure(new Error(`${REGISTRY_DIR}/${file} is not a registry entry`));
|
|
59
|
+
}
|
|
60
|
+
entries.set(entry.value.name, entry.value);
|
|
61
|
+
}
|
|
62
|
+
return success({ release, entries });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `names` and every component they reach through other components, transitively, in the order
|
|
66
|
+
* first reached. A name the registry does not hold is skipped here; callers check names first.
|
|
67
|
+
*/
|
|
68
|
+
export function withDependencies(registry, names) {
|
|
69
|
+
let reached = [];
|
|
70
|
+
let pending = [...names];
|
|
71
|
+
while (pending.length > 0) {
|
|
72
|
+
let name = pending.shift() ?? "";
|
|
73
|
+
if (reached.includes(name))
|
|
74
|
+
continue;
|
|
75
|
+
let entry = registry.entries.get(name);
|
|
76
|
+
if (entry === undefined)
|
|
77
|
+
continue;
|
|
78
|
+
reached.push(name);
|
|
79
|
+
pending.push(...entry.dependencies);
|
|
80
|
+
}
|
|
81
|
+
return reached;
|
|
82
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `changelog.jsonl` every published `@sdxc/kit` carries: one entry per commit, package and
|
|
3
|
+
* release, written by the release build. `sdxc upgrade` reads it offline from the installed
|
|
4
|
+
* package, so the prompt describes exactly the releases that package was built from.
|
|
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
|
+
/** The file name at the root of the `@sdxc/kit` package. */
|
|
12
|
+
export declare const CHANGELOG_FILE = "changelog.jsonl";
|
|
13
|
+
/** One line of the changelog; unknown keys are ignored so a newer file still reads. */
|
|
14
|
+
declare const ENTRY_SCHEMA: s.Schema<{
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
release: string;
|
|
18
|
+
package: string;
|
|
19
|
+
breaking: boolean;
|
|
20
|
+
body: string;
|
|
21
|
+
}, {
|
|
22
|
+
type: string;
|
|
23
|
+
title: string;
|
|
24
|
+
release: string;
|
|
25
|
+
package: string;
|
|
26
|
+
breaking: boolean;
|
|
27
|
+
body: string;
|
|
28
|
+
}>;
|
|
29
|
+
/** One commit's note as it applies to one package in one release. */
|
|
30
|
+
export type ChangelogEntry = s.InferOutput<typeof ENTRY_SCHEMA>;
|
|
31
|
+
/**
|
|
32
|
+
* Every entry of the changelog in the `@sdxc/kit` package at `packageRoot`. A missing file, a line
|
|
33
|
+
* that is not JSON, or a line without the entry fields is a failure naming the file and line.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readChangelog(packageRoot: string): Promise<Result<ChangelogEntry[], Error>>;
|
|
36
|
+
/**
|
|
37
|
+
* The entries of a changelog's text. A line that is not JSON, or one without the entry fields,
|
|
38
|
+
* is a failure naming `source` and the line.
|
|
39
|
+
*
|
|
40
|
+
* @param source - Where the text came from, for messages
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseChangelog(text: string, source: string): Result<ChangelogEntry[], Error>;
|
|
43
|
+
/** The entries of releases after `from` up to and including `to`, in file order. */
|
|
44
|
+
export declare function entriesBetween(entries: readonly ChangelogEntry[], from: string, to: string): ChangelogEntry[];
|
|
45
|
+
/**
|
|
46
|
+
* The first day the changelog of release `version` covers in full, as a dated version: the
|
|
47
|
+
* same calendar day a year earlier. Releases before it kept only their breaking entries.
|
|
48
|
+
*/
|
|
49
|
+
export declare function fullHistoryStart(version: string): string;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `changelog.jsonl` every published `@sdxc/kit` carries: one entry per commit, package and
|
|
3
|
+
* release, written by the release build. `sdxc upgrade` reads it offline from the installed
|
|
4
|
+
* package, so the prompt describes exactly the releases that package was built from.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import * as s from "@sdxc/json-schema";
|
|
12
|
+
import * as JSONL from "@sdxc/jsonl";
|
|
13
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
14
|
+
import { compare } from "@sdxc/semver";
|
|
15
|
+
/** The file name at the root of the `@sdxc/kit` package. */
|
|
16
|
+
export const CHANGELOG_FILE = "changelog.jsonl";
|
|
17
|
+
/** One line of the changelog; unknown keys are ignored so a newer file still reads. */
|
|
18
|
+
const ENTRY_SCHEMA = s.object({
|
|
19
|
+
release: s.string(),
|
|
20
|
+
package: s.string(),
|
|
21
|
+
type: s.string(),
|
|
22
|
+
breaking: s.boolean(),
|
|
23
|
+
title: s.string(),
|
|
24
|
+
body: s.string(),
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Every entry of the changelog in the `@sdxc/kit` package at `packageRoot`. A missing file, a line
|
|
28
|
+
* that is not JSON, or a line without the entry fields is a failure naming the file and line.
|
|
29
|
+
*/
|
|
30
|
+
export async function readChangelog(packageRoot) {
|
|
31
|
+
let path = join(packageRoot, CHANGELOG_FILE);
|
|
32
|
+
let text = await wrap(() => readFile(path, "utf8"));
|
|
33
|
+
if (isFailure(text)) {
|
|
34
|
+
return failure(new Error(`This @sdxc/kit carries no ${CHANGELOG_FILE} (${path})`));
|
|
35
|
+
}
|
|
36
|
+
return parseChangelog(text.data, path);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The entries of a changelog's text. A line that is not JSON, or one without the entry fields,
|
|
40
|
+
* is a failure naming `source` and the line.
|
|
41
|
+
*
|
|
42
|
+
* @param source - Where the text came from, for messages
|
|
43
|
+
*/
|
|
44
|
+
export function parseChangelog(text, source) {
|
|
45
|
+
let values = JSONL.parse(text);
|
|
46
|
+
if (isFailure(values))
|
|
47
|
+
return failure(new Error(`${source}: ${values.error.message}`));
|
|
48
|
+
let entries = [];
|
|
49
|
+
for (let [index, value] of values.data.entries()) {
|
|
50
|
+
let checked = s.parseSafe(ENTRY_SCHEMA, value);
|
|
51
|
+
if (!checked.success) {
|
|
52
|
+
return failure(new Error(`${source}: entry ${index + 1} is not a changelog entry`));
|
|
53
|
+
}
|
|
54
|
+
entries.push(checked.value);
|
|
55
|
+
}
|
|
56
|
+
return success(entries);
|
|
57
|
+
}
|
|
58
|
+
/** The entries of releases after `from` up to and including `to`, in file order. */
|
|
59
|
+
export function entriesBetween(entries, from, to) {
|
|
60
|
+
return entries.filter((entry) => compare(entry.release, from) > 0 && compare(entry.release, to) <= 0);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The first day the changelog of release `version` covers in full, as a dated version: the
|
|
64
|
+
* same calendar day a year earlier. Releases before it kept only their breaking entries.
|
|
65
|
+
*/
|
|
66
|
+
export function fullHistoryStart(version) {
|
|
67
|
+
let [year = 0, month = 1, day = 1] = version.split(".").map(Number);
|
|
68
|
+
return `${year - 1}.${month}.${day}`;
|
|
69
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `sdxc upgrade` reads from and changes in the project: the release its `@sdxc/*` pins are
|
|
3
|
+
* on, the dependency pins in `package.json`, and the files that import an `@sdxc/*` package.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import type { Result } from "@sdxc/result";
|
|
9
|
+
import * as s from "@sdxc/json-schema";
|
|
10
|
+
/** The fields of `package.json` the upgrade reads. */
|
|
11
|
+
declare const MANIFEST_SCHEMA: s.Schema<{
|
|
12
|
+
dependencies?: Record<string, string> | undefined;
|
|
13
|
+
devDependencies?: Record<string, string> | undefined;
|
|
14
|
+
packageManager?: string | undefined;
|
|
15
|
+
scripts?: Record<string, string> | undefined;
|
|
16
|
+
optionalDependencies?: Record<string, string> | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
dependencies?: Record<string, string> | undefined;
|
|
19
|
+
devDependencies?: Record<string, string> | undefined;
|
|
20
|
+
packageManager?: string | undefined;
|
|
21
|
+
scripts?: Record<string, string> | undefined;
|
|
22
|
+
optionalDependencies?: Record<string, string> | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
/** The project's `package.json` fields the upgrade reads. */
|
|
25
|
+
export type Manifest = s.InferOutput<typeof MANIFEST_SCHEMA>;
|
|
26
|
+
/** One dependency pin `bumpManifest` changed. */
|
|
27
|
+
export interface Bump {
|
|
28
|
+
name: string;
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
}
|
|
32
|
+
/** The project's `package.json`, as written and as parsed. */
|
|
33
|
+
export declare function readManifest(root: string): Promise<Result<{
|
|
34
|
+
text: string;
|
|
35
|
+
manifest: Manifest;
|
|
36
|
+
}, Error>>;
|
|
37
|
+
/**
|
|
38
|
+
* The release the project is on: the newest date among the exact `@sdxc/*` pins its dependency
|
|
39
|
+
* sections list, or `null` when it pins none.
|
|
40
|
+
*/
|
|
41
|
+
export declare function currentRelease(manifest: Manifest): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* `text` with each named dependency's pin set to its version, in every dependency section that
|
|
44
|
+
* lists it, and every other byte kept, so the diff is exactly the bumped lines.
|
|
45
|
+
*
|
|
46
|
+
* @param versions - The exact versions to pin, by package name.
|
|
47
|
+
*/
|
|
48
|
+
export declare function bumpManifest(text: string, versions: Record<string, string>): {
|
|
49
|
+
text: string;
|
|
50
|
+
bumps: Bump[];
|
|
51
|
+
};
|
|
52
|
+
/** Whether a dependency section of the manifest lists `name`. */
|
|
53
|
+
export declare function lists(manifest: Manifest, name: string): boolean;
|
|
54
|
+
/** Every `@sdxc/*` package the manifest lists, which the upgrade moves together. */
|
|
55
|
+
export declare function listedScopedPackages(manifest: Manifest): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Every `@sdxc/*` specifier the project's source files import, with the
|
|
58
|
+
* files (relative to `root`) that import it. Installed and generated folders and dot-folders
|
|
59
|
+
* are skipped; a file the scanner cannot read is skipped too.
|
|
60
|
+
*/
|
|
61
|
+
export declare function projectImports(root: string): Promise<Map<string, string[]>>;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `sdxc upgrade` reads from and changes in the project: the release its `@sdxc/*` pins are
|
|
3
|
+
* on, the dependency pins in `package.json`, and the files that import an `@sdxc/*` package.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
9
|
+
import { join, relative } from "node:path";
|
|
10
|
+
import { findModuleReferences } from "@sdxc/codemod";
|
|
11
|
+
import * as s from "@sdxc/json-schema";
|
|
12
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
13
|
+
import { projectRelease, scopedPackageOf } from "../releases.js";
|
|
14
|
+
/** The `package.json` sections a project's installed versions come from. */
|
|
15
|
+
const DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
16
|
+
/** Files whose imports the upgrade reads. */
|
|
17
|
+
const SOURCE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
18
|
+
/** Folders that hold installed or generated code, which the project's own imports never live in. */
|
|
19
|
+
const SKIPPED_FOLDERS = new Set(["node_modules", "dist", "build", "coverage"]);
|
|
20
|
+
/** The fields of `package.json` the upgrade reads. */
|
|
21
|
+
const MANIFEST_SCHEMA = s.object({
|
|
22
|
+
packageManager: s.optional(s.string()),
|
|
23
|
+
scripts: s.optional(s.record(s.string(), s.string())),
|
|
24
|
+
dependencies: s.optional(s.record(s.string(), s.string())),
|
|
25
|
+
devDependencies: s.optional(s.record(s.string(), s.string())),
|
|
26
|
+
optionalDependencies: s.optional(s.record(s.string(), s.string())),
|
|
27
|
+
});
|
|
28
|
+
/** The project's `package.json`, as written and as parsed. */
|
|
29
|
+
export async function readManifest(root) {
|
|
30
|
+
let text = await wrap(() => readFile(join(root, "package.json"), "utf8"));
|
|
31
|
+
if (isFailure(text))
|
|
32
|
+
return text;
|
|
33
|
+
let parsed = wrap(() => JSON.parse(text.data));
|
|
34
|
+
if (isFailure(parsed))
|
|
35
|
+
return failure(new Error(`package.json: ${parsed.error.message}`));
|
|
36
|
+
let checked = s.parseSafe(MANIFEST_SCHEMA, parsed.data);
|
|
37
|
+
if (!checked.success)
|
|
38
|
+
return failure(new Error("package.json: a dependency field is malformed"));
|
|
39
|
+
return success({ text: text.data, manifest: checked.value });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The release the project is on: the newest date among the exact `@sdxc/*` pins its dependency
|
|
43
|
+
* sections list, or `null` when it pins none.
|
|
44
|
+
*/
|
|
45
|
+
export function currentRelease(manifest) {
|
|
46
|
+
return projectRelease(DEPENDENCY_FIELDS.map((field) => manifest[field]));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `text` with each named dependency's pin set to its version, in every dependency section that
|
|
50
|
+
* lists it, and every other byte kept, so the diff is exactly the bumped lines.
|
|
51
|
+
*
|
|
52
|
+
* @param versions - The exact versions to pin, by package name.
|
|
53
|
+
*/
|
|
54
|
+
export function bumpManifest(text, versions) {
|
|
55
|
+
let bumps = [];
|
|
56
|
+
let output = text;
|
|
57
|
+
for (let field of DEPENDENCY_FIELDS) {
|
|
58
|
+
let header = new RegExp(`"${field}"\\s*:\\s*\\{`).exec(output);
|
|
59
|
+
if (header === null)
|
|
60
|
+
continue;
|
|
61
|
+
let start = header.index + header[0].length;
|
|
62
|
+
let end = output.indexOf("}", start);
|
|
63
|
+
if (end === -1)
|
|
64
|
+
continue;
|
|
65
|
+
let section = output.slice(start, end);
|
|
66
|
+
for (let [name, version] of Object.entries(versions)) {
|
|
67
|
+
let pin = new RegExp(`("${escapeRegExp(name)}"\\s*:\\s*")([^"]*)(")`);
|
|
68
|
+
section = section.replace(pin, (_, before, from, after) => {
|
|
69
|
+
if (from !== version)
|
|
70
|
+
bumps.push({ name, from, to: version });
|
|
71
|
+
return `${before}${version}${after}`;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
output = `${output.slice(0, start)}${section}${output.slice(end)}`;
|
|
75
|
+
}
|
|
76
|
+
return { text: output, bumps };
|
|
77
|
+
}
|
|
78
|
+
/** Whether a dependency section of the manifest lists `name`. */
|
|
79
|
+
export function lists(manifest, name) {
|
|
80
|
+
return DEPENDENCY_FIELDS.some((field) => manifest[field]?.[name] !== undefined);
|
|
81
|
+
}
|
|
82
|
+
/** Every `@sdxc/*` package the manifest lists, which the upgrade moves together. */
|
|
83
|
+
export function listedScopedPackages(manifest) {
|
|
84
|
+
let names = DEPENDENCY_FIELDS.flatMap((field) => Object.keys(manifest[field] ?? {}));
|
|
85
|
+
return [...new Set(names.filter((name) => name.startsWith("@sdxc/")))].sort();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Every `@sdxc/*` specifier the project's source files import, with the
|
|
89
|
+
* files (relative to `root`) that import it. Installed and generated folders and dot-folders
|
|
90
|
+
* are skipped; a file the scanner cannot read is skipped too.
|
|
91
|
+
*/
|
|
92
|
+
export async function projectImports(root) {
|
|
93
|
+
let imports = new Map();
|
|
94
|
+
for (let file of await sourceFiles(root)) {
|
|
95
|
+
let source = await wrap(() => readFile(file, "utf8"));
|
|
96
|
+
if (isFailure(source))
|
|
97
|
+
continue;
|
|
98
|
+
let references = findModuleReferences(file, source.data);
|
|
99
|
+
if (isFailure(references))
|
|
100
|
+
continue;
|
|
101
|
+
let path = relative(root, file);
|
|
102
|
+
for (let { specifier } of references.data) {
|
|
103
|
+
if (scopedPackageOf(specifier) === null)
|
|
104
|
+
continue;
|
|
105
|
+
let files = imports.get(specifier) ?? [];
|
|
106
|
+
if (!files.includes(path))
|
|
107
|
+
files.push(path);
|
|
108
|
+
imports.set(specifier, files);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return imports;
|
|
112
|
+
}
|
|
113
|
+
async function sourceFiles(directory) {
|
|
114
|
+
let entries = await wrap(() => readdir(directory, { withFileTypes: true }));
|
|
115
|
+
if (isFailure(entries))
|
|
116
|
+
return [];
|
|
117
|
+
let files = [];
|
|
118
|
+
for (let entry of entries.data) {
|
|
119
|
+
if (entry.name.startsWith(".") || SKIPPED_FOLDERS.has(entry.name))
|
|
120
|
+
continue;
|
|
121
|
+
let path = join(directory, entry.name);
|
|
122
|
+
if (entry.isDirectory())
|
|
123
|
+
files.push(...(await sourceFiles(path)));
|
|
124
|
+
else if (entry.isFile() && SOURCE_FILE.test(entry.name) && !entry.name.endsWith(".d.ts")) {
|
|
125
|
+
files.push(path);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return files.sort();
|
|
129
|
+
}
|
|
130
|
+
function escapeRegExp(text) {
|
|
131
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
132
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt `sdxc upgrade` hands an AI agent: the release notes of the packages the project
|
|
3
|
+
* imports, for every release it moved across, breaking changes first, with the components to
|
|
4
|
+
* refresh, the commands that verify the edit, and where each package is documented.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Result } from "@sdxc/result";
|
|
10
|
+
import type { ChangelogEntry } from "./changelog.js";
|
|
11
|
+
/** A vendored component whose source changed after the release it was copied from. */
|
|
12
|
+
export interface ChangedComponent {
|
|
13
|
+
name: string;
|
|
14
|
+
/** The release the lock file records for the copy. */
|
|
15
|
+
release: string;
|
|
16
|
+
/** The latest release whose commits touched the component. */
|
|
17
|
+
changedIn: string;
|
|
18
|
+
}
|
|
19
|
+
/** Everything the prompt says, already gathered from the project and the installed release. */
|
|
20
|
+
export interface PromptInput {
|
|
21
|
+
from: string;
|
|
22
|
+
to: string;
|
|
23
|
+
/** The whole changelog of the target release. */
|
|
24
|
+
entries: readonly ChangelogEntry[];
|
|
25
|
+
/** The npm names of the `@sdxc/*` packages the project imports. */
|
|
26
|
+
packages: readonly string[];
|
|
27
|
+
remix: {
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
} | null;
|
|
31
|
+
components: readonly ChangedComponent[];
|
|
32
|
+
/** Each verification command, ready to run. */
|
|
33
|
+
verify: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The prompt for moving from `input.from` to `input.to`, as Markdown. Only the imported
|
|
37
|
+
* packages' entries appear; notes typed docs, test, refactor, chore, style, ci or build state
|
|
38
|
+
* that a consumer has nothing to do, so they are left to the GitHub Releases.
|
|
39
|
+
*/
|
|
40
|
+
export declare function renderPrompt(input: PromptInput): string;
|
|
41
|
+
/**
|
|
42
|
+
* Gathers the prompt for the project at `root` from the `@sdxc/kit` at `packageRoot`, which is
|
|
43
|
+
* the target release: its version, its changelog, its component registry and its
|
|
44
|
+
* `remix` peer, compared with `remixFrom` when the bump changed `remix`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildPrompt(options: {
|
|
47
|
+
root: string;
|
|
48
|
+
packageRoot: string;
|
|
49
|
+
from: string;
|
|
50
|
+
remixFrom: string | null;
|
|
51
|
+
}): Promise<Result<string, Error>>;
|