@sshkeda/check 3.0.0 → 4.0.1
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 +5 -41
- package/docs/how-to-grant-a-permission.md +28 -0
- package/docs/how-to-make-check-pass.md +4 -31
- package/package.json +2 -2
- package/scripts/check.ts +2 -3
- package/src/internal/ban-fixed-values-in-recoveries.ts +1 -1
- package/src/lib/project-directory/index.ts +0 -1
- package/src/lib/project-directory/internal/read-the-project-directory.ts +1 -5
- package/src/lib/tasks/internal/declare-the-check-task.ts +6 -6
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +4 -4
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +4 -4
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +4 -4
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +15 -1
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +1 -2
- package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +4 -4
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +4 -4
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +7 -29
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +14 -181
- package/src/lib/tasks/lib/enforce-file-types/index.ts +4 -4
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +28 -17
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +4 -4
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +4 -4
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +4 -4
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +4 -4
- package/src/lib/tasks/shared/check-each-nested-package.ts +2 -0
- package/src/lib/tasks/shared/declare-lint-config-task.ts +4 -4
- package/src/lib/tasks/shared/declare-start-directory-task.ts +40 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +4 -4
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +9 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +10 -15
- package/src/lib/tasks/shared/watch-the-typescript-api-process.ts +177 -0
- package/src/shared/bans-each-permission-lifts.ts +0 -7
- package/src/shared/record-and-grant-permissions-by-path.ts +1 -3
- package/src/lib/tasks/internal/verify-where-check-was-started.ts +0 -50
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +0 -178
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
2
|
import { Effect, FileSystem, Option, Path, Predicate, References, Result, Schema } from "effect";
|
|
3
|
-
import { parseSync
|
|
4
|
-
import type {
|
|
3
|
+
import { parseSync } from "oxc-parser";
|
|
4
|
+
import type { ParseResult, Statement } from "oxc-parser";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
TASK_PACKAGE,
|
|
8
|
-
TASK_NAMESPACE_EXPORT,
|
|
9
|
-
TASK_MAIN_MEMBER,
|
|
10
|
-
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
6
|
+
import { TASK_PACKAGE } from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
11
7
|
import { retiredWordIn } from "../../../../../shared/find-retired-words.ts";
|
|
12
8
|
import {
|
|
13
9
|
isEntryFileName,
|
|
@@ -65,7 +61,6 @@ import {
|
|
|
65
61
|
JSON_OBJECT,
|
|
66
62
|
packageManifestObject,
|
|
67
63
|
} from "../../../shared/read-package-manifest-object.ts";
|
|
68
|
-
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
69
64
|
import { toolFileOf, toolFileIsPlaced } from "../../../shared/tool-file-locations.ts";
|
|
70
65
|
import {
|
|
71
66
|
BunTestFileName,
|
|
@@ -93,8 +88,7 @@ import {
|
|
|
93
88
|
MisplacedToolFile,
|
|
94
89
|
TopLevelNonScript,
|
|
95
90
|
TopLevelScriptHoldsOtherStatement,
|
|
96
|
-
|
|
97
|
-
TopLevelScriptWithoutMain,
|
|
91
|
+
TopLevelScriptWithoutDefaultExport,
|
|
98
92
|
UngrantedDocument,
|
|
99
93
|
UngrantedDirectory,
|
|
100
94
|
UnlistedPatchGranted,
|
|
@@ -111,7 +105,6 @@ import {
|
|
|
111
105
|
modulesWithLayoutDirectoryNamesAmong,
|
|
112
106
|
moduleWithLayoutDirectoryNameViolations,
|
|
113
107
|
} from "./find-module-layout-violations.ts";
|
|
114
|
-
import { taskImportsIn, isTaskLayoutFile } from "./resolve-task-imports.ts";
|
|
115
108
|
|
|
116
109
|
const KEBAB_CASE_PART = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
117
110
|
const BUN_TEST_FILE_EXTENSION = /\.(?:test|spec)(?<extension>\.[^.]+)$/u;
|
|
@@ -163,116 +156,6 @@ export const pathViolations = (path: string, isNamedByBunPatch = false) => {
|
|
|
163
156
|
return violations;
|
|
164
157
|
};
|
|
165
158
|
|
|
166
|
-
const directTaskImports = (parsed: ParseResult) =>
|
|
167
|
-
new Map(
|
|
168
|
-
parsed.module.staticImports
|
|
169
|
-
.filter((declaration) => declaration.moduleRequest.value === TASK_PACKAGE)
|
|
170
|
-
.flatMap((declaration) =>
|
|
171
|
-
declaration.entries
|
|
172
|
-
.filter((entry) => !entry.isType)
|
|
173
|
-
.map(
|
|
174
|
-
(entry) =>
|
|
175
|
-
[
|
|
176
|
-
entry.localName.value,
|
|
177
|
-
entry.importName.kind === "NamespaceObject" ? [] : [entry.importName.name ?? ""],
|
|
178
|
-
] as const,
|
|
179
|
-
),
|
|
180
|
-
),
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
const callsTaskMember = (
|
|
184
|
-
parsed: ParseResult,
|
|
185
|
-
member: string,
|
|
186
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
187
|
-
) => {
|
|
188
|
-
const calls: CallExpression[] = [];
|
|
189
|
-
const aliases = new Map<string, Expression>();
|
|
190
|
-
new Visitor({
|
|
191
|
-
CallExpression(node) {
|
|
192
|
-
calls.push(node);
|
|
193
|
-
},
|
|
194
|
-
VariableDeclarator({ id, init: initializer }) {
|
|
195
|
-
const isNamedInitializer = id.type === "Identifier" && initializer !== null;
|
|
196
|
-
if (isNamedInitializer) {
|
|
197
|
-
aliases.set(id.name, initializer);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
}).visit(parsed.program);
|
|
201
|
-
const taskReference = (
|
|
202
|
-
expression: Expression,
|
|
203
|
-
seen: ReadonlySet<string> = new Set(),
|
|
204
|
-
): readonly string[] | undefined => {
|
|
205
|
-
if (expression.type === "Identifier") {
|
|
206
|
-
const imported = imports.get(expression.name);
|
|
207
|
-
if (imported !== undefined) {
|
|
208
|
-
return imported;
|
|
209
|
-
}
|
|
210
|
-
const alias = aliases.get(expression.name);
|
|
211
|
-
const isUnfollowedAlias = alias !== undefined && !seen.has(expression.name);
|
|
212
|
-
return isUnfollowedAlias
|
|
213
|
-
? taskReference(alias, new Set([...seen, expression.name]))
|
|
214
|
-
: undefined;
|
|
215
|
-
}
|
|
216
|
-
const isStaticMember =
|
|
217
|
-
expression.type === "MemberExpression" &&
|
|
218
|
-
!expression.computed &&
|
|
219
|
-
expression.property.type === "Identifier";
|
|
220
|
-
if (!isStaticMember) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const object = taskReference(expression.object, seen);
|
|
224
|
-
return object === undefined ? undefined : [...object, expression.property.name];
|
|
225
|
-
};
|
|
226
|
-
return calls.some(
|
|
227
|
-
({ callee }) => taskReference(callee)?.join(".") === `${TASK_NAMESPACE_EXPORT}.${member}`,
|
|
228
|
-
);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const importedMemberPath = (
|
|
232
|
-
expression: Expression,
|
|
233
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
234
|
-
): readonly string[] | undefined => {
|
|
235
|
-
if (expression.type === "Identifier") {
|
|
236
|
-
return imports.get(expression.name);
|
|
237
|
-
}
|
|
238
|
-
const isStaticMember =
|
|
239
|
-
expression.type === "MemberExpression" &&
|
|
240
|
-
!expression.computed &&
|
|
241
|
-
expression.property.type === "Identifier";
|
|
242
|
-
if (!isStaticMember) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
const object = importedMemberPath(expression.object, imports);
|
|
246
|
-
return object === undefined ? undefined : [...object, expression.property.name];
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const isMainGuard = (statement: Statement, imports: ReadonlyMap<string, readonly string[]>) => {
|
|
250
|
-
if (statement.type !== "IfStatement") {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
const { test, consequent, alternate } = statement;
|
|
254
|
-
const testsImportMetaMain =
|
|
255
|
-
test.type === "MemberExpression" &&
|
|
256
|
-
!test.computed &&
|
|
257
|
-
test.object.type === "MetaProperty" &&
|
|
258
|
-
test.object.meta.name === "import" &&
|
|
259
|
-
test.object.property.name === "meta" &&
|
|
260
|
-
test.property.type === "Identifier" &&
|
|
261
|
-
test.property.name === "main";
|
|
262
|
-
const [only, ...others] = consequent.type === "BlockStatement" ? consequent.body : [];
|
|
263
|
-
const expression = only?.type === "ExpressionStatement" ? only.expression : undefined;
|
|
264
|
-
const call = expression?.type === "CallExpression" ? expression : undefined;
|
|
265
|
-
const [task, ...otherArguments] = call?.arguments ?? [];
|
|
266
|
-
const runsOneNamedTask =
|
|
267
|
-
call !== undefined &&
|
|
268
|
-
others.length === 0 &&
|
|
269
|
-
otherArguments.length === 0 &&
|
|
270
|
-
task?.type === "Identifier" &&
|
|
271
|
-
importedMemberPath(call.callee, imports)?.join(".") ===
|
|
272
|
-
`${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}`;
|
|
273
|
-
return testsImportMetaMain && alternate === null && runsOneNamedTask;
|
|
274
|
-
};
|
|
275
|
-
|
|
276
159
|
const isDefaultExport = (statement: Statement) =>
|
|
277
160
|
statement.type === "ExportDefaultDeclaration" &&
|
|
278
161
|
statement.declaration.type !== "TSInterfaceDeclaration";
|
|
@@ -280,30 +163,6 @@ const isDefaultExport = (statement: Statement) =>
|
|
|
280
163
|
const statementsOtherThanImports = (parsed: ParseResult) =>
|
|
281
164
|
parsed.program.body.filter((statement) => statement.type !== "ImportDeclaration");
|
|
282
165
|
|
|
283
|
-
const statementsOtherThanImportsAndMain = (
|
|
284
|
-
parsed: ParseResult,
|
|
285
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
286
|
-
) => {
|
|
287
|
-
const nonImports = statementsOtherThanImports(parsed);
|
|
288
|
-
const firstGuard = nonImports.findIndex((statement) => isMainGuard(statement, imports));
|
|
289
|
-
return nonImports.filter((_statement, index) => index !== firstGuard);
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const mainScriptViolations = (
|
|
293
|
-
path: string,
|
|
294
|
-
text: string,
|
|
295
|
-
parsed: ParseResult,
|
|
296
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
297
|
-
) => {
|
|
298
|
-
const lineAt = lineNumbersIn(text);
|
|
299
|
-
return statementsOtherThanImportsAndMain(parsed, imports).map((statement) => {
|
|
300
|
-
const location = `${path}:${lineAt(statement.start)}`;
|
|
301
|
-
return isDefaultExport(statement)
|
|
302
|
-
? new TopLevelScriptWithMainAndDefaultExport({ location })
|
|
303
|
-
: new TopLevelScriptHoldsOtherStatement({ location, entryPoint: "main-guard" });
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
|
|
307
166
|
const defaultExportScriptViolations = (path: string, text: string, parsed: ParseResult) => {
|
|
308
167
|
const lineAt = lineNumbersIn(text);
|
|
309
168
|
return statementsOtherThanImports(parsed)
|
|
@@ -312,23 +171,16 @@ const defaultExportScriptViolations = (path: string, text: string, parsed: Parse
|
|
|
312
171
|
(statement) =>
|
|
313
172
|
new TopLevelScriptHoldsOtherStatement({
|
|
314
173
|
location: `${path}:${lineAt(statement.start)}`,
|
|
315
|
-
entryPoint: "default-export",
|
|
316
174
|
}),
|
|
317
175
|
);
|
|
318
176
|
};
|
|
319
177
|
|
|
320
|
-
export const sourceViolations = (
|
|
321
|
-
path: string,
|
|
322
|
-
text: string,
|
|
323
|
-
resolvedImports?: ReadonlyMap<string, readonly string[]>,
|
|
324
|
-
isListedUnderBin = false,
|
|
325
|
-
) => {
|
|
178
|
+
export const sourceViolations = (path: string, text: string, isListedUnderBin = false) => {
|
|
326
179
|
const violations: (
|
|
327
180
|
| MisplacedAtPackageRoot
|
|
328
181
|
| SourceOutsideInternalOrShared
|
|
329
182
|
| TopLevelScriptHoldsOtherStatement
|
|
330
|
-
|
|
|
331
|
-
| TopLevelScriptWithoutMain
|
|
183
|
+
| TopLevelScriptWithoutDefaultExport
|
|
332
184
|
)[] = [];
|
|
333
185
|
const isMisplacedTool = toolFileOf(path) !== undefined && !toolFileIsPlaced(path);
|
|
334
186
|
if (isMisplacedTool) {
|
|
@@ -348,32 +200,21 @@ export const sourceViolations = (
|
|
|
348
200
|
violations.push(new SourceOutsideInternalOrShared({ location: path }));
|
|
349
201
|
}
|
|
350
202
|
|
|
351
|
-
const parsed = parseSync(path, text);
|
|
352
|
-
const imports = resolvedImports ?? directTaskImports(parsed);
|
|
353
203
|
const isRootCodeFile = !path.includes("/") && !isRootSupportFile(path);
|
|
354
204
|
if (isRootCodeFile) {
|
|
355
|
-
violations.push(
|
|
356
|
-
new MisplacedAtPackageRoot({
|
|
357
|
-
location: path,
|
|
358
|
-
place: callsTaskMember(parsed, TASK_MAIN_MEMBER, imports)
|
|
359
|
-
? "root-task-script"
|
|
360
|
-
: "root-code-file",
|
|
361
|
-
}),
|
|
362
|
-
);
|
|
205
|
+
violations.push(new MisplacedAtPackageRoot({ location: path, place: "root-code-file" }));
|
|
363
206
|
}
|
|
364
207
|
const isTaskScript = isTopLevelScript(path) && !isListedUnderBin;
|
|
365
208
|
if (!isTaskScript) {
|
|
366
209
|
return violations;
|
|
367
210
|
}
|
|
368
|
-
const
|
|
211
|
+
const parsed = parseSync(path, text);
|
|
369
212
|
const hasDefaultExport = parsed.program.body.some((statement) => isDefaultExport(statement));
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
violations.push(new TopLevelScriptWithoutMain({ location: path }));
|
|
376
|
-
}
|
|
213
|
+
violations.push(
|
|
214
|
+
...(hasDefaultExport
|
|
215
|
+
? defaultExportScriptViolations(path, text, parsed)
|
|
216
|
+
: [new TopLevelScriptWithoutDefaultExport({ location: path })]),
|
|
217
|
+
);
|
|
377
218
|
return violations;
|
|
378
219
|
};
|
|
379
220
|
|
|
@@ -852,18 +693,10 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
852
693
|
return found;
|
|
853
694
|
}
|
|
854
695
|
const text = yield* fileSystem.readFileString(pathModule.join(directory, path));
|
|
855
|
-
const absoluteDirectory = yield* absolutePathOf(directory);
|
|
856
|
-
const imports = isTaskLayoutFile(path)
|
|
857
|
-
? yield* taskImportsIn(
|
|
858
|
-
pathModule.join(absoluteDirectory, path),
|
|
859
|
-
text,
|
|
860
|
-
absoluteDirectory,
|
|
861
|
-
)
|
|
862
|
-
: undefined;
|
|
863
696
|
return [
|
|
864
697
|
...found,
|
|
865
698
|
...(isScriptFile
|
|
866
|
-
? sourceViolations(path, text,
|
|
699
|
+
? sourceViolations(path, text, binaryFiles.has(path))
|
|
867
700
|
: yield* manifestViolations(path, text, repository)),
|
|
868
701
|
];
|
|
869
702
|
}),
|
|
@@ -4,7 +4,7 @@ import { Effect } from "effect";
|
|
|
4
4
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
5
5
|
import { fileTypeViolationsOfEachPackage } from "./internal/find-file-type-violations.ts";
|
|
6
6
|
|
|
7
|
-
export const fileTypes = Task.make(
|
|
8
|
-
"file-types",
|
|
9
|
-
fileTypeViolationsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
10
|
-
);
|
|
7
|
+
export const fileTypes = Task.make({
|
|
8
|
+
name: "file-types",
|
|
9
|
+
run: fileTypeViolationsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
10
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
|
-
import { Effect, Path } from "effect";
|
|
2
|
+
import { Effect, Path, Schema } from "effect";
|
|
3
3
|
|
|
4
4
|
import { projectDirectory } from "../../../../project-directory/index.ts";
|
|
5
5
|
import { inEachPackage, packageDirectoriesIn } from "../../../shared/check-each-nested-package.ts";
|
|
6
|
+
import { startDirectory } from "../../../shared/declare-start-directory-task.ts";
|
|
6
7
|
import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
|
|
7
8
|
import { listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
8
9
|
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
@@ -20,9 +21,19 @@ const ownedFilesOfPackage = (checkedProject: string, packageDirectory: string) =
|
|
|
20
21
|
return { directory: packageDirectory, files: yield* ownedFilesAmong(directory, packageFiles) };
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const FilesOfEachPackage = Schema.Struct({
|
|
25
|
+
checkedProject: Schema.String,
|
|
26
|
+
filesOfEachPackage: Schema.Array(
|
|
27
|
+
Schema.Struct({ directory: Schema.String, files: Schema.Array(Schema.String) }),
|
|
28
|
+
),
|
|
29
|
+
packageFiles: Schema.Array(Schema.String),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const formatterFiles = Task.make({
|
|
33
|
+
name: "formatter-files",
|
|
34
|
+
output: FilesOfEachPackage,
|
|
35
|
+
run: Effect.gen(function* () {
|
|
36
|
+
yield* startDirectory;
|
|
26
37
|
const path = yield* Path.Path;
|
|
27
38
|
const checkedProject = yield* projectDirectory;
|
|
28
39
|
const filesOfEachPackage = yield* Effect.forEach(
|
|
@@ -42,11 +53,11 @@ const formatterFiles = Task.make(
|
|
|
42
53
|
locatedFromTheProject,
|
|
43
54
|
Effect.provide(ProjectQueryCachesLive),
|
|
44
55
|
),
|
|
45
|
-
);
|
|
56
|
+
});
|
|
46
57
|
|
|
47
|
-
const formatInputs = Task.make(
|
|
48
|
-
"format-inputs",
|
|
49
|
-
Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
|
|
58
|
+
const formatInputs = Task.make({
|
|
59
|
+
name: "format-inputs",
|
|
60
|
+
run: Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
|
|
50
61
|
inEachPackage("format-inputs", (packageDirectory, packageDirectoryFromTheProject) =>
|
|
51
62
|
checkedFormatInputsIn(
|
|
52
63
|
packageDirectory,
|
|
@@ -55,11 +66,11 @@ const formatInputs = Task.make(
|
|
|
55
66
|
).pipe(quietViolations("format-inputs")),
|
|
56
67
|
),
|
|
57
68
|
),
|
|
58
|
-
);
|
|
69
|
+
});
|
|
59
70
|
|
|
60
|
-
const unformattedFiles = Task.make(
|
|
61
|
-
"bun-fmt",
|
|
62
|
-
Effect.andThen(
|
|
71
|
+
const unformattedFiles = Task.make({
|
|
72
|
+
name: "bun-fmt",
|
|
73
|
+
run: Effect.andThen(
|
|
63
74
|
inEachPackage("bun-fmt", (packageDirectory) =>
|
|
64
75
|
checkedFormatConfigIn(packageDirectory).pipe(quietViolations("bun-fmt")),
|
|
65
76
|
),
|
|
@@ -67,9 +78,9 @@ const unformattedFiles = Task.make(
|
|
|
67
78
|
unformattedFilesAmong(checkedProject, packageFiles),
|
|
68
79
|
),
|
|
69
80
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
70
|
-
);
|
|
81
|
+
});
|
|
71
82
|
|
|
72
|
-
export const formatting = Task.make(
|
|
73
|
-
"formatting",
|
|
74
|
-
Task.allSettled([formatInputs, unformattedFiles]),
|
|
75
|
-
);
|
|
83
|
+
export const formatting = Task.make({
|
|
84
|
+
name: "formatting",
|
|
85
|
+
run: Task.allSettled([formatInputs, unformattedFiles]),
|
|
86
|
+
});
|
|
@@ -7,10 +7,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
|
|
|
7
7
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
8
8
|
import { checkLintRulesWithOxlintIn } from "./internal/check-lint-rules-with-oxlint.ts";
|
|
9
9
|
|
|
10
|
-
export const oxlint = Task.make(
|
|
11
|
-
"oxlint",
|
|
12
|
-
Effect.andThen(
|
|
10
|
+
export const oxlint = Task.make({
|
|
11
|
+
name: "oxlint",
|
|
12
|
+
run: Effect.andThen(
|
|
13
13
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
14
14
|
inEachPackage("oxlint", checkLintRulesWithOxlintIn),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
|
-
);
|
|
16
|
+
});
|
|
@@ -7,10 +7,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
|
|
|
7
7
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
8
8
|
import { findDisableDirectivesInLintedFilesOf } from "./internal/find-disable-directives.ts";
|
|
9
9
|
|
|
10
|
-
export const directives = Task.make(
|
|
11
|
-
"directives",
|
|
12
|
-
Effect.andThen(
|
|
10
|
+
export const directives = Task.make({
|
|
11
|
+
name: "directives",
|
|
12
|
+
run: Effect.andThen(
|
|
13
13
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
14
14
|
inEachPackage("directives", findDisableDirectivesInLintedFilesOf),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
|
-
);
|
|
16
|
+
});
|
|
@@ -6,10 +6,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
|
|
|
6
6
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
7
7
|
import { lintedFilesNotTypeCheckedInEachPackage } from "./internal/find-linted-files-not-type-checked.ts";
|
|
8
8
|
|
|
9
|
-
export const lintedFilesTypeChecked = Task.make(
|
|
10
|
-
"linted-files-type-checked",
|
|
11
|
-
Effect.andThen(
|
|
9
|
+
export const lintedFilesTypeChecked = Task.make({
|
|
10
|
+
name: "linted-files-type-checked",
|
|
11
|
+
run: Effect.andThen(
|
|
12
12
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
13
13
|
lintedFilesNotTypeCheckedInEachPackage,
|
|
14
14
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
15
|
-
);
|
|
15
|
+
});
|
|
@@ -5,7 +5,7 @@ import { inEachPackage } from "../../shared/check-each-nested-package.ts";
|
|
|
5
5
|
import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
|
|
6
6
|
import { checkTypesWithBunCheckIn } from "./internal/check-types-with-bun-check.ts";
|
|
7
7
|
|
|
8
|
-
export const typeCheck = Task.make(
|
|
9
|
-
"type-check",
|
|
10
|
-
Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
|
|
11
|
-
);
|
|
8
|
+
export const typeCheck = Task.make({
|
|
9
|
+
name: "type-check",
|
|
10
|
+
run: Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
|
|
11
|
+
});
|
|
@@ -4,6 +4,7 @@ import { Array as Arrays, Effect, Path } from "effect";
|
|
|
4
4
|
import type { PlatformError } from "effect";
|
|
5
5
|
|
|
6
6
|
import { projectDirectory } from "../../project-directory/index.ts";
|
|
7
|
+
import { startDirectory } from "./declare-start-directory-task.ts";
|
|
7
8
|
import { listedPackageFiles } from "./list-package-files.ts";
|
|
8
9
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
9
10
|
import { locatedFromTheProject, printedFromTheProject } from "./report-paths-from-the-project.ts";
|
|
@@ -69,6 +70,7 @@ export const inEachPackage = <Requirements>(
|
|
|
69
70
|
) => Effect.Effect<void, PlatformError.PlatformError | ReportedErrors, Requirements>,
|
|
70
71
|
) =>
|
|
71
72
|
Effect.gen(function* () {
|
|
73
|
+
yield* startDirectory;
|
|
72
74
|
const pathModule = yield* Path.Path;
|
|
73
75
|
const checkedProject = yield* projectDirectory.pipe(quietViolations(tool));
|
|
74
76
|
const packageDirectories = yield* packageDirectoriesIn(checkedProject).pipe(
|
|
@@ -6,9 +6,9 @@ import { loadedLintConfigIn } from "./load-the-lint-config.ts";
|
|
|
6
6
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
7
7
|
import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
|
|
8
8
|
|
|
9
|
-
export const lintConfigFile = Task.make(
|
|
10
|
-
"lint-config",
|
|
11
|
-
inEachPackage("lint-config", (packageDirectory) =>
|
|
9
|
+
export const lintConfigFile = Task.make({
|
|
10
|
+
name: "lint-config",
|
|
11
|
+
run: inEachPackage("lint-config", (packageDirectory) =>
|
|
12
12
|
loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
|
|
13
13
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
14
|
-
);
|
|
14
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect, FileSystem, Path, References, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
import { projectDirectory } from "../../project-directory/index.ts";
|
|
5
|
+
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
6
|
+
|
|
7
|
+
const PACKAGE_MANIFEST_FILE = "package.json";
|
|
8
|
+
|
|
9
|
+
class PackageManifestMissing extends Schema.TaggedError<PackageManifestMissing>()(
|
|
10
|
+
"PackageManifestMissing",
|
|
11
|
+
{ directory: Schema.String },
|
|
12
|
+
) {
|
|
13
|
+
public override get message() {
|
|
14
|
+
return `${this.directory} has no ${PACKAGE_MANIFEST_FILE}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class RepositoryNotFound extends Schema.TaggedError<RepositoryNotFound>()("RepositoryNotFound", {
|
|
19
|
+
directory: Schema.String,
|
|
20
|
+
}) {
|
|
21
|
+
public override get message() {
|
|
22
|
+
return `${this.directory} is not inside a git repository`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const startDirectory = Task.make({
|
|
27
|
+
name: "start-directory",
|
|
28
|
+
run: Effect.gen(function* () {
|
|
29
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
30
|
+
const path = yield* Path.Path;
|
|
31
|
+
const directory = path.resolve(yield* projectDirectory);
|
|
32
|
+
if (!(yield* fileSystem.exists(path.join(directory, PACKAGE_MANIFEST_FILE)))) {
|
|
33
|
+
return yield* new PackageManifestMissing({ directory });
|
|
34
|
+
}
|
|
35
|
+
yield* Task.exec("git", ["rev-parse", "--show-toplevel"], { cwd: directory }).pipe(
|
|
36
|
+
Effect.provideService(References.MinimumLogLevel, "Warn"),
|
|
37
|
+
Effect.catchTag("CommandFailed", () => Effect.fail(new RepositoryNotFound({ directory }))),
|
|
38
|
+
);
|
|
39
|
+
}).pipe(quietViolations("start-directory")),
|
|
40
|
+
});
|
|
@@ -26,9 +26,9 @@ const locatedFromThePackage = (
|
|
|
26
26
|
: printable;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export const typeScriptConfig = Task.make(
|
|
30
|
-
"typescript-config",
|
|
31
|
-
inEachPackage("typescript-config", (packageDirectory) =>
|
|
29
|
+
export const typeScriptConfig = Task.make({
|
|
30
|
+
name: "typescript-config",
|
|
31
|
+
run: inEachPackage("typescript-config", (packageDirectory) =>
|
|
32
32
|
Path.Path.use((path) =>
|
|
33
33
|
findTypeScriptConfigViolations(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
|
|
34
34
|
quietViolations("typescript-config"),
|
|
@@ -43,4 +43,4 @@ export const typeScriptConfig = Task.make(
|
|
|
43
43
|
),
|
|
44
44
|
),
|
|
45
45
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
46
|
-
);
|
|
46
|
+
});
|
|
@@ -13,6 +13,15 @@ export class TypeScriptApiFailed extends Schema.TaggedError<TypeScriptApiFailed>
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export class TypeScriptApiProcessStopped extends Schema.TaggedError<TypeScriptApiProcessStopped>()(
|
|
17
|
+
"TypeScriptApiProcessStopped",
|
|
18
|
+
{ reason: Schema.String },
|
|
19
|
+
) {
|
|
20
|
+
public override get message() {
|
|
21
|
+
return this.reason;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
export class TypeScriptReturnedNothing extends Schema.TaggedError<TypeScriptReturnedNothing>()(
|
|
17
26
|
"TypeScriptReturnedNothing",
|
|
18
27
|
{ operation: Schema.String },
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
isTypeLiteralNode,
|
|
34
34
|
isVariableDeclaration,
|
|
35
35
|
} from "typescript/unstable/ast/is";
|
|
36
|
-
import {
|
|
36
|
+
import { SymbolFlags } from "typescript/unstable/async";
|
|
37
37
|
import type { Checker, Program, Symbol as TypeScriptSymbol, Type } from "typescript/unstable/async";
|
|
38
38
|
|
|
39
39
|
import { isDeclarationFile, isScript, packagePathOf } from "./classify-files-by-role.ts";
|
|
@@ -48,11 +48,13 @@ import {
|
|
|
48
48
|
ProgramFilesOutsideProject,
|
|
49
49
|
ProjectReferencesUndecodable,
|
|
50
50
|
TypeScriptApiFailed,
|
|
51
|
+
TypeScriptApiProcessStopped,
|
|
51
52
|
TypeScriptConfigUnparsable,
|
|
52
53
|
TypeScriptProjectFileMissing,
|
|
53
54
|
TypeScriptReturnedNothing,
|
|
54
55
|
} from "./project-config-and-tool-errors.ts";
|
|
55
56
|
import { absolutePathOf } from "./resolve-absolute-paths.ts";
|
|
57
|
+
import { openedApi } from "./watch-the-typescript-api-process.ts";
|
|
56
58
|
|
|
57
59
|
export const TYPESCRIPT_PROJECT_FILE = "tsconfig.json";
|
|
58
60
|
|
|
@@ -91,10 +93,16 @@ const PROJECT_REFERENCES = Schema.Struct({
|
|
|
91
93
|
references: Schema.optionalKey(Schema.Array(Schema.Struct({ path: Schema.String }))),
|
|
92
94
|
});
|
|
93
95
|
|
|
96
|
+
const isProcessStopped = Schema.is(TypeScriptApiProcessStopped);
|
|
97
|
+
|
|
94
98
|
export const typeScriptRequest = <Value>(operation: string, request: () => Promise<Value>) =>
|
|
95
99
|
Effect.tryPromise({
|
|
96
100
|
try: request,
|
|
97
|
-
catch: (cause) =>
|
|
101
|
+
catch: (cause) =>
|
|
102
|
+
new TypeScriptApiFailed({
|
|
103
|
+
operation,
|
|
104
|
+
reason: isProcessStopped(cause) ? cause.reason : String(cause),
|
|
105
|
+
}),
|
|
98
106
|
});
|
|
99
107
|
|
|
100
108
|
export const typeMembers = (type: Type) =>
|
|
@@ -204,19 +212,6 @@ export const projectConfigFiles = (projectFile: string) =>
|
|
|
204
212
|
return configFiles;
|
|
205
213
|
});
|
|
206
214
|
|
|
207
|
-
const openedApi = (sourceTextOverrides: ReadonlyMap<string, string>) =>
|
|
208
|
-
Effect.acquireRelease(
|
|
209
|
-
Effect.sync(
|
|
210
|
-
() =>
|
|
211
|
-
new API(
|
|
212
|
-
sourceTextOverrides.size === 0
|
|
213
|
-
? {}
|
|
214
|
-
: { fs: { readFile: (fileName) => sourceTextOverrides.get(fileName) } },
|
|
215
|
-
),
|
|
216
|
-
),
|
|
217
|
-
(openApi) => Effect.promise(() => openApi.close()),
|
|
218
|
-
);
|
|
219
|
-
|
|
220
215
|
const parseCompilerOptionsAndInputs = (configFile: string) =>
|
|
221
216
|
Effect.gen(function* () {
|
|
222
217
|
const path = yield* Path.Path;
|