codemod 2.0.0-alpha.1 → 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 +56 -2
- package/codemod +17 -30
- package/package.json +80 -10
- package/register.d.mts +2 -0
- package/register.mjs +67 -0
- package/runtime/addon.d.mts +114 -0
- package/runtime/addon.mjs +55 -0
- package/runtime/ast-grep.d.mts +20 -0
- package/runtime/ast-grep.mjs +82 -0
- package/runtime/context.d.mts +49 -0
- package/runtime/context.mjs +59 -0
- package/runtime/hooks.d.mts +2 -0
- package/runtime/hooks.mjs +7 -0
- package/runtime/host.d.mts +121 -0
- package/runtime/host.mjs +450 -0
- package/runtime/llm.d.mts +2 -0
- package/runtime/llm.mjs +5 -0
- package/runtime/metrics.d.mts +9 -0
- package/runtime/metrics.mjs +42 -0
- package/runtime/modules.d.mts +3 -0
- package/runtime/modules.mjs +17 -0
- 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 +879 -0
- package/runtime/runtime.d.mts +15 -0
- package/runtime/runtime.mjs +40 -0
- package/runtime/workflow.d.mts +19 -0
- package/runtime/workflow.mjs +126 -0
- package/testing/index.d.mts +157 -0
- package/testing/index.mjs +648 -0
- package/types/index.d.ts +8 -0
- package/types/langs/angular.d.ts +5 -0
- package/types/langs/c.d.ts +5 -0
- package/types/langs/c_sharp.d.ts +5 -0
- package/types/langs/cpp.d.ts +5 -0
- package/types/langs/css.d.ts +5 -0
- package/types/langs/elixir.d.ts +5 -0
- package/types/langs/go.d.ts +5 -0
- package/types/langs/html.d.ts +5 -0
- package/types/langs/java.d.ts +5 -0
- package/types/langs/javascript.d.ts +5 -0
- package/types/langs/json.d.ts +5 -0
- package/types/langs/kotlin.d.ts +5 -0
- package/types/langs/package.json +3 -0
- package/types/langs/php.d.ts +5 -0
- package/types/langs/python.d.ts +5 -0
- package/types/langs/ruby.d.ts +5 -0
- package/types/langs/rust.d.ts +5 -0
- package/types/langs/scala.d.ts +5 -0
- package/types/langs/toml.d.ts +5 -0
- package/types/langs/tsx.d.ts +5 -0
- package/types/langs/typescript.d.ts +5 -0
- package/types/langs/xml.d.ts +5 -0
- package/types/langs/yaml.d.ts +5 -0
- package/types/llm.d.ts +6 -0
- package/types/llrt/abort.d.ts +69 -0
- package/types/llrt/assert.d.ts +39 -0
- package/types/llrt/async_hooks.d.ts +210 -0
- package/types/llrt/buffer.d.ts +1186 -0
- package/types/llrt/child_process.d.ts +447 -0
- package/types/llrt/console.d.ts +210 -0
- package/types/llrt/crypto.d.ts +854 -0
- package/types/llrt/dgram.d.ts +381 -0
- package/types/llrt/dns.d.ts +124 -0
- package/types/llrt/dom-events.d.ts +51 -0
- package/types/llrt/events.d.ts +245 -0
- package/types/llrt/exceptions.d.ts +26 -0
- package/types/llrt/fetch.d.ts +332 -0
- package/types/llrt/fs/promises.d.ts +554 -0
- package/types/llrt/fs.d.ts +360 -0
- package/types/llrt/globals.d.ts +23 -0
- package/types/llrt/https.d.ts +27 -0
- package/types/llrt/index.d.ts +33 -0
- package/types/llrt/module.d.ts +285 -0
- package/types/llrt/navigator.d.ts +9 -0
- package/types/llrt/net.d.ts +488 -0
- package/types/llrt/os.d.ts +293 -0
- package/types/llrt/path.d.ts +150 -0
- package/types/llrt/perf_hooks.d.ts +23 -0
- package/types/llrt/process.d.ts +502 -0
- package/types/llrt/stream/web.d.ts +526 -0
- package/types/llrt/stream.d.ts +366 -0
- package/types/llrt/string_decoder.d.ts +63 -0
- package/types/llrt/timers.d.ts +72 -0
- package/types/llrt/timezone.d.ts +101 -0
- package/types/llrt/tty.d.ts +11 -0
- package/types/llrt/url.d.ts +774 -0
- package/types/llrt/util.d.ts +240 -0
- package/types/llrt/zlib.d.ts +177 -0
- package/types/main.d.ts +5 -0
- package/types/metrics.d.ts +5 -0
- package/types/modules/ast-grep.d.ts +634 -0
- package/types/modules/langs.d.ts +87 -0
- package/types/modules/llm.d.ts +23 -0
- package/types/modules/metrics.d.ts +107 -0
- package/types/modules/runtime.d.ts +66 -0
- package/types/modules/workflow.d.ts +915 -0
- package/types/runtime.d.ts +6 -0
- package/types/workflow.d.ts +5 -0
- package/vite.d.mts +7 -0
- package/vite.mjs +32 -0
|
@@ -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;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// `codemod/runtime` in Node.js and Bun. Progress and warnings become the
|
|
2
|
+
// step's log lines, written as the CLI writes them; failures throw, and stay
|
|
3
|
+
// reported even when the code catches the error.
|
|
4
|
+
import { context } from "./context.mjs";
|
|
5
|
+
function text(message, what) {
|
|
6
|
+
if (typeof message !== "string")
|
|
7
|
+
throw new TypeError(`${what} expects a message string`);
|
|
8
|
+
return message;
|
|
9
|
+
}
|
|
10
|
+
function log(prefix, message, meta) {
|
|
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}`);
|
|
16
|
+
}
|
|
17
|
+
export function progress(message, meta) {
|
|
18
|
+
log("[progress]", text(message, "progress()"), meta);
|
|
19
|
+
}
|
|
20
|
+
export function warn(message, meta) {
|
|
21
|
+
log("[warn]", text(message, "warn()"), meta);
|
|
22
|
+
}
|
|
23
|
+
export function setCurrentUnit(_unitId, _meta) { }
|
|
24
|
+
function fail(message, what) {
|
|
25
|
+
const step = context.getStore()?.step;
|
|
26
|
+
if (step)
|
|
27
|
+
step.failure = text(message, what);
|
|
28
|
+
throw new Error(text(message, what));
|
|
29
|
+
}
|
|
30
|
+
export function failFile(message, _meta) {
|
|
31
|
+
fail(message, "failFile()");
|
|
32
|
+
}
|
|
33
|
+
export function failStep(message, _meta) {
|
|
34
|
+
fail(message, "failStep()");
|
|
35
|
+
}
|
|
36
|
+
export function isCanceled() {
|
|
37
|
+
return context.getStore()?.run.canceled() ?? false;
|
|
38
|
+
}
|
|
39
|
+
const runtime = { progress, warn, setCurrentUnit, failFile, failStep, isCanceled };
|
|
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;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// `codemod:workflow` in Node.js and Bun: the shared orchestrator, with the
|
|
2
|
+
// run looked up per call (see context.mjs).
|
|
3
|
+
//
|
|
4
|
+
// In the workflow body, `step`, `getState` and `setState` go to the run's
|
|
5
|
+
// orchestrator. Inside a function step or a `forEachFile` callback, the state
|
|
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
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { current } from "./context.mjs";
|
|
10
|
+
import { createTasks } from "./orchestrator.mjs";
|
|
11
|
+
export { AwaitingApprovalError, CanceledError, StepError } from "./orchestrator.mjs";
|
|
12
|
+
/** Identifies a callback given as a function, for replay checks. */
|
|
13
|
+
export function callbackId(fn) {
|
|
14
|
+
return `fn:${createHash("sha256").update(String(fn)).digest("hex").slice(0, 16)}`;
|
|
15
|
+
}
|
|
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);
|
|
33
|
+
}
|
|
34
|
+
// In a step or callback the state functions behave as in the engine's
|
|
35
|
+
// isolates: values are copied in and out, and what the step leaves different
|
|
36
|
+
// from the state it started with becomes its state changes.
|
|
37
|
+
export function getState(key) {
|
|
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;
|
|
45
|
+
}
|
|
46
|
+
export function setState(key, value, persist = true) {
|
|
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);
|
|
57
|
+
}
|
|
58
|
+
export function unsetState(key) {
|
|
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);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A value as state keeps it, the way the engine's isolates convert one:
|
|
67
|
+
* what is not JSON becomes `null`, and objects keep their own enumerable
|
|
68
|
+
* properties (so a `Date` or a `Map` becomes `{}`).
|
|
69
|
+
*/
|
|
70
|
+
function stateValue(value) {
|
|
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
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Callbacks run on one thread here, so a lock has nothing to wait for. */
|
|
93
|
+
export function acquireLock(name) {
|
|
94
|
+
const scope = current("acquireLock()");
|
|
95
|
+
if (!scope.step)
|
|
96
|
+
return scope.runtime.acquireLock(name);
|
|
97
|
+
return () => { };
|
|
98
|
+
}
|
|
99
|
+
// Step outputs are kept for the transforms that still set them; nothing in a
|
|
100
|
+
// workflow reads them back but these functions.
|
|
101
|
+
export function setStepOutput(name, value) {
|
|
102
|
+
const scope = current("setStepOutput()");
|
|
103
|
+
if (!scope.step)
|
|
104
|
+
return scope.runtime.setStepOutput(name, value);
|
|
105
|
+
scope.step.outputs.set(name, String(value));
|
|
106
|
+
}
|
|
107
|
+
export function getStepOutput(stepId, name) {
|
|
108
|
+
const scope = current("getStepOutput()");
|
|
109
|
+
if (!scope.step)
|
|
110
|
+
return scope.runtime.getStepOutput(stepId, name);
|
|
111
|
+
return scope.step.outputs.get(name) ?? null;
|
|
112
|
+
}
|
|
113
|
+
export function getOrSetStepOutput(stepId, name, value) {
|
|
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;
|
|
123
|
+
}
|
|
124
|
+
export function __evaluate(kind, expression, scope) {
|
|
125
|
+
return current("__evaluate()").runtime.__evaluate(kind, expression, scope);
|
|
126
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
/** File contents by path, relative to the target (`"src/a.ts"`). */
|
|
5
|
+
export type FileTree = {
|
|
6
|
+
readonly [path: string]: string;
|
|
7
|
+
};
|
|
8
|
+
/** A `URL` (`new URL("./tests", import.meta.url)`); only `file:` URLs are paths. */
|
|
9
|
+
export interface UrlLike {
|
|
10
|
+
readonly href: string;
|
|
11
|
+
}
|
|
12
|
+
/** A path, or a `file:` URL. */
|
|
13
|
+
export type PathLike = string | UrlLike;
|
|
14
|
+
/** An `AbortSignal`. */
|
|
15
|
+
export interface AbortSignalLike {
|
|
16
|
+
readonly aborted: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A workflow module: what `import("./workflow.ts")` gives. */
|
|
19
|
+
export interface WorkflowModule {
|
|
20
|
+
readonly default: (...args: never[]) => unknown;
|
|
21
|
+
}
|
|
22
|
+
/** A capability a transform may use beyond those codemod.yaml declares. */
|
|
23
|
+
export type Capability = "fs" | "fetch" | "child_process";
|
|
24
|
+
export interface RunWorkflowOptions {
|
|
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;
|
|
61
|
+
}
|
|
62
|
+
export type RunStatus = "succeeded" | "failed" | "canceled" | "awaiting-approval" | "stopped";
|
|
63
|
+
export interface StepRun {
|
|
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;
|
|
75
|
+
}
|
|
76
|
+
export interface LogLine {
|
|
77
|
+
/** Label of the step that logged it; `null` for the workflow body. */
|
|
78
|
+
readonly step: string | null;
|
|
79
|
+
readonly line: string;
|
|
80
|
+
}
|
|
81
|
+
export interface WorkflowRun {
|
|
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;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Run a workflow (a workflow file, a package directory, or the workflow
|
|
131
|
+
* module itself, with `options.path`) on a copy of `options.target`. Resolves for every outcome; check `run.status`, or use
|
|
132
|
+
* `assertTree`, which fails when the run did not succeed. Rejects when the
|
|
133
|
+
* workflow cannot run at all (for example it does not build), or when an
|
|
134
|
+
* `until` or `given` label matches no step.
|
|
135
|
+
*/
|
|
136
|
+
export declare function runWorkflow(workflow: PathLike | WorkflowModule, options: RunWorkflowOptions): Promise<WorkflowRun>;
|
|
137
|
+
/**
|
|
138
|
+
* The fixtures in a directory: each subdirectory with `input/` and
|
|
139
|
+
* `expected/` directories, or `input.<ext>` and `expected.<ext>` files (the
|
|
140
|
+
* layouts `codemod jssg test` reads), and optionally `params.json`. Groups of
|
|
141
|
+
* fixtures may be nested.
|
|
142
|
+
*/
|
|
143
|
+
export declare function fixtures(dir: PathLike): Fixture[];
|
|
144
|
+
/**
|
|
145
|
+
* Assert that `actual` holds exactly the expected files. Throws an
|
|
146
|
+
* `AssertionError` with `actual` and `expected` set and a diff in the
|
|
147
|
+
* message.
|
|
148
|
+
*
|
|
149
|
+
* - `actual`: a run (which must have succeeded or stopped), a directory, or
|
|
150
|
+
* files by path.
|
|
151
|
+
* - `expected`: a directory, files by path, or a single file, in which case
|
|
152
|
+
* the run must have left exactly one file.
|
|
153
|
+
*
|
|
154
|
+
* Line endings are compared as `\n`. With `CODEMOD_UPDATE_FIXTURES=1`, an
|
|
155
|
+
* expected directory or file is rewritten to match `actual` instead.
|
|
156
|
+
*/
|
|
157
|
+
export declare function assertTree(actual: WorkflowRun | PathLike | FileTree, expected: PathLike | FileTree, options?: AssertTreeOptions): void;
|