@shivaedev/quality 0.67.2 → 0.68.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 +20 -0
- package/README.md +22 -5
- package/dist/PackageManifest.d.ts +1 -0
- package/dist/PackageManifest.d.ts.map +1 -1
- package/dist/PackageManifest.js +1 -1
- package/dist/PackageManifest.js.map +1 -1
- package/dist/adapters/biome/browserDiagnostic.d.ts +3 -0
- package/dist/adapters/biome/browserDiagnostic.d.ts.map +1 -0
- package/dist/adapters/biome/browserDiagnostic.js +93 -0
- package/dist/adapters/biome/browserDiagnostic.js.map +1 -0
- package/dist/adapters/biome/browserTargets.d.ts +19 -0
- package/dist/adapters/biome/browserTargets.d.ts.map +1 -0
- package/dist/adapters/biome/browserTargets.js +26 -0
- package/dist/adapters/biome/browserTargets.js.map +1 -0
- package/dist/adapters/biome/run.js +2 -2
- package/dist/adapters/biome/run.js.map +1 -1
- package/dist/adapters/biome/vitestEntry.d.ts +4 -0
- package/dist/adapters/biome/vitestEntry.d.ts.map +1 -0
- package/dist/adapters/biome/vitestEntry.js +27 -0
- package/dist/adapters/biome/vitestEntry.js.map +1 -0
- package/dist/adapters/biome/withExceptionConfig.d.ts +1 -1
- package/dist/adapters/biome/withExceptionConfig.d.ts.map +1 -1
- package/dist/adapters/biome/withExceptionConfig.js +4 -2
- package/dist/adapters/biome/withExceptionConfig.js.map +1 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +1 -4
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/run.js +3 -3
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/biome/recognizeDiagnostics.d.ts.map +1 -1
- package/dist/biome/recognizeDiagnostics.js +13 -6
- package/dist/biome/recognizeDiagnostics.js.map +1 -1
- package/dist/inventory/collect.js +2 -2
- package/dist/inventory/collect.js.map +1 -1
- package/dist/inventory/toolOwnedFiles.d.ts +4 -0
- package/dist/inventory/toolOwnedFiles.d.ts.map +1 -0
- package/dist/inventory/toolOwnedFiles.js +36 -0
- package/dist/inventory/toolOwnedFiles.js.map +1 -0
- package/dist/rules/files/otherNames.d.ts.map +1 -1
- package/dist/rules/files/otherNames.js +13 -1
- package/dist/rules/files/otherNames.js.map +1 -1
- package/dist/rules/stories/adapters/authTables.d.ts +3 -0
- package/dist/rules/stories/adapters/authTables.d.ts.map +1 -0
- package/dist/rules/stories/adapters/authTables.js +52 -0
- package/dist/rules/stories/adapters/authTables.js.map +1 -0
- package/dist/rules/stories/adapters/eventConsumption.d.ts +5 -0
- package/dist/rules/stories/adapters/eventConsumption.d.ts.map +1 -0
- package/dist/rules/stories/adapters/eventConsumption.js +30 -0
- package/dist/rules/stories/adapters/eventConsumption.js.map +1 -0
- package/dist/rules/stories/adapters/outcomeShapes.d.ts +5 -0
- package/dist/rules/stories/adapters/outcomeShapes.d.ts.map +1 -0
- package/dist/rules/stories/adapters/outcomeShapes.js +46 -0
- package/dist/rules/stories/adapters/outcomeShapes.js.map +1 -0
- package/dist/rules/stories/adapters/sqlTables.d.ts +5 -0
- package/dist/rules/stories/adapters/sqlTables.d.ts.map +1 -0
- package/dist/rules/stories/adapters/sqlTables.js +85 -0
- package/dist/rules/stories/adapters/sqlTables.js.map +1 -0
- package/dist/rules/stories/adapters/sqlTokens.d.ts +3 -0
- package/dist/rules/stories/adapters/sqlTokens.d.ts.map +1 -0
- package/dist/rules/stories/adapters/sqlTokens.js +30 -0
- package/dist/rules/stories/adapters/sqlTokens.js.map +1 -0
- package/dist/rules/stories/authSql.d.ts.map +1 -1
- package/dist/rules/stories/authSql.js +18 -111
- package/dist/rules/stories/authSql.js.map +1 -1
- package/dist/rules/stories/domainOutcomes.d.ts.map +1 -1
- package/dist/rules/stories/domainOutcomes.js +24 -17
- package/dist/rules/stories/domainOutcomes.js.map +1 -1
- package/dist/rules/stories/waitOnEvents.d.ts.map +1 -1
- package/dist/rules/stories/waitOnEvents.js +18 -2
- package/dist/rules/stories/waitOnEvents.js.map +1 -1
- package/package.json +5 -3
- package/src/PackageManifest.ts +1 -1
- package/src/adapters/biome/browserDiagnostic.ts +100 -0
- package/src/adapters/biome/browserTargets.ts +27 -0
- package/src/adapters/biome/run.ts +2 -2
- package/src/adapters/biome/vitestEntry.ts +37 -0
- package/src/adapters/biome/withExceptionConfig.ts +4 -2
- package/src/adapters/knip/configuration.ts +1 -4
- package/src/adapters/knip/run.ts +3 -3
- package/src/biome/recognizeDiagnostics.ts +12 -5
- package/src/inventory/collect.ts +2 -2
- package/src/inventory/toolOwnedFiles.ts +41 -0
- package/src/rules/files/otherNames.ts +13 -1
- package/src/rules/stories/adapters/authTables.ts +58 -0
- package/src/rules/stories/adapters/eventConsumption.ts +35 -0
- package/src/rules/stories/adapters/outcomeShapes.ts +57 -0
- package/src/rules/stories/adapters/sqlTables.ts +96 -0
- package/src/rules/stories/adapters/sqlTokens.ts +31 -0
- package/src/rules/stories/authSql.ts +20 -128
- package/src/rules/stories/domainOutcomes.ts +25 -18
- package/src/rules/stories/waitOnEvents.ts +24 -2
- package/dist/inventory/shadcnAlias.d.ts +0 -2
- package/dist/inventory/shadcnAlias.d.ts.map +0 -1
- package/dist/inventory/shadcnAlias.js +0 -73
- package/dist/inventory/shadcnAlias.js.map +0 -1
- package/dist/inventory/shadcnFiles.d.ts +0 -4
- package/dist/inventory/shadcnFiles.d.ts.map +0 -1
- package/dist/inventory/shadcnFiles.js +0 -83
- package/dist/inventory/shadcnFiles.js.map +0 -1
- package/dist/inventory/shadcnFolders.d.ts +0 -6
- package/dist/inventory/shadcnFolders.d.ts.map +0 -1
- package/dist/inventory/shadcnFolders.js +0 -27
- package/dist/inventory/shadcnFolders.js.map +0 -1
- package/src/inventory/shadcnAlias.ts +0 -88
- package/src/inventory/shadcnFiles.ts +0 -87
- package/src/inventory/shadcnFolders.ts +0 -36
|
@@ -1,44 +1,51 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import { importGraph } from "#imports/graph.ts";
|
|
3
4
|
import { defineRule } from "#rule.ts";
|
|
4
|
-
import {
|
|
5
|
+
import { internalValue, shapeModule } from "#rules/stories/adapters/outcomeShapes.ts";
|
|
6
|
+
import { importBindings } from "./importBindings.ts";
|
|
7
|
+
import { storyOrigins } from "./origins.ts";
|
|
5
8
|
import { storySources } from "./sources.ts";
|
|
6
|
-
import { memberName, nodesWhere,
|
|
9
|
+
import { findingAt, memberName, nodesWhere, unwrapped } from "./syntax.ts";
|
|
7
10
|
|
|
8
11
|
const MESSAGE =
|
|
9
|
-
'Uses an Exit, Cause or Result value or reads
|
|
12
|
+
'Uses an Exit, Cause or Result value or reads an internal outcome tag in a story. Have the kit\'s verb or readout return the outcome in the domain\'s words, such as "unauthorized" or "rolled back", and expect that; build failing inputs in a kit trait.';
|
|
10
13
|
|
|
11
|
-
const SHAPES = ["Exit", "Cause", "Result"];
|
|
12
14
|
const OUTCOME_TAGS = new Set(["Failure", "Success"]);
|
|
13
15
|
|
|
14
|
-
function shapeModule(source: ts.SourceFile): (node: ts.Expression) => boolean {
|
|
15
|
-
const bindings = importBindings(source);
|
|
16
|
-
return (node) => {
|
|
17
|
-
const value = unwrapped(node);
|
|
18
|
-
return ts.isIdentifier(value) && SHAPES.some((shape) => bindsModule(bindings.get(value.text), shape, ["effect"]));
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
function outcomeTag(node: ts.PropertyAssignment): boolean {
|
|
23
17
|
const name = ts.isIdentifier(node.name) || ts.isStringLiteral(node.name) ? node.name.text : undefined;
|
|
24
18
|
const value = unwrapped(node.initializer);
|
|
25
19
|
return name === "_tag" && ts.isStringLiteralLike(value) && OUTCOME_TAGS.has(value.text);
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
function shapeReads(source: ts.SourceFile): readonly ts.Node[] {
|
|
29
|
-
const
|
|
22
|
+
function shapeReads(source: ts.SourceFile, checker: ts.TypeChecker): readonly ts.Node[] {
|
|
23
|
+
const bindings = importBindings(source);
|
|
30
24
|
return nodesWhere(
|
|
31
25
|
source,
|
|
32
26
|
(node) =>
|
|
33
27
|
((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))
|
|
34
|
-
&& (memberName(node) === "_tag"
|
|
35
|
-
|| (ts.isBindingElement(node)
|
|
28
|
+
&& (shapeModule(node.expression, bindings) || (memberName(node) === "_tag" && internalValue(node.expression, bindings, checker))))
|
|
29
|
+
|| (ts.isBindingElement(node)
|
|
30
|
+
&& (node.propertyName ?? node.name).getText(source) === "_tag"
|
|
31
|
+
&& ts.isVariableDeclaration(node.parent.parent)
|
|
32
|
+
&& node.parent.parent.initializer !== undefined
|
|
33
|
+
&& internalValue(node.parent.parent.initializer, bindings, checker))
|
|
36
34
|
|| (ts.isPropertyAssignment(node) && outcomeTag(node)),
|
|
37
35
|
);
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
export const domainOutcomes = defineRule({
|
|
41
|
-
check: (inputs) =>
|
|
42
|
-
|
|
39
|
+
check: (inputs) =>
|
|
40
|
+
Effect.gen(function* () {
|
|
41
|
+
const stories = yield* storySources(inputs);
|
|
42
|
+
const origins = storyOrigins(inputs, yield* importGraph(inputs));
|
|
43
|
+
const checker = origins.checker;
|
|
44
|
+
return stories.flatMap((file) => {
|
|
45
|
+
const source = origins.source(file.path);
|
|
46
|
+
return source === undefined ? [] : shapeReads(source, checker).map((node) => ({ ...findingAt(source, node, MESSAGE), file: file.path }));
|
|
47
|
+
});
|
|
48
|
+
}),
|
|
49
|
+
description: "Story verbs and readouts return outcomes in the domain's words, not Exit, Cause or Result shapes or their internal tag reads.",
|
|
43
50
|
id: "tests/domain-outcomes",
|
|
44
51
|
});
|
|
@@ -2,6 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import { isTestSupport } from "#naming/testName.ts";
|
|
4
4
|
import { defineRule } from "#rule.ts";
|
|
5
|
+
import { eventConsumption, repeatedEventConsumption } from "#rules/stories/adapters/eventConsumption.ts";
|
|
5
6
|
import { failingSleep } from "#rules/stories/adapters/failureDeadline.ts";
|
|
6
7
|
import { realTime } from "#rules/stories/adapters/realTime.ts";
|
|
7
8
|
import { bindsModule, type ImportBinding, importBindings } from "./importBindings.ts";
|
|
@@ -12,6 +13,7 @@ const MESSAGE =
|
|
|
12
13
|
"Waits on time in a story or reachable test-support: a sleep, a real timer, a wall-clock read such as Date.now(), polling with eventually or waitFor, fake timers or a clock adjustment in the spec. Settle on the engine's own signal through a kit verb, such as a Deferred the engine completes, story.runUntil or screenDriver's settle(). A deadline bounds a failure but does not prove completion; reaching it must fail the story. When time passing is the behaviour, name it in a kit verb that advances TestClock.";
|
|
13
14
|
|
|
14
15
|
const VI_TIMING = /^(?:useFakeTimers|advanceTimers\w*|runAllTimers\w*|runOnlyPendingTimers\w*|runAllTicks|setSystemTime|waitFor|waitUntil)$/u;
|
|
16
|
+
const REPEATED_READS = new Set(["repeat", "repeatUntil", "repeatWhile"]);
|
|
15
17
|
const CLOCK_CHANGES = new Set(["adjust", "setTime"]);
|
|
16
18
|
|
|
17
19
|
function receiverOf(callee: ts.Expression): ts.Identifier | undefined {
|
|
@@ -29,7 +31,7 @@ function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, Import
|
|
|
29
31
|
if (ts.isIdentifier(callee)) {
|
|
30
32
|
const binding = bindings.get(callee.text);
|
|
31
33
|
return (
|
|
32
|
-
binding?.imported === "eventually"
|
|
34
|
+
(binding?.imported === "eventually" && binding.module === "@shivaedev/test/eventually.ts")
|
|
33
35
|
|| (binding?.module === "effect/Effect" && binding.imported === "sleep" && !failingSleep(call, bindings))
|
|
34
36
|
|| realTime(call, bindings)
|
|
35
37
|
);
|
|
@@ -43,17 +45,37 @@ function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, Import
|
|
|
43
45
|
return (
|
|
44
46
|
realTime(call, bindings)
|
|
45
47
|
|| (member === "sleep" && bindsModule(binding, "Effect", ["effect"]) && !failingSleep(call, bindings))
|
|
48
|
+
|| (REPEATED_READS.has(member) && bindsModule(binding, "Effect", ["effect"]) && !repeatedEventConsumption(call, bindings))
|
|
46
49
|
|| (VI_TIMING.test(member) && vitestTiming(receiver, bindings))
|
|
47
50
|
|| (!support && CLOCK_CHANGES.has(member) && bindsModule(binding, "TestClock", ["effect/testing"]))
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
function hasTimedCall(node: ts.Node, bindings: ReadonlyMap<string, ImportBinding>, support: boolean): boolean {
|
|
55
|
+
return (
|
|
56
|
+
(ts.isCallExpression(node) && timedWait(node, bindings, support))
|
|
57
|
+
|| (ts.isNewExpression(node) && realTime(node, bindings))
|
|
58
|
+
|| ts.forEachChild(node, (child) => hasTimedCall(child, bindings, support)) === true
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readsInCondition(node: ts.Node): boolean {
|
|
63
|
+
return ts.isYieldExpression(node) || ts.forEachChild(node, readsInCondition) === true;
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
function timedWaits(source: ts.SourceFile): readonly ts.Node[] {
|
|
52
67
|
const bindings = importBindings(source);
|
|
53
68
|
const support = isTestSupport(source.fileName);
|
|
54
69
|
const found: ts.Node[] = [];
|
|
55
70
|
function visit(node: ts.Node): void {
|
|
56
|
-
if (
|
|
71
|
+
if (
|
|
72
|
+
(ts.isCallExpression(node) && timedWait(node, bindings, support))
|
|
73
|
+
|| (ts.isNewExpression(node) && realTime(node, bindings))
|
|
74
|
+
|| (ts.isWhileStatement(node)
|
|
75
|
+
&& readsInCondition(node.expression)
|
|
76
|
+
&& !eventConsumption(node, bindings)
|
|
77
|
+
&& !hasTimedCall(node, bindings, support))
|
|
78
|
+
) {
|
|
57
79
|
found.push(node);
|
|
58
80
|
}
|
|
59
81
|
ts.forEachChild(node, visit);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shadcnAlias.d.ts","sourceRoot":"","sources":["../../src/inventory/shadcnAlias.ts"],"names":[],"mappings":"AAmCA,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAoDpE"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
const PROBE = "__quality_shadcn__.tsx";
|
|
4
|
-
function capture(pattern, alias) {
|
|
5
|
-
const star = pattern.indexOf("*");
|
|
6
|
-
if (star === -1) {
|
|
7
|
-
return pattern === alias ? "" : undefined;
|
|
8
|
-
}
|
|
9
|
-
const prefix = pattern.slice(0, star);
|
|
10
|
-
const suffix = pattern.slice(star + 1);
|
|
11
|
-
return alias.startsWith(prefix) && alias.endsWith(suffix)
|
|
12
|
-
? alias.slice(prefix.length, suffix.length === 0 ? undefined : -suffix.length)
|
|
13
|
-
: undefined;
|
|
14
|
-
}
|
|
15
|
-
function pathTarget(alias, options, directory) {
|
|
16
|
-
const pathsBase = Reflect.get(options, "pathsBasePath");
|
|
17
|
-
const base = options.baseUrl ?? (typeof pathsBase === "string" ? pathsBase : directory);
|
|
18
|
-
const patterns = Object.entries(options.paths ?? {}).toSorted(([left], [right]) => right.indexOf("*") - left.indexOf("*"));
|
|
19
|
-
const exact = options.paths?.[alias]?.[0];
|
|
20
|
-
if (exact !== undefined) {
|
|
21
|
-
return resolve(base, exact);
|
|
22
|
-
}
|
|
23
|
-
for (const [pattern, targets] of patterns) {
|
|
24
|
-
const captured = capture(pattern, alias);
|
|
25
|
-
const target = targets[0];
|
|
26
|
-
if (captured !== undefined && target !== undefined) {
|
|
27
|
-
return resolve(base, target.replace("*", captured));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
export function shadcnAlias(directory, alias) {
|
|
33
|
-
if (alias.startsWith(".") || isAbsolute(alias)) {
|
|
34
|
-
return resolve(directory, alias);
|
|
35
|
-
}
|
|
36
|
-
const config = ts.findConfigFile(directory, ts.sys.fileExists);
|
|
37
|
-
const parsed = config === undefined
|
|
38
|
-
? undefined
|
|
39
|
-
: ts.getParsedCommandLineOfConfigFile(config, {}, {
|
|
40
|
-
...ts.sys,
|
|
41
|
-
onUnRecoverableConfigFileDiagnostic: () => undefined,
|
|
42
|
-
});
|
|
43
|
-
if (parsed?.errors.length) {
|
|
44
|
-
throw new Error(ts.formatDiagnostics(parsed.errors, {
|
|
45
|
-
getCanonicalFileName: (file) => file,
|
|
46
|
-
getCurrentDirectory: () => directory,
|
|
47
|
-
getNewLine: () => "\n",
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
const options = parsed?.options ?? {};
|
|
51
|
-
const target = pathTarget(alias, options, config === undefined ? directory : dirname(config));
|
|
52
|
-
if (target !== undefined) {
|
|
53
|
-
return target;
|
|
54
|
-
}
|
|
55
|
-
if (!alias.startsWith("#")) {
|
|
56
|
-
throw new Error(`Cannot resolve shadcn UI alias "${alias}" from ${directory}. Check tsconfig paths.`);
|
|
57
|
-
}
|
|
58
|
-
// A synthetic child lets TypeScript resolve directory aliases through package imports without requiring a stock component to exist.
|
|
59
|
-
const resolved = ts.resolveModuleName(`${alias}/${PROBE}`, join(directory, "components.tsx"), {
|
|
60
|
-
...options,
|
|
61
|
-
customConditions: ["@shivaedev/source", ...(options.customConditions ?? [])],
|
|
62
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
63
|
-
}, {
|
|
64
|
-
...ts.sys,
|
|
65
|
-
directoryExists: () => true,
|
|
66
|
-
fileExists: (file) => file.endsWith(`/${PROBE}`) || ts.sys.fileExists(file),
|
|
67
|
-
}).resolvedModule;
|
|
68
|
-
if (resolved === undefined) {
|
|
69
|
-
throw new Error(`Cannot resolve shadcn UI alias "${alias}" from ${directory}. Check tsconfig paths or package imports.`);
|
|
70
|
-
}
|
|
71
|
-
return dirname(resolved.resolvedFileName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AAG,CAAC,OAAO,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;QAC5E,gBAAgB,EAAE,EAAE,CAAC,oBAAoB,CAAC,OAAO;KACjD,EACD;QACC,GAAG,EAAE,CAAC,GAAG;QACT,eAAe,EAAE,GAAG,EAAE,CAAC,IAAI;QAC3B,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;KAC3E,CACD,CAAC,cAAc,CAAC;IACjB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,mCAAmC,KAAK,UAAU,SAAS,4CAA4C,CAAC,CAAC;IAC1H,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
export declare const SHADCN_FILE_GLOB: string;
|
|
3
|
-
export declare const shadcnFiles: (root: string) => Effect.Effect<string[], import("./filesystem.ts").FilesystemFailure | import("../failure.ts").SetupFailure, import("../rule.ts").RuleServices>;
|
|
4
|
-
//# sourceMappingURL=shadcnFiles.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shadcnFiles.d.ts","sourceRoot":"","sources":["../../src/inventory/shadcnFiles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAwEhC,eAAO,MAAM,gBAAgB,QAA8C,CAAC;AAE5E,eAAO,MAAM,WAAW,kKAWtB,CAAC"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { basename, join, matchesGlob, relative } from "node:path";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { posix } from "./ignoreScope.js";
|
|
4
|
-
import { shadcnFolders } from "./shadcnFolders.js";
|
|
5
|
-
import { walk } from "./walk.js";
|
|
6
|
-
// Registry item names are the CLI ownership convention; custom names stay authored.
|
|
7
|
-
const COMPONENTS = [
|
|
8
|
-
"accordion",
|
|
9
|
-
"alert",
|
|
10
|
-
"alert-dialog",
|
|
11
|
-
"aspect-ratio",
|
|
12
|
-
"attachment",
|
|
13
|
-
"avatar",
|
|
14
|
-
"badge",
|
|
15
|
-
"breadcrumb",
|
|
16
|
-
"bubble",
|
|
17
|
-
"button",
|
|
18
|
-
"button-group",
|
|
19
|
-
"calendar",
|
|
20
|
-
"card",
|
|
21
|
-
"carousel",
|
|
22
|
-
"chart",
|
|
23
|
-
"checkbox",
|
|
24
|
-
"collapsible",
|
|
25
|
-
"combobox",
|
|
26
|
-
"command",
|
|
27
|
-
"context-menu",
|
|
28
|
-
"dialog",
|
|
29
|
-
"direction",
|
|
30
|
-
"drawer",
|
|
31
|
-
"dropdown-menu",
|
|
32
|
-
"empty",
|
|
33
|
-
"field",
|
|
34
|
-
"form",
|
|
35
|
-
"hover-card",
|
|
36
|
-
"input",
|
|
37
|
-
"input-group",
|
|
38
|
-
"input-otp",
|
|
39
|
-
"item",
|
|
40
|
-
"kbd",
|
|
41
|
-
"label",
|
|
42
|
-
"marker",
|
|
43
|
-
"menubar",
|
|
44
|
-
"message",
|
|
45
|
-
"message-scroller",
|
|
46
|
-
"native-select",
|
|
47
|
-
"navigation-menu",
|
|
48
|
-
"pagination",
|
|
49
|
-
"popover",
|
|
50
|
-
"progress",
|
|
51
|
-
"radio-group",
|
|
52
|
-
"resizable",
|
|
53
|
-
"scroll-area",
|
|
54
|
-
"select",
|
|
55
|
-
"separator",
|
|
56
|
-
"sheet",
|
|
57
|
-
"sidebar",
|
|
58
|
-
"skeleton",
|
|
59
|
-
"slider",
|
|
60
|
-
"sonner",
|
|
61
|
-
"spinner",
|
|
62
|
-
"switch",
|
|
63
|
-
"table",
|
|
64
|
-
"tabs",
|
|
65
|
-
"textarea",
|
|
66
|
-
"toast",
|
|
67
|
-
"toaster",
|
|
68
|
-
"toggle",
|
|
69
|
-
"toggle-group",
|
|
70
|
-
"tooltip",
|
|
71
|
-
];
|
|
72
|
-
export const SHADCN_FILE_GLOB = `{${COMPONENTS.join(",")}}.{ts,tsx,js,jsx}`;
|
|
73
|
-
export const shadcnFiles = Effect.fn("Inventory.shadcnFiles")(function* (root) {
|
|
74
|
-
const folders = yield* shadcnFolders(root);
|
|
75
|
-
const files = yield* Effect.forEach(folders, (folder) => walk(join(root, folder)));
|
|
76
|
-
return [
|
|
77
|
-
...new Set(files
|
|
78
|
-
.flat()
|
|
79
|
-
.filter((path) => matchesGlob(basename(path), SHADCN_FILE_GLOB))
|
|
80
|
-
.map((path) => posix(relative(root, path)))),
|
|
81
|
-
];
|
|
82
|
-
});
|
|
83
|
-
//# sourceMappingURL=shadcnFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shadcnFiles.js","sourceRoot":"","sources":["../../src/inventory/shadcnFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,oFAAoF;AACpF,MAAM,UAAU,GAAG;IAClB,WAAW;IACX,OAAO;IACP,cAAc;IACd,cAAc;IACd,YAAY;IACZ,QAAQ;IACR,OAAO;IACP,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,UAAU;IACV,MAAM;IACN,UAAU;IACV,OAAO;IACP,UAAU;IACV,aAAa;IACb,UAAU;IACV,SAAS;IACT,cAAc;IACd,QAAQ;IACR,WAAW;IACX,QAAQ;IACR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}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import type { SetupFailure } from "#failure.ts";
|
|
3
|
-
import type { RuleServices } from "#rule.ts";
|
|
4
|
-
import { FilesystemFailure } from "./filesystem.ts";
|
|
5
|
-
export declare const shadcnFolders: (root: string) => Effect.Effect<readonly string[], FilesystemFailure | SetupFailure, RuleServices>;
|
|
6
|
-
//# sourceMappingURL=shadcnFolders.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shadcnFolders.d.ts","sourceRoot":"","sources":["../../src/inventory/shadcnFolders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,iBAAiB,CAAC;AAOtE,eAAO,MAAM,aAAa,oGAwBxB,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as NodePath from "@effect/platform-node/NodePath";
|
|
2
|
-
import { Effect, Path, Schema } from "effect";
|
|
3
|
-
import { FilesystemFailure, readRequiredText } from "./filesystem.js";
|
|
4
|
-
import { posix } from "./ignoreScope.js";
|
|
5
|
-
import { shadcnAlias } from "./shadcnAlias.js";
|
|
6
|
-
import { walk } from "./walk.js";
|
|
7
|
-
const Components = Schema.fromJsonString(Schema.Struct({ aliases: Schema.Struct({ ui: Schema.NonEmptyString }) }));
|
|
8
|
-
export const shadcnFolders = Effect.fn("Inventory.shadcnFolders")(function* (root) {
|
|
9
|
-
const { basename } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
|
|
10
|
-
const paths = (yield* walk(root)).filter((path) => basename(path) === "components.json");
|
|
11
|
-
return yield* Effect.forEach(paths, (path) => Effect.gen(function* () {
|
|
12
|
-
const { dirname, relative } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
|
|
13
|
-
const text = yield* readRequiredText(path);
|
|
14
|
-
return yield* Effect.try({
|
|
15
|
-
catch: (cause) => new FilesystemFailure({ message: `cannot resolve ${path}: ${String(cause)}`, path }),
|
|
16
|
-
try: () => {
|
|
17
|
-
const { aliases } = Schema.decodeUnknownSync(Components)(text);
|
|
18
|
-
const folder = posix(relative(root, shadcnAlias(dirname(path), aliases.ui)));
|
|
19
|
-
if (folder === "" || folder === ".." || folder.startsWith("../")) {
|
|
20
|
-
throw new Error("the shadcn UI folder must be inside the repository and cannot be its root");
|
|
21
|
-
}
|
|
22
|
-
return folder;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}));
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=shadcnFolders.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shadcnFolders.js","sourceRoot":"","sources":["../../src/inventory/shadcnFolders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,QAAQ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AAI,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;oBAClE,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;gBAC9F,CAAC;gBACD,OAAO,MAAM,CAAC;YACf,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CACF,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
const PROBE = "__quality_shadcn__.tsx";
|
|
5
|
-
|
|
6
|
-
function capture(pattern: string, alias: string): string | undefined {
|
|
7
|
-
const star = pattern.indexOf("*");
|
|
8
|
-
if (star === -1) {
|
|
9
|
-
return pattern === alias ? "" : undefined;
|
|
10
|
-
}
|
|
11
|
-
const prefix = pattern.slice(0, star);
|
|
12
|
-
const suffix = pattern.slice(star + 1);
|
|
13
|
-
return alias.startsWith(prefix) && alias.endsWith(suffix)
|
|
14
|
-
? alias.slice(prefix.length, suffix.length === 0 ? undefined : -suffix.length)
|
|
15
|
-
: undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function pathTarget(alias: string, options: ts.CompilerOptions, directory: string): string | undefined {
|
|
19
|
-
const pathsBase: unknown = Reflect.get(options, "pathsBasePath");
|
|
20
|
-
const base = options.baseUrl ?? (typeof pathsBase === "string" ? pathsBase : directory);
|
|
21
|
-
const patterns = Object.entries(options.paths ?? {}).toSorted(([left], [right]) => right.indexOf("*") - left.indexOf("*"));
|
|
22
|
-
const exact = options.paths?.[alias]?.[0];
|
|
23
|
-
if (exact !== undefined) {
|
|
24
|
-
return resolve(base, exact);
|
|
25
|
-
}
|
|
26
|
-
for (const [pattern, targets] of patterns) {
|
|
27
|
-
const captured = capture(pattern, alias);
|
|
28
|
-
const target = targets[0];
|
|
29
|
-
if (captured !== undefined && target !== undefined) {
|
|
30
|
-
return resolve(base, target.replace("*", captured));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function shadcnAlias(directory: string, alias: string): string {
|
|
37
|
-
if (alias.startsWith(".") || isAbsolute(alias)) {
|
|
38
|
-
return resolve(directory, alias);
|
|
39
|
-
}
|
|
40
|
-
const config = ts.findConfigFile(directory, ts.sys.fileExists);
|
|
41
|
-
const parsed =
|
|
42
|
-
config === undefined
|
|
43
|
-
? undefined
|
|
44
|
-
: ts.getParsedCommandLineOfConfigFile(
|
|
45
|
-
config,
|
|
46
|
-
{},
|
|
47
|
-
{
|
|
48
|
-
...ts.sys,
|
|
49
|
-
onUnRecoverableConfigFileDiagnostic: () => undefined,
|
|
50
|
-
},
|
|
51
|
-
);
|
|
52
|
-
if (parsed?.errors.length) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
ts.formatDiagnostics(parsed.errors, {
|
|
55
|
-
getCanonicalFileName: (file) => file,
|
|
56
|
-
getCurrentDirectory: () => directory,
|
|
57
|
-
getNewLine: () => "\n",
|
|
58
|
-
}),
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
const options = parsed?.options ?? {};
|
|
62
|
-
const target = pathTarget(alias, options, config === undefined ? directory : dirname(config));
|
|
63
|
-
if (target !== undefined) {
|
|
64
|
-
return target;
|
|
65
|
-
}
|
|
66
|
-
if (!alias.startsWith("#")) {
|
|
67
|
-
throw new Error(`Cannot resolve shadcn UI alias "${alias}" from ${directory}. Check tsconfig paths.`);
|
|
68
|
-
}
|
|
69
|
-
// A synthetic child lets TypeScript resolve directory aliases through package imports without requiring a stock component to exist.
|
|
70
|
-
const resolved = ts.resolveModuleName(
|
|
71
|
-
`${alias}/${PROBE}`,
|
|
72
|
-
join(directory, "components.tsx"),
|
|
73
|
-
{
|
|
74
|
-
...options,
|
|
75
|
-
customConditions: ["@shivaedev/source", ...(options.customConditions ?? [])],
|
|
76
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
...ts.sys,
|
|
80
|
-
directoryExists: () => true,
|
|
81
|
-
fileExists: (file) => file.endsWith(`/${PROBE}`) || ts.sys.fileExists(file),
|
|
82
|
-
},
|
|
83
|
-
).resolvedModule;
|
|
84
|
-
if (resolved === undefined) {
|
|
85
|
-
throw new Error(`Cannot resolve shadcn UI alias "${alias}" from ${directory}. Check tsconfig paths or package imports.`);
|
|
86
|
-
}
|
|
87
|
-
return dirname(resolved.resolvedFileName);
|
|
88
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { basename, join, matchesGlob, relative } from "node:path";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { posix } from "./ignoreScope.ts";
|
|
4
|
-
import { shadcnFolders } from "./shadcnFolders.ts";
|
|
5
|
-
import { walk } from "./walk.ts";
|
|
6
|
-
|
|
7
|
-
// Registry item names are the CLI ownership convention; custom names stay authored.
|
|
8
|
-
const COMPONENTS = [
|
|
9
|
-
"accordion",
|
|
10
|
-
"alert",
|
|
11
|
-
"alert-dialog",
|
|
12
|
-
"aspect-ratio",
|
|
13
|
-
"attachment",
|
|
14
|
-
"avatar",
|
|
15
|
-
"badge",
|
|
16
|
-
"breadcrumb",
|
|
17
|
-
"bubble",
|
|
18
|
-
"button",
|
|
19
|
-
"button-group",
|
|
20
|
-
"calendar",
|
|
21
|
-
"card",
|
|
22
|
-
"carousel",
|
|
23
|
-
"chart",
|
|
24
|
-
"checkbox",
|
|
25
|
-
"collapsible",
|
|
26
|
-
"combobox",
|
|
27
|
-
"command",
|
|
28
|
-
"context-menu",
|
|
29
|
-
"dialog",
|
|
30
|
-
"direction",
|
|
31
|
-
"drawer",
|
|
32
|
-
"dropdown-menu",
|
|
33
|
-
"empty",
|
|
34
|
-
"field",
|
|
35
|
-
"form",
|
|
36
|
-
"hover-card",
|
|
37
|
-
"input",
|
|
38
|
-
"input-group",
|
|
39
|
-
"input-otp",
|
|
40
|
-
"item",
|
|
41
|
-
"kbd",
|
|
42
|
-
"label",
|
|
43
|
-
"marker",
|
|
44
|
-
"menubar",
|
|
45
|
-
"message",
|
|
46
|
-
"message-scroller",
|
|
47
|
-
"native-select",
|
|
48
|
-
"navigation-menu",
|
|
49
|
-
"pagination",
|
|
50
|
-
"popover",
|
|
51
|
-
"progress",
|
|
52
|
-
"radio-group",
|
|
53
|
-
"resizable",
|
|
54
|
-
"scroll-area",
|
|
55
|
-
"select",
|
|
56
|
-
"separator",
|
|
57
|
-
"sheet",
|
|
58
|
-
"sidebar",
|
|
59
|
-
"skeleton",
|
|
60
|
-
"slider",
|
|
61
|
-
"sonner",
|
|
62
|
-
"spinner",
|
|
63
|
-
"switch",
|
|
64
|
-
"table",
|
|
65
|
-
"tabs",
|
|
66
|
-
"textarea",
|
|
67
|
-
"toast",
|
|
68
|
-
"toaster",
|
|
69
|
-
"toggle",
|
|
70
|
-
"toggle-group",
|
|
71
|
-
"tooltip",
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
export const SHADCN_FILE_GLOB = `{${COMPONENTS.join(",")}}.{ts,tsx,js,jsx}`;
|
|
75
|
-
|
|
76
|
-
export const shadcnFiles = Effect.fn("Inventory.shadcnFiles")(function* (root: string) {
|
|
77
|
-
const folders = yield* shadcnFolders(root);
|
|
78
|
-
const files = yield* Effect.forEach(folders, (folder) => walk(join(root, folder)));
|
|
79
|
-
return [
|
|
80
|
-
...new Set(
|
|
81
|
-
files
|
|
82
|
-
.flat()
|
|
83
|
-
.filter((path) => matchesGlob(basename(path), SHADCN_FILE_GLOB))
|
|
84
|
-
.map((path) => posix(relative(root, path))),
|
|
85
|
-
),
|
|
86
|
-
];
|
|
87
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as NodePath from "@effect/platform-node/NodePath";
|
|
2
|
-
import { Effect, Path, Schema } from "effect";
|
|
3
|
-
import type { SetupFailure } from "#failure.ts";
|
|
4
|
-
import type { RuleServices } from "#rule.ts";
|
|
5
|
-
import { FilesystemFailure, readRequiredText } from "./filesystem.ts";
|
|
6
|
-
import { posix } from "./ignoreScope.ts";
|
|
7
|
-
import { shadcnAlias } from "./shadcnAlias.ts";
|
|
8
|
-
import { walk } from "./walk.ts";
|
|
9
|
-
|
|
10
|
-
const Components = Schema.fromJsonString(Schema.Struct({ aliases: Schema.Struct({ ui: Schema.NonEmptyString }) }));
|
|
11
|
-
|
|
12
|
-
export const shadcnFolders = Effect.fn("Inventory.shadcnFolders")(function* (
|
|
13
|
-
root: string,
|
|
14
|
-
): Effect.fn.Return<readonly string[], FilesystemFailure | SetupFailure, RuleServices> {
|
|
15
|
-
const { basename } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
|
|
16
|
-
|
|
17
|
-
const paths = (yield* walk(root)).filter((path) => basename(path) === "components.json");
|
|
18
|
-
return yield* Effect.forEach(paths, (path) =>
|
|
19
|
-
Effect.gen(function* () {
|
|
20
|
-
const { dirname, relative } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
|
|
21
|
-
|
|
22
|
-
const text = yield* readRequiredText(path);
|
|
23
|
-
return yield* Effect.try({
|
|
24
|
-
catch: (cause) => new FilesystemFailure({ message: `cannot resolve ${path}: ${String(cause)}`, path }),
|
|
25
|
-
try: () => {
|
|
26
|
-
const { aliases } = Schema.decodeUnknownSync(Components)(text);
|
|
27
|
-
const folder = posix(relative(root, shadcnAlias(dirname(path), aliases.ui)));
|
|
28
|
-
if (folder === "" || folder === ".." || folder.startsWith("../")) {
|
|
29
|
-
throw new Error("the shadcn UI folder must be inside the repository and cannot be its root");
|
|
30
|
-
}
|
|
31
|
-
return folder;
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}),
|
|
35
|
-
);
|
|
36
|
-
});
|