@shivaedev/quality 0.55.0 → 0.56.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/CHANGELOG.md +8 -0
- package/README.md +13 -13
- package/dist/adapters/ImportCompiler.d.ts +21 -0
- package/dist/adapters/ImportCompiler.d.ts.map +1 -0
- package/dist/adapters/ImportCompiler.js +22 -0
- package/dist/adapters/ImportCompiler.js.map +1 -0
- package/dist/adapters/imports/browserChecker.d.ts +3 -0
- package/dist/adapters/imports/browserChecker.d.ts.map +1 -0
- package/dist/adapters/imports/browserChecker.js +8 -0
- package/dist/adapters/imports/browserChecker.js.map +1 -0
- package/dist/adapters/imports/departures.d.ts +5 -0
- package/dist/adapters/imports/departures.d.ts.map +1 -0
- package/dist/adapters/imports/departures.js +61 -0
- package/dist/adapters/imports/departures.js.map +1 -0
- package/dist/adapters/imports/graph.d.ts +4 -0
- package/dist/adapters/imports/graph.d.ts.map +1 -0
- package/dist/adapters/imports/graph.js +44 -0
- package/dist/adapters/imports/graph.js.map +1 -0
- package/dist/adapters/imports/projects.d.ts.map +1 -0
- package/dist/adapters/imports/projects.js.map +1 -0
- package/dist/{imports → adapters/imports}/resolve.d.ts +3 -10
- package/dist/adapters/imports/resolve.d.ts.map +1 -0
- package/dist/{imports → adapters/imports}/resolve.js +1 -1
- package/dist/adapters/imports/resolve.js.map +1 -0
- package/dist/adapters/knip/entryPointFindings.d.ts +2 -1
- package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
- package/dist/adapters/knip/entryPointFindings.js +7 -6
- package/dist/adapters/knip/entryPointFindings.js.map +1 -1
- package/dist/adapters/knip/run.d.ts +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/knip/run.js +1 -1
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/rule.d.ts +9 -0
- package/dist/adapters/rule.d.ts.map +1 -0
- package/dist/adapters/rule.js +35 -0
- package/dist/adapters/rule.js.map +1 -0
- package/dist/adapters/standardSchema.d.ts.map +1 -0
- package/dist/adapters/standardSchema.js.map +1 -0
- package/dist/config/decode.d.ts +2 -2
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +3 -2
- package/dist/config/decode.js.map +1 -1
- package/dist/config/resolve.d.ts +2 -2
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resolve.js +2 -1
- package/dist/config/resolve.js.map +1 -1
- package/dist/config.d.ts +5 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/decoded.d.ts.map +1 -1
- package/dist/decoded.js +1 -1
- package/dist/decoded.js.map +1 -1
- package/dist/imports/Endpoint.d.ts +9 -0
- package/dist/imports/Endpoint.d.ts.map +1 -0
- package/dist/imports/Endpoint.js +2 -0
- package/dist/imports/Endpoint.js.map +1 -0
- package/dist/imports/browserGlobals.d.ts +2 -1
- package/dist/imports/browserGlobals.d.ts.map +1 -1
- package/dist/imports/browserGlobals.js +6 -9
- package/dist/imports/browserGlobals.js.map +1 -1
- package/dist/imports/departures.d.ts +3 -2
- package/dist/imports/departures.d.ts.map +1 -1
- package/dist/imports/departures.js +8 -61
- package/dist/imports/departures.js.map +1 -1
- package/dist/imports/fences/check.d.ts +3 -2
- package/dist/imports/fences/check.d.ts.map +1 -1
- package/dist/imports/fences/check.js +5 -4
- package/dist/imports/fences/check.js.map +1 -1
- package/dist/imports/fences/compilePolicy.js.map +1 -1
- package/dist/imports/fences/match.d.ts +1 -1
- package/dist/imports/fences/match.d.ts.map +1 -1
- package/dist/imports/fences/match.js.map +1 -1
- package/dist/imports/fences/reach.d.ts +1 -1
- package/dist/imports/fences/reach.d.ts.map +1 -1
- package/dist/imports/fences/vocabulary.d.ts +1 -1
- package/dist/imports/fences/vocabulary.d.ts.map +1 -1
- package/dist/imports/graph.d.ts +4 -3
- package/dist/imports/graph.d.ts.map +1 -1
- package/dist/imports/graph.js +17 -55
- package/dist/imports/graph.js.map +1 -1
- package/dist/rule.d.ts +12 -8
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js +8 -31
- package/dist/rule.js.map +1 -1
- package/dist/rules/effect/program.js +1 -1
- package/dist/rules/effect/program.js.map +1 -1
- package/dist/rules/imports/adminPaths.js +1 -1
- package/dist/rules/imports/adminPaths.js.map +1 -1
- package/dist/rules/imports/aliased.d.ts.map +1 -1
- package/dist/rules/imports/aliased.js +3 -2
- package/dist/rules/imports/aliased.js.map +1 -1
- package/dist/rules/imports/cycles.d.ts.map +1 -1
- package/dist/rules/imports/cycles.js +4 -3
- package/dist/rules/imports/cycles.js.map +1 -1
- package/dist/rules/imports/manifest.d.ts.map +1 -1
- package/dist/rules/imports/manifest.js +6 -5
- package/dist/rules/imports/manifest.js.map +1 -1
- package/dist/rules/imports/noTestCode.d.ts.map +1 -1
- package/dist/rules/imports/noTestCode.js +3 -2
- package/dist/rules/imports/noTestCode.js.map +1 -1
- package/dist/rules/imports/resolvable.js +1 -1
- package/dist/rules/imports/resolvable.js.map +1 -1
- package/dist/rules/imports/runtime.d.ts.map +1 -1
- package/dist/rules/imports/runtime.js +3 -2
- package/dist/rules/imports/runtime.js.map +1 -1
- package/dist/rules/stories/engine.d.ts.map +1 -1
- package/dist/rules/stories/engine.js +5 -4
- package/dist/rules/stories/engine.js.map +1 -1
- package/dist/rules/stories/engineOf.d.ts +1 -1
- package/dist/rules/stories/engineOf.d.ts.map +1 -1
- package/dist/rules/stories/globalRetries.js +1 -1
- package/dist/rules/stories/globalRetries.js.map +1 -1
- package/dist/rules/stories/noExpect.d.ts.map +1 -1
- package/dist/rules/stories/noExpect.js +4 -3
- package/dist/rules/stories/noExpect.js.map +1 -1
- package/dist/rules/stories/sources.d.ts +1 -1
- package/dist/rules/stories/sources.d.ts.map +1 -1
- package/dist/rules/stories/sources.js +1 -1
- package/dist/rules/stories/sources.js.map +1 -1
- package/dist/rules/stories/specs.d.ts.map +1 -1
- package/dist/rules/stories/specs.js +5 -4
- package/dist/rules/stories/specs.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/ImportCompiler.ts +30 -0
- package/src/adapters/imports/browserChecker.ts +8 -0
- package/src/adapters/imports/departures.ts +82 -0
- package/src/adapters/imports/graph.ts +48 -0
- package/src/{imports → adapters/imports}/resolve.ts +4 -7
- package/src/adapters/knip/entryPointFindings.ts +12 -9
- package/src/adapters/knip/run.ts +1 -1
- package/src/adapters/rule.ts +53 -0
- package/src/config/decode.ts +5 -4
- package/src/config/resolve.ts +7 -6
- package/src/config.ts +5 -5
- package/src/decoded.ts +1 -1
- package/src/imports/Endpoint.ts +3 -0
- package/src/imports/browserGlobals.ts +6 -10
- package/src/imports/departures.ts +9 -80
- package/src/imports/fences/check.ts +6 -5
- package/src/imports/fences/compilePolicy.ts +1 -1
- package/src/imports/fences/match.ts +1 -1
- package/src/imports/fences/reach.ts +1 -1
- package/src/imports/fences/vocabulary.ts +1 -1
- package/src/imports/graph.ts +25 -61
- package/src/rule.ts +20 -52
- package/src/rules/effect/program.ts +1 -1
- package/src/rules/imports/adminPaths.ts +1 -1
- package/src/rules/imports/aliased.ts +10 -7
- package/src/rules/imports/cycles.ts +4 -3
- package/src/rules/imports/manifest.ts +8 -5
- package/src/rules/imports/noTestCode.ts +12 -9
- package/src/rules/imports/resolvable.ts +1 -1
- package/src/rules/imports/runtime.ts +3 -2
- package/src/rules/stories/engine.ts +5 -4
- package/src/rules/stories/engineOf.ts +1 -1
- package/src/rules/stories/globalRetries.ts +1 -1
- package/src/rules/stories/noExpect.ts +4 -3
- package/src/rules/stories/sources.ts +1 -1
- package/src/rules/stories/specs.ts +5 -4
- package/dist/imports/projects.d.ts.map +0 -1
- package/dist/imports/projects.js.map +0 -1
- package/dist/imports/resolve.d.ts.map +0 -1
- package/dist/imports/resolve.js.map +0 -1
- package/dist/standardSchema.d.ts.map +0 -1
- package/dist/standardSchema.js.map +0 -1
- /package/dist/{imports → adapters/imports}/projects.d.ts +0 -0
- /package/dist/{imports → adapters/imports}/projects.js +0 -0
- /package/dist/{standardSchema.d.ts → adapters/standardSchema.d.ts} +0 -0
- /package/dist/{standardSchema.js → adapters/standardSchema.js} +0 -0
- /package/src/{imports → adapters/imports}/projects.ts +0 -0
- /package/src/{standardSchema.ts → adapters/standardSchema.ts} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
import { importGraph } from "#imports/graph.ts";
|
|
3
4
|
import { packageOf } from "#imports/workspace.ts";
|
|
@@ -45,9 +46,9 @@ function uncoveredRegistration(call, originOf) {
|
|
|
45
46
|
return origin === "plain" || ((namesTest(call.expression) || testShaped(call, originOf)) && declarationScope(call, originOf));
|
|
46
47
|
}
|
|
47
48
|
export const storySpecs = defineRule({
|
|
48
|
-
check:
|
|
49
|
-
const graph =
|
|
50
|
-
const exempt =
|
|
49
|
+
check: Effect.fn("Stories.check")(function* (inputs) {
|
|
50
|
+
const graph = yield* importGraph(inputs);
|
|
51
|
+
const exempt = yield* Effect.promise(() => storyPrerequisites(inputs, graph.packages));
|
|
51
52
|
const origins = storyOrigins(inputs, graph);
|
|
52
53
|
const unit = unitTests(graph, inputs.sources);
|
|
53
54
|
return inputs.sources.flatMap((file) => {
|
|
@@ -81,7 +82,7 @@ export const storySpecs = defineRule({
|
|
|
81
82
|
},
|
|
82
83
|
];
|
|
83
84
|
});
|
|
84
|
-
},
|
|
85
|
+
}),
|
|
85
86
|
description: "Every package tests its real engine through its own test-story kit, and a plain test lives only in a .unit file that reaches no engine and mocks nothing. Typecheck tests and the test-story, test and types packages need no kit.",
|
|
86
87
|
id: "tests/story-specs",
|
|
87
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specs.js","sourceRoot":"","sources":["../../../src/rules/stories/specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAA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|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@biomejs/biome": "2.6.3",
|
|
54
54
|
"@shivaedev/heavy-lock": "0.8.0",
|
|
55
|
-
"@shivaedev/
|
|
55
|
+
"@shivaedev/service": "0.6.1",
|
|
56
56
|
"@vitest/coverage-v8": "5.0.5",
|
|
57
57
|
"ignore": "7.0.14",
|
|
58
58
|
"knip": "6.43.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@effect/platform-node": "4.0.6",
|
|
64
64
|
"@effect/platform-node-shared": "4.0.6",
|
|
65
65
|
"@effect/vitest": "4.0.6",
|
|
66
|
-
"@shivaedev/test-story": "0.
|
|
66
|
+
"@shivaedev/test-story": "0.34.0",
|
|
67
67
|
"@types/node": "24.19.2",
|
|
68
68
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
69
69
|
"effect": "4.0.6",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { Data, Effect } from "effect";
|
|
3
|
+
import type ts from "typescript";
|
|
4
|
+
import { defineService } from "@shivaedev/service/defineService.ts";
|
|
5
|
+
import { browserChecker } from "#adapters/imports/browserChecker.ts";
|
|
6
|
+
import { departures } from "#adapters/imports/departures.ts";
|
|
7
|
+
import { graph } from "#adapters/imports/graph.ts";
|
|
8
|
+
import type { WorkspacePackage } from "#imports/workspace.ts";
|
|
9
|
+
import type { RuleInputs } from "#rule.ts";
|
|
10
|
+
|
|
11
|
+
export class ImportAnalysisFailure extends Data.TaggedError("ImportAnalysisFailure")<{
|
|
12
|
+
readonly message: string;
|
|
13
|
+
readonly root: string;
|
|
14
|
+
}> {}
|
|
15
|
+
|
|
16
|
+
function failure(root: string, cause: unknown): ImportAnalysisFailure {
|
|
17
|
+
return new ImportAnalysisFailure({ message: `Cannot analyze imports in ${root}: ${cause instanceof Error ? cause.message : String(cause)}`, root });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ImportCompiler = defineService({
|
|
21
|
+
id: "@shivaedev/quality/ImportCompiler",
|
|
22
|
+
initialize: Effect.void,
|
|
23
|
+
methods: () => ({
|
|
24
|
+
browserChecker: (source: ts.SourceFile) => Effect.sync(() => browserChecker(source)),
|
|
25
|
+
departures: (inputs: RuleInputs, packages: readonly WorkspacePackage[]) =>
|
|
26
|
+
Effect.try({ catch: (cause) => failure(inputs.root, cause), try: () => departures(inputs, packages) }),
|
|
27
|
+
graph: (inputs: RuleInputs) => Effect.try({ catch: (cause) => failure(inputs.root, cause), try: () => graph(inputs, realpathSync(inputs.root)) }),
|
|
28
|
+
}),
|
|
29
|
+
requires: [],
|
|
30
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function browserChecker(source: ts.SourceFile): ts.TypeChecker {
|
|
4
|
+
const options: ts.CompilerOptions = { allowJs: true, noLib: true, noResolve: true };
|
|
5
|
+
const host = ts.createCompilerHost(options);
|
|
6
|
+
host.getSourceFile = (path) => (path === source.fileName ? source : undefined);
|
|
7
|
+
return ts.createProgram([source.fileName], options, host).getTypeChecker();
|
|
8
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { posix } from "node:path";
|
|
3
|
+
import type { Departure } from "#imports/departures.ts";
|
|
4
|
+
import type { ImportRequest } from "#imports/extract.ts";
|
|
5
|
+
import { type SpecifierSite, specifierSites } from "#imports/specifiers.ts";
|
|
6
|
+
import { packageOf, type WorkspacePackage } from "#imports/workspace.ts";
|
|
7
|
+
import { moduleRoot } from "#naming/moduleRoot.ts";
|
|
8
|
+
import type { RuleInputs } from "#rule.ts";
|
|
9
|
+
import { parse } from "#rules/parse.ts";
|
|
10
|
+
import { type Project, projectsFor } from "./projects.ts";
|
|
11
|
+
import { resolveImport } from "./resolve.ts";
|
|
12
|
+
|
|
13
|
+
const QUERY = /\?.*$/u;
|
|
14
|
+
|
|
15
|
+
const RELATIVE = /^\.\.?(?:\/|$)/u;
|
|
16
|
+
|
|
17
|
+
const MAY_BE_RELATIVE = /["'`]\.\.?[/"'`]|\\/u;
|
|
18
|
+
|
|
19
|
+
const TRAILING_SLASHES = /\/+$/u;
|
|
20
|
+
|
|
21
|
+
function noAmbient(): boolean {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function leavesLexically(path: string): boolean {
|
|
26
|
+
const normal = posix.normalize(path).replace(TRAILING_SLASHES, "");
|
|
27
|
+
return normal === ".." || normal.startsWith("../") || normal.includes("/");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface FileContext {
|
|
31
|
+
readonly from: string;
|
|
32
|
+
readonly packages: readonly WorkspacePackage[];
|
|
33
|
+
readonly path: string;
|
|
34
|
+
readonly project: Project;
|
|
35
|
+
readonly root: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function registersAdmin(from: string, specifier: string, target: string | undefined): boolean {
|
|
39
|
+
const root = moduleRoot(from);
|
|
40
|
+
const folder = posix.dirname(from);
|
|
41
|
+
return (
|
|
42
|
+
root !== undefined
|
|
43
|
+
&& (folder === `${root}/client` || folder === `${root}/server`)
|
|
44
|
+
&& /^registration\.[cm]?[jt]sx?$/u.test(posix.basename(from))
|
|
45
|
+
&& specifier.startsWith("./admin/")
|
|
46
|
+
&& target?.startsWith(`${folder}/admin/`) === true
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A relative import leaves its folder when its path climbs or descends, or when it names a folder whose index file lies below.
|
|
51
|
+
function departureAt(context: FileContext, site: SpecifierSite): Departure | undefined {
|
|
52
|
+
const path = site.specifier.replace(QUERY, "");
|
|
53
|
+
if (!RELATIVE.test(path)) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const request: ImportRequest = { kind: "import", line: site.line, specifier: site.specifier, type: site.type };
|
|
57
|
+
const target = resolveImport(context.root, noAmbient, request, context.from, context.project);
|
|
58
|
+
const local = target?.kind === "file" ? target.path : undefined;
|
|
59
|
+
if (registersAdmin(context.path, path, local)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
if (!(leavesLexically(path) || (local !== undefined && posix.dirname(local) !== posix.dirname(context.path)))) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const owner = local === undefined ? undefined : packageOf(context.packages, local);
|
|
66
|
+
const workspace = owner !== undefined && owner !== packageOf(context.packages, context.path) ? owner.name : undefined;
|
|
67
|
+
return { ...site, file: context.path, installed: target?.kind === "external" ? target.package : undefined, workspace };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function departures(inputs: RuleInputs, packages: readonly WorkspacePackage[]): readonly Departure[] {
|
|
71
|
+
const root = realpathSync(inputs.root);
|
|
72
|
+
const projectOf = projectsFor(root);
|
|
73
|
+
return inputs.sources.flatMap((file) => {
|
|
74
|
+
const syntax = MAY_BE_RELATIVE.test(file.text) ? parse(file) : undefined;
|
|
75
|
+
if (syntax === undefined) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
const from = posix.join(root, file.path);
|
|
79
|
+
const context = { from, packages, path: file.path, project: projectOf(from), root };
|
|
80
|
+
return specifierSites(syntax).flatMap((site) => departureAt(context, site) ?? []);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { join, posix } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { ambientModules } from "#imports/ambient.ts";
|
|
4
|
+
import { type ImportRequest, importsOf } from "#imports/extract.ts";
|
|
5
|
+
import type { ImportEdge, ImportGraph, UnresolvedImport } from "#imports/graph.ts";
|
|
6
|
+
import type { RuleInputs } from "#rule.ts";
|
|
7
|
+
import { parse } from "#rules/parse.ts";
|
|
8
|
+
import { type Project, projectsFor } from "./projects.ts";
|
|
9
|
+
import { isDeclarationFile, presumedTarget, resolveImport } from "./resolve.ts";
|
|
10
|
+
|
|
11
|
+
const QUERY = /\?.*$/u;
|
|
12
|
+
|
|
13
|
+
function relativeTarget(from: string, request: ImportRequest): string | undefined {
|
|
14
|
+
const relative = request.kind === "path-reference" || request.specifier.startsWith("./") || request.specifier.startsWith("../");
|
|
15
|
+
return relative ? posix.join(posix.dirname(from), request.specifier.replace(QUERY, "")) : undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// A relative import or a package import of a missing file still names a path, so fences see it before its generator writes it.
|
|
19
|
+
function missingTarget(root: string, from: string, request: ImportRequest, project: Project): string | undefined {
|
|
20
|
+
const target = presumedTarget(root, request, join(root, from), project) ?? relativeTarget(from, request);
|
|
21
|
+
return target === undefined || target.startsWith("../") ? undefined : target;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function graph(inputs: RuleInputs, root: string): Pick<ImportGraph, "configFindings" | "edges" | "modules" | "unresolved"> {
|
|
25
|
+
const projectOf = projectsFor(root);
|
|
26
|
+
const parsed = inputs.sources.flatMap((file) => {
|
|
27
|
+
const syntax = parse(file);
|
|
28
|
+
return syntax === undefined ? [] : [{ file, path: join(root, file.path), syntax }];
|
|
29
|
+
});
|
|
30
|
+
const ambient = ambientModules(parsed);
|
|
31
|
+
const edges: ImportEdge[] = [];
|
|
32
|
+
const unresolved: UnresolvedImport[] = [];
|
|
33
|
+
for (const { file, path, syntax } of parsed) {
|
|
34
|
+
const project = projectOf(path);
|
|
35
|
+
syntax.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, undefined, ts.sys, project.options);
|
|
36
|
+
for (const request of importsOf(syntax, isDeclarationFile(file.path), project.options)) {
|
|
37
|
+
const to = resolveImport(root, ambient, request, path, project);
|
|
38
|
+
if (to === undefined) {
|
|
39
|
+
const missing = missingTarget(root, file.path, request, project);
|
|
40
|
+
unresolved.push({ ...request, from: file.path, missing });
|
|
41
|
+
edges.push(...(missing === undefined ? [] : [{ ...request, from: file.path, to: { kind: "file" as const, path: missing } }]));
|
|
42
|
+
} else {
|
|
43
|
+
edges.push({ ...request, from: file.path, to });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { configFindings: projectOf.findings, edges, modules: parsed.map(({ file }) => file.path), unresolved };
|
|
48
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { dirname, join, relative } from "node:path";
|
|
3
3
|
import ts from "typescript";
|
|
4
|
+
import type { Ambient } from "#imports/ambient.ts";
|
|
5
|
+
import type { Endpoint } from "#imports/Endpoint.ts";
|
|
6
|
+
import type { ImportRequest } from "#imports/extract.ts";
|
|
7
|
+
import { builtinName, nameAt, packageNameOf } from "#imports/packageName.ts";
|
|
4
8
|
import { posix } from "#inventory/ignoreScope.ts";
|
|
5
|
-
import type { Ambient } from "./ambient.ts";
|
|
6
|
-
import type { ImportRequest } from "./extract.ts";
|
|
7
|
-
import { builtinName, nameAt, packageNameOf } from "./packageName.ts";
|
|
8
9
|
import type { Project } from "./projects.ts";
|
|
9
10
|
|
|
10
|
-
export type Endpoint =
|
|
11
|
-
| { readonly kind: "file"; readonly path: string }
|
|
12
|
-
| { readonly kind: "external"; readonly package: string; readonly specifier: string };
|
|
13
|
-
|
|
14
11
|
const NODE_MODULES = "/node_modules/";
|
|
15
12
|
|
|
16
13
|
const ASSET_DECLARATION = /\.d(?<extension>\.[^./]+)\.ts$/u;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { join, posix } from "node:path";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { projectsFor } from "#adapters/imports/projects.ts";
|
|
2
4
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
5
|
import { ambientModules } from "#imports/ambient.ts";
|
|
4
6
|
import { importGraph } from "#imports/graph.ts";
|
|
5
7
|
import { isTooling } from "#imports/isTooling.ts";
|
|
6
8
|
import { packageNameOf } from "#imports/packageName.ts";
|
|
7
|
-
import { projectsFor } from "#imports/projects.ts";
|
|
8
9
|
import { packageOf } from "#imports/workspace.ts";
|
|
9
10
|
import { entryPointsOf, isApplication, provider } from "#manifests/entryPoints.ts";
|
|
10
11
|
import { isTestCode } from "#naming/testName.ts";
|
|
@@ -15,8 +16,8 @@ function importedPackage(specifier: string) {
|
|
|
15
16
|
return /^[.#/]/u.test(specifier) ? undefined : packageNameOf(specifier);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export
|
|
19
|
-
const graph =
|
|
19
|
+
export const entryPointFindings = Effect.fn("Knip.entryPointFindings")(function* (inputs: RuleInputs, findings: Findings) {
|
|
20
|
+
const graph = yield* importGraph(inputs);
|
|
20
21
|
const projectOf = projectsFor(inputs.root);
|
|
21
22
|
const ambient = ambientModules(
|
|
22
23
|
inputs.sources.flatMap((file) => {
|
|
@@ -28,11 +29,13 @@ export async function entryPointFindings(inputs: RuleInputs, findings: Findings)
|
|
|
28
29
|
const workspace = new Map(graph.packages.map(({ name, directory }) => [name, directory]));
|
|
29
30
|
const directories = [".", ...graph.packages.map(({ directory }) => directory)];
|
|
30
31
|
const policies = new Map(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
yield* Effect.promise(() =>
|
|
33
|
+
Promise.all(
|
|
34
|
+
directories.map(async (directory) => {
|
|
35
|
+
const manifest = await readPackageManifest(inputs.readText, posix.join(directory, "package.json"));
|
|
36
|
+
return [directory, isApplication(manifest) ? await entryPointsOf(inputs, directory, manifest, workspace) : []] as const;
|
|
37
|
+
}),
|
|
38
|
+
),
|
|
36
39
|
),
|
|
37
40
|
);
|
|
38
41
|
function owner(path: string) {
|
|
@@ -72,4 +75,4 @@ export async function entryPointFindings(inputs: RuleInputs, findings: Findings)
|
|
|
72
75
|
: supplied !== undefined && workspace.get(supplied.name) === directory && target === name;
|
|
73
76
|
});
|
|
74
77
|
});
|
|
75
|
-
}
|
|
78
|
+
});
|
package/src/adapters/knip/run.ts
CHANGED
|
@@ -74,5 +74,5 @@ export const runKnip = Effect.fn("Knip.runKnip")(function* (inputs: RuleInputs)
|
|
|
74
74
|
return report.filter((finding) => checked.has(finding.file));
|
|
75
75
|
}),
|
|
76
76
|
);
|
|
77
|
-
return yield*
|
|
77
|
+
return yield* entryPointFindings(inputs, findings);
|
|
78
78
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { validOrFail } from "#decoded.ts";
|
|
3
|
+
import type { Configured, Findings, RegisteredRule, RuleContext } from "#rule.ts";
|
|
4
|
+
import { describeIssue, type StandardSchemaV1 } from "./standardSchema.ts";
|
|
5
|
+
|
|
6
|
+
export type RuleCheckResult<TServices> = Findings | PromiseLike<Findings> | Effect.Effect<Findings, unknown, TServices>;
|
|
7
|
+
|
|
8
|
+
export const ruleConfiguration = Symbol("@shivaedev/quality/ruleConfiguration");
|
|
9
|
+
|
|
10
|
+
export const noOptions: StandardSchemaV1<undefined, undefined> = {
|
|
11
|
+
"~standard": {
|
|
12
|
+
validate: (value) => (value === undefined ? { value: undefined } : { issues: [{ message: "this rule takes no options" }] }),
|
|
13
|
+
vendor: "@shivaedev/quality",
|
|
14
|
+
version: 1,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function configureRegistered<TServices>(rule: RegisteredRule<TServices>, options: unknown): Promise<Configured<TServices>> {
|
|
19
|
+
return rule[ruleConfiguration](options);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function configureWith<TInput, TOptions, TServices>(
|
|
23
|
+
schema: StandardSchemaV1<TInput, TOptions>,
|
|
24
|
+
check: (context: RuleContext<TOptions>) => RuleCheckResult<TServices>,
|
|
25
|
+
id: string,
|
|
26
|
+
absent: unknown,
|
|
27
|
+
validate?: (context: RuleContext<TOptions>) => readonly string[],
|
|
28
|
+
) {
|
|
29
|
+
return async (options: unknown): Promise<Configured<TServices>> => {
|
|
30
|
+
const result = await schema["~standard"].validate(options ?? absent);
|
|
31
|
+
if (result.issues !== undefined) {
|
|
32
|
+
return { _tag: "Invalid", issues: result.issues.map(describeIssue) };
|
|
33
|
+
}
|
|
34
|
+
const value = result.value;
|
|
35
|
+
return {
|
|
36
|
+
_tag: "Ready",
|
|
37
|
+
check: (inputs) =>
|
|
38
|
+
Effect.scoped(
|
|
39
|
+
Effect.gen(function* () {
|
|
40
|
+
const context = { ...inputs, options: value };
|
|
41
|
+
const issues = validate?.(context).map((issue) => `rules.${id}.options: ${issue}`) ?? [];
|
|
42
|
+
yield* validOrFail(
|
|
43
|
+
inputs.configFile ?? "quality.config.ts",
|
|
44
|
+
issues.length === 0 ? { _tag: "Valid", value: undefined } : { _tag: "Invalid", issues },
|
|
45
|
+
);
|
|
46
|
+
const signal = yield* Effect.abortSignal;
|
|
47
|
+
const checked = check({ ...inputs, options: value, signal });
|
|
48
|
+
return yield* Effect.isEffect(checked) ? checked : Effect.promise(() => Promise.resolve(checked));
|
|
49
|
+
}),
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
package/src/config/decode.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { ruleConfiguration } from "#adapters/rule.ts";
|
|
2
3
|
import { type Decoded, decodeWith } from "#decoded.ts";
|
|
3
4
|
import { ExceptionDeclaration } from "#exceptions/declaration.ts";
|
|
4
|
-
import type {
|
|
5
|
+
import type { RegisteredRule } from "#rule.ts";
|
|
5
6
|
|
|
6
|
-
function isRule(value: unknown): value is
|
|
7
|
+
function isRule(value: unknown): value is RegisteredRule {
|
|
7
8
|
return (
|
|
8
9
|
typeof value === "object"
|
|
9
10
|
&& value !== null
|
|
@@ -11,8 +12,8 @@ function isRule(value: unknown): value is Rule {
|
|
|
11
12
|
&& typeof value.id === "string"
|
|
12
13
|
&& "description" in value
|
|
13
14
|
&& typeof value.description === "string"
|
|
14
|
-
&&
|
|
15
|
-
&& typeof value
|
|
15
|
+
&& ruleConfiguration in value
|
|
16
|
+
&& typeof value[ruleConfiguration] === "function"
|
|
16
17
|
);
|
|
17
18
|
}
|
|
18
19
|
|
package/src/config/resolve.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { configureRegistered } from "#adapters/rule.ts";
|
|
2
3
|
import type { Decoded } from "#decoded.ts";
|
|
3
4
|
import type { ActiveRule } from "#engine/runRules.ts";
|
|
4
5
|
import type { RuleIndex } from "#engine/violation.ts";
|
|
5
|
-
import type {
|
|
6
|
+
import type { RegisteredRule } from "#rule.ts";
|
|
6
7
|
import { builtInRules } from "#rules/builtIn.ts";
|
|
7
8
|
import type { ConfigInput } from "./decode.ts";
|
|
8
9
|
|
|
@@ -20,13 +21,13 @@ function optionsOf(setting: Setting | undefined): unknown {
|
|
|
20
21
|
return typeof setting === "object" ? setting.options : undefined;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
function duplicateIssues(rules: readonly
|
|
24
|
+
function duplicateIssues(rules: readonly RegisteredRule[]): readonly string[] {
|
|
24
25
|
return rules.flatMap((rule, index) =>
|
|
25
26
|
rules.findIndex((other) => other.id === rule.id) === index ? [] : [`local: rule id "${rule.id}" is already defined`],
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
function activeRule(rule:
|
|
30
|
+
function activeRule(rule: RegisteredRule, check: ActiveRule["check"]): ActiveRule {
|
|
30
31
|
return {
|
|
31
32
|
check,
|
|
32
33
|
description: rule.description,
|
|
@@ -37,8 +38,8 @@ function activeRule(rule: Rule, check: ActiveRule["check"]): ActiveRule {
|
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
function activate(rule:
|
|
41
|
-
return Effect.tryPromise({ catch: messageOf, try: () => rule
|
|
41
|
+
function activate(rule: RegisteredRule, setting: Setting | undefined): Effect.Effect<Decoded<ActiveRule>> {
|
|
42
|
+
return Effect.tryPromise({ catch: messageOf, try: () => configureRegistered(rule, optionsOf(setting)) }).pipe(
|
|
42
43
|
Effect.match({
|
|
43
44
|
onFailure: (failure): Decoded<ActiveRule> => ({ _tag: "Invalid", issues: [`rules.${rule.id}.options: validation threw: ${failure}`] }),
|
|
44
45
|
onSuccess: (configured): Decoded<ActiveRule> =>
|
|
@@ -53,7 +54,7 @@ function activate(rule: Rule, setting: Setting | undefined): Effect.Effect<Decod
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
export const resolveRules = Effect.fn("Config.resolveRules")(function* (config: ConfigInput): Effect.fn.Return<Decoded<ResolvedRules>> {
|
|
56
|
-
const rules: readonly
|
|
57
|
+
const rules: readonly RegisteredRule[] = [...builtInRules, ...(config.local ?? [])];
|
|
57
58
|
const settings = config.rules ?? {};
|
|
58
59
|
const known = new Set(rules.map((rule) => rule.id));
|
|
59
60
|
const families = new Set(rules.filter((rule) => rule.family === true).map((rule) => rule.id));
|
package/src/config.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { ExceptionDeclaration } from "#exceptions/declaration.ts";
|
|
2
|
-
import type { Rule } from "#rule.ts";
|
|
2
|
+
import type { RegisteredRule, Rule } from "#rule.ts";
|
|
3
3
|
import type { builtInRules } from "#rules/builtIn.ts";
|
|
4
4
|
|
|
5
5
|
export type Level = "error";
|
|
6
6
|
|
|
7
7
|
export type RuleSetting<TInput> = "error" | { readonly level?: "error"; readonly options?: TInput };
|
|
8
8
|
|
|
9
|
-
type InputOf<TCandidate> = TCandidate extends Rule<string, infer TInput, unknown> ? TInput :
|
|
9
|
+
type InputOf<TCandidate> = TCandidate extends Rule<string, infer TInput, unknown> ? TInput : unknown;
|
|
10
10
|
|
|
11
|
-
export type RuleSettings<TRules extends readonly
|
|
11
|
+
export type RuleSettings<TRules extends readonly RegisteredRule<unknown>[]> = {
|
|
12
12
|
readonly [TCandidate in TRules[number] as TCandidate["id"]]?: RuleSetting<InputOf<TCandidate>>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export type BuiltInRules = typeof builtInRules;
|
|
16
16
|
|
|
17
|
-
export interface QualityConfig<TLocal extends readonly
|
|
17
|
+
export interface QualityConfig<TLocal extends readonly RegisteredRule<unknown>[] = readonly RegisteredRule<unknown>[]> {
|
|
18
18
|
readonly baseline?: string;
|
|
19
19
|
readonly exceptions?: readonly ExceptionDeclaration[];
|
|
20
20
|
readonly extensions?: readonly string[];
|
|
@@ -24,7 +24,7 @@ export interface QualityConfig<TLocal extends readonly Rule<string, unknown, unk
|
|
|
24
24
|
readonly sources?: readonly string[];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function defineConfig<const TLocal extends readonly
|
|
27
|
+
export function defineConfig<const TLocal extends readonly RegisteredRule<unknown>[] = readonly []>(
|
|
28
28
|
config: QualityConfig<TLocal>,
|
|
29
29
|
): QualityConfig<TLocal> {
|
|
30
30
|
return config;
|
package/src/decoded.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Result, Schema, SchemaIssue } from "effect";
|
|
2
|
+
import { describeIssue } from "#adapters/standardSchema.ts";
|
|
2
3
|
import { SetupFailure } from "./failure.ts";
|
|
3
|
-
import { describeIssue } from "./standardSchema.ts";
|
|
4
4
|
|
|
5
5
|
export type Decoded<TValue> = { readonly _tag: "Valid"; readonly value: TValue } | { readonly _tag: "Invalid"; readonly issues: readonly string[] };
|
|
6
6
|
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import ts from "typescript";
|
|
3
|
+
import { ImportCompiler } from "#adapters/ImportCompiler.ts";
|
|
2
4
|
import type { Finding, SourceFile } from "#rule.ts";
|
|
3
5
|
import { parse } from "#rules/parse.ts";
|
|
4
6
|
import { browserNames } from "./browserNames.ts";
|
|
5
7
|
|
|
6
|
-
function checkerOf(source: ts.SourceFile): ts.TypeChecker {
|
|
7
|
-
const options: ts.CompilerOptions = { allowJs: true, noLib: true, noResolve: true };
|
|
8
|
-
const host = ts.createCompilerHost(options);
|
|
9
|
-
host.getSourceFile = (path) => (path === source.fileName ? source : undefined);
|
|
10
|
-
return ts.createProgram([source.fileName], options, host).getTypeChecker();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
8
|
function unbound(checker: ts.TypeChecker, node: ts.Identifier): boolean {
|
|
14
9
|
return (checker.getSymbolAtLocation(node)?.declarations ?? []).length === 0;
|
|
15
10
|
}
|
|
@@ -107,13 +102,14 @@ function superclassesOf(node: ts.HeritageClause): readonly ts.Expression[] {
|
|
|
107
102
|
return node.types.map((base) => base.expression);
|
|
108
103
|
}
|
|
109
104
|
|
|
110
|
-
export
|
|
105
|
+
export const browserGlobals = Effect.fn("Imports.browserGlobals")(function* (file: SourceFile) {
|
|
111
106
|
const parsed = parse(file);
|
|
112
107
|
if (parsed === undefined) {
|
|
113
108
|
return [];
|
|
114
109
|
}
|
|
115
110
|
const source = parsed;
|
|
116
|
-
const
|
|
111
|
+
const compiler = yield* ImportCompiler;
|
|
112
|
+
const checker = yield* compiler.browserChecker(source);
|
|
117
113
|
const findings: Finding[] = [];
|
|
118
114
|
function visit(node: ts.Node): void {
|
|
119
115
|
if (ts.isHeritageClause(node)) {
|
|
@@ -139,4 +135,4 @@ export function browserGlobals(file: SourceFile): readonly Finding[] {
|
|
|
139
135
|
}
|
|
140
136
|
visit(source);
|
|
141
137
|
return findings;
|
|
142
|
-
}
|
|
138
|
+
}, Effect.provide(ImportCompiler.layer));
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { moduleRoot } from "#naming/moduleRoot.ts";
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { ImportCompiler } from "#adapters/ImportCompiler.ts";
|
|
4
3
|
import type { RuleInputs } from "#rule.ts";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { type Project, projectsFor } from "./projects.ts";
|
|
8
|
-
import { resolveImport } from "./resolve.ts";
|
|
9
|
-
import { type SpecifierSite, specifierSites } from "./specifiers.ts";
|
|
10
|
-
import { packageOf, type WorkspacePackage, workspacePackages } from "./workspace.ts";
|
|
4
|
+
import type { SpecifierSite } from "./specifiers.ts";
|
|
5
|
+
import { workspacePackages } from "./workspace.ts";
|
|
11
6
|
|
|
12
7
|
export interface Departure extends SpecifierSite {
|
|
13
8
|
readonly file: string;
|
|
@@ -15,74 +10,8 @@ export interface Departure extends SpecifierSite {
|
|
|
15
10
|
readonly workspace: string | undefined;
|
|
16
11
|
}
|
|
17
12
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const TRAILING_SLASHES = /\/+$/u;
|
|
25
|
-
|
|
26
|
-
function noAmbient(): boolean {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function leavesLexically(path: string): boolean {
|
|
31
|
-
const normal = posix.normalize(path).replace(TRAILING_SLASHES, "");
|
|
32
|
-
return normal === ".." || normal.startsWith("../") || normal.includes("/");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface FileContext {
|
|
36
|
-
readonly from: string;
|
|
37
|
-
readonly packages: readonly WorkspacePackage[];
|
|
38
|
-
readonly path: string;
|
|
39
|
-
readonly project: Project;
|
|
40
|
-
readonly root: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function registersAdmin(from: string, specifier: string, target: string | undefined): boolean {
|
|
44
|
-
const root = moduleRoot(from);
|
|
45
|
-
const folder = posix.dirname(from);
|
|
46
|
-
return (
|
|
47
|
-
root !== undefined
|
|
48
|
-
&& (folder === `${root}/client` || folder === `${root}/server`)
|
|
49
|
-
&& /^registration\.[cm]?[jt]sx?$/u.test(posix.basename(from))
|
|
50
|
-
&& specifier.startsWith("./admin/")
|
|
51
|
-
&& target?.startsWith(`${folder}/admin/`) === true
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// A relative import leaves its folder when its path climbs or descends, or when it names a folder whose index file lies below.
|
|
56
|
-
function departureAt(context: FileContext, site: SpecifierSite): Departure | undefined {
|
|
57
|
-
const path = site.specifier.replace(QUERY, "");
|
|
58
|
-
if (!RELATIVE.test(path)) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
const request: ImportRequest = { kind: "import", line: site.line, specifier: site.specifier, type: site.type };
|
|
62
|
-
const target = resolveImport(context.root, noAmbient, request, context.from, context.project);
|
|
63
|
-
const local = target?.kind === "file" ? target.path : undefined;
|
|
64
|
-
if (registersAdmin(context.path, path, local)) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
if (!(leavesLexically(path) || (local !== undefined && posix.dirname(local) !== posix.dirname(context.path)))) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const owner = local === undefined ? undefined : packageOf(context.packages, local);
|
|
71
|
-
const workspace = owner !== undefined && owner !== packageOf(context.packages, context.path) ? owner.name : undefined;
|
|
72
|
-
return { ...site, file: context.path, installed: target?.kind === "external" ? target.package : undefined, workspace };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function departures(inputs: RuleInputs): Promise<readonly Departure[]> {
|
|
76
|
-
const root = realpathSync(inputs.root);
|
|
77
|
-
const projectOf = projectsFor(root);
|
|
78
|
-
const packages = await workspacePackages(inputs);
|
|
79
|
-
return inputs.sources.flatMap((file) => {
|
|
80
|
-
const syntax = MAY_BE_RELATIVE.test(file.text) ? parse(file) : undefined;
|
|
81
|
-
if (syntax === undefined) {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
const from = posix.join(root, file.path);
|
|
85
|
-
const context = { from, packages, path: file.path, project: projectOf(from), root };
|
|
86
|
-
return specifierSites(syntax).flatMap((site) => departureAt(context, site) ?? []);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
13
|
+
export const departures = Effect.fn("Imports.departures")(function* (inputs: RuleInputs) {
|
|
14
|
+
const packages = yield* Effect.promise(() => workspacePackages(inputs));
|
|
15
|
+
const compiler = yield* ImportCompiler;
|
|
16
|
+
return yield* compiler.departures(inputs, packages);
|
|
17
|
+
}, Effect.provide(ImportCompiler.layer));
|