@zuke-build/cli 0.0.0-stage → 2.6.0

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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -2
  3. package/mod.d.ts +99 -0
  4. package/mod.js +893 -0
  5. package/package.json +35 -4
  6. package/src/binary_launcher.d.ts +49 -0
  7. package/src/binary_launcher.js +327 -0
  8. package/src/binary_pin.d.ts +47 -0
  9. package/src/binary_pin.js +117 -0
  10. package/src/build_file.d.ts +25 -0
  11. package/src/build_file.js +65 -0
  12. package/src/cache.d.ts +23 -0
  13. package/src/cache.js +26 -0
  14. package/src/deno_isolated.d.ts +14 -0
  15. package/src/deno_isolated.js +70 -0
  16. package/src/deno_path.d.ts +115 -0
  17. package/src/deno_path.js +205 -0
  18. package/src/deno_pin.d.ts +37 -0
  19. package/src/deno_pin.js +32 -0
  20. package/src/dependencies.d.ts +48 -0
  21. package/src/dependencies.js +80 -0
  22. package/src/dispatch.d.ts +220 -0
  23. package/src/dispatch.js +538 -0
  24. package/src/embedded_engine.d.ts +28 -0
  25. package/src/embedded_engine.js +21 -0
  26. package/src/engine_pin.d.ts +56 -0
  27. package/src/engine_pin.js +196 -0
  28. package/src/fs.d.ts +14 -0
  29. package/src/fs.js +25 -0
  30. package/src/import.d.ts +132 -0
  31. package/src/import.js +289 -0
  32. package/src/install_source.d.ts +79 -0
  33. package/src/install_source.js +104 -0
  34. package/src/launcher.d.ts +37 -0
  35. package/src/launcher.js +464 -0
  36. package/src/mcp_config.d.ts +63 -0
  37. package/src/mcp_config.js +86 -0
  38. package/src/output.d.ts +38 -0
  39. package/src/output.js +43 -0
  40. package/src/paint.d.ts +42 -0
  41. package/src/paint.js +38 -0
  42. package/src/project.d.ts +69 -0
  43. package/src/project.js +132 -0
  44. package/src/pyproject.d.ts +30 -0
  45. package/src/pyproject.js +156 -0
  46. package/src/python_build.d.ts +27 -0
  47. package/src/python_build.js +197 -0
  48. package/src/records.d.ts +9 -0
  49. package/src/records.js +13 -0
  50. package/src/relock.d.ts +11 -0
  51. package/src/relock.js +182 -0
  52. package/src/setup.d.ts +251 -0
  53. package/src/setup.js +601 -0
  54. package/src/star.d.ts +44 -0
  55. package/src/star.js +100 -0
  56. package/src/starter.d.ts +55 -0
  57. package/src/starter.js +126 -0
  58. package/src/toml.d.ts +32 -0
  59. package/src/toml.js +354 -0
  60. package/src/translate.d.ts +69 -0
  61. package/src/translate.js +198 -0
  62. package/src/upgrade.d.ts +113 -0
  63. package/src/upgrade.js +344 -0
  64. package/src/version.d.ts +11 -0
  65. package/src/version.js +13 -0
  66. package/src/version_report.d.ts +55 -0
  67. package/src/version_report.js +187 -0
  68. package/zuke.js +8 -0
package/src/setup.d.ts ADDED
@@ -0,0 +1,251 @@
1
+ import { isRecord } from "./records.ts";
2
+ import type { BinaryPin } from "./binary_pin.ts";
3
+ export { isRecord };
4
+ /**
5
+ * The import map entries a scaffolded build needs, keyed by bare specifier.
6
+ *
7
+ * The scaffolded `zuke.ts` imports `@zuke/core` (and `zuke import`'s output
8
+ * `@zuke/cmd`) by bare specifier, so `deno.json` has to map each one to its
9
+ * `jsr:` dependency — see {@link "./starter.ts".STARTER_IMPORTS} for why the
10
+ * specifier does not go in the source file.
11
+ */
12
+ export type ScaffoldImports = Readonly<Record<string, string>>;
13
+ /**
14
+ * Whether a `deno.json` document delegates its import map to a separate file
15
+ * and would be broken by growing an `imports` block.
16
+ *
17
+ * Deno ignores the `importMap` field the moment `imports` or `scopes` appears
18
+ * in the config, so writing `imports` beside a lone `importMap` silently
19
+ * disables the project's entire module resolution. A document that already has
20
+ * `imports` or `scopes` is not delegating — Deno is ignoring `importMap` there
21
+ * already — so merging into it changes nothing.
22
+ */
23
+ export declare function delegatesImportMap(root: Record<string, unknown>): boolean;
24
+ /**
25
+ * Merge the default Zuke tasks and `imports` into a `deno.json` document,
26
+ * preserving the existing content. `existing` is the file text, or `null` to
27
+ * start fresh; `imports` are the bare-specifier mappings the scaffolded build
28
+ * resolves through, and `buildFile` is the file the `zuke` task runs.
29
+ *
30
+ * Merging is additive per key: a task or import the document already declares
31
+ * is left exactly as it is (but for a `zuke` task setup wrote for another
32
+ * build file, which follows the build file), so a project that has pinned `@zuke/core` to a
33
+ * specific version keeps that pin. A document that delegates to an external
34
+ * `importMap` keeps that delegation and grows no `imports` block — see
35
+ * {@link delegatesImportMap}; the caller reports the entry as a manual step
36
+ * instead.
37
+ */
38
+ export declare function mergeDenoJson(existing: string | null, imports: ScaffoldImports, buildFile: string): string;
39
+ /**
40
+ * Whether a `deno.json` text already carries everything the scaffold needs.
41
+ *
42
+ * `"present"` means both the `zuke` task, for this build file, and every
43
+ * scaffold import are already declared, so there is nothing to merge.
44
+ */
45
+ export type DenoJsonState = "present" | "absent" | "unparseable";
46
+ /**
47
+ * Classify a `deno.json` text by whether the scaffold has anything to add to
48
+ * it: the `zuke` task, or any of `imports`.
49
+ *
50
+ * The imports are part of the question because the build file is written by the
51
+ * same run and imports them by bare specifier. Treating the `zuke` task alone
52
+ * as "already set up" — as this did before the imports existed — would skip the
53
+ * file on a project being re-scaffolded and leave a `zuke.ts` whose specifiers
54
+ * nothing resolves.
55
+ */
56
+ export declare function denoJsonState(text: string, imports: ScaffoldImports, buildFile: string): DenoJsonState;
57
+ /**
58
+ * The scaffold specifiers `root` maps somewhere other than their `jsr:@zuke/…`
59
+ * dependency, in declaration order.
60
+ *
61
+ * Keeping a mapping the project already declared is the right default — it is
62
+ * how a deliberate version pin, or a link to a local checkout, survives. But
63
+ * the run should not go on to report the dependency as simply "present", so the
64
+ * caller names what it found and leaves the decision to the reader.
65
+ */
66
+ export declare function remappedImports(root: Record<string, unknown>, imports: ScaffoldImports): string[];
67
+ /** Injected side effects, so {@link runSetup} is unit-testable. */
68
+ export interface SetupHost {
69
+ /** Whether a path exists. */
70
+ exists(path: string): Promise<boolean>;
71
+ /** Whether a path exists and is a directory (a reserved-name collision). */
72
+ isDirectory(path: string): Promise<boolean>;
73
+ /**
74
+ * Whether a path is a symbolic link, without following it. Scaffolding
75
+ * refuses to write through one: the writes below follow links, so a link
76
+ * planted at a scaffold name by the very repository being set up would
77
+ * redirect them outside the target directory.
78
+ *
79
+ * The guard covers the names scaffolding chooses, which is where the hazard
80
+ * is — the caller never asked for `.gitignore` to be written, so a repository
81
+ * redirecting it is a decision nobody made. It reports what is there when it
82
+ * runs, and a link planted after it would escape it; that is why
83
+ * {@link SetupHost.writeText} does not write through a link either, so the
84
+ * refusal is the friendly answer rather than the only defence.
85
+ *
86
+ * Two things stay out of scope. The directory the caller names with `--dir`
87
+ * is the caller's to name, symlink or not. And a **hard** link is
88
+ * indistinguishable from the file it shares, so no probe can see one; git
89
+ * cannot check one out either, which is what keeps it out of the threat this
90
+ * guards.
91
+ */
92
+ isSymlink(path: string): Promise<boolean>;
93
+ /** Read a file as UTF-8 text. */
94
+ readText(path: string): Promise<string>;
95
+ /**
96
+ * Whether stdout is an interactive terminal, which decides whether the
97
+ * CLI's own output is rich. Optional: an implementation without it is
98
+ * asked through Deno, the way every other process decides.
99
+ */
100
+ isTerminal?(): boolean;
101
+ /**
102
+ * Write UTF-8 text to a file, creating or replacing it.
103
+ *
104
+ * An implementation must not write *through* a symbolic link standing at
105
+ * `path`: the scaffolder's confinement to its target directory rests on this,
106
+ * and the pre-write {@link SetupHost.isSymlink} check alone cannot carry it,
107
+ * since a link can appear after the check.
108
+ */
109
+ writeText(path: string, content: string): Promise<void>;
110
+ /** Set a file's permission bits (may be unsupported on some platforms). */
111
+ chmod(path: string, mode: number): Promise<void>;
112
+ /** Emit a line of progress output. */
113
+ log(message: string): void;
114
+ }
115
+ /**
116
+ * The real, `Deno`-backed {@link SetupHost}. Every probe reads the link itself
117
+ * rather than its target (see {@link lstatOrNull}), so a symlink is reported
118
+ * as a symlink instead of as whatever it points at.
119
+ */
120
+ export declare const defaultHost: SetupHost;
121
+ /** Options controlling {@link runSetup}. */
122
+ export interface SetupOptions {
123
+ /** Directory to scaffold into (e.g. `"."`). */
124
+ dir: string;
125
+ /** Overwrite existing files instead of skipping them. */
126
+ force: boolean;
127
+ /** Build class name for the starter build file. */
128
+ name: string;
129
+ /**
130
+ * The TypeScript build file's name (`--build-file`). Omitted: the name the
131
+ * project already has (see {@link existingBuildFile}), or `build.ts` for a
132
+ * new one. Not for {@link SetupOptions.sdk}, whose build is `build.py`.
133
+ */
134
+ buildFile?: string;
135
+ /**
136
+ * The base name for the launcher scripts (`<name>` and `<name>.ps1`).
137
+ * Defaults to `"zuke"`; override it when a `zuke/` directory already occupies
138
+ * that name in the target directory.
139
+ */
140
+ launcherName?: string;
141
+ /**
142
+ * The build file's contents: the `zuke.ts`, or with {@link SetupOptions.sdk}
143
+ * the `build.py`. Defaults to {@link starterBuild} (or
144
+ * {@link starterPythonBuild}); `zuke import` passes a build generated from
145
+ * an existing project's tasks instead.
146
+ */
147
+ buildContent?: string;
148
+ /**
149
+ * The bare specifiers {@link SetupOptions.buildContent} imports, mapped to
150
+ * their `jsr:` dependencies, merged into `deno.json` so they resolve.
151
+ * Defaults to {@link STARTER_IMPORTS}; a caller that supplies its own
152
+ * `buildContent` supplies the imports that build needs (`zuke import` adds
153
+ * `@zuke/cmd` when it generates a command).
154
+ */
155
+ imports?: ScaffoldImports;
156
+ /**
157
+ * Scaffold launchers that bootstrap their runtime when it is missing (the
158
+ * default), or plain ones that require it on `PATH` and fail closed
159
+ * (`false`). The runtime is a pinned, checksum-verified Deno for a
160
+ * TypeScript build (see {@link "./launcher.ts"}), and the pinned `zuke`
161
+ * release for one another SDK hosts (see {@link "./binary_launcher.ts"}).
162
+ */
163
+ bootstrapDeno?: boolean;
164
+ /**
165
+ * Also write an `.mcp.json` registering the build's MCP server (`--mcp`), so
166
+ * an agent client picks the build up from the first commit. `allowRun`
167
+ * adds `--allow-run`, letting the agent execute targets rather than only
168
+ * inspect them. Omitted: no file is written.
169
+ */
170
+ mcp?: McpSetupOptions;
171
+ /**
172
+ * Scaffold a build the Python SDK describes and `@zuke/engine` runs
173
+ * (`--sdk python`): a starter `build.py` in place of `zuke.ts`, a
174
+ * `zuke.json` naming `sdk.command` and the engine release, and no
175
+ * `deno.json`, since the project has no Deno code of its own. Its
176
+ * launchers run the pinned `zuke` binary, which carries that engine, so
177
+ * nothing in the project needs Deno. Omitted: a TypeScript build.
178
+ */
179
+ sdk?: SdkSetupOptions;
180
+ }
181
+ /** What `--sdk python` scaffolds against. */
182
+ export interface SdkSetupOptions {
183
+ /**
184
+ * The `zuke` release the launchers run; `zuke.json` pins the engine it
185
+ * carries.
186
+ */
187
+ pin: BinaryPin;
188
+ }
189
+ /** What `--mcp` writes into `.mcp.json`. */
190
+ export interface McpSetupOptions {
191
+ /** Register the server with `--allow-run`, so the agent may run targets. */
192
+ allowRun: boolean;
193
+ }
194
+ /** What happened to one scaffolded file. */
195
+ export type FileStatus = "created" | "overwritten" | "skipped";
196
+ /** The outcome for a single file. */
197
+ export interface FileResult {
198
+ /** The file's name, relative to the setup directory. */
199
+ path: string;
200
+ /** What `setup` did with it. */
201
+ status: FileStatus;
202
+ }
203
+ /** The result of a {@link runSetup} run. */
204
+ export interface SetupResult {
205
+ /** One entry per file `setup` considered. */
206
+ files: FileResult[];
207
+ /**
208
+ * What `setup` could not do, each line naming the problem and the fix.
209
+ *
210
+ * Non-empty means the scaffold is **incomplete**: the `zuke.ts` on disk
211
+ * imports `@zuke/core` by bare specifier, and nothing resolves it until the
212
+ * reader acts. The caller reports these and exits non-zero rather than
213
+ * printing `Next: ./zuke` over a build that cannot start.
214
+ */
215
+ manualSteps: string[];
216
+ /**
217
+ * Advisory observations about the existing project that `setup` deliberately
218
+ * left alone. Worth printing, but nothing is broken and the exit code stays
219
+ * 0.
220
+ */
221
+ notes: string[];
222
+ }
223
+ /** Join a directory and file name without pulling in path utilities. */
224
+ export declare function joinPath(dir: string, name: string): string;
225
+ /** The default launcher base name. */
226
+ export declare const DEFAULT_LAUNCHER = "zuke";
227
+ /**
228
+ * The build file the TypeScript project in `dir` already has: the one its
229
+ * `zuke.json` names, `zuke.ts` when it names none, and `zuke.ts` too for a
230
+ * directory that holds one with no `zuke.json` yet. `undefined` for a
231
+ * directory with neither, which is a new project. A `zuke.json` that is a
232
+ * link is not read: scaffolding refuses it.
233
+ *
234
+ * @throws {Error} when `zuke.json` names a build file that is not a valid name.
235
+ */
236
+ export declare function existingBuildFile(dir: string, host: SetupHost): Promise<string | undefined>;
237
+ /**
238
+ * Whether `name` in `dir` is a file of the project's own that is not a Zuke
239
+ * build: it exists and does not import `@zuke/core`. A new project must not
240
+ * take such a name, because its `zuke.json` would point at an unrelated
241
+ * script, and `--force` would overwrite it.
242
+ */
243
+ export declare function unrelatedBuildFile(dir: string, name: string, host: SetupHost): Promise<boolean>;
244
+ /**
245
+ * Scaffold Zuke into `options.dir`: a starter build file, the launcher scripts,
246
+ * and a `deno.json` task block. Existing files are skipped unless
247
+ * `options.force` is set; `deno.json` is always merged (never clobbered). Fails
248
+ * up front if a target name is occupied by a directory (see
249
+ * {@link SetupOptions.launcherName}).
250
+ */
251
+ export declare function runSetup(options: SetupOptions, host?: SetupHost): Promise<SetupResult>;