@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.
Files changed (144) hide show
  1. package/README.md +2 -92
  2. package/package.json +5 -44
  3. package/LICENSE.md +0 -21
  4. package/config.schema.json +0 -89
  5. package/dist/bin.d.ts +0 -9
  6. package/dist/bin.js +0 -10
  7. package/dist/cli.d.ts +0 -33
  8. package/dist/cli.js +0 -58
  9. package/dist/commands/create.d.ts +0 -20
  10. package/dist/commands/create.js +0 -164
  11. package/dist/commands/init.d.ts +0 -16
  12. package/dist/commands/init.js +0 -27
  13. package/dist/commands/make.d.ts +0 -335
  14. package/dist/commands/make.js +0 -152
  15. package/dist/commands/run.d.ts +0 -23
  16. package/dist/commands/run.js +0 -51
  17. package/dist/commands/ui/add.d.ts +0 -23
  18. package/dist/commands/ui/add.js +0 -50
  19. package/dist/commands/ui/diff.d.ts +0 -20
  20. package/dist/commands/ui/diff.js +0 -28
  21. package/dist/commands/ui/list.d.ts +0 -24
  22. package/dist/commands/ui/list.js +0 -45
  23. package/dist/commands/ui/remove.d.ts +0 -22
  24. package/dist/commands/ui/remove.js +0 -48
  25. package/dist/commands/ui/update.d.ts +0 -23
  26. package/dist/commands/ui/update.js +0 -37
  27. package/dist/commands/upgrade.d.ts +0 -30
  28. package/dist/commands/upgrade.js +0 -184
  29. package/dist/config.d.ts +0 -81
  30. package/dist/config.js +0 -157
  31. package/dist/contract.d.ts +0 -161
  32. package/dist/contract.js +0 -308
  33. package/dist/create/github.d.ts +0 -63
  34. package/dist/create/github.js +0 -172
  35. package/dist/create/target.d.ts +0 -31
  36. package/dist/create/target.js +0 -56
  37. package/dist/create/templates.d.ts +0 -62
  38. package/dist/create/templates.js +0 -228
  39. package/dist/dependencies.d.ts +0 -34
  40. package/dist/dependencies.js +0 -76
  41. package/dist/diff.d.ts +0 -14
  42. package/dist/diff.js +0 -103
  43. package/dist/format.d.ts +0 -21
  44. package/dist/format.js +0 -40
  45. package/dist/init.d.ts +0 -38
  46. package/dist/init.js +0 -92
  47. package/dist/lock.d.ts +0 -74
  48. package/dist/lock.js +0 -214
  49. package/dist/make/declare.d.ts +0 -54
  50. package/dist/make/declare.js +0 -495
  51. package/dist/make/generate.d.ts +0 -56
  52. package/dist/make/generate.js +0 -139
  53. package/dist/make/imports.d.ts +0 -43
  54. package/dist/make/imports.js +0 -104
  55. package/dist/make/index.d.ts +0 -43
  56. package/dist/make/index.js +0 -136
  57. package/dist/make/kinds.d.ts +0 -39
  58. package/dist/make/kinds.js +0 -95
  59. package/dist/make/migrations.d.ts +0 -21
  60. package/dist/make/migrations.js +0 -48
  61. package/dist/make/names.d.ts +0 -31
  62. package/dist/make/names.js +0 -47
  63. package/dist/make/stubs.d.ts +0 -44
  64. package/dist/make/stubs.js +0 -89
  65. package/dist/middleware.d.ts +0 -44
  66. package/dist/middleware.js +0 -49
  67. package/dist/package-manager.d.ts +0 -41
  68. package/dist/package-manager.js +0 -80
  69. package/dist/project.d.ts +0 -19
  70. package/dist/project.js +0 -42
  71. package/dist/releases.d.ts +0 -40
  72. package/dist/releases.js +0 -110
  73. package/dist/testing.d.ts +0 -47
  74. package/dist/testing.js +0 -126
  75. package/dist/ui/commands.d.ts +0 -114
  76. package/dist/ui/commands.js +0 -432
  77. package/dist/ui/imports.d.ts +0 -46
  78. package/dist/ui/imports.js +0 -160
  79. package/dist/ui/layout.d.ts +0 -48
  80. package/dist/ui/layout.js +0 -138
  81. package/dist/ui/registry.d.ts +0 -58
  82. package/dist/ui/registry.js +0 -82
  83. package/dist/upgrade/changelog.d.ts +0 -50
  84. package/dist/upgrade/changelog.js +0 -69
  85. package/dist/upgrade/project.d.ts +0 -62
  86. package/dist/upgrade/project.js +0 -132
  87. package/dist/upgrade/prompt.d.ts +0 -51
  88. package/dist/upgrade/prompt.js +0 -227
  89. package/dist/upgrade/registry.d.ts +0 -33
  90. package/dist/upgrade/registry.js +0 -50
  91. package/lock.schema.json +0 -60
  92. package/stubs/command.stub +0 -12
  93. package/stubs/command.test.stub +0 -18
  94. package/stubs/controller.form.stub +0 -33
  95. package/stubs/controller.stub +0 -17
  96. package/stubs/controller.test.stub +0 -15
  97. package/stubs/email.stub +0 -44
  98. package/stubs/email.test.stub +0 -16
  99. package/stubs/factory.stub +0 -10
  100. package/stubs/initializer.stub +0 -7
  101. package/stubs/initializer.test.stub +0 -13
  102. package/stubs/job.cron.stub +0 -12
  103. package/stubs/job.stub +0 -11
  104. package/stubs/job.test.stub +0 -15
  105. package/stubs/mcp.resource.stub +0 -12
  106. package/stubs/mcp.stub +0 -10
  107. package/stubs/mcp.test.stub +0 -15
  108. package/stubs/middleware.stub +0 -11
  109. package/stubs/middleware.test.stub +0 -13
  110. package/stubs/migration.stub +0 -1
  111. package/stubs/model.stub +0 -24
  112. package/stubs/model.test.stub +0 -15
  113. package/stubs/policy.stub +0 -13
  114. package/stubs/policy.test.stub +0 -17
  115. package/stubs/service.stub +0 -13
  116. package/stubs/service.test.stub +0 -14
  117. package/stubs/validator.stub +0 -14
  118. package/stubs/validator.test.stub +0 -22
  119. package/templates/app/README.md +0 -57
  120. package/templates/app/app/commands/about.test.ts +0 -29
  121. package/templates/app/app/commands/about.ts +0 -34
  122. package/templates/app/app/commands/index.ts +0 -15
  123. package/templates/app/app/http/controllers/home.tsx +0 -22
  124. package/templates/app/app/http/controllers/not-found.tsx +0 -25
  125. package/templates/app/app/initializers/assets.ts +0 -11
  126. package/templates/app/app/initializers/cli.ts +0 -35
  127. package/templates/app/app/initializers/dispatcher.ts +0 -18
  128. package/templates/app/app/initializers/logger.ts +0 -10
  129. package/templates/app/app/initializers/mcp.ts +0 -16
  130. package/templates/app/app/initializers/router.tsx +0 -65
  131. package/templates/app/app/jobs/index.ts +0 -10
  132. package/templates/app/app/mcp/resources/index.ts +0 -9
  133. package/templates/app/app/mcp/tools/index.ts +0 -10
  134. package/templates/app/bootstrap/browser.ts +0 -27
  135. package/templates/app/bootstrap/cli.ts +0 -9
  136. package/templates/app/bootstrap/worker.ts +0 -31
  137. package/templates/app/cloudflare.config.ts +0 -28
  138. package/templates/app/config/router-context.d.ts +0 -20
  139. package/templates/app/gitignore +0 -9
  140. package/templates/app/package.json +0 -38
  141. package/templates/app/resources/layouts/document.tsx +0 -58
  142. package/templates/app/routes/web.ts +0 -12
  143. package/templates/app/tsconfig.json +0 -40
  144. package/templates/app/vite.config.ts +0 -40
package/dist/ui/layout.js DELETED
@@ -1,138 +0,0 @@
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
- }
@@ -1,58 +0,0 @@
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[];
@@ -1,82 +0,0 @@
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
- }
@@ -1,50 +0,0 @@
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 {};
@@ -1,69 +0,0 @@
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
- }
@@ -1,62 +0,0 @@
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 {};
@@ -1,132 +0,0 @@
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
- }
@@ -1,51 +0,0 @@
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>>;