codemod 2.0.0-alpha.2 → 2.0.0-alpha.3
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 +0 -1
- package/package.json +14 -12
- package/register.d.mts +2 -11
- package/register.mjs +53 -46
- package/runtime/addon.d.mts +114 -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 +49 -0
- package/runtime/context.mjs +35 -53
- package/runtime/hooks.d.mts +2 -0
- package/runtime/hooks.mjs +4 -6
- package/runtime/host.d.mts +82 -81
- package/runtime/host.mjs +383 -323
- package/runtime/llm.d.mts +2 -0
- package/runtime/llm.mjs +1 -7
- package/runtime/metrics.d.mts +9 -0
- package/runtime/metrics.mjs +31 -34
- package/runtime/modules.d.mts +3 -0
- package/runtime/modules.mjs +8 -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 +829 -607
- package/runtime/runtime.d.mts +15 -0
- package/runtime/runtime.mjs +18 -26
- package/runtime/workflow.d.mts +19 -0
- package/runtime/workflow.mjs +83 -92
- package/testing/index.d.mts +109 -155
- package/testing/index.mjs +555 -545
- package/types/langs/package.json +3 -0
- package/types/modules/workflow.d.ts +180 -15
- package/vite.d.mts +4 -21
- package/vite.mjs +23 -17
|
@@ -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,19 @@
|
|
|
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 getState(key?: string): unknown;
|
|
12
|
+
export declare function setState(key: string, value: unknown, persist?: boolean): void;
|
|
13
|
+
export declare function unsetState(key: string): void;
|
|
14
|
+
/** Callbacks run on one thread here, so a lock has nothing to wait for. */
|
|
15
|
+
export declare function acquireLock(name: string): () => void;
|
|
16
|
+
export declare function setStepOutput(name: string, value: unknown): void;
|
|
17
|
+
export declare function getStepOutput(stepId: string, name: string): string | null;
|
|
18
|
+
export declare function getOrSetStepOutput(stepId: string, name: string, value: unknown): string;
|
|
19
|
+
export declare function __evaluate(kind: string, expression: string, scope: unknown): unknown;
|
package/runtime/workflow.mjs
CHANGED
|
@@ -5,131 +5,122 @@
|
|
|
5
5
|
// orchestrator. Inside a function step or a `forEachFile` callback, the state
|
|
6
6
|
// functions see the state the step started with, and what they set becomes
|
|
7
7
|
// the step's state changes, as in the engine's isolates.
|
|
8
|
-
|
|
9
8
|
import { createHash } from "node:crypto";
|
|
10
|
-
|
|
11
9
|
import { current } from "./context.mjs";
|
|
12
10
|
import { createTasks } from "./orchestrator.mjs";
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
AwaitingApprovalError,
|
|
16
|
-
CanceledError,
|
|
17
|
-
NondeterminismError,
|
|
18
|
-
StepError,
|
|
19
|
-
} from "./orchestrator.mjs";
|
|
20
|
-
|
|
11
|
+
export { AwaitingApprovalError, CanceledError, StepError } from "./orchestrator.mjs";
|
|
21
12
|
/** Identifies a callback given as a function, for replay checks. */
|
|
22
13
|
export function callbackId(fn) {
|
|
23
|
-
|
|
14
|
+
return `fn:${createHash("sha256").update(String(fn)).digest("hex").slice(0, 16)}`;
|
|
24
15
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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);
|
|
16
|
+
export const { __callback, forEachFile, shell, jssg, astGrep, shard, codemod, agent, installSkill, approval, branch, commit, pullRequest, } = createTasks({ callbackId });
|
|
17
|
+
/** The run's orchestrator, for what only the workflow body may call. */
|
|
18
|
+
function body(what) {
|
|
19
|
+
const scope = current(what);
|
|
20
|
+
if (scope.step) {
|
|
21
|
+
throw new Error(`${what} cannot be called inside a step or forEachFile callback; call it from the workflow body`);
|
|
22
|
+
}
|
|
23
|
+
return scope.runtime;
|
|
24
|
+
}
|
|
25
|
+
export function step(...args) {
|
|
26
|
+
return body("step()").step(...args);
|
|
27
|
+
}
|
|
28
|
+
export function sleep(duration) {
|
|
29
|
+
return body("sleep()").sleep(duration);
|
|
30
|
+
}
|
|
31
|
+
export function waitForEvent(name, options) {
|
|
32
|
+
return body("waitForEvent()").waitForEvent(name, options);
|
|
50
33
|
}
|
|
51
|
-
|
|
52
34
|
// In a step or callback the state functions behave as in the engine's
|
|
53
35
|
// isolates: values are copied in and out, and what the step leaves different
|
|
54
36
|
// from the state it started with becomes its state changes.
|
|
55
|
-
|
|
56
37
|
export function getState(key) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
38
|
+
const scope = current("getState()");
|
|
39
|
+
if (!scope.step)
|
|
40
|
+
return scope.runtime.getState(key);
|
|
41
|
+
const state = scope.step.state;
|
|
42
|
+
if (key === undefined)
|
|
43
|
+
return structuredClone(Object.fromEntries(state));
|
|
44
|
+
return state.has(key) ? structuredClone(state.get(key)) : undefined;
|
|
62
45
|
}
|
|
63
|
-
|
|
64
46
|
export function setState(key, value, persist = true) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
const scope = current("setState()");
|
|
48
|
+
if (!scope.step)
|
|
49
|
+
return scope.runtime.setState(key, value);
|
|
50
|
+
const step = scope.step;
|
|
51
|
+
step.state.set(key, stateValue(value));
|
|
52
|
+
step.removed.delete(key);
|
|
53
|
+
if (persist)
|
|
54
|
+
step.unpersisted.delete(key);
|
|
55
|
+
else
|
|
56
|
+
step.unpersisted.add(key);
|
|
72
57
|
}
|
|
73
|
-
|
|
74
58
|
export function unsetState(key) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
const scope = current("unsetState()");
|
|
60
|
+
if (!scope.step)
|
|
61
|
+
return scope.runtime.unsetState(key);
|
|
62
|
+
scope.step.state.delete(key);
|
|
63
|
+
scope.step.removed.add(key);
|
|
79
64
|
}
|
|
80
|
-
|
|
81
65
|
/**
|
|
82
66
|
* A value as state keeps it, the way the engine's isolates convert one:
|
|
83
67
|
* what is not JSON becomes `null`, and objects keep their own enumerable
|
|
84
68
|
* properties (so a `Date` or a `Map` becomes `{}`).
|
|
85
69
|
*/
|
|
86
70
|
function stateValue(value) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
71
|
+
switch (typeof value) {
|
|
72
|
+
case "boolean":
|
|
73
|
+
case "string":
|
|
74
|
+
return value;
|
|
75
|
+
case "number":
|
|
76
|
+
return Number.isFinite(value) ? value : null;
|
|
77
|
+
case "bigint":
|
|
78
|
+
return Number(value);
|
|
79
|
+
case "object":
|
|
80
|
+
if (value === null)
|
|
81
|
+
return null;
|
|
82
|
+
if (Array.isArray(value))
|
|
83
|
+
return value.map(stateValue);
|
|
84
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
85
|
+
key,
|
|
86
|
+
stateValue(item),
|
|
87
|
+
]));
|
|
88
|
+
default:
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
102
91
|
}
|
|
103
|
-
|
|
104
92
|
/** Callbacks run on one thread here, so a lock has nothing to wait for. */
|
|
105
93
|
export function acquireLock(name) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
const scope = current("acquireLock()");
|
|
95
|
+
if (!scope.step)
|
|
96
|
+
return scope.runtime.acquireLock(name);
|
|
97
|
+
return () => { };
|
|
109
98
|
}
|
|
110
|
-
|
|
111
99
|
// Step outputs are kept for the transforms that still set them; nothing in a
|
|
112
100
|
// workflow reads them back but these functions.
|
|
113
|
-
|
|
114
101
|
export function setStepOutput(name, value) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
const scope = current("setStepOutput()");
|
|
103
|
+
if (!scope.step)
|
|
104
|
+
return scope.runtime.setStepOutput(name, value);
|
|
105
|
+
scope.step.outputs.set(name, String(value));
|
|
118
106
|
}
|
|
119
|
-
|
|
120
107
|
export function getStepOutput(stepId, name) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
const scope = current("getStepOutput()");
|
|
109
|
+
if (!scope.step)
|
|
110
|
+
return scope.runtime.getStepOutput(stepId, name);
|
|
111
|
+
return scope.step.outputs.get(name) ?? null;
|
|
124
112
|
}
|
|
125
|
-
|
|
126
113
|
export function getOrSetStepOutput(stepId, name, value) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
114
|
+
const scope = current("getOrSetStepOutput()");
|
|
115
|
+
if (!scope.step)
|
|
116
|
+
return scope.runtime.getOrSetStepOutput(stepId, name, value);
|
|
117
|
+
const existing = scope.step.outputs.get(name);
|
|
118
|
+
if (existing !== undefined)
|
|
119
|
+
return existing;
|
|
120
|
+
const text = String(value);
|
|
121
|
+
scope.step.outputs.set(name, text);
|
|
122
|
+
return text;
|
|
131
123
|
}
|
|
132
|
-
|
|
133
124
|
export function __evaluate(kind, expression, scope) {
|
|
134
|
-
|
|
125
|
+
return current("__evaluate()").runtime.__evaluate(kind, expression, scope);
|
|
135
126
|
}
|
package/testing/index.d.mts
CHANGED
|
@@ -1,149 +1,131 @@
|
|
|
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
|
+
/** Metrics the transforms recorded. */
|
|
106
|
+
readonly metrics: Record<string, unknown>;
|
|
107
|
+
/** The first step with this label. Throws when there is none. */
|
|
108
|
+
step(label: string): StepRun;
|
|
109
|
+
/** A unified diff of every file the run changed. */
|
|
110
|
+
diff(): string;
|
|
111
|
+
}
|
|
112
|
+
export interface Fixture {
|
|
113
|
+
/** The fixture's directory, relative to the fixtures directory (`"renames/default-export"`). */
|
|
114
|
+
readonly name: string;
|
|
115
|
+
readonly dir: string;
|
|
116
|
+
/** `input/`, or the `input.<ext>` file: pass it as `target`. */
|
|
117
|
+
readonly input: string;
|
|
118
|
+
/** `expected/`, or the `expected.<ext>` file: pass it to `assertTree`. */
|
|
119
|
+
readonly expected: string;
|
|
120
|
+
/** From `params.json`, or empty. */
|
|
121
|
+
readonly params: Record<string, JsonValue>;
|
|
122
|
+
}
|
|
123
|
+
export interface AssertTreeOptions {
|
|
124
|
+
/** Ignore whitespace at the ends of lines and of files. */
|
|
125
|
+
ignoreWhitespace?: boolean;
|
|
126
|
+
/** Put in front of the failure message. */
|
|
127
|
+
message?: string;
|
|
145
128
|
}
|
|
146
|
-
|
|
147
129
|
/**
|
|
148
130
|
* Run a workflow (a workflow file, a package directory, or the workflow
|
|
149
131
|
* module itself, with `options.path`) on a copy of `options.target`. Resolves for every outcome; check `run.status`, or use
|
|
@@ -151,38 +133,14 @@ export interface WorkflowRun {
|
|
|
151
133
|
* workflow cannot run at all (for example it does not build), or when an
|
|
152
134
|
* `until` or `given` label matches no step.
|
|
153
135
|
*/
|
|
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
|
-
|
|
136
|
+
export declare function runWorkflow(workflow: PathLike | WorkflowModule, options: RunWorkflowOptions): Promise<WorkflowRun>;
|
|
171
137
|
/**
|
|
172
138
|
* The fixtures in a directory: each subdirectory with `input/` and
|
|
173
139
|
* `expected/` directories, or `input.<ext>` and `expected.<ext>` files (the
|
|
174
|
-
* layouts `codemod jssg test` and
|
|
140
|
+
* layouts `codemod jssg test` reads), and optionally `params.json`. Groups of
|
|
175
141
|
* fixtures may be nested.
|
|
176
142
|
*/
|
|
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
|
-
|
|
143
|
+
export declare function fixtures(dir: PathLike): Fixture[];
|
|
186
144
|
/**
|
|
187
145
|
* Assert that `actual` holds exactly the expected files. Throws an
|
|
188
146
|
* `AssertionError` with `actual` and `expected` set and a diff in the
|
|
@@ -196,8 +154,4 @@ export interface AssertTreeOptions {
|
|
|
196
154
|
* Line endings are compared as `\n`. With `CODEMOD_UPDATE_FIXTURES=1`, an
|
|
197
155
|
* expected directory or file is rewritten to match `actual` instead.
|
|
198
156
|
*/
|
|
199
|
-
export function assertTree(
|
|
200
|
-
actual: WorkflowRun | PathLike | FileTree,
|
|
201
|
-
expected: PathLike | FileTree,
|
|
202
|
-
options?: AssertTreeOptions,
|
|
203
|
-
): void;
|
|
157
|
+
export declare function assertTree(actual: WorkflowRun | PathLike | FileTree, expected: PathLike | FileTree, options?: AssertTreeOptions): void;
|