@sshkeda/check 1.0.0 → 1.0.2
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/docs/how-to-make-check-pass.md +1 -1
- package/package.json +1 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +25 -4
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +9 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +5 -1
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +89 -15
|
@@ -37,7 +37,7 @@ These names need no reason:
|
|
|
37
37
|
- `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
|
|
38
38
|
- `pollsWithADeadline`: Allows `Effect.repeat` with `Schedule.spaced`, under a deadline.
|
|
39
39
|
- `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
|
|
40
|
-
- `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `
|
|
40
|
+
- `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `.github`. Check doesn't apply its directory-shape rules inside it, but files there still need their own `hasAnUnlistedFileType` grant.
|
|
41
41
|
- `patchesADependency`: Allows a patch file from `bun patch`.
|
|
42
42
|
|
|
43
43
|
These names need a reason, written as `{ name: "reason" }`:
|
package/package.json
CHANGED
|
@@ -408,6 +408,19 @@ const PACKAGE_ROOT_DIRECTORIES: ReadonlySet<string> = new Set([
|
|
|
408
408
|
DOCS_DIRECTORY,
|
|
409
409
|
]);
|
|
410
410
|
|
|
411
|
+
const isRootDirectoryOutsideTheLayout = (directory: string) =>
|
|
412
|
+
!directory.includes("/") && !PACKAGE_ROOT_DIRECTORIES.has(directory);
|
|
413
|
+
|
|
414
|
+
const directoriesExemptFromShapeRules = (
|
|
415
|
+
directories: Iterable<string>,
|
|
416
|
+
grants: Effect.Success<ReturnType<typeof loadedLintConfigIn>>,
|
|
417
|
+
) =>
|
|
418
|
+
[...directories].filter(
|
|
419
|
+
(directory) =>
|
|
420
|
+
isRootDirectoryOutsideTheLayout(directory) &&
|
|
421
|
+
grants.some((grant) => grant.path === directory && grant.allow.includes(DIRECTORY)),
|
|
422
|
+
);
|
|
423
|
+
|
|
411
424
|
export const directoriesHoldingOnlyADirectory = (
|
|
412
425
|
paths: readonly string[],
|
|
413
426
|
nestedPackageDirectories: readonly string[],
|
|
@@ -589,8 +602,8 @@ export const permissionGrantViolations = (
|
|
|
589
602
|
]),
|
|
590
603
|
...outermostPackageDirectories,
|
|
591
604
|
]);
|
|
592
|
-
const directoriesNeedingGrants = [...ownedDirectories].filter(
|
|
593
|
-
(directory)
|
|
605
|
+
const directoriesNeedingGrants = [...ownedDirectories].filter((directory) =>
|
|
606
|
+
isRootDirectoryOutsideTheLayout(directory),
|
|
594
607
|
);
|
|
595
608
|
const violations: (
|
|
596
609
|
| CannotImportTargetMissing
|
|
@@ -770,6 +783,12 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
770
783
|
const ownedDirectories = new Set(
|
|
771
784
|
distinctDirectoriesOf([...ownedPaths, ...nestedPackageDirectories]),
|
|
772
785
|
);
|
|
786
|
+
const shapeExemptDirectories = Option.match(grants, {
|
|
787
|
+
onNone: () => [],
|
|
788
|
+
onSome: (found) => directoriesExemptFromShapeRules(ownedDirectories, found),
|
|
789
|
+
});
|
|
790
|
+
const isShapeChecked = ({ location }: { readonly location: string }) =>
|
|
791
|
+
!shapeExemptDirectories.some((exempt) => isWithin(location, exempt));
|
|
773
792
|
const grantViolations = Option.match(grants, {
|
|
774
793
|
onNone: () => [],
|
|
775
794
|
onSome: (found) => [
|
|
@@ -812,11 +831,13 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
812
831
|
const violations = [
|
|
813
832
|
...fileViolations.flat(),
|
|
814
833
|
...directoryNameViolations(ownedPaths),
|
|
815
|
-
...directoryShapeViolations(ownedPaths),
|
|
834
|
+
...directoryShapeViolations(ownedPaths).filter((violation) => isShapeChecked(violation)),
|
|
816
835
|
...directoriesHoldingOnlyADirectory(
|
|
817
836
|
[...new Set([...paths, ...generated])],
|
|
818
837
|
nestedPackageDirectories,
|
|
819
|
-
).filter(
|
|
838
|
+
).filter(
|
|
839
|
+
(violation) => ownedDirectories.has(violation.location) && isShapeChecked(violation),
|
|
840
|
+
),
|
|
820
841
|
...packageRootViolations(ownedPaths),
|
|
821
842
|
...duplicateFileNameViolations(ownedPaths),
|
|
822
843
|
...grantViolations,
|
|
@@ -336,6 +336,15 @@ export class ToolExited extends Schema.TaggedError<ToolExited>()("ToolExited", {
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
+
export class ToolNotStarted extends Schema.TaggedError<ToolNotStarted>()("ToolNotStarted", {
|
|
340
|
+
command: Schema.String,
|
|
341
|
+
reason: Schema.String,
|
|
342
|
+
}) {
|
|
343
|
+
public override get message() {
|
|
344
|
+
return `${this.command} did not start: ${this.reason}`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
339
348
|
export class ToolStoppedBySignal extends Schema.TaggedError<ToolStoppedBySignal>()(
|
|
340
349
|
"ToolStoppedBySignal",
|
|
341
350
|
{ program: Schema.String, command: Schema.String, signal: Schema.String },
|
|
@@ -280,7 +280,11 @@ const compiledFilesOf = (
|
|
|
280
280
|
const projectDirectory = path.dirname(yield* absolutePathOf(projectFile));
|
|
281
281
|
const listedFilesOfEachProject = yield* Effect.forEach(projects, ([configFile, { program }]) =>
|
|
282
282
|
typeScriptRequest("list the program files", () => program.getSourceFileNames()).pipe(
|
|
283
|
-
Effect.map((fileNames) => ({
|
|
283
|
+
Effect.map((fileNames) => ({
|
|
284
|
+
configFile,
|
|
285
|
+
program,
|
|
286
|
+
fileNames: fileNames.filter((fileName) => path.isAbsolute(fileName)),
|
|
287
|
+
})),
|
|
284
288
|
),
|
|
285
289
|
);
|
|
286
290
|
const everyListedFile = listedFilesOfEachProject.flatMap(({ fileNames }) => fileNames);
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
import type { Subprocess } from "bun";
|
|
1
4
|
import type { Array as Arrays, Schema } from "effect";
|
|
2
|
-
import { Effect,
|
|
3
|
-
import { ChildProcess } from "effect/process";
|
|
5
|
+
import { Effect, FileSystem } from "effect";
|
|
4
6
|
|
|
5
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ToolExited,
|
|
9
|
+
ToolNotStarted,
|
|
10
|
+
ToolReportUndecodable,
|
|
11
|
+
ToolStoppedBySignal,
|
|
12
|
+
} from "./project-config-and-tool-errors.ts";
|
|
6
13
|
|
|
7
14
|
const LINE_BREAK = "\n";
|
|
8
15
|
|
|
@@ -48,6 +55,65 @@ export const mergedExit = (exits: Arrays.NonEmptyReadonlyArray<ToolExited>) => {
|
|
|
48
55
|
});
|
|
49
56
|
};
|
|
50
57
|
|
|
58
|
+
const WINDOWS = "win32";
|
|
59
|
+
|
|
60
|
+
const openedStandardOutputFile = (file: string) =>
|
|
61
|
+
Effect.acquireRelease(
|
|
62
|
+
Effect.promise(() => open(file, "w")),
|
|
63
|
+
(handle) => Effect.promise(() => handle.close()),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const stopTheProcessGroupOf = (child: Subprocess) =>
|
|
67
|
+
Effect.gen(function* () {
|
|
68
|
+
if (process.platform === WINDOWS) {
|
|
69
|
+
yield* Effect.try(() =>
|
|
70
|
+
Bun.spawn(["taskkill", "/pid", `${child.pid}`, "/T", "/F"], {
|
|
71
|
+
stdin: "ignore",
|
|
72
|
+
stdout: "ignore",
|
|
73
|
+
stderr: "ignore",
|
|
74
|
+
}),
|
|
75
|
+
).pipe(
|
|
76
|
+
Effect.flatMap((taskkill) => Effect.promise(() => taskkill.exited)),
|
|
77
|
+
Effect.catchTag("UnknownError", () => Effect.void),
|
|
78
|
+
);
|
|
79
|
+
child.kill();
|
|
80
|
+
} else {
|
|
81
|
+
yield* Effect.try(() => process.kill(-child.pid, "SIGKILL")).pipe(
|
|
82
|
+
Effect.catchTag("UnknownError", () => Effect.void),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
yield* Effect.promise(() => child.exited);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const spawnedTool = (
|
|
89
|
+
command: string,
|
|
90
|
+
binary: string,
|
|
91
|
+
toolArguments: readonly string[],
|
|
92
|
+
standardOutput: number,
|
|
93
|
+
workingDirectory?: string,
|
|
94
|
+
environment?: Record<string, string>,
|
|
95
|
+
) =>
|
|
96
|
+
Effect.acquireRelease(
|
|
97
|
+
Effect.try({
|
|
98
|
+
try: () =>
|
|
99
|
+
Bun.spawn([binary, ...toolArguments], {
|
|
100
|
+
...(workingDirectory === undefined ? {} : { cwd: workingDirectory }),
|
|
101
|
+
env: { ...process.env, ...environment },
|
|
102
|
+
detached: process.platform !== WINDOWS,
|
|
103
|
+
stdin: "ignore",
|
|
104
|
+
stdout: standardOutput,
|
|
105
|
+
stderr: "pipe",
|
|
106
|
+
}),
|
|
107
|
+
catch: (cause) =>
|
|
108
|
+
new ToolNotStarted({
|
|
109
|
+
command,
|
|
110
|
+
reason:
|
|
111
|
+
cause instanceof Error ? cause.message : "the spawn threw a value that is not an Error",
|
|
112
|
+
}),
|
|
113
|
+
}),
|
|
114
|
+
stopTheProcessGroupOf,
|
|
115
|
+
);
|
|
116
|
+
|
|
51
117
|
export const runTool = (
|
|
52
118
|
program: string,
|
|
53
119
|
binary: string,
|
|
@@ -57,25 +123,33 @@ export const runTool = (
|
|
|
57
123
|
) =>
|
|
58
124
|
Effect.scoped(
|
|
59
125
|
Effect.gen(function* () {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
126
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
127
|
+
const standardOutputFile = yield* fileSystem.makeTempFileScoped();
|
|
128
|
+
const handle = yield* openedStandardOutputFile(standardOutputFile);
|
|
129
|
+
const command = [binary, ...toolArguments].join(" ");
|
|
130
|
+
const child = yield* spawnedTool(
|
|
131
|
+
command,
|
|
132
|
+
binary,
|
|
133
|
+
toolArguments,
|
|
134
|
+
handle.fd,
|
|
135
|
+
workingDirectory,
|
|
136
|
+
environment,
|
|
137
|
+
);
|
|
138
|
+
const [standardError, code] = yield* Effect.all(
|
|
68
139
|
[
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
child.exitCode,
|
|
140
|
+
Effect.promise(() => new Response(child.stderr).text()),
|
|
141
|
+
Effect.promise(() => child.exited),
|
|
72
142
|
],
|
|
73
143
|
{ concurrency: "unbounded" },
|
|
74
144
|
);
|
|
145
|
+
const standardOutput = yield* fileSystem.readFileString(standardOutputFile);
|
|
146
|
+
if (child.signalCode !== null) {
|
|
147
|
+
return yield* new ToolStoppedBySignal({ program, command, signal: `${child.signalCode}` });
|
|
148
|
+
}
|
|
75
149
|
if (code !== 0) {
|
|
76
150
|
return yield* new ToolExited({
|
|
77
151
|
program,
|
|
78
|
-
command
|
|
152
|
+
command,
|
|
79
153
|
code,
|
|
80
154
|
standardOutput,
|
|
81
155
|
standardError: standardError.trim(),
|