am-i-done 0.4.1 → 0.5.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.
- package/README.md +3 -1
- package/bin/am-i-done.ts +2 -2
- package/bin/doing-it-wrong.ts +2 -2
- package/package.json +1 -1
- package/src/cache.ts +1 -1
- package/src/cli/am-i-done.ts +39 -16
- package/src/cli/doing-it-wrong.ts +6 -6
- package/src/cli/init.ts +2 -2
- package/src/config.ts +1 -1
- package/src/context.ts +1 -1
- package/src/engine/engine.ts +9 -9
- package/src/engine/evaluate.ts +5 -5
- package/src/engine/files.ts +2 -2
- package/src/engine/fixtures.ts +4 -4
- package/src/engine/graph.ts +1 -1
- package/src/engine/report.ts +3 -3
- package/src/engine/rule.ts +3 -3
- package/src/engine/suppress.ts +3 -3
- package/src/index.ts +7 -7
- package/src/log.ts +1 -1
- package/src/output-guard.ts +1 -1
- package/src/rules/fixtures/no-raw-temp__paths.spec.ts.fixture +6 -0
- package/src/rules/fixtures/no-raw-temp__raw.spec.ts.fixture +5 -2
- package/src/rules/no-as-any.rule.ts +1 -1
- package/src/rules/no-empty-catch.rule.ts +3 -3
- package/src/rules/no-focused-tests.rule.ts +1 -1
- package/src/rules/no-import-cycles.rule.ts +2 -2
- package/src/rules/no-raw-temp.rule.ts +15 -3
- package/src/rules/no-skipped-tests.rule.ts +1 -1
- package/src/rules/no-ts-expect-error.rule.ts +1 -1
- package/src/rules/no-ts-ignore.rule.ts +1 -1
- package/src/rules/shell-injection.rule.ts +1 -1
- package/src/rules/test-uses-bun-test.rule.ts +1 -1
- package/src/runner.ts +7 -7
- package/src/spawn.ts +1 -1
- package/src/spec-cache.ts +4 -4
- package/src/stage-process.ts +2 -2
- package/src/stages/builtin/bun-version.stage.ts +1 -1
- package/src/stages/builtin/lint.stage.ts +2 -2
- package/src/stages/builtin/rules.stage.ts +6 -6
- package/src/stages/builtin/test.stage.ts +5 -5
- package/src/stages/builtin/typecheck.stage.ts +1 -1
- package/src/stages/load.ts +7 -7
- package/src/stages/order.ts +2 -2
- package/src/tmp-preload.ts +1 -1
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,9 @@ A built-in whose tool is missing is left out, and every run says so (`left out:
|
|
|
57
57
|
tsconfig.json)`); one named in `[stages] load` must have its tool. `bun run am-i-done --list` prints
|
|
58
58
|
the plan. Modes pick stages: `--pre-commit`, `--pre-push`,
|
|
59
59
|
`--ci` (the default under CI), or `--mode <name>` for your own. `--only <stage>` and `--from <stage>`
|
|
60
|
-
rerun part of it; the failure message prints the exact command.
|
|
60
|
+
rerun part of it; the failure message prints the exact command. `--skip <stage>` (repeatable) leaves
|
|
61
|
+
a stage out where it cannot run (a CI job without the data it needs): such a run is never cached,
|
|
62
|
+
and says what it left out.
|
|
61
63
|
|
|
62
64
|
### What makes it strict
|
|
63
65
|
|
package/bin/am-i-done.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { amIDone, runCli } from "../src/cli/am-i-done.
|
|
3
|
-
import { init } from "../src/cli/init.
|
|
2
|
+
import { amIDone, runCli } from "../src/cli/am-i-done.js";
|
|
3
|
+
import { init } from "../src/cli/init.js";
|
|
4
4
|
|
|
5
5
|
await runCli((argv, io) => (argv[0] === "init" ? init(argv.slice(1), io) : amIDone(argv, io)));
|
package/bin/doing-it-wrong.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { runCli } from "../src/cli/am-i-done.
|
|
3
|
-
import { doingItWrong } from "../src/cli/doing-it-wrong.
|
|
2
|
+
import { runCli } from "../src/cli/am-i-done.js";
|
|
3
|
+
import { doingItWrong } from "../src/cli/doing-it-wrong.js";
|
|
4
4
|
|
|
5
5
|
await runCli(doingItWrong);
|
package/package.json
CHANGED
package/src/cache.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, lstatSync, readdirSync, readFileSync, readlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { dotenvLines, envLines, fileHash, type Git, gitIn, sha } from "./fingerprint.
|
|
3
|
+
import { dotenvLines, envLines, fileHash, type Git, gitIn, sha } from "./fingerprint.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The local skip: a run whose whole state matches a recent pass is not run again.
|
package/src/cli/am-i-done.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { availableParallelism } from "node:os";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { findPass, recordPass, stateKey } from "../cache.
|
|
5
|
-
import { type Config, loadConfig } from "../config.
|
|
6
|
-
import { detectContext } from "../context.
|
|
7
|
-
import { gitIn } from "../fingerprint.
|
|
8
|
-
import { consoleLogger, PLAIN, runOutput, styleFor } from "../log.
|
|
9
|
-
import { type PlannedStage, type RunOptions, runStages } from "../runner.
|
|
10
|
-
import { planStages } from "../stages/load.
|
|
11
|
-
import { today } from "../today.
|
|
12
|
-
import type { Context, Logger } from "../types.
|
|
4
|
+
import { findPass, recordPass, stateKey } from "../cache.js";
|
|
5
|
+
import { type Config, loadConfig } from "../config.js";
|
|
6
|
+
import { detectContext } from "../context.js";
|
|
7
|
+
import { gitIn } from "../fingerprint.js";
|
|
8
|
+
import { consoleLogger, PLAIN, runOutput, styleFor } from "../log.js";
|
|
9
|
+
import { type PlannedStage, type RunOptions, runStages } from "../runner.js";
|
|
10
|
+
import { planStages } from "../stages/load.js";
|
|
11
|
+
import { today } from "../today.js";
|
|
12
|
+
import type { Context, Logger } from "../types.js";
|
|
13
13
|
|
|
14
14
|
export const USAGE = `Usage: am-i-done [options]
|
|
15
15
|
|
|
@@ -19,6 +19,7 @@ Runs every stage of the project's definition of done, and says whether the work
|
|
|
19
19
|
--mode <name> Run a mode by name
|
|
20
20
|
--only <stage> Run one stage, by id or number
|
|
21
21
|
--from <stage> Start at a stage, by id or number
|
|
22
|
+
--skip <stage> Leave a stage out of this run (repeatable); the run is not a full one
|
|
22
23
|
--serial One stage at a time, output live
|
|
23
24
|
--cores <n> Core budget for running stages side by side
|
|
24
25
|
--no-fail-fast Keep going after a failure
|
|
@@ -48,6 +49,7 @@ const OPTIONS = {
|
|
|
48
49
|
mode: { type: "string" },
|
|
49
50
|
only: { type: "string" },
|
|
50
51
|
from: { type: "string" },
|
|
52
|
+
skip: { type: "string", multiple: true },
|
|
51
53
|
serial: { type: "boolean" },
|
|
52
54
|
cores: { type: "string" },
|
|
53
55
|
"no-fail-fast": { type: "boolean" },
|
|
@@ -82,8 +84,9 @@ export async function amIDone(argv: string[], io: Io): Promise<number> {
|
|
|
82
84
|
io.console.info(listPlan(plan, mode));
|
|
83
85
|
return 0;
|
|
84
86
|
}
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
+
const skipped = values.skip ?? [];
|
|
88
|
+
const selected = without(select(plan, values.only, values.from), skipped);
|
|
89
|
+
const whole = wholeRun(values);
|
|
87
90
|
const cache = whole ? localCache(config, context, mode, io.env) : undefined;
|
|
88
91
|
const age = cache?.lastPass();
|
|
89
92
|
if (age !== undefined) {
|
|
@@ -97,6 +100,7 @@ export async function amIDone(argv: string[], io: Io): Promise<number> {
|
|
|
97
100
|
progress: out.progress,
|
|
98
101
|
});
|
|
99
102
|
if (report.success) cache?.record();
|
|
103
|
+
if (skipped.length > 0) io.console.warn(`⚠ not a full run: --skip left out ${skipped.join(", ")}`);
|
|
100
104
|
const kept = out.finish(report.success);
|
|
101
105
|
if (kept !== undefined) io.console.error(`Full log: ${kept}`);
|
|
102
106
|
return report.success ? 0 : 1;
|
|
@@ -163,14 +167,33 @@ export function select(plan: readonly PlannedStage[], only?: string, from?: stri
|
|
|
163
167
|
return i;
|
|
164
168
|
};
|
|
165
169
|
if (only !== undefined) {
|
|
166
|
-
|
|
167
|
-
return [{ stage: stage.stage, deps: [] }];
|
|
170
|
+
return [{ ...(plan[at(only)] as PlannedStage), deps: [] }];
|
|
168
171
|
}
|
|
169
172
|
if (from === undefined) return [...plan];
|
|
170
173
|
const start = at(from);
|
|
171
|
-
return plan
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
return plan.slice(start).map((p) => ({ ...p, deps: p.deps.filter((d) => d >= start).map((d) => d - start) }));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A run of every stage this mode has, which alone may use or record the local skip. */
|
|
178
|
+
const wholeRun = (values: Flags): boolean =>
|
|
179
|
+
values.only === undefined && values.from === undefined && (values.skip ?? []).length === 0 && !values["no-cache"];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The plan without `ids`, for a run that cannot do some stages here (one that needs data this
|
|
183
|
+
* machine lacks). A stage that waited on a skipped one no longer waits. It never counts as a full
|
|
184
|
+
* run: nothing is cached, and the run says what it left out.
|
|
185
|
+
*/
|
|
186
|
+
export function without(plan: readonly PlannedStage[], ids: readonly string[]): PlannedStage[] {
|
|
187
|
+
const unknown = ids.filter((id) => !plan.some((p) => p.stage.id === id));
|
|
188
|
+
if (unknown.length > 0)
|
|
189
|
+
throw new Error(
|
|
190
|
+
`--skip: no stage ${unknown.map((id) => `"${id}"`).join(", ")} in this run. Stages: ${plan.map((p) => p.stage.id).join(", ")}`,
|
|
191
|
+
);
|
|
192
|
+
const kept = plan.flatMap((p, i) => (ids.includes(p.stage.id) ? [] : [i]));
|
|
193
|
+
return kept.map((i) => {
|
|
194
|
+
const p = plan[i] as PlannedStage;
|
|
195
|
+
return { ...p, deps: p.deps.flatMap((d) => (kept.includes(d) ? [kept.indexOf(d)] : [])) };
|
|
196
|
+
});
|
|
174
197
|
}
|
|
175
198
|
|
|
176
199
|
export function listPlan(plan: readonly PlannedStage[], mode: string): string {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { relative, resolve } from "node:path";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { loadConfig } from "../config.
|
|
4
|
-
import { loadRules, runEngine } from "../engine/engine.
|
|
5
|
-
import { formatCatalog, formatResult, SHOWN_PER_RULE } from "../engine/report.
|
|
6
|
-
import { styleFor } from "../log.
|
|
7
|
-
import { today } from "../today.
|
|
8
|
-
import type { Io } from "./am-i-done.
|
|
3
|
+
import { loadConfig } from "../config.js";
|
|
4
|
+
import { loadRules, runEngine } from "../engine/engine.js";
|
|
5
|
+
import { formatCatalog, formatResult, SHOWN_PER_RULE } from "../engine/report.js";
|
|
6
|
+
import { styleFor } from "../log.js";
|
|
7
|
+
import { today } from "../today.js";
|
|
8
|
+
import type { Io } from "./am-i-done.js";
|
|
9
9
|
|
|
10
10
|
export const USAGE = `Usage: doing-it-wrong [paths...] [options]
|
|
11
11
|
|
package/src/cli/init.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { CONFIG_FILE } from "../config.
|
|
5
|
-
import type { Io } from "./am-i-done.
|
|
4
|
+
import { CONFIG_FILE } from "../config.js";
|
|
5
|
+
import type { Io } from "./am-i-done.js";
|
|
6
6
|
|
|
7
7
|
export const TEMPLATES = join(import.meta.dir, "..", "..", "templates");
|
|
8
8
|
|
package/src/config.ts
CHANGED
package/src/context.ts
CHANGED
package/src/engine/engine.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join, relative } from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { Config } from "../config.
|
|
4
|
-
import { ID, loadModules } from "../modules.
|
|
5
|
-
import { today } from "../today.
|
|
6
|
-
import { warnUntilProblems, warnUntilSchema } from "../waivers.
|
|
7
|
-
import { chooseParser, loadParser } from "./ast.
|
|
8
|
-
import { evaluate, type Workspace, wantsTests, workspace } from "./evaluate.
|
|
9
|
-
import { fileMeta, listFiles, matchesAny } from "./files.
|
|
10
|
-
import { checkFixtures, FIXTURE_DIR, loadFixtures } from "./fixtures.
|
|
11
|
-
import type { FileMeta, Rule, Violation } from "./rule.
|
|
3
|
+
import type { Config } from "../config.js";
|
|
4
|
+
import { ID, loadModules } from "../modules.js";
|
|
5
|
+
import { today } from "../today.js";
|
|
6
|
+
import { warnUntilProblems, warnUntilSchema } from "../waivers.js";
|
|
7
|
+
import { chooseParser, loadParser } from "./ast.js";
|
|
8
|
+
import { evaluate, type Workspace, wantsTests, workspace } from "./evaluate.js";
|
|
9
|
+
import { fileMeta, listFiles, matchesAny } from "./files.js";
|
|
10
|
+
import { checkFixtures, FIXTURE_DIR, loadFixtures } from "./fixtures.js";
|
|
11
|
+
import type { FileMeta, Rule, Violation } from "./rule.js";
|
|
12
12
|
|
|
13
13
|
/** Where the built-in rules live. */
|
|
14
14
|
export const BUILTIN_RULES = join(import.meta.dir, "..", "rules");
|
package/src/engine/evaluate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Ast, type Parser, parseLoaded } from "./ast.
|
|
2
|
-
import { buildGraph, type ImportGraph } from "./graph.
|
|
3
|
-
import { jsxIn, maskComments, maskNonCode, maskNonComments } from "./mask.
|
|
1
|
+
import { type Ast, type Parser, parseLoaded } from "./ast.js";
|
|
2
|
+
import { buildGraph, type ImportGraph } from "./graph.js";
|
|
3
|
+
import { jsxIn, maskComments, maskNonCode, maskNonComments } from "./mask.js";
|
|
4
4
|
import {
|
|
5
5
|
type CheckRule,
|
|
6
6
|
type FileMeta,
|
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
snippetAt,
|
|
15
15
|
type Verdict,
|
|
16
16
|
type Violation,
|
|
17
|
-
} from "./rule.
|
|
18
|
-
import { covers, type Suppression, suppressions } from "./suppress.
|
|
17
|
+
} from "./rule.js";
|
|
18
|
+
import { covers, type Suppression, suppressions } from "./suppress.js";
|
|
19
19
|
|
|
20
20
|
/** Whether `rule` looks at `file` at all, by its `tests` setting. Path globs are the caller's concern. */
|
|
21
21
|
export function wantsTests(rule: Rule, file: FileMeta): boolean {
|
package/src/engine/files.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { extname, join } from "node:path";
|
|
3
|
-
import { gitIn } from "../fingerprint.
|
|
4
|
-
import type { FileMeta } from "./rule.
|
|
3
|
+
import { gitIn } from "../fingerprint.js";
|
|
4
|
+
import type { FileMeta } from "./rule.js";
|
|
5
5
|
|
|
6
6
|
const SCRIPT_LOADERS: Record<string, Bun.JavaScriptLoader> = {
|
|
7
7
|
ts: "ts",
|
package/src/engine/fixtures.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Parser } from "./ast.
|
|
4
|
-
import { type Evaluation, evaluate, wantsTests, workspace } from "./evaluate.
|
|
5
|
-
import { fileMeta, matchesAny } from "./files.
|
|
6
|
-
import type { FileMeta, Rule } from "./rule.
|
|
3
|
+
import type { Parser } from "./ast.js";
|
|
4
|
+
import { type Evaluation, evaluate, wantsTests, workspace } from "./evaluate.js";
|
|
5
|
+
import { fileMeta, matchesAny } from "./files.js";
|
|
6
|
+
import type { FileMeta, Rule } from "./rule.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Rule fixtures: one file per scenario, `<rulesDir>/fixtures/<rule-id>__<scenario>.<ext>.fixture`.
|
package/src/engine/graph.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname, join, normalize, relative } from "node:path";
|
|
2
|
-
import { type FileMeta, SCRIPT_EXTENSION_ORDER } from "./rule.
|
|
2
|
+
import { type FileMeta, SCRIPT_EXTENSION_ORDER } from "./rule.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The project's import graph: which project file imports which.
|
package/src/engine/report.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Style } from "../log.
|
|
2
|
-
import type { EngineResult } from "./engine.
|
|
3
|
-
import type { Rule, Violation } from "./rule.
|
|
1
|
+
import type { Style } from "../log.js";
|
|
2
|
+
import type { EngineResult } from "./engine.js";
|
|
3
|
+
import type { Rule, Violation } from "./rule.js";
|
|
4
4
|
|
|
5
5
|
/** Violations shown per rule unless `--all`. */
|
|
6
6
|
export const SHOWN_PER_RULE = 10;
|
package/src/engine/rule.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WarnUntil } from "../waivers.
|
|
1
|
+
import type { WarnUntil } from "../waivers.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The rule DSL.
|
|
@@ -11,8 +11,8 @@ import type { WarnUntil } from "../waivers.ts";
|
|
|
11
11
|
* clean.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import type { Ast } from "./ast.
|
|
15
|
-
import type { ImportGraph } from "./graph.
|
|
14
|
+
import type { Ast } from "./ast.js";
|
|
15
|
+
import type { ImportGraph } from "./graph.js";
|
|
16
16
|
|
|
17
17
|
declare const VERDICT: unique symbol;
|
|
18
18
|
export type Verdict = { readonly [VERDICT]: "checked" | "skipped" };
|
package/src/engine/suppress.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { citesIssue } from "../waivers.
|
|
2
|
-
import { jsxIn, maskNonComments } from "./mask.
|
|
3
|
-
import { SCRIPT_EXTENSIONS } from "./rule.
|
|
1
|
+
import { citesIssue } from "../waivers.js";
|
|
2
|
+
import { jsxIn, maskNonComments } from "./mask.js";
|
|
3
|
+
import { SCRIPT_EXTENSIONS } from "./rule.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Suppression comments.
|
package/src/index.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* import type { Stage } from "am-i-done";
|
|
5
5
|
* export default { id: "docs", description: "Build the docs", command: "bun run docs" } satisfies Stage;
|
|
6
6
|
*/
|
|
7
|
-
export { type Ast, type Parser, type Raw, type TSESTree, walk } from "./engine/ast.
|
|
8
|
-
export type { ImportGraph } from "./engine/graph.
|
|
9
|
-
export type { CheckRule, FileMeta, ImportRule, PatternRule, Rule, RuleContext, Verdict } from "./engine/rule.
|
|
10
|
-
export { BIOME_LEFTOVERS, REACT_ACT } from "./output-guard.
|
|
11
|
-
export { type SpawnOptions, type SpawnResult, spawnCaptured } from "./spawn.
|
|
7
|
+
export { type Ast, type Parser, type Raw, type TSESTree, walk } from "./engine/ast.js";
|
|
8
|
+
export type { ImportGraph } from "./engine/graph.js";
|
|
9
|
+
export type { CheckRule, FileMeta, ImportRule, PatternRule, Rule, RuleContext, Verdict } from "./engine/rule.js";
|
|
10
|
+
export { BIOME_LEFTOVERS, REACT_ACT } from "./output-guard.js";
|
|
11
|
+
export { type SpawnOptions, type SpawnResult, spawnCaptured } from "./spawn.js";
|
|
12
12
|
export type {
|
|
13
13
|
Context,
|
|
14
14
|
ContextFilter,
|
|
@@ -19,5 +19,5 @@ export type {
|
|
|
19
19
|
StageFunction,
|
|
20
20
|
StageOptions,
|
|
21
21
|
StageResult,
|
|
22
|
-
} from "./types.
|
|
23
|
-
export type { WarnUntil } from "./waivers.
|
|
22
|
+
} from "./types.js";
|
|
23
|
+
export type { WarnUntil } from "./waivers.js";
|
package/src/log.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Context, Logger } from "./types.
|
|
3
|
+
import type { Context, Logger } from "./types.js";
|
|
4
4
|
|
|
5
5
|
type Paint = (text: string) => string;
|
|
6
6
|
export interface Style {
|
package/src/output-guard.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { expect, it } from "bun:test";
|
|
2
|
+
it("treats /tmp paths as data", () => {
|
|
3
|
+
expect(batchRoot("/tmp/x/om-1")).toEqual({ root: "/tmp/x/om-1" });
|
|
4
|
+
expect(parseArgs(["--out", "/tmp/x"])).toEqual({ out: "/tmp/x" });
|
|
5
|
+
expect(message).toBe('ENOENT reading "/tmp/x/src/z.spec.ts"');
|
|
6
|
+
});
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
// @expect
|
|
1
|
+
// @expect 10
|
|
2
2
|
import { mkdtempSync } from "node:fs";
|
|
3
3
|
import os, { tmpdir as tmp } from "node:os";
|
|
4
4
|
const a = mkdtempSync(join(os.tmpdir(), "x-"));
|
|
5
5
|
const b = await fs.promises.mkdtemp("y");
|
|
6
6
|
using c = fs.mkdtempDisposableSync(tmp());
|
|
7
|
-
|
|
7
|
+
writeFileSync("/tmp/fixed/out.json", "{}");
|
|
8
|
+
await Bun.write(`/tmp/${name}.txt`, data);
|
|
9
|
+
Bun.spawn(["make"], { cwd: "/tmp/build" });
|
|
10
|
+
Bun.spawn(["make"], { env: { TMPDIR: "/tmp" } });
|
|
8
11
|
await $`mktemp -d`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Rule } from "../engine/rule.
|
|
1
|
+
import type { Rule } from "../engine/rule.js";
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
id: "no-empty-catch",
|
|
@@ -10,8 +10,8 @@ export default {
|
|
|
10
10
|
scope: "all",
|
|
11
11
|
scold: "An empty catch swallows the error, and whatever went wrong goes on silently.",
|
|
12
12
|
guidance: [
|
|
13
|
-
"Handle the error, rethrow it
|
|
13
|
+
"Handle the error, or rethrow it. Returning `null` or `undefined` is still swallowing it, unless the caller treats that value as the failure.",
|
|
14
14
|
"If ignoring it is correct, say why in a comment inside the block: `catch { /* ENOENT: already gone */ }`,",
|
|
15
|
-
"or inside the handler: `.catch(() => { /* best effort: the cache is rebuilt on read */ })`.",
|
|
15
|
+
"or inside the handler: `.catch(() => { /* best effort: the cache is rebuilt on read */ })`, or before the value it returns: `.catch(() => /* absent means not cached */ null)`.",
|
|
16
16
|
],
|
|
17
17
|
} satisfies Rule;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxIn, maskComments } from "../engine/mask.
|
|
2
|
-
import { importOffset, position, type Rule, snippetAt } from "../engine/rule.
|
|
1
|
+
import { jsxIn, maskComments } from "../engine/mask.js";
|
|
2
|
+
import { importOffset, position, type Rule, snippetAt } from "../engine/rule.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A cycle makes load order matter: one module of it sees another half-initialised, and the bug
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import { maskComments, maskNonCode } from "../engine/mask.
|
|
3
|
-
import { position, type Rule, snippetAt } from "../engine/rule.
|
|
2
|
+
import { maskComments, maskNonCode } from "../engine/mask.js";
|
|
3
|
+
import { position, type Rule, snippetAt } from "../engine/rule.js";
|
|
4
4
|
|
|
5
5
|
/** The helper itself: the one file allowed to make temp directories by hand. */
|
|
6
6
|
const OWNER = join(import.meta.dir, "..", "tmp.ts");
|
|
7
7
|
const CALLS = /\b(?:mkdtemp|mkdtempSync|mkdtempDisposable|mkdtempDisposableSync|tmpdir)\s*\(/g;
|
|
8
8
|
const ALIAS = /\btmpdir\s+as\s+([A-Za-z_$][\w$]*)/g;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A `/tmp/...` literal is a temp file only where something is made there: handed to a call that
|
|
11
|
+
* writes, or set as a child's working or temp directory. Elsewhere it is just a path (a test input,
|
|
12
|
+
* an expected value), and nothing is created. A path held in a variable and written later is
|
|
13
|
+
* beyond a pattern.
|
|
14
|
+
*/
|
|
15
|
+
const SINKS =
|
|
16
|
+
"mkdir|mkdirSync|writeFile|writeFileSync|appendFile|appendFileSync|open|openSync|createWriteStream|cp|cpSync|copyFile|copyFileSync|rename|renameSync|symlink|symlinkSync|Bun\\.write";
|
|
17
|
+
const LITERALS = new RegExp(
|
|
18
|
+
`\\b(?:${SINKS})\\s*\\(\\s*["'\`]\\/tmp\\/|\\b(?:cwd|TMPDIR|TMP|TEMP)\\s*:\\s*["'\`]\\/tmp\\b|\\bmktemp\\b`,
|
|
19
|
+
"g",
|
|
20
|
+
);
|
|
10
21
|
|
|
11
22
|
/**
|
|
12
23
|
* Temp directories made by hand leak: a spec that throws before its cleanup, or a run that is
|
|
@@ -25,6 +36,7 @@ export default {
|
|
|
25
36
|
"Code that runs outside specs uses the same helper; what a scope misses goes at exit, and a killed process's leftovers on the next run.",
|
|
26
37
|
'Add `preload = ["am-i-done/tmp/preload"]` under [test] in bunfig.toml to sweep at the start and end of every test run.',
|
|
27
38
|
"A child process that needs a temp dir gets one passed in (its TMPDIR set to `dir.path`), not a hard-coded /tmp path.",
|
|
39
|
+
"A project with a temp helper of its own exempts that one file: // doing-it-wrong-ignore-file no-raw-temp: <why> (#123)",
|
|
28
40
|
],
|
|
29
41
|
check(ctx) {
|
|
30
42
|
if (ctx.file.path === OWNER) return ctx.skipped();
|
package/src/runner.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { availableParallelism, loadavg } from "node:os";
|
|
3
|
-
import { bufferedLogger, formatDuration, type Style } from "./log.
|
|
4
|
-
import { describeFindings, scanOutput } from "./output-guard.
|
|
5
|
-
import { schedule } from "./scheduler.
|
|
6
|
-
import { endAll, spawnCaptured } from "./spawn.
|
|
7
|
-
import { stageArgv } from "./stage-process.
|
|
8
|
-
import { tmpDir } from "./tmp.
|
|
9
|
-
import type { Context, Logger, Stage, StageOptions, StageResult } from "./types.
|
|
3
|
+
import { bufferedLogger, formatDuration, type Style } from "./log.js";
|
|
4
|
+
import { describeFindings, scanOutput } from "./output-guard.js";
|
|
5
|
+
import { schedule } from "./scheduler.js";
|
|
6
|
+
import { endAll, spawnCaptured } from "./spawn.js";
|
|
7
|
+
import { stageArgv } from "./stage-process.js";
|
|
8
|
+
import { tmpDir } from "./tmp.js";
|
|
9
|
+
import type { Context, Logger, Stage, StageOptions, StageResult } from "./types.js";
|
|
10
10
|
|
|
11
11
|
export type Rerun = "diagnose" | "off" | "pass";
|
|
12
12
|
/** `warn`: failed, but its `warnUntil` date has not come. `blocked`: never started. */
|
package/src/spawn.ts
CHANGED
package/src/spec-cache.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { extname, join, relative } from "node:path";
|
|
3
|
-
import { fileMeta, listFiles } from "./engine/files.
|
|
4
|
-
import { buildGraph } from "./engine/graph.
|
|
5
|
-
import { SCRIPT_EXTENSIONS } from "./engine/rule.
|
|
6
|
-
import { dotenvLines, envLines, fileHash, sha } from "./fingerprint.
|
|
3
|
+
import { fileMeta, listFiles } from "./engine/files.js";
|
|
4
|
+
import { buildGraph } from "./engine/graph.js";
|
|
5
|
+
import { SCRIPT_EXTENSIONS } from "./engine/rule.js";
|
|
6
|
+
import { dotenvLines, envLines, fileHash, sha } from "./fingerprint.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The per-spec cache: a spec whose inputs are unchanged since it last passed is not run again.
|
package/src/stage-process.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
|
-
import { consoleLogger } from "./log.
|
|
3
|
-
import type { Context, Logger, Stage, StageResult } from "./types.
|
|
2
|
+
import { consoleLogger } from "./log.js";
|
|
3
|
+
import type { Context, Logger, Stage, StageResult } from "./types.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Where a function stage runs: a `bun` process of its own, started by the runner like any command.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Stage } from "../../types.
|
|
3
|
+
import type { Stage } from "../../types.js";
|
|
4
4
|
|
|
5
5
|
/** `package.json`'s `packageManager` when it names Bun, else `undefined`. */
|
|
6
6
|
export function bunPin(root: string): string | undefined {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { BIOME_LEFTOVERS } from "../../output-guard.
|
|
4
|
-
import type { Stage, StageOptions } from "../../types.
|
|
3
|
+
import { BIOME_LEFTOVERS } from "../../output-guard.js";
|
|
4
|
+
import type { Stage, StageOptions } from "../../types.js";
|
|
5
5
|
|
|
6
6
|
const checkOnly = (options: StageOptions): StageOptions => ({ ...options, args: ["."] });
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { loadConfig } from "../../config.
|
|
2
|
-
import { loadRules, runEngine } from "../../engine/engine.
|
|
3
|
-
import { formatResult } from "../../engine/report.
|
|
4
|
-
import { PLAIN } from "../../log.
|
|
5
|
-
import { today } from "../../today.
|
|
6
|
-
import type { Stage } from "../../types.
|
|
1
|
+
import { loadConfig } from "../../config.js";
|
|
2
|
+
import { loadRules, runEngine } from "../../engine/engine.js";
|
|
3
|
+
import { formatResult } from "../../engine/report.js";
|
|
4
|
+
import { PLAIN } from "../../log.js";
|
|
5
|
+
import { today } from "../../today.js";
|
|
6
|
+
import type { Stage } from "../../types.js";
|
|
7
7
|
|
|
8
8
|
/** In-process: the rules share the runner's process and read every file once. */
|
|
9
9
|
export default {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type Config, loadConfig } from "../../config.
|
|
2
|
-
import { REACT_ACT, scanOutput } from "../../output-guard.
|
|
3
|
-
import { spawnCaptured } from "../../spawn.
|
|
4
|
-
import { measuresCoverage, planSpecs } from "../../spec-cache.
|
|
5
|
-
import type { Stage, StageOptions, StageResult } from "../../types.
|
|
1
|
+
import { type Config, loadConfig } from "../../config.js";
|
|
2
|
+
import { REACT_ACT, scanOutput } from "../../output-guard.js";
|
|
3
|
+
import { spawnCaptured } from "../../spawn.js";
|
|
4
|
+
import { measuresCoverage, planSpecs } from "../../spec-cache.js";
|
|
5
|
+
import type { Stage, StageOptions, StageResult } from "../../types.js";
|
|
6
6
|
|
|
7
7
|
async function bunTest(options: StageOptions, paths: string[]): Promise<StageResult> {
|
|
8
8
|
const argv = ["bun", "test", ...options.args, ...paths.map((p) => `./${p}`)];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { Stage } from "../../types.
|
|
3
|
+
import type { Stage } from "../../types.js";
|
|
4
4
|
|
|
5
5
|
/** `--no-script`: without it `bun check` runs a package.json `check` script, which may be this gate. */
|
|
6
6
|
export default {
|
package/src/stages/load.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { Config } from "../config.
|
|
4
|
-
import { ID, loadModules } from "../modules.
|
|
5
|
-
import type { PlannedStage } from "../runner.
|
|
6
|
-
import { today } from "../today.
|
|
7
|
-
import { PHASES, type Stage, type StageFunction } from "../types.
|
|
8
|
-
import { warnUntilProblems, warnUntilSchema } from "../waivers.
|
|
9
|
-
import { order } from "./order.
|
|
3
|
+
import type { Config } from "../config.js";
|
|
4
|
+
import { ID, loadModules } from "../modules.js";
|
|
5
|
+
import type { PlannedStage } from "../runner.js";
|
|
6
|
+
import { today } from "../today.js";
|
|
7
|
+
import { PHASES, type Stage, type StageFunction } from "../types.js";
|
|
8
|
+
import { warnUntilProblems, warnUntilSchema } from "../waivers.js";
|
|
9
|
+
import { order } from "./order.js";
|
|
10
10
|
|
|
11
11
|
/** Where the built-in stages live. */
|
|
12
12
|
export const BUILTIN_DIR = join(import.meta.dir, "builtin");
|
package/src/stages/order.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PlannedStage } from "../runner.
|
|
2
|
-
import { PHASES, type Phase, type Stage } from "../types.
|
|
1
|
+
import type { PlannedStage } from "../runner.js";
|
|
2
|
+
import { PHASES, type Phase, type Stage } from "../types.js";
|
|
3
3
|
|
|
4
4
|
const rank = (stage: Stage): number => PHASES.indexOf(stage.phase ?? "check");
|
|
5
5
|
const phaseOf = (stage: Stage): Phase => stage.phase ?? "check";
|
package/src/tmp-preload.ts
CHANGED
package/src/types.ts
CHANGED