codemod 2.0.0-alpha.2 → 2.0.0-alpha.4
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 +1 -2
- package/package.json +14 -16
- package/register.d.mts +2 -11
- package/register.mjs +53 -46
- package/runtime/addon.d.mts +119 -0
- package/runtime/addon.mjs +36 -40
- package/runtime/ast-grep.d.mts +20 -0
- package/runtime/ast-grep.mjs +50 -61
- package/runtime/context.d.mts +25 -0
- package/runtime/context.mjs +10 -64
- package/runtime/hooks.d.mts +2 -0
- package/runtime/hooks.mjs +4 -6
- package/runtime/host.d.mts +81 -81
- package/runtime/host.mjs +428 -326
- package/runtime/llm.d.mts +2 -0
- package/runtime/llm.mjs +1 -7
- package/runtime/modules.d.mts +3 -0
- package/runtime/modules.mjs +7 -10
- package/runtime/orchestrator-version.d.mts +2 -0
- package/runtime/orchestrator-version.mjs +3 -0
- package/runtime/orchestrator.d.mts +261 -0
- package/runtime/orchestrator.mjs +823 -608
- package/runtime/runtime.d.mts +15 -0
- package/runtime/runtime.mjs +18 -26
- package/runtime/workflow.d.mts +24 -0
- package/runtime/workflow.mjs +42 -121
- package/testing/index.d.mts +107 -155
- package/testing/index.mjs +552 -545
- package/types/index.d.ts +0 -1
- package/types/langs/package.json +3 -0
- package/types/modules/ast-grep.d.ts +22 -1
- package/types/modules/workflow.d.ts +386 -231
- package/vite.d.mts +4 -21
- package/vite.mjs +23 -17
- package/runtime/metrics.mjs +0 -45
- package/types/metrics.d.ts +0 -5
- package/types/modules/metrics.d.ts +0 -107
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function progress(message: string, meta?: unknown): void;
|
|
2
|
+
export declare function warn(message: string, meta?: unknown): void;
|
|
3
|
+
export declare function setCurrentUnit(_unitId: string, _meta?: unknown): void;
|
|
4
|
+
export declare function failFile(message: string, _meta?: unknown): never;
|
|
5
|
+
export declare function failStep(message: string, _meta?: unknown): never;
|
|
6
|
+
export declare function isCanceled(): boolean;
|
|
7
|
+
declare const runtime: {
|
|
8
|
+
progress: typeof progress;
|
|
9
|
+
warn: typeof warn;
|
|
10
|
+
setCurrentUnit: typeof setCurrentUnit;
|
|
11
|
+
failFile: typeof failFile;
|
|
12
|
+
failStep: typeof failStep;
|
|
13
|
+
isCanceled: typeof isCanceled;
|
|
14
|
+
};
|
|
15
|
+
export default runtime;
|
package/runtime/runtime.mjs
CHANGED
|
@@ -1,48 +1,40 @@
|
|
|
1
1
|
// `codemod/runtime` in Node.js and Bun. Progress and warnings become the
|
|
2
2
|
// step's log lines, written as the CLI writes them; failures throw, and stay
|
|
3
3
|
// reported even when the code catches the error.
|
|
4
|
-
|
|
5
4
|
import { context } from "./context.mjs";
|
|
6
|
-
|
|
7
5
|
function text(message, what) {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
if (typeof message !== "string")
|
|
7
|
+
throw new TypeError(`${what} expects a message string`);
|
|
8
|
+
return message;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
function log(prefix, message, meta) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const store = context.getStore();
|
|
12
|
+
if (!store)
|
|
13
|
+
return;
|
|
14
|
+
const line = meta === undefined ? message : `${message} ${JSON.stringify(meta)}`;
|
|
15
|
+
store.run.log(store.step?.position ?? null, `${prefix} ${line}`);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
export function progress(message, meta) {
|
|
20
|
-
|
|
18
|
+
log("[progress]", text(message, "progress()"), meta);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
export function warn(message, meta) {
|
|
24
|
-
|
|
21
|
+
log("[warn]", text(message, "warn()"), meta);
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
export function setCurrentUnit(_unitId, _meta) {}
|
|
28
|
-
|
|
23
|
+
export function setCurrentUnit(_unitId, _meta) { }
|
|
29
24
|
function fail(message, what) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
const step = context.getStore()?.step;
|
|
26
|
+
if (step)
|
|
27
|
+
step.failure = text(message, what);
|
|
28
|
+
throw new Error(text(message, what));
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
export function failFile(message, _meta) {
|
|
36
|
-
|
|
31
|
+
fail(message, "failFile()");
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
export function failStep(message, _meta) {
|
|
40
|
-
|
|
34
|
+
fail(message, "failStep()");
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
export function isCanceled() {
|
|
44
|
-
|
|
37
|
+
return context.getStore()?.run.canceled() ?? false;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
const runtime = { progress, warn, setCurrentUnit, failFile, failStep, isCanceled };
|
|
48
40
|
export default runtime;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Callback, Duration, Json } from "./orchestrator.mts";
|
|
2
|
+
export { AwaitingApprovalError, CanceledError, StepError } from "./orchestrator.mts";
|
|
3
|
+
/** Identifies a callback given as a function, for replay checks. */
|
|
4
|
+
export declare function callbackId(fn: Callback): string;
|
|
5
|
+
export declare const __callback: (id: string, captures: () => Json) => import("./orchestrator.mts").CallbackReference, forEachFile: (selector: unknown, callback?: unknown) => import("./orchestrator.mts").ForEachFileTask | import("./orchestrator.mts").HostTask, shell: (command: unknown, ...rest: unknown[]) => import("./orchestrator.mts").HostTask | ((strings: TemplateStringsArray, ...values: unknown[]) => import("./orchestrator.mts").HostTask), jssg: (path: string, options?: object) => import("./orchestrator.mts").HostTask, astGrep: (path: string, options?: object) => import("./orchestrator.mts").HostTask, shard: (options: object) => import("./orchestrator.mts").HostTask, codemod: (source: string, options?: object) => import("./orchestrator.mts").HostTask, agent: (prompt: string, options?: object) => import("./orchestrator.mts").HostTask, installSkill: (options: object) => import("./orchestrator.mts").HostTask, approval: (message: string) => import("./orchestrator.mts").HostTask, branch: (name: string) => import("./orchestrator.mts").HostTask, commit: (message: string, options?: object) => import("./orchestrator.mts").HostTask, pullRequest: (options: object) => import("./orchestrator.mts").HostTask;
|
|
6
|
+
export declare function step(...args: unknown[]): Promise<Json>;
|
|
7
|
+
export declare function sleep(duration: Duration): Promise<Json>;
|
|
8
|
+
export declare function waitForEvent(name: string, options?: {
|
|
9
|
+
timeout?: Duration;
|
|
10
|
+
}): Promise<Json>;
|
|
11
|
+
export declare function __evaluate(kind: string, expression: string, scope: unknown): unknown;
|
|
12
|
+
export declare function dependencyGraph(_options: unknown, _callback: unknown): never;
|
|
13
|
+
export declare const registry: Readonly<{
|
|
14
|
+
npm: (_name: string) => Promise<never>;
|
|
15
|
+
cargo: (_name: string) => Promise<never>;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const semver: Readonly<{
|
|
18
|
+
satisfies: () => never;
|
|
19
|
+
compare: () => never;
|
|
20
|
+
gt: () => never;
|
|
21
|
+
lt: () => never;
|
|
22
|
+
isBreaking: () => never;
|
|
23
|
+
isPrerelease: () => never;
|
|
24
|
+
}>;
|
package/runtime/workflow.mjs
CHANGED
|
@@ -1,135 +1,56 @@
|
|
|
1
1
|
// `codemod:workflow` in Node.js and Bun: the shared orchestrator, with the
|
|
2
2
|
// run looked up per call (see context.mjs).
|
|
3
3
|
//
|
|
4
|
-
// In the workflow body, `step
|
|
5
|
-
//
|
|
6
|
-
// functions see the state the step started with, and what they set becomes
|
|
7
|
-
// the step's state changes, as in the engine's isolates.
|
|
8
|
-
|
|
4
|
+
// In the workflow body, `step` goes to the run's orchestrator. Workflows have
|
|
5
|
+
// no state: a step gets values from the body and returns what it found.
|
|
9
6
|
import { createHash } from "node:crypto";
|
|
10
|
-
|
|
11
7
|
import { current } from "./context.mjs";
|
|
12
8
|
import { createTasks } from "./orchestrator.mjs";
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
AwaitingApprovalError,
|
|
16
|
-
CanceledError,
|
|
17
|
-
NondeterminismError,
|
|
18
|
-
StepError,
|
|
19
|
-
} from "./orchestrator.mjs";
|
|
20
|
-
|
|
9
|
+
export { AwaitingApprovalError, CanceledError, StepError } from "./orchestrator.mjs";
|
|
21
10
|
/** Identifies a callback given as a function, for replay checks. */
|
|
22
11
|
export function callbackId(fn) {
|
|
23
|
-
|
|
12
|
+
return `fn:${createHash("sha256").update(String(fn)).digest("hex").slice(0, 16)}`;
|
|
24
13
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
codemod,
|
|
34
|
-
agent,
|
|
35
|
-
installSkill,
|
|
36
|
-
approval,
|
|
37
|
-
branch,
|
|
38
|
-
commit,
|
|
39
|
-
pullRequest,
|
|
40
|
-
} = createTasks({ callbackId });
|
|
41
|
-
|
|
42
|
-
export function step(labelOrTask, maybeTask) {
|
|
43
|
-
const scope = current("step()");
|
|
44
|
-
if (scope.step) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
"step() cannot be called inside a step or forEachFile callback; start steps from the workflow body",
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return scope.runtime.step(labelOrTask, maybeTask);
|
|
14
|
+
export const { __callback, forEachFile, shell, jssg, astGrep, shard, codemod, agent, installSkill, approval, branch, commit, pullRequest, } = createTasks({ callbackId });
|
|
15
|
+
/** The run's orchestrator, for what only the workflow body may call. */
|
|
16
|
+
function body(what) {
|
|
17
|
+
const scope = current(what);
|
|
18
|
+
if (scope.step) {
|
|
19
|
+
throw new Error(`${what} cannot be called inside a step or forEachFile callback; call it from the workflow body`);
|
|
20
|
+
}
|
|
21
|
+
return scope.runtime;
|
|
50
22
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// isolates: values are copied in and out, and what the step leaves different
|
|
54
|
-
// from the state it started with becomes its state changes.
|
|
55
|
-
|
|
56
|
-
export function getState(key) {
|
|
57
|
-
const scope = current("getState()");
|
|
58
|
-
if (!scope.step) return scope.runtime.getState(key);
|
|
59
|
-
const state = scope.step.state;
|
|
60
|
-
if (key === undefined) return structuredClone(Object.fromEntries(state));
|
|
61
|
-
return state.has(key) ? structuredClone(state.get(key)) : undefined;
|
|
23
|
+
export function step(...args) {
|
|
24
|
+
return body("step()").step(...args);
|
|
62
25
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const scope = current("setState()");
|
|
66
|
-
if (!scope.step) return scope.runtime.setState(key, value);
|
|
67
|
-
const step = scope.step;
|
|
68
|
-
step.state.set(key, stateValue(value));
|
|
69
|
-
step.removed.delete(key);
|
|
70
|
-
if (persist) step.unpersisted.delete(key);
|
|
71
|
-
else step.unpersisted.add(key);
|
|
26
|
+
export function sleep(duration) {
|
|
27
|
+
return body("sleep()").sleep(duration);
|
|
72
28
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const scope = current("unsetState()");
|
|
76
|
-
if (!scope.step) return scope.runtime.unsetState(key);
|
|
77
|
-
scope.step.state.delete(key);
|
|
78
|
-
scope.step.removed.add(key);
|
|
29
|
+
export function waitForEvent(name, options) {
|
|
30
|
+
return body("waitForEvent()").waitForEvent(name, options);
|
|
79
31
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* A value as state keeps it, the way the engine's isolates convert one:
|
|
83
|
-
* what is not JSON becomes `null`, and objects keep their own enumerable
|
|
84
|
-
* properties (so a `Date` or a `Map` becomes `{}`).
|
|
85
|
-
*/
|
|
86
|
-
function stateValue(value) {
|
|
87
|
-
switch (typeof value) {
|
|
88
|
-
case "boolean":
|
|
89
|
-
case "string":
|
|
90
|
-
return value;
|
|
91
|
-
case "number":
|
|
92
|
-
return Number.isFinite(value) ? value : null;
|
|
93
|
-
case "bigint":
|
|
94
|
-
return Number(value);
|
|
95
|
-
case "object":
|
|
96
|
-
if (value === null) return null;
|
|
97
|
-
if (Array.isArray(value)) return value.map(stateValue);
|
|
98
|
-
return Object.fromEntries(Object.keys(value).map((key) => [key, stateValue(value[key])]));
|
|
99
|
-
default:
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Callbacks run on one thread here, so a lock has nothing to wait for. */
|
|
105
|
-
export function acquireLock(name) {
|
|
106
|
-
const scope = current("acquireLock()");
|
|
107
|
-
if (!scope.step) return scope.runtime.acquireLock(name);
|
|
108
|
-
return () => {};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Step outputs are kept for the transforms that still set them; nothing in a
|
|
112
|
-
// workflow reads them back but these functions.
|
|
113
|
-
|
|
114
|
-
export function setStepOutput(name, value) {
|
|
115
|
-
const scope = current("setStepOutput()");
|
|
116
|
-
if (!scope.step) return scope.runtime.setStepOutput(name, value);
|
|
117
|
-
scope.step.outputs.set(name, String(value));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function getStepOutput(stepId, name) {
|
|
121
|
-
const scope = current("getStepOutput()");
|
|
122
|
-
if (!scope.step) return scope.runtime.getStepOutput(stepId, name);
|
|
123
|
-
return scope.step.outputs.get(name) ?? null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function getOrSetStepOutput(stepId, name, value) {
|
|
127
|
-
const scope = current("getOrSetStepOutput()");
|
|
128
|
-
if (!scope.step) return scope.runtime.getOrSetStepOutput(stepId, name, value);
|
|
129
|
-
if (!scope.step.outputs.has(name)) scope.step.outputs.set(name, String(value));
|
|
130
|
-
return scope.step.outputs.get(name);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
32
|
export function __evaluate(kind, expression, scope) {
|
|
134
|
-
|
|
135
|
-
}
|
|
33
|
+
return current("__evaluate()").runtime.__evaluate(kind, expression, scope);
|
|
34
|
+
}
|
|
35
|
+
// The dependency APIs need the engine's lockfile reader and registry client,
|
|
36
|
+
// which only the codemod CLI has. They are exported here so a workflow that
|
|
37
|
+
// imports them still loads, and fail with a clear message when used.
|
|
38
|
+
const QUICKJS_ONLY = 'is not available on the Node.js host yet: run the workflow with the codemod CLI, or test it with { host: "quickjs" }';
|
|
39
|
+
function unavailable(what) {
|
|
40
|
+
throw new Error(`${what} ${QUICKJS_ONLY}`);
|
|
41
|
+
}
|
|
42
|
+
export function dependencyGraph(_options, _callback) {
|
|
43
|
+
return unavailable("dependencyGraph()");
|
|
44
|
+
}
|
|
45
|
+
export const registry = Object.freeze({
|
|
46
|
+
npm: (_name) => Promise.reject(new Error(`registry.npm() ${QUICKJS_ONLY}`)),
|
|
47
|
+
cargo: (_name) => Promise.reject(new Error(`registry.cargo() ${QUICKJS_ONLY}`)),
|
|
48
|
+
});
|
|
49
|
+
export const semver = Object.freeze({
|
|
50
|
+
satisfies: () => unavailable("semver.satisfies()"),
|
|
51
|
+
compare: () => unavailable("semver.compare()"),
|
|
52
|
+
gt: () => unavailable("semver.gt()"),
|
|
53
|
+
lt: () => unavailable("semver.lt()"),
|
|
54
|
+
isBreaking: () => unavailable("semver.isBreaking()"),
|
|
55
|
+
isPrerelease: () => unavailable("semver.isPrerelease()"),
|
|
56
|
+
});
|
package/testing/index.d.mts
CHANGED
|
@@ -1,149 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* ```ts
|
|
5
|
-
* import { test } from "node:test";
|
|
6
|
-
* import { runWorkflow, fixtures, assertTree } from "codemod/testing";
|
|
7
|
-
*
|
|
8
|
-
* for (const fixture of fixtures("tests")) {
|
|
9
|
-
* test(fixture.name, async () => {
|
|
10
|
-
* const run = await runWorkflow("workflow.ts", { target: fixture.input, params: fixture.params });
|
|
11
|
-
* assertTree(run, fixture.expected);
|
|
12
|
-
* });
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Each run copies its target into a temporary directory first, so fixtures
|
|
17
|
-
* are never changed. Paths are resolved against the current directory;
|
|
18
|
-
* pass `new URL("./workflow.ts", import.meta.url)` to resolve against the
|
|
19
|
-
* test file instead.
|
|
20
|
-
*
|
|
21
|
-
* TypeScript workflows run in the test's own process, so breakpoints,
|
|
22
|
-
* coverage and mocks work in the workflow's code. `host: "quickjs"` runs them
|
|
23
|
-
* with the codemod CLI instead, in the sandboxed runtime `codemod run` uses.
|
|
24
|
-
*
|
|
25
|
-
* @module
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export type JsonValue =
|
|
29
|
-
| string
|
|
30
|
-
| number
|
|
31
|
-
| boolean
|
|
32
|
-
| null
|
|
33
|
-
| JsonValue[]
|
|
34
|
-
| { [key: string]: JsonValue };
|
|
35
|
-
|
|
1
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
36
4
|
/** File contents by path, relative to the target (`"src/a.ts"`). */
|
|
37
|
-
export type FileTree = {
|
|
38
|
-
|
|
5
|
+
export type FileTree = {
|
|
6
|
+
readonly [path: string]: string;
|
|
7
|
+
};
|
|
39
8
|
/** A `URL` (`new URL("./tests", import.meta.url)`); only `file:` URLs are paths. */
|
|
40
9
|
export interface UrlLike {
|
|
41
|
-
|
|
10
|
+
readonly href: string;
|
|
42
11
|
}
|
|
43
|
-
|
|
44
12
|
/** A path, or a `file:` URL. */
|
|
45
13
|
export type PathLike = string | UrlLike;
|
|
46
|
-
|
|
47
14
|
/** An `AbortSignal`. */
|
|
48
15
|
export interface AbortSignalLike {
|
|
49
|
-
|
|
16
|
+
readonly aborted: boolean;
|
|
50
17
|
}
|
|
51
|
-
|
|
52
18
|
/** A workflow module: what `import("./workflow.ts")` gives. */
|
|
53
19
|
export interface WorkflowModule {
|
|
54
|
-
|
|
20
|
+
readonly default: (...args: never[]) => unknown;
|
|
55
21
|
}
|
|
56
|
-
|
|
57
22
|
/** A capability a transform may use beyond those codemod.yaml declares. */
|
|
58
23
|
export type Capability = "fs" | "fetch" | "child_process";
|
|
59
|
-
|
|
60
24
|
export interface RunWorkflowOptions {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The files the workflow runs on: a directory or a single file (copied
|
|
27
|
+
* first), or files by path.
|
|
28
|
+
*/
|
|
29
|
+
target: PathLike | FileTree;
|
|
30
|
+
/** The workflow's parameters. */
|
|
31
|
+
params?: Record<string, JsonValue>;
|
|
32
|
+
/**
|
|
33
|
+
* Stop after the step with this label: steps the workflow starts after it
|
|
34
|
+
* do not run. The run's status is then `"stopped"`.
|
|
35
|
+
*/
|
|
36
|
+
until?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Results for steps that should not run, by label. The workflow gets the
|
|
39
|
+
* given value as the step's result.
|
|
40
|
+
*/
|
|
41
|
+
given?: Record<string, JsonValue>;
|
|
42
|
+
/** Give every approval the workflow asks for. Default `true`. */
|
|
43
|
+
approve?: boolean;
|
|
44
|
+
/** Capabilities granted on top of those codemod.yaml declares. */
|
|
45
|
+
capabilities?: Capability[];
|
|
46
|
+
/** Which workflow to run when codemod.yaml defines several. */
|
|
47
|
+
workflowName?: string;
|
|
48
|
+
/** Keep the temporary directory the run changed (`run.dir`). */
|
|
49
|
+
keep?: boolean;
|
|
50
|
+
/** Stops the run. */
|
|
51
|
+
signal?: AbortSignalLike;
|
|
52
|
+
/**
|
|
53
|
+
* Where the workflow runs. `"node"` (the default for TypeScript workflows):
|
|
54
|
+
* in this process. `"quickjs"`: with the codemod CLI, in the sandboxed
|
|
55
|
+
* runtime `codemod run` uses, where capabilities are enforced. YAML
|
|
56
|
+
* workflows always run with the CLI.
|
|
57
|
+
*/
|
|
58
|
+
host?: "node" | "quickjs";
|
|
59
|
+
/** The workflow file, when `workflow` is the module itself. */
|
|
60
|
+
path?: PathLike;
|
|
97
61
|
}
|
|
98
|
-
|
|
99
62
|
export type RunStatus = "succeeded" | "failed" | "canceled" | "awaiting-approval" | "stopped";
|
|
100
|
-
|
|
101
63
|
export interface StepRun {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
64
|
+
readonly position: number;
|
|
65
|
+
readonly label: string;
|
|
66
|
+
/**
|
|
67
|
+
* `"partial"`: the step finished, but some of its files failed; `error`
|
|
68
|
+
* says how many.
|
|
69
|
+
*/
|
|
70
|
+
readonly status: "succeeded" | "partial" | "failed";
|
|
71
|
+
readonly result: JsonValue | null;
|
|
72
|
+
readonly error: string | null;
|
|
73
|
+
/** The step did not run: its result came from `given`. */
|
|
74
|
+
readonly given: boolean;
|
|
109
75
|
}
|
|
110
|
-
|
|
111
76
|
export interface LogLine {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
77
|
+
/** Label of the step that logged it; `null` for the workflow body. */
|
|
78
|
+
readonly step: string | null;
|
|
79
|
+
readonly line: string;
|
|
115
80
|
}
|
|
116
|
-
|
|
117
81
|
export interface WorkflowRun {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
82
|
+
readonly status: RunStatus;
|
|
83
|
+
/** Whether the run succeeded, or stopped at its `until` step. */
|
|
84
|
+
readonly ok: boolean;
|
|
85
|
+
/** What the workflow returned, when it succeeded. */
|
|
86
|
+
readonly output: JsonValue | null;
|
|
87
|
+
/** Why the run failed. */
|
|
88
|
+
readonly error: string | null;
|
|
89
|
+
/** The approval the run waits for (`approve: false`). */
|
|
90
|
+
readonly awaiting: string | null;
|
|
91
|
+
/** The `until` step the run stopped after. */
|
|
92
|
+
readonly stoppedAt: string | null;
|
|
93
|
+
/** The directory the run changed; removed afterwards unless `keep` is set. */
|
|
94
|
+
readonly dir: string;
|
|
95
|
+
/** Every file after the run. */
|
|
96
|
+
readonly files: FileTree;
|
|
97
|
+
/** Files the run wrote or created, with their new text; `null` for files it removed. */
|
|
98
|
+
readonly changes: {
|
|
99
|
+
readonly [path: string]: string | null;
|
|
100
|
+
};
|
|
101
|
+
/** Every step, in the order the workflow started them. */
|
|
102
|
+
readonly steps: readonly StepRun[];
|
|
103
|
+
/** Console output, from steps, callbacks and the workflow body. */
|
|
104
|
+
readonly logs: readonly LogLine[];
|
|
105
|
+
/** The first step with this label. Throws when there is none. */
|
|
106
|
+
step(label: string): StepRun;
|
|
107
|
+
/** A unified diff of every file the run changed. */
|
|
108
|
+
diff(): string;
|
|
109
|
+
}
|
|
110
|
+
export interface Fixture {
|
|
111
|
+
/** The fixture's directory, relative to the fixtures directory (`"renames/default-export"`). */
|
|
112
|
+
readonly name: string;
|
|
113
|
+
readonly dir: string;
|
|
114
|
+
/** `input/`, or the `input.<ext>` file: pass it as `target`. */
|
|
115
|
+
readonly input: string;
|
|
116
|
+
/** `expected/`, or the `expected.<ext>` file: pass it to `assertTree`. */
|
|
117
|
+
readonly expected: string;
|
|
118
|
+
/** From `params.json`, or empty. */
|
|
119
|
+
readonly params: Record<string, JsonValue>;
|
|
120
|
+
}
|
|
121
|
+
export interface AssertTreeOptions {
|
|
122
|
+
/** Ignore whitespace at the ends of lines and of files. */
|
|
123
|
+
ignoreWhitespace?: boolean;
|
|
124
|
+
/** Put in front of the failure message. */
|
|
125
|
+
message?: string;
|
|
145
126
|
}
|
|
146
|
-
|
|
147
127
|
/**
|
|
148
128
|
* Run a workflow (a workflow file, a package directory, or the workflow
|
|
149
129
|
* module itself, with `options.path`) on a copy of `options.target`. Resolves for every outcome; check `run.status`, or use
|
|
@@ -151,38 +131,14 @@ export interface WorkflowRun {
|
|
|
151
131
|
* workflow cannot run at all (for example it does not build), or when an
|
|
152
132
|
* `until` or `given` label matches no step.
|
|
153
133
|
*/
|
|
154
|
-
export function runWorkflow(
|
|
155
|
-
workflow: PathLike | WorkflowModule,
|
|
156
|
-
options: RunWorkflowOptions,
|
|
157
|
-
): Promise<WorkflowRun>;
|
|
158
|
-
|
|
159
|
-
export interface Fixture {
|
|
160
|
-
/** The fixture's directory, relative to the fixtures directory (`"renames/default-export"`). */
|
|
161
|
-
readonly name: string;
|
|
162
|
-
readonly dir: string;
|
|
163
|
-
/** `input/`, or the `input.<ext>` file: pass it as `target`. */
|
|
164
|
-
readonly input: string;
|
|
165
|
-
/** `expected/`, or the `expected.<ext>` file: pass it to `assertTree`. */
|
|
166
|
-
readonly expected: string;
|
|
167
|
-
/** From `params.json`, or empty. */
|
|
168
|
-
readonly params: Record<string, JsonValue>;
|
|
169
|
-
}
|
|
170
|
-
|
|
134
|
+
export declare function runWorkflow(workflow: PathLike | WorkflowModule, options: RunWorkflowOptions): Promise<WorkflowRun>;
|
|
171
135
|
/**
|
|
172
136
|
* The fixtures in a directory: each subdirectory with `input/` and
|
|
173
137
|
* `expected/` directories, or `input.<ext>` and `expected.<ext>` files (the
|
|
174
|
-
* layouts `codemod jssg test` and
|
|
138
|
+
* layouts `codemod jssg test` reads), and optionally `params.json`. Groups of
|
|
175
139
|
* fixtures may be nested.
|
|
176
140
|
*/
|
|
177
|
-
export function fixtures(dir: PathLike): Fixture[];
|
|
178
|
-
|
|
179
|
-
export interface AssertTreeOptions {
|
|
180
|
-
/** Ignore whitespace at the ends of lines and of files. */
|
|
181
|
-
ignoreWhitespace?: boolean;
|
|
182
|
-
/** Put in front of the failure message. */
|
|
183
|
-
message?: string;
|
|
184
|
-
}
|
|
185
|
-
|
|
141
|
+
export declare function fixtures(dir: PathLike): Fixture[];
|
|
186
142
|
/**
|
|
187
143
|
* Assert that `actual` holds exactly the expected files. Throws an
|
|
188
144
|
* `AssertionError` with `actual` and `expected` set and a diff in the
|
|
@@ -196,8 +152,4 @@ export interface AssertTreeOptions {
|
|
|
196
152
|
* Line endings are compared as `\n`. With `CODEMOD_UPDATE_FIXTURES=1`, an
|
|
197
153
|
* expected directory or file is rewritten to match `actual` instead.
|
|
198
154
|
*/
|
|
199
|
-
export function assertTree(
|
|
200
|
-
actual: WorkflowRun | PathLike | FileTree,
|
|
201
|
-
expected: PathLike | FileTree,
|
|
202
|
-
options?: AssertTreeOptions,
|
|
203
|
-
): void;
|
|
155
|
+
export declare function assertTree(actual: WorkflowRun | PathLike | FileTree, expected: PathLike | FileTree, options?: AssertTreeOptions): void;
|