@shivaedev/quality 0.73.3 → 0.74.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/CHANGELOG.md +16 -0
- package/README.md +9 -1
- package/dist/adapters/buildEntryPaths.d.ts +1 -1
- package/dist/adapters/buildEntryPaths.d.ts.map +1 -1
- package/dist/adapters/buildEntryPaths.js +9 -6
- package/dist/adapters/buildEntryPaths.js.map +1 -1
- package/dist/adapters/buildEntryValue.d.ts +1 -0
- package/dist/adapters/buildEntryValue.d.ts.map +1 -1
- package/dist/adapters/buildEntryValue.js +1 -1
- package/dist/adapters/buildEntryValue.js.map +1 -1
- package/dist/adapters/buildHelper.d.ts +1 -0
- package/dist/adapters/buildHelper.d.ts.map +1 -1
- package/dist/adapters/buildHelper.js +9 -8
- package/dist/adapters/buildHelper.js.map +1 -1
- package/dist/adapters/bundlerExternals.d.ts +4 -0
- package/dist/adapters/bundlerExternals.d.ts.map +1 -0
- package/dist/adapters/bundlerExternals.js +46 -0
- package/dist/adapters/bundlerExternals.js.map +1 -0
- package/dist/adapters/bundlerSources.d.ts +1 -0
- package/dist/adapters/bundlerSources.d.ts.map +1 -1
- package/dist/adapters/bundlerSources.js +17 -4
- package/dist/adapters/bundlerSources.js.map +1 -1
- package/dist/adapters/bundlerTargets.d.ts +8 -0
- package/dist/adapters/bundlerTargets.d.ts.map +1 -0
- package/dist/adapters/{bundlerEntries.js → bundlerTargets.js} +20 -17
- package/dist/adapters/bundlerTargets.js.map +1 -0
- package/dist/adapters/importedCall.d.ts +4 -0
- package/dist/adapters/importedCall.d.ts.map +1 -1
- package/dist/adapters/importedCall.js +6 -3
- package/dist/adapters/importedCall.js.map +1 -1
- package/dist/adapters/knip/configuration.d.ts +4 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +36 -5
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/knip/run.js +10 -5
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/reachableBuilds.d.ts +9 -0
- package/dist/adapters/reachableBuilds.d.ts.map +1 -0
- package/dist/adapters/{reachableBuildEntries.js → reachableBuilds.js} +15 -11
- package/dist/adapters/reachableBuilds.js.map +1 -0
- package/dist/adapters/spawnedEntries.d.ts.map +1 -1
- package/dist/adapters/spawnedEntries.js +4 -5
- package/dist/adapters/spawnedEntries.js.map +1 -1
- package/dist/config/decode.d.ts +1 -0
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +1 -0
- package/dist/config/decode.js.map +1 -1
- package/dist/config/load.d.ts +1 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +1 -0
- package/dist/config/load.js.map +1 -1
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +1 -0
- package/dist/engine/session.js.map +1 -1
- package/dist/inventory/programmaticBuilds.d.ts +4 -0
- package/dist/inventory/programmaticBuilds.d.ts.map +1 -0
- package/dist/inventory/programmaticBuilds.js +13 -0
- package/dist/inventory/programmaticBuilds.js.map +1 -0
- package/dist/rule.d.ts +1 -0
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js.map +1 -1
- package/dist/rules/files/namedAfterExport.js +2 -2
- package/dist/rules/files/namedAfterExport.js.map +1 -1
- package/dist/testing/ruleChecks.d.ts +16 -0
- package/dist/testing/ruleChecks.d.ts.map +1 -0
- package/dist/testing/ruleChecks.js +42 -0
- package/dist/testing/ruleChecks.js.map +1 -0
- package/dist/testing/ruleStory.d.ts +7 -11
- package/dist/testing/ruleStory.d.ts.map +1 -1
- package/dist/testing/ruleStory.js +3 -19
- package/dist/testing/ruleStory.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/buildEntryPaths.ts +10 -6
- package/src/adapters/buildEntryValue.ts +1 -1
- package/src/adapters/buildHelper.ts +10 -9
- package/src/adapters/bundlerExternals.ts +57 -0
- package/src/adapters/bundlerSources.ts +23 -4
- package/src/adapters/{bundlerEntries.ts → bundlerTargets.ts} +38 -18
- package/src/adapters/importedCall.ts +7 -3
- package/src/adapters/knip/configuration.ts +47 -5
- package/src/adapters/knip/run.ts +10 -5
- package/src/adapters/{reachableBuildEntries.ts → reachableBuilds.ts} +19 -10
- package/src/adapters/spawnedEntries.ts +4 -5
- package/src/config/decode.ts +1 -0
- package/src/config/load.ts +2 -0
- package/src/config.ts +1 -0
- package/src/engine/session.ts +1 -0
- package/src/inventory/{programmaticEntries.ts → programmaticBuilds.ts} +5 -3
- package/src/rule.ts +1 -0
- package/src/rules/files/namedAfterExport.ts +2 -2
- package/src/testing/ruleChecks.ts +57 -0
- package/src/testing/ruleStory.ts +4 -26
- package/dist/adapters/bundlerEntries.d.ts +0 -4
- package/dist/adapters/bundlerEntries.d.ts.map +0 -1
- package/dist/adapters/bundlerEntries.js.map +0 -1
- package/dist/adapters/reachableBuildEntries.d.ts +0 -5
- package/dist/adapters/reachableBuildEntries.d.ts.map +0 -1
- package/dist/adapters/reachableBuildEntries.js.map +0 -1
- package/dist/inventory/programmaticEntries.d.ts +0 -4
- package/dist/inventory/programmaticEntries.d.ts.map +0 -1
- package/dist/inventory/programmaticEntries.js +0 -11
- package/dist/inventory/programmaticEntries.js.map +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Cause, Effect, Path } from "effect";
|
|
2
|
+
import { configureRegistered } from "#adapters/rule.ts";
|
|
3
|
+
import { scanned } from "#testing/adapters/imports.ts";
|
|
4
|
+
export function ruleChecks(engine, tell) {
|
|
5
|
+
return {
|
|
6
|
+
check: Effect.fn("RuleStory.check")(function* (rule, options, directory = ".", entries) {
|
|
7
|
+
tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
8
|
+
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
9
|
+
if (configured._tag === "Invalid") {
|
|
10
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
11
|
+
}
|
|
12
|
+
const path = yield* Path.Path;
|
|
13
|
+
const scannedInputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
14
|
+
const inputs = entries === undefined ? scannedInputs : { ...scannedInputs, entries };
|
|
15
|
+
engine.findings = yield* configured.check(inputs);
|
|
16
|
+
return engine.findings;
|
|
17
|
+
}),
|
|
18
|
+
checkOutcome: Effect.fn("RuleStory.checkOutcome")(function* (rule, entries) {
|
|
19
|
+
tell(`quality checks ${rule.id} with declared entries`);
|
|
20
|
+
const configured = yield* Effect.promise(() => rule.configure(undefined));
|
|
21
|
+
if (configured._tag === "Invalid") {
|
|
22
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
23
|
+
}
|
|
24
|
+
const inputs = yield* Effect.promise(() => scanned(engine.root));
|
|
25
|
+
const result = yield* Effect.exit(configured.check({ ...inputs, entries }));
|
|
26
|
+
if (result._tag === "Failure") {
|
|
27
|
+
engine.failure = Cause.pretty(result.cause);
|
|
28
|
+
return "failed";
|
|
29
|
+
}
|
|
30
|
+
engine.failure = undefined;
|
|
31
|
+
engine.findings = result.value;
|
|
32
|
+
return "passed";
|
|
33
|
+
}),
|
|
34
|
+
failureMessage: () => engine.failure === undefined ? Effect.die(new Error("Run a failed check before reading its failure message")) : Effect.succeed(engine.failure),
|
|
35
|
+
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule, options) {
|
|
36
|
+
tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
37
|
+
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
38
|
+
return configured._tag === "Invalid" ? configured.issues : [];
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMapping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AAC;gBAC/B,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5C,OAAO,QAAQ,CAAC;YACjB,CAAC;YACD,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;YAC3B,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;YAC/B,OAAO,QAAQ,CAAC;QACjB,CAAC,CAAC;QACF,cAAc,EAAE,GAAG,EAAE,CACpB,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/I,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAoB,EAAE,OAAgB;YAClG,IAAI,CAAC,sBAAsB,IAAI,CAAC,EAAE,SAAS,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtE,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YACnF,OAAO,UAAU,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,CAAC,CAAC;KACF,CAAC;AACH,CAAC"}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path } from "effect";
|
|
2
|
-
import type { Finding
|
|
3
|
-
import { type Run } from "#testing/adapters/cli.ts";
|
|
2
|
+
import type { Finding } from "#rule.ts";
|
|
4
3
|
import { type SeedFile } from "#testing/adapters/tree.ts";
|
|
5
|
-
|
|
6
|
-
answer: Run | undefined;
|
|
7
|
-
findings: Findings | undefined;
|
|
8
|
-
readonly root: string;
|
|
9
|
-
}
|
|
4
|
+
import { type RuleEngine } from "#testing/ruleChecks.ts";
|
|
10
5
|
export declare function locationOf(finding: Finding): string;
|
|
11
6
|
export declare function makeRuleStory(): import("@shivaedev/test-story/server/storyKit.ts").StoryKit<RuleEngine, "repository", {
|
|
12
|
-
check: <TInput>(rule: Rule<string, TInput, import("#rule.ts").RuleServices>, options?: TInput | undefined, directory?: string | undefined) => Effect.Effect<Findings, unknown, Path.Path | import("#rule.ts").RuleServices>;
|
|
13
|
-
|
|
7
|
+
check: <TInput>(rule: import("#rule.ts").Rule<string, TInput, import("#rule.ts").RuleServices>, options?: TInput | undefined, directory?: string | undefined, entries?: readonly string[] | undefined) => Effect.Effect<import("#rule.ts").Findings, unknown, Path.Path | import("#rule.ts").RuleServices>;
|
|
8
|
+
checkOutcome: <TInput>(rule: import("#rule.ts").Rule<string, TInput, import("#rule.ts").RuleServices>, entries: readonly string[]) => Effect.Effect<"failed" | "passed", never, import("#rule.ts").RuleServices>;
|
|
9
|
+
failureMessage: () => Effect.Effect<string, never, never>;
|
|
10
|
+
optionIssues: (rule: import("#rule.ts").RegisteredRule<import("#rule.ts").RuleServices>, options: unknown) => Effect.Effect<readonly string[], never, never>;
|
|
11
|
+
findings: () => Effect.Effect<import("#rule.ts").Findings, never, never>;
|
|
14
12
|
gate: () => Effect.Effect<void, never, never>;
|
|
15
13
|
gateOutcome: () => Effect.Effect<string, never, never>;
|
|
16
14
|
gateReport: () => Effect.Effect<string, never, never>;
|
|
17
15
|
gateReports: (prefix: string) => Effect.Effect<string, never, never>;
|
|
18
16
|
locations: () => Effect.Effect<string[], never, never>;
|
|
19
17
|
messages: () => Effect.Effect<string[], never, never>;
|
|
20
|
-
optionIssues: (rule: RegisteredRule<import("#rule.ts").RuleServices>, options: unknown) => Effect.Effect<readonly string[], never, never>;
|
|
21
18
|
removes: (path: string) => Effect.Effect<void, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | Path.Path>;
|
|
22
19
|
writes: (...files: readonly SeedFile[]) => Effect.Effect<void, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | Path.Path>;
|
|
23
20
|
}, never, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | FileSystem.FileSystem | Path.Path> & {
|
|
@@ -25,5 +22,4 @@ export declare function makeRuleStory(): import("@shivaedev/test-story/server/st
|
|
|
25
22
|
readonly repositoryHas: (...files: readonly SeedFile[]) => import("@shivaedev/test-story/server/storyKit.ts").Trait<RuleEngine, "repository", FileSystem.FileSystem | Path.Path>;
|
|
26
23
|
readonly repositoryLinks: (path: string, target: string) => import("@shivaedev/test-story/server/storyKit.ts").Trait<RuleEngine, "repository", FileSystem.FileSystem | Path.Path>;
|
|
27
24
|
};
|
|
28
|
-
export {};
|
|
29
25
|
//# sourceMappingURL=ruleStory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleStory.d.ts","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ruleStory.d.ts","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,wBAAwB,CAAC;AAgBrE,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEnD;AA6BD,wBAAgB,aAAa;;;;;;;;;0BAsBJ,MAAM;;;;uBAeT,SAAS,QAAQ,EAAE;;;uCAOP,SAAS,QAAQ,EAAE;qCAIrB,MAAM,UAAU,MAAM;EAqBrD"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path } from "effect";
|
|
2
2
|
import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
|
|
3
|
-
import { configureRegistered } from "#adapters/rule.ts";
|
|
4
3
|
import { services } from "#cli/runMain.ts";
|
|
5
4
|
import { runQuality } from "#testing/adapters/cli.ts";
|
|
6
|
-
import { scanned } from "#testing/adapters/imports.ts";
|
|
7
5
|
import { packageRoot } from "#testing/adapters/tree.ts";
|
|
6
|
+
import { ruleChecks } from "#testing/ruleChecks.ts";
|
|
8
7
|
const writeAll = Effect.fn("RuleStory.writeAll")(function* (root, files) {
|
|
9
8
|
const fs = yield* FileSystem.FileSystem;
|
|
10
9
|
const path = yield* Path.Path;
|
|
@@ -49,7 +48,7 @@ export function makeRuleStory() {
|
|
|
49
48
|
create: () => Effect.gen(function* () {
|
|
50
49
|
const fs = yield* FileSystem.FileSystem;
|
|
51
50
|
const root = yield* fs.makeTempDirectoryScoped({ prefix: "quality-rule-" });
|
|
52
|
-
const engine = { answer: undefined, findings: undefined, root };
|
|
51
|
+
const engine = { answer: undefined, failure: undefined, findings: undefined, root };
|
|
53
52
|
return engine;
|
|
54
53
|
}),
|
|
55
54
|
inspect: ({ findings }) => ({ findings }),
|
|
@@ -57,17 +56,7 @@ export function makeRuleStory() {
|
|
|
57
56
|
name: "Quality rule",
|
|
58
57
|
stages: ["repository"],
|
|
59
58
|
verbs: (engine, story) => ({
|
|
60
|
-
|
|
61
|
-
story.tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
62
|
-
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
63
|
-
if (configured._tag === "Invalid") {
|
|
64
|
-
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
65
|
-
}
|
|
66
|
-
const path = yield* Path.Path;
|
|
67
|
-
const inputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
68
|
-
engine.findings = yield* configured.check(inputs);
|
|
69
|
-
return engine.findings;
|
|
70
|
-
}),
|
|
59
|
+
...ruleChecks(engine, story.tell),
|
|
71
60
|
findings: () => checked(engine),
|
|
72
61
|
gate: Effect.fn("RuleStory.gate")(function* () {
|
|
73
62
|
story.tell("quality runs the repository gate");
|
|
@@ -81,11 +70,6 @@ export function makeRuleStory() {
|
|
|
81
70
|
.join("\n\n")),
|
|
82
71
|
locations: () => Effect.map(checked(engine), (findings) => findings.map(locationOf)),
|
|
83
72
|
messages: () => Effect.map(checked(engine), (findings) => findings.map((finding) => finding.message)),
|
|
84
|
-
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule, options) {
|
|
85
|
-
story.tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
86
|
-
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
87
|
-
return configured._tag === "Invalid" ? configured.issues : [];
|
|
88
|
-
}),
|
|
89
73
|
removes: Effect.fn("RuleStory.removes")(function* (path) {
|
|
90
74
|
story.tell(`the author removes ${path}`);
|
|
91
75
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleStory.js","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ruleStory.js","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CA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AAC,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7H,CAAC;IAED,SAAS,eAAe,CAAC,IAAY,EAAE,MAAc;QACpD,OAAO,SAAS,CAAC,KAAK,CAAC,YAAY,EAAE,wBAAwB,IAAI,OAAO,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAC5F,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;YACxC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/B,KAAK,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3F,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CACF,CAAC;IACH,CAAC;IAED,SAAS,gBAAgB;QACxB,OAAO,eAAe,CAAC,iCAAiC,EAAE,WAAW,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,OAAO,GAIT,EAAE,GAAG,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;IACvE,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.1",
|
|
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": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@effect/platform-node": "4.1.1",
|
|
69
69
|
"@effect/platform-node-shared": "4.1.1",
|
|
70
70
|
"@effect/vitest": "4.1.1",
|
|
71
|
-
"@shivaedev/test-story": "0.45.
|
|
71
|
+
"@shivaedev/test-story": "0.45.5",
|
|
72
72
|
"@types/node": "24.19.2",
|
|
73
73
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
74
74
|
"effect": "4.1.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@effect/platform-node": "4.1.1",
|
|
79
79
|
"@effect/platform-node-shared": "4.1.1",
|
|
80
|
-
"@shivaedev/test-story": "0.45.
|
|
80
|
+
"@shivaedev/test-story": "0.45.5",
|
|
81
81
|
"effect": "4.1.1",
|
|
82
82
|
"vitest": "5.0.5"
|
|
83
83
|
},
|
|
@@ -3,10 +3,14 @@ import ts from "typescript";
|
|
|
3
3
|
import { type BuildBindings, buildEntryValue, buildOption } from "#adapters/buildEntryValue.ts";
|
|
4
4
|
import { importedCall } from "#adapters/importedCall.ts";
|
|
5
5
|
|
|
6
|
+
function sourcePath(node: ts.Node, root: string): string {
|
|
7
|
+
return posix.resolve(root, node.getSourceFile().fileName);
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
function pathFromCall(
|
|
7
11
|
node: ts.CallExpression,
|
|
8
12
|
cwd: string,
|
|
9
|
-
|
|
13
|
+
root: string,
|
|
10
14
|
paths: (expression: ts.Expression) => readonly string[],
|
|
11
15
|
): readonly string[] {
|
|
12
16
|
if (node.expression.getText() === "process.cwd" && node.arguments.length === 0) {
|
|
@@ -19,7 +23,7 @@ function pathFromCall(
|
|
|
19
23
|
&& ts.isMetaProperty(argument.expression)
|
|
20
24
|
&& argument.expression.keywordToken === ts.SyntaxKind.ImportKeyword
|
|
21
25
|
&& argument.name.text === "url"
|
|
22
|
-
? [
|
|
26
|
+
? [sourcePath(argument, root)]
|
|
23
27
|
: [];
|
|
24
28
|
}
|
|
25
29
|
if (imported === undefined || !/^(?:node:)?path$/u.test(imported.module) || !["join", "resolve", "dirname"].includes(imported.name)) {
|
|
@@ -53,7 +57,7 @@ function valuesOf(node: ts.Expression): readonly ts.Expression[] {
|
|
|
53
57
|
export function buildEntryPaths(
|
|
54
58
|
expression: ts.Expression,
|
|
55
59
|
cwd: string,
|
|
56
|
-
|
|
60
|
+
root: string,
|
|
57
61
|
active: ReadonlySet<ts.Node> = new Set(),
|
|
58
62
|
bindings: BuildBindings = new Map(),
|
|
59
63
|
): readonly string[] {
|
|
@@ -63,7 +67,7 @@ export function buildEntryPaths(
|
|
|
63
67
|
}
|
|
64
68
|
const visited = new Set([...active, node]);
|
|
65
69
|
function paths(value: ts.Expression) {
|
|
66
|
-
return buildEntryPaths(value, cwd,
|
|
70
|
+
return buildEntryPaths(value, cwd, root, visited, bindings);
|
|
67
71
|
}
|
|
68
72
|
if (ts.isStringLiteralLike(node)) {
|
|
69
73
|
return [node.text];
|
|
@@ -75,7 +79,7 @@ export function buildEntryPaths(
|
|
|
75
79
|
(ts.isIdentifier(node) && node.text === "__dirname")
|
|
76
80
|
|| (ts.isPropertyAccessExpression(node) && node.expression.kind === ts.SyntaxKind.MetaProperty && node.name.text === "dirname")
|
|
77
81
|
) {
|
|
78
|
-
return [posix.dirname(
|
|
82
|
+
return [posix.dirname(sourcePath(node, root))];
|
|
79
83
|
}
|
|
80
|
-
return ts.isCallExpression(node) ? pathFromCall(node, cwd,
|
|
84
|
+
return ts.isCallExpression(node) ? pathFromCall(node, cwd, root, paths) : valuesOf(node).flatMap(paths);
|
|
81
85
|
}
|
|
@@ -2,7 +2,7 @@ import ts from "typescript";
|
|
|
2
2
|
|
|
3
3
|
export type BuildBindings = ReadonlyMap<ts.ParameterDeclaration, ts.Expression>;
|
|
4
4
|
|
|
5
|
-
function declaredValue(statements: readonly ts.Statement[], name: string): ts.Expression | undefined {
|
|
5
|
+
export function declaredValue(statements: readonly ts.Statement[], name: string): ts.Expression | undefined {
|
|
6
6
|
for (const statement of statements) {
|
|
7
7
|
if (!(ts.isVariableStatement(statement) && statement.declarationList.flags & ts.NodeFlags.Const)) {
|
|
8
8
|
continue;
|
|
@@ -51,17 +51,18 @@ function localHelper(expression: ts.Expression, call: ts.CallExpression): Helper
|
|
|
51
51
|
return undefined;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
if (imported === undefined || !(imported.module.startsWith(".") || imported.module.startsWith("#"))) {
|
|
54
|
+
export function importedSource(node: ts.Node, module: string, sources: ReadonlyMap<string, ts.SourceFile>): ts.SourceFile | undefined {
|
|
55
|
+
if (!(module.startsWith(".") || module.startsWith("#"))) {
|
|
57
56
|
return undefined;
|
|
58
57
|
}
|
|
59
|
-
const modulePath =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
const modulePath = module.startsWith("#") ? module.slice(1) : posix.join(posix.dirname(node.getSourceFile().fileName), module);
|
|
59
|
+
return sources.get(modulePath) ?? [...sources.values()].find((candidate) => candidate.fileName.replaceAll("\\", "/").endsWith(`/${modulePath}`));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function importedHelper(call: ts.CallExpression, sources: ReadonlyMap<string, ts.SourceFile>): Helper | undefined {
|
|
63
|
+
const imported = importedCall(call);
|
|
64
|
+
const source = imported === undefined ? undefined : importedSource(call, imported.module, sources);
|
|
65
|
+
return source === undefined || imported === undefined ? undefined : declared(source, imported.name);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
export function buildHelper(call: ts.CallExpression, sources: ReadonlyMap<string, ts.SourceFile>, bindings: BuildBindings): Helper | undefined {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { type BuildBindings, buildEntryValue, buildOption, declaredValue } from "#adapters/buildEntryValue.ts";
|
|
3
|
+
import { importedSource } from "#adapters/buildHelper.ts";
|
|
4
|
+
import { importedName } from "#adapters/importedCall.ts";
|
|
5
|
+
import { packageNameOf } from "#imports/packageName.ts";
|
|
6
|
+
|
|
7
|
+
function importedValue(node: ts.Identifier, sources: ReadonlyMap<string, ts.SourceFile>): ts.Expression | undefined {
|
|
8
|
+
const imported = importedName(node);
|
|
9
|
+
const source = imported === undefined ? undefined : importedSource(node, imported.module, sources);
|
|
10
|
+
return source === undefined || imported === undefined ? undefined : declaredValue(source.statements, imported.name);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function externalNames(
|
|
14
|
+
expression: ts.Expression,
|
|
15
|
+
bindings: BuildBindings,
|
|
16
|
+
sources: ReadonlyMap<string, ts.SourceFile>,
|
|
17
|
+
active: ReadonlySet<ts.Node>,
|
|
18
|
+
): readonly string[] {
|
|
19
|
+
const node = buildEntryValue(expression, new Set(), bindings);
|
|
20
|
+
if (active.has(node)) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const visited = new Set([...active, node]);
|
|
24
|
+
function names(value: ts.Expression) {
|
|
25
|
+
return externalNames(value, bindings, sources, visited);
|
|
26
|
+
}
|
|
27
|
+
if (ts.isStringLiteralLike(node)) {
|
|
28
|
+
return [node.text];
|
|
29
|
+
}
|
|
30
|
+
if (ts.isSpreadElement(node)) {
|
|
31
|
+
return names(node.expression);
|
|
32
|
+
}
|
|
33
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
34
|
+
return node.elements.flatMap(names);
|
|
35
|
+
}
|
|
36
|
+
if (ts.isIdentifier(node)) {
|
|
37
|
+
const value = importedValue(node, sources);
|
|
38
|
+
return value === undefined ? [] : names(value);
|
|
39
|
+
}
|
|
40
|
+
// A filter keeps only names the list already declares external, so the whole list stands in for its predicate.
|
|
41
|
+
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "filter"
|
|
42
|
+
? names(node.expression.expression)
|
|
43
|
+
: [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function bundlerExternals(
|
|
47
|
+
options: ts.ObjectLiteralExpression,
|
|
48
|
+
bindings: BuildBindings,
|
|
49
|
+
sources: ReadonlyMap<string, ts.SourceFile>,
|
|
50
|
+
): readonly string[] {
|
|
51
|
+
const external = buildOption(options, "external");
|
|
52
|
+
return external === undefined
|
|
53
|
+
? []
|
|
54
|
+
: externalNames(external, bindings, sources, new Set())
|
|
55
|
+
.filter((name) => !(name.startsWith(".") || name.startsWith("/")))
|
|
56
|
+
.map(packageNameOf);
|
|
57
|
+
}
|
|
@@ -30,12 +30,14 @@ function directSources(files: readonly SourceFile[]): Map<string, ts.SourceFile>
|
|
|
30
30
|
return sources;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function fileEdges(graph: ImportGraph): readonly (readonly [from: string, to: string])[] {
|
|
34
|
+
return graph.edges.flatMap((edge) => (!edge.type && edge.to.kind === "file" ? [[edge.from, edge.to.path] as const] : []));
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
function importedBy(graph: ImportGraph): ReadonlyMap<string, readonly string[]> {
|
|
34
38
|
const importers = new Map<string, string[]>();
|
|
35
|
-
for (const
|
|
36
|
-
|
|
37
|
-
importers.set(edge.to.path, [...(importers.get(edge.to.path) ?? []), edge.from]);
|
|
38
|
-
}
|
|
39
|
+
for (const [from, to] of fileEdges(graph)) {
|
|
40
|
+
importers.set(to, [...(importers.get(to) ?? []), from]);
|
|
39
41
|
}
|
|
40
42
|
return importers;
|
|
41
43
|
}
|
|
@@ -58,3 +60,20 @@ export function bundlerSources(files: readonly SourceFile[], graph: ImportGraph)
|
|
|
58
60
|
}
|
|
59
61
|
return sources;
|
|
60
62
|
}
|
|
63
|
+
|
|
64
|
+
export function bundlerModules(
|
|
65
|
+
sources: ReadonlyMap<string, ts.SourceFile>,
|
|
66
|
+
files: readonly SourceFile[],
|
|
67
|
+
graph: ImportGraph,
|
|
68
|
+
): ReadonlyMap<string, ts.SourceFile> {
|
|
69
|
+
const filesByPath = new Map(files.map((file) => [file.path, file]));
|
|
70
|
+
const modules = new Map(sources);
|
|
71
|
+
for (const [from, to] of fileEdges(graph)) {
|
|
72
|
+
const file = sources.has(from) && !modules.has(to) ? filesByPath.get(to) : undefined;
|
|
73
|
+
const source = file === undefined ? undefined : parse(file);
|
|
74
|
+
if (source !== undefined) {
|
|
75
|
+
modules.set(to, source);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return modules;
|
|
79
|
+
}
|
|
@@ -3,6 +3,7 @@ import ts from "typescript";
|
|
|
3
3
|
import { buildEntryPaths } from "#adapters/buildEntryPaths.ts";
|
|
4
4
|
import { type BuildBindings, buildEntryValue, buildOption } from "#adapters/buildEntryValue.ts";
|
|
5
5
|
import { buildArguments, buildHelper } from "#adapters/buildHelper.ts";
|
|
6
|
+
import { bundlerExternals } from "#adapters/bundlerExternals.ts";
|
|
6
7
|
import { importedCall } from "#adapters/importedCall.ts";
|
|
7
8
|
import { mappedBuildBindings } from "#adapters/mappedBuildBindings.ts";
|
|
8
9
|
import type { SourceFile } from "#rule.ts";
|
|
@@ -28,42 +29,59 @@ function entryOption(call: ts.CallExpression): string | undefined {
|
|
|
28
29
|
return imported?.module === "esbuild" && ESBUILD.has(imported.name) ? "entryPoints" : undefined;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
export interface BundlerTargets {
|
|
33
|
+
readonly entries: readonly string[];
|
|
34
|
+
readonly externals: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface BuildConfig {
|
|
38
|
+
readonly option: string;
|
|
39
|
+
readonly options: ts.ObjectLiteralExpression;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildConfigs(call: ts.CallExpression, bindings: BuildBindings): readonly BuildConfig[] {
|
|
32
43
|
const option = entryOption(call);
|
|
33
44
|
const [argument] = call.arguments;
|
|
34
|
-
const
|
|
35
|
-
if (option === undefined ||
|
|
45
|
+
const value = argument === undefined ? undefined : buildEntryValue(argument, new Set(), bindings);
|
|
46
|
+
if (option === undefined || value === undefined) {
|
|
36
47
|
return [];
|
|
37
48
|
}
|
|
38
|
-
const configs = option === "input" && ts.isArrayLiteralExpression(
|
|
39
|
-
return configs.flatMap((config) =>
|
|
49
|
+
const configs = option === "input" && ts.isArrayLiteralExpression(value) ? value.elements : [value];
|
|
50
|
+
return configs.flatMap((config) => {
|
|
51
|
+
const options = buildEntryValue(config, new Set(), bindings);
|
|
52
|
+
return ts.isObjectLiteralExpression(options) ? [{ option, options }] : [];
|
|
53
|
+
});
|
|
40
54
|
}
|
|
41
55
|
|
|
42
|
-
function configuredEntries(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
function configuredEntries(
|
|
57
|
+
options: ts.ObjectLiteralExpression,
|
|
58
|
+
option: string,
|
|
59
|
+
cwd: string,
|
|
60
|
+
root: string,
|
|
61
|
+
bindings: BuildBindings,
|
|
62
|
+
): readonly string[] {
|
|
47
63
|
const directory = buildOption(options, "absWorkingDir");
|
|
48
|
-
const working = directory === undefined ? cwd : buildEntryPaths(directory, cwd,
|
|
64
|
+
const working = directory === undefined ? cwd : buildEntryPaths(directory, cwd, root, new Set(), bindings)[0];
|
|
49
65
|
if (working === undefined) {
|
|
50
66
|
return [];
|
|
51
67
|
}
|
|
52
68
|
const entries = buildOption(options, option);
|
|
53
|
-
return entries === undefined ? [] : buildEntryPaths(entries, cwd,
|
|
69
|
+
return entries === undefined ? [] : buildEntryPaths(entries, cwd, root, new Set(), bindings).map((path) => posix.resolve(cwd, working, path));
|
|
54
70
|
}
|
|
55
71
|
|
|
56
|
-
export function
|
|
72
|
+
export function bundlerTargets(
|
|
57
73
|
file: SourceFile,
|
|
58
74
|
root: string,
|
|
59
75
|
directory: string,
|
|
60
76
|
sources: ReadonlyMap<string, ts.SourceFile> = new Map(),
|
|
61
|
-
|
|
77
|
+
modules: ReadonlyMap<string, ts.SourceFile> = sources,
|
|
78
|
+
): BundlerTargets {
|
|
62
79
|
const source = sources.get(file.path) ?? parse(file);
|
|
63
80
|
if (source === undefined) {
|
|
64
|
-
return [];
|
|
81
|
+
return { entries: [], externals: [] };
|
|
65
82
|
}
|
|
66
83
|
const entries: string[] = [];
|
|
84
|
+
const externals: string[] = [];
|
|
67
85
|
function visit(node: ts.Node, bindings: BuildBindings, active: ReadonlySet<ts.Node>): void {
|
|
68
86
|
if (ts.isFunctionLike(node)) {
|
|
69
87
|
const body = callbackBody(node);
|
|
@@ -75,11 +93,13 @@ export function bundlerEntries(
|
|
|
75
93
|
return;
|
|
76
94
|
}
|
|
77
95
|
if (ts.isCallExpression(node)) {
|
|
96
|
+
const configs = buildConfigs(node, bindings);
|
|
78
97
|
entries.push(
|
|
79
|
-
...
|
|
80
|
-
posix.relative(root, path),
|
|
98
|
+
...configs.flatMap(({ option, options }) =>
|
|
99
|
+
configuredEntries(options, option, posix.join(root, directory), root, bindings).map((path) => posix.relative(root, path)),
|
|
81
100
|
),
|
|
82
101
|
);
|
|
102
|
+
externals.push(...configs.flatMap(({ options }) => bundlerExternals(options, bindings, modules)));
|
|
83
103
|
const helper = buildHelper(node, sources, bindings);
|
|
84
104
|
if (helper?.body !== undefined && !active.has(helper)) {
|
|
85
105
|
entries.push(posix.relative(root, posix.resolve(root, helper.getSourceFile().fileName)));
|
|
@@ -89,5 +109,5 @@ export function bundlerEntries(
|
|
|
89
109
|
ts.forEachChild(node, (child) => visit(child, bindings, active));
|
|
90
110
|
}
|
|
91
111
|
visit(source, new Map(), new Set());
|
|
92
|
-
return entries;
|
|
112
|
+
return { entries, externals };
|
|
93
113
|
}
|
|
@@ -13,15 +13,19 @@ function calledName(expression: ts.LeftHandSideExpression, clause: ts.ImportClau
|
|
|
13
13
|
return namespace === expression.expression.text ? expression.name.text : undefined;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function
|
|
17
|
-
for (const statement of
|
|
16
|
+
export function importedName(expression: ts.LeftHandSideExpression): { readonly module: string; readonly name: string } | undefined {
|
|
17
|
+
for (const statement of expression.getSourceFile().statements) {
|
|
18
18
|
if (!(ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) || statement.importClause === undefined) {
|
|
19
19
|
continue;
|
|
20
20
|
}
|
|
21
|
-
const name = calledName(
|
|
21
|
+
const name = calledName(expression, statement.importClause);
|
|
22
22
|
if (name !== undefined) {
|
|
23
23
|
return { module: statement.moduleSpecifier.text, name };
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export function importedCall(call: ts.CallExpression): { readonly module: string; readonly name: string } | undefined {
|
|
30
|
+
return importedName(call.expression);
|
|
31
|
+
}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globSync, statSync } from "node:fs";
|
|
2
|
+
import { join, posix } from "node:path";
|
|
2
3
|
import { isToolConfig } from "#adapters/isToolConfig.ts";
|
|
3
4
|
import { KNIP_ISSUES } from "#adapters/knip/findings.ts";
|
|
4
5
|
import { mockEntries } from "#adapters/knip/mockEntries.ts";
|
|
5
6
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
7
|
+
import type { ReachableBuilds } from "#adapters/reachableBuilds.ts";
|
|
6
8
|
import { scriptPaths } from "#adapters/scriptPaths.ts";
|
|
7
9
|
import { exportedModule, exportTargets } from "#imports/packageExports.ts";
|
|
8
10
|
import { packageOf, workspacePackages } from "#imports/workspace.ts";
|
|
11
|
+
import type { PackageManifest } from "#PackageManifest.ts";
|
|
9
12
|
import type { RuleInputs } from "#rule.ts";
|
|
10
13
|
|
|
11
14
|
const ENTRIES = ["**/*.{test,spec,stories,story}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}", "src/test-support/**", "*.config.{ts,mts,cts,js,mjs,cjs}"];
|
|
12
15
|
|
|
16
|
+
export function declaredEntries(inputs: RuleInputs): readonly string[] {
|
|
17
|
+
return (inputs.entries ?? []).flatMap((pattern) => {
|
|
18
|
+
const matches = globSync(pattern, { cwd: inputs.root }).filter((path) => statSync(join(inputs.root, path)).isFile());
|
|
19
|
+
if (matches.length === 0) {
|
|
20
|
+
throw new Error(`quality.config.ts entries pattern "${pattern}" matched no files`);
|
|
21
|
+
}
|
|
22
|
+
return matches;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
function importPaths(imports: Readonly<Record<string, unknown>>) {
|
|
14
27
|
return Object.fromEntries(
|
|
15
28
|
Object.entries(imports).flatMap(([name, target]) => {
|
|
@@ -27,7 +40,19 @@ function importPaths(imports: Readonly<Record<string, unknown>>) {
|
|
|
27
40
|
);
|
|
28
41
|
}
|
|
29
42
|
|
|
30
|
-
|
|
43
|
+
function externalDependencies(manifest: PackageManifest, externals: ReadonlySet<string>): readonly string[] {
|
|
44
|
+
const dependencies = [manifest.dependencies, manifest.devDependencies, manifest.optionalDependencies, manifest.peerDependencies].flatMap((names) =>
|
|
45
|
+
Object.keys(names ?? {}),
|
|
46
|
+
);
|
|
47
|
+
return dependencies.filter((name) => externals.has(name));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function knipConfiguration(
|
|
51
|
+
inputs: RuleInputs,
|
|
52
|
+
toolOwned: readonly string[] = [],
|
|
53
|
+
builds: ReachableBuilds = { entries: new Set(), externals: new Map() },
|
|
54
|
+
declared: readonly string[] = declaredEntries(inputs),
|
|
55
|
+
) {
|
|
31
56
|
const packages = await workspacePackages(inputs);
|
|
32
57
|
const manifests = await Promise.all(
|
|
33
58
|
[".", ...packages.map(({ directory }) => directory)].map(async (directory) => {
|
|
@@ -42,7 +67,7 @@ export async function knipConfiguration(inputs: RuleInputs, toolOwned: readonly
|
|
|
42
67
|
.filter(({ path }) => (packageOf(packages, path)?.directory ?? ".") === directory)
|
|
43
68
|
.map(({ path }) => posix.relative(directory, path));
|
|
44
69
|
const scriptEntries = sources.filter((path) => scripted.has(posix.join(directory, path)));
|
|
45
|
-
const bundled = sources.filter((path) =>
|
|
70
|
+
const bundled = sources.filter((path) => builds.entries.has(posix.join(directory, path)) || mocked.has(posix.join(directory, path)));
|
|
46
71
|
const bins = exportTargets(manifest.bin).map((target) => target.replace(/^\.\//u, ""));
|
|
47
72
|
const binaries = sources.filter(
|
|
48
73
|
(path) => bins.includes(path) || bins.includes(path.replace(/^src\//u, "dist/").replace(/\.(?<mode>[cm]?)tsx?$/u, ".$<mode>js")),
|
|
@@ -52,15 +77,32 @@ export async function knipConfiguration(inputs: RuleInputs, toolOwned: readonly
|
|
|
52
77
|
// Migration runners load these files from their directory, so no import reaches them.
|
|
53
78
|
const migrations = sources.filter((path) => /(?:^|\/)server\/migrations\//u.test(path));
|
|
54
79
|
const ui = toolOwned.filter((file) => (packageOf(packages, file)?.directory ?? ".") === directory).map((file) => posix.relative(directory, file));
|
|
80
|
+
const workspaceEntries = declared
|
|
81
|
+
.filter((file) => (packageOf(packages, file)?.directory ?? ".") === directory)
|
|
82
|
+
.map((file) => posix.relative(directory, file));
|
|
55
83
|
const styles = inputs.files
|
|
56
84
|
.filter((path) => path.endsWith(".css") && (packageOf(packages, path)?.directory ?? ".") === directory)
|
|
57
85
|
.map((path) => posix.relative(directory, path));
|
|
58
86
|
return [
|
|
59
87
|
directory,
|
|
60
88
|
{
|
|
61
|
-
entry: [
|
|
89
|
+
entry: [
|
|
90
|
+
...ENTRIES,
|
|
91
|
+
...publicFiles,
|
|
92
|
+
...configs,
|
|
93
|
+
...migrations,
|
|
94
|
+
...bins,
|
|
95
|
+
...binaries,
|
|
96
|
+
...scriptEntries,
|
|
97
|
+
...bundled,
|
|
98
|
+
...ui,
|
|
99
|
+
...styles,
|
|
100
|
+
...workspaceEntries,
|
|
101
|
+
],
|
|
102
|
+
// A bundle leaves its externals as runtime imports, which the bundling package's own dependencies satisfy.
|
|
103
|
+
ignoreDependencies: externalDependencies(manifest, builds.externals.get(directory === "." ? "" : directory) ?? new Set()),
|
|
62
104
|
paths: importPaths(manifest.imports ?? {}),
|
|
63
|
-
project: [...sources, ...ui, ...styles],
|
|
105
|
+
project: [...sources, ...ui, ...styles, ...workspaceEntries],
|
|
64
106
|
vitest: { config: ["vitest*.config.{ts,mts,cts,js,mjs,cjs}", "vitest.{workspace,projects}.{ts,mts,cts,js,mjs,cjs,json}"] },
|
|
65
107
|
},
|
|
66
108
|
] as const;
|