@shivaedev/quality 0.59.0 → 0.60.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +5 -3
  3. package/dist/adapters/bodyReference.d.ts +9 -0
  4. package/dist/adapters/bodyReference.d.ts.map +1 -0
  5. package/dist/adapters/bodyReference.js +10 -0
  6. package/dist/adapters/bodyReference.js.map +1 -0
  7. package/dist/adapters/bodyReferences.d.ts +1 -6
  8. package/dist/adapters/bodyReferences.d.ts.map +1 -1
  9. package/dist/adapters/bodyReferences.js +16 -12
  10. package/dist/adapters/bodyReferences.js.map +1 -1
  11. package/dist/adapters/engineEscapes.d.ts.map +1 -1
  12. package/dist/adapters/engineEscapes.js.map +1 -1
  13. package/dist/adapters/imports/projects.js +1 -1
  14. package/dist/adapters/imports/projects.js.map +1 -1
  15. package/dist/adapters/knip/configuration.d.ts.map +1 -1
  16. package/dist/adapters/knip/configuration.js +9 -1
  17. package/dist/adapters/knip/configuration.js.map +1 -1
  18. package/dist/adapters/knip/run.js +1 -1
  19. package/dist/adapters/knip/run.js.map +1 -1
  20. package/dist/adapters/queueReadoutFindings.js +1 -1
  21. package/dist/adapters/queueReadoutFindings.js.map +1 -1
  22. package/dist/adapters/serviceAccess.d.ts +1 -1
  23. package/dist/adapters/serviceAccess.d.ts.map +1 -1
  24. package/dist/{rules/stories/program.d.ts → adapters/storyProgram.d.ts} +1 -1
  25. package/dist/adapters/storyProgram.d.ts.map +1 -0
  26. package/dist/{rules/stories/program.js → adapters/storyProgram.js} +14 -5
  27. package/dist/adapters/storyProgram.js.map +1 -0
  28. package/dist/adapters/tanstackRoutes.d.ts +11 -0
  29. package/dist/adapters/tanstackRoutes.d.ts.map +1 -0
  30. package/dist/adapters/tanstackRoutes.js +65 -0
  31. package/dist/adapters/tanstackRoutes.js.map +1 -0
  32. package/dist/inventory/routeFiles.d.ts +7 -0
  33. package/dist/inventory/routeFiles.d.ts.map +1 -0
  34. package/dist/inventory/routeFiles.js +62 -0
  35. package/dist/inventory/routeFiles.js.map +1 -0
  36. package/dist/inventory/shadcnAlias.js +1 -1
  37. package/dist/inventory/shadcnAlias.js.map +1 -1
  38. package/dist/rules/builtIn.d.ts +2 -2
  39. package/dist/rules/files/folderNames.d.ts +1 -1
  40. package/dist/rules/files/folderNames.d.ts.map +1 -1
  41. package/dist/rules/files/folderNames.js +6 -4
  42. package/dist/rules/files/folderNames.js.map +1 -1
  43. package/dist/rules/files/namedAfterExport.d.ts +1 -1
  44. package/dist/rules/files/namedAfterExport.d.ts.map +1 -1
  45. package/dist/rules/files/namedAfterExport.js +5 -3
  46. package/dist/rules/files/namedAfterExport.js.map +1 -1
  47. package/dist/rules/manifestsExportsShape.d.ts.map +1 -1
  48. package/dist/rules/manifestsExportsShape.js +2 -1
  49. package/dist/rules/manifestsExportsShape.js.map +1 -1
  50. package/dist/rules/manifestsSourceFirst.d.ts.map +1 -1
  51. package/dist/rules/manifestsSourceFirst.js +4 -4
  52. package/dist/rules/manifestsSourceFirst.js.map +1 -1
  53. package/dist/rules/stories/adapterOnlyFakes.js +1 -1
  54. package/dist/rules/stories/adapterOnlyFakes.js.map +1 -1
  55. package/dist/rules/stories/origins.d.ts.map +1 -1
  56. package/dist/rules/stories/origins.js +1 -1
  57. package/dist/rules/stories/origins.js.map +1 -1
  58. package/dist/testing/adapters/cli.js +1 -1
  59. package/dist/testing/adapters/cli.js.map +1 -1
  60. package/dist/testing/adapters/hookRepository.js +1 -1
  61. package/dist/testing/adapters/hookRepository.js.map +1 -1
  62. package/dist/testing/adapters/packageExports.d.ts +1 -1
  63. package/dist/testing/adapters/packageExports.d.ts.map +1 -1
  64. package/dist/testing/adapters/packageExports.js +6 -3
  65. package/dist/testing/adapters/packageExports.js.map +1 -1
  66. package/package.json +9 -9
  67. package/src/adapters/bodyReference.ts +19 -0
  68. package/src/adapters/bodyReferences.ts +16 -23
  69. package/src/adapters/engineEscapes.ts +2 -1
  70. package/src/adapters/imports/projects.ts +1 -1
  71. package/src/adapters/knip/configuration.ts +8 -1
  72. package/src/adapters/knip/run.ts +1 -1
  73. package/src/adapters/queueReadoutFindings.ts +1 -1
  74. package/src/adapters/serviceAccess.ts +1 -1
  75. package/src/{rules/stories/program.ts → adapters/storyProgram.ts} +13 -4
  76. package/src/adapters/tanstackRoutes.ts +73 -0
  77. package/src/inventory/routeFiles.ts +78 -0
  78. package/src/inventory/shadcnAlias.ts +1 -1
  79. package/src/rules/files/folderNames.ts +7 -5
  80. package/src/rules/files/namedAfterExport.ts +5 -3
  81. package/src/rules/manifestsExportsShape.ts +2 -1
  82. package/src/rules/manifestsSourceFirst.ts +4 -5
  83. package/src/rules/stories/adapterOnlyFakes.ts +1 -1
  84. package/src/rules/stories/origins.ts +1 -1
  85. package/src/testing/adapters/cli.ts +1 -1
  86. package/src/testing/adapters/hookRepository.ts +1 -1
  87. package/src/testing/adapters/packageExports.ts +6 -3
  88. package/dist/rules/stories/program.d.ts.map +0 -1
  89. package/dist/rules/stories/program.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/quality",
3
- "version": "0.59.0",
3
+ "version": "0.60.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": {
@@ -17,14 +17,14 @@
17
17
  "imports": {
18
18
  "#test/*": "./src/test-support/*",
19
19
  "#*.ts": {
20
- "source": "./src/*.ts",
20
+ "@shivaedev/source": "./src/*.ts",
21
21
  "types": "./dist/*.d.ts",
22
22
  "default": "./dist/*.js"
23
23
  }
24
24
  },
25
25
  "exports": {
26
26
  "./*.ts": {
27
- "source": "./src/*.ts",
27
+ "@shivaedev/source": "./src/*.ts",
28
28
  "types": "./dist/*.d.ts",
29
29
  "default": "./dist/*.js"
30
30
  },
@@ -51,9 +51,9 @@
51
51
  ],
52
52
  "dependencies": {
53
53
  "@biomejs/biome": "2.6.3",
54
- "@shivaedev/errors": "0.8.0",
55
- "@shivaedev/heavy-lock": "0.9.0",
56
- "@shivaedev/service": "0.6.2",
54
+ "@shivaedev/errors": "0.9.0",
55
+ "@shivaedev/heavy-lock": "0.10.0",
56
+ "@shivaedev/service": "0.7.0",
57
57
  "@vitest/coverage-v8": "5.0.5",
58
58
  "ignore": "7.0.14",
59
59
  "knip": "6.43.0",
@@ -64,8 +64,8 @@
64
64
  "@effect/platform-node": "4.0.6",
65
65
  "@effect/platform-node-shared": "4.0.6",
66
66
  "@effect/vitest": "4.0.6",
67
- "@shivaedev/test": "0.14.0",
68
- "@shivaedev/test-story": "0.37.1",
67
+ "@shivaedev/test": "0.15.0",
68
+ "@shivaedev/test-story": "0.38.0",
69
69
  "@types/node": "24.19.2",
70
70
  "@typescript/native": "npm:typescript@7.0.2",
71
71
  "effect": "4.0.6",
@@ -74,7 +74,7 @@
74
74
  "peerDependencies": {
75
75
  "@effect/platform-node": "4.0.6",
76
76
  "@effect/platform-node-shared": "4.0.6",
77
- "@shivaedev/test-story": "0.37.1",
77
+ "@shivaedev/test-story": "0.38.0",
78
78
  "effect": "4.0.6",
79
79
  "vitest": "5.0.5"
80
80
  },
@@ -0,0 +1,19 @@
1
+ export interface BodyReference {
2
+ readonly file?: string | undefined;
3
+ readonly kind: "data" | "import" | "service" | "told";
4
+ readonly module: string;
5
+ readonly path: readonly string[];
6
+ }
7
+
8
+ export function dataFactory({ module, path }: BodyReference): boolean {
9
+ return (module === "effect" && (path[0] === "Schema" || path[0] === "Data")) || module === "effect/Schema" || module === "effect/Data";
10
+ }
11
+
12
+ export function serviceFactory({ module, path }: BodyReference): boolean {
13
+ return (
14
+ (module === "@shivaedev/service/defineService.ts" && path[0] === "defineService")
15
+ || ((module === "effect" || module === "effect/Context")
16
+ && path.at(-1) !== undefined
17
+ && ["Service", "Tag", "GenericTag", "Reference"].includes(path.at(-1) ?? ""))
18
+ );
19
+ }
@@ -1,13 +1,7 @@
1
1
  import ts from "typescript";
2
2
  import { importFrom } from "#rules/stories/importOrigin.ts";
3
- import { memberName, unwrapped } from "#rules/stories/syntax.ts";
4
-
5
- export interface BodyReference {
6
- readonly file?: string | undefined;
7
- readonly kind: "data" | "import" | "service" | "told";
8
- readonly module: string;
9
- readonly path: readonly string[];
10
- }
3
+ import { memberName } from "#rules/stories/syntax.ts";
4
+ import { type BodyReference, dataFactory, serviceFactory } from "./bodyReference.ts";
11
5
 
12
6
  export function storyBody(body: ts.Expression, checker: ts.TypeChecker) {
13
7
  const declaration = checker.getTypeAtLocation(body).getCallSignatures()[0]?.declaration;
@@ -34,7 +28,8 @@ export function bodyReferences(body: ts.SignatureDeclaration, checker: ts.TypeCh
34
28
  const visiting = new Set<ts.Node>();
35
29
  const told = body.parameters[0];
36
30
  function symbol(value: ts.Symbol | undefined): BodyReference | undefined {
37
- return value?.declarations?.map(visit).find((reference) => reference !== undefined);
31
+ const direct = value?.declarations?.map(visit).find((reference) => reference !== undefined);
32
+ return direct ?? (value !== undefined && value.flags & ts.SymbolFlags.Alias ? symbol(checker.getAliasedSymbol(value)) : undefined);
38
33
  }
39
34
  function imported(node: ts.ImportSpecifier | ts.NamespaceImport | ts.ImportClause): BodyReference | undefined {
40
35
  const name = importName(node);
@@ -79,7 +74,18 @@ export function bodyReferences(body: ts.SignatureDeclaration, checker: ts.TypeCh
79
74
  }
80
75
  return member(receiver, memberName(node) ?? "");
81
76
  }
77
+ function variable(node: ts.VariableDeclaration): BodyReference | undefined {
78
+ const value = node.initializer ?? node.type;
79
+ return value === undefined ? undefined : visit(value);
80
+ }
82
81
  function expression(node: ts.Node): BodyReference | undefined {
82
+ if (ts.isTypeReferenceNode(node)) {
83
+ const target = visit(node.typeName);
84
+ return target?.kind === "import" && dataFactory(target) ? { kind: "data", module: target.module, path: [] } : undefined;
85
+ }
86
+ if (ts.isQualifiedName(node)) {
87
+ return member(visit(node.left), node.right.text);
88
+ }
83
89
  if (ts.isIdentifier(node)) {
84
90
  return symbol(checker.getSymbolAtLocation(node));
85
91
  }
@@ -104,7 +110,7 @@ export function bodyReferences(body: ts.SignatureDeclaration, checker: ts.TypeCh
104
110
  return imported(node);
105
111
  }
106
112
  if (ts.isVariableDeclaration(node)) {
107
- return node.initializer === undefined ? undefined : visit(unwrapped(node.initializer));
113
+ return variable(node);
108
114
  }
109
115
  if (ts.isBindingElement(node)) {
110
116
  return binding(node);
@@ -126,16 +132,3 @@ export function bodyReferences(body: ts.SignatureDeclaration, checker: ts.TypeCh
126
132
  }
127
133
  return visit;
128
134
  }
129
-
130
- function dataFactory({ module, path }: BodyReference): boolean {
131
- return (module === "effect" && (path[0] === "Schema" || path[0] === "Data")) || module === "effect/Schema" || module === "effect/Data";
132
- }
133
-
134
- function serviceFactory({ module, path }: BodyReference): boolean {
135
- return (
136
- (module === "@shivaedev/service/defineService.ts" && path[0] === "defineService")
137
- || ((module === "effect" || module === "effect/Context")
138
- && path.at(-1) !== undefined
139
- && ["Service", "Tag", "GenericTag", "Reference"].includes(path.at(-1) ?? ""))
140
- );
141
- }
@@ -3,7 +3,8 @@ import ts from "typescript";
3
3
  import { isTestSupport, testName } from "#naming/testName.ts";
4
4
  import { engineOf } from "#rules/stories/engineOf.ts";
5
5
  import { memberName, unwrapped } from "#rules/stories/syntax.ts";
6
- import { type BodyReference, bodyReferences, storyBody } from "./bodyReferences.ts";
6
+ import type { BodyReference } from "./bodyReference.ts";
7
+ import { bodyReferences, storyBody } from "./bodyReferences.ts";
7
8
  import { serviceAccess } from "./serviceAccess.ts";
8
9
 
9
10
  export interface EngineEscape {
@@ -29,7 +29,7 @@ function resolutionOptions(options: ts.CompilerOptions, declarations: boolean):
29
29
  function projectOf(root: string, parsed: ParsedProject | undefined): Project {
30
30
  const options = parsed?.options ?? {
31
31
  allowJs: true,
32
- customConditions: ["source"],
32
+ customConditions: ["@shivaedev/source"],
33
33
  module: ts.ModuleKind.ESNext,
34
34
  moduleResolution: ts.ModuleResolutionKind.Bundler,
35
35
  resolveJsonModule: true,
@@ -11,7 +11,14 @@ const ENTRIES = ["**/*.{test,spec,stories,story}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}
11
11
  function importPaths(imports: Readonly<Record<string, unknown>>) {
12
12
  return Object.fromEntries(
13
13
  Object.entries(imports).flatMap(([name, target]) => {
14
- const selected = typeof target === "object" && target !== null && "source" in target ? target.source : target;
14
+ let selected = target;
15
+ if (typeof target === "object" && target !== null) {
16
+ if ("@shivaedev/source" in target) {
17
+ selected = target["@shivaedev/source"];
18
+ } else if ("source" in target) {
19
+ selected = target.source;
20
+ }
21
+ }
15
22
  const paths = exportTargets(selected).filter((path) => path.startsWith("./"));
16
23
  return paths.length === 0 ? [] : [[name, paths]];
17
24
  }),
@@ -40,7 +40,7 @@ export const runKnip = Effect.fn("Knip.runKnip")(function* (inputs: RuleInputs)
40
40
  ChildProcess.make(
41
41
  process.execPath,
42
42
  [
43
- "--conditions=source",
43
+ "--conditions=@shivaedev/source",
44
44
  "--eval",
45
45
  LAUNCH,
46
46
  pathToFileURL(API).href,
@@ -5,10 +5,10 @@ import { importGraph } from "#imports/graph.ts";
5
5
  import { packageOf } from "#imports/workspace.ts";
6
6
  import { isTestCode } from "#naming/testName.ts";
7
7
  import type { RuleInputs } from "#rule.ts";
8
- import { storyProgram } from "#rules/stories/program.ts";
9
8
  import { nodesWhere } from "#rules/stories/syntax.ts";
10
9
  import { readPackageManifest } from "./manifestInventory.ts";
11
10
  import { queueTestingOrigin } from "./queueTestingOrigin.ts";
11
+ import { storyProgram } from "./storyProgram.ts";
12
12
 
13
13
  const MESSAGE =
14
14
  "Reads jobs-testing queue storage. An enqueued job or its state does not prove the work ran. Assert the application's visible result instead; use jobs-testing only to control and settle workers.";
@@ -1,6 +1,6 @@
1
1
  import { basename } from "node:path";
2
2
  import ts from "typescript";
3
- import type { BodyReference } from "./bodyReferences.ts";
3
+ import type { BodyReference } from "./bodyReference.ts";
4
4
 
5
5
  function nativeService({ module, path }: BodyReference): boolean {
6
6
  const name = path[0];
@@ -1,5 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import ts from "typescript";
3
+ import { projectsFor } from "#adapters/imports/projects.ts";
3
4
  import type { ImportGraph } from "#imports/graph.ts";
4
5
  import type { RuleInputs } from "#rule.ts";
5
6
 
@@ -17,18 +18,26 @@ export function storyProgram(inputs: RuleInputs, graph: ImportGraph): ts.Program
17
18
  ),
18
19
  );
19
20
  const options: ts.CompilerOptions = { allowJs: true, noLib: true, types: [] };
21
+ const projectOf = projectsFor(inputs.root);
20
22
  const host: ts.CompilerHost = {
21
23
  ...ts.createCompilerHost(options),
22
- fileExists: (path) => sources.has(path),
24
+ fileExists: (path) => sources.has(path) || ts.sys.fileExists(path),
23
25
  getSourceFile: (path) => {
24
- const text = sources.get(path);
26
+ const text = sources.get(path) ?? ts.sys.readFile(path);
25
27
  return text === undefined ? undefined : ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
26
28
  },
27
- readFile: (path) => sources.get(path),
29
+ readFile: (path) => sources.get(path) ?? ts.sys.readFile(path),
28
30
  resolveModuleNames: (names, from) =>
29
31
  names.map((name) => {
30
32
  const path = targets.get(`${from}:${name}`);
31
- return path === undefined ? undefined : { extension: ts.Extension.Ts, resolvedFileName: path };
33
+ if (path !== undefined) {
34
+ return { extension: ts.Extension.Ts, resolvedFileName: path };
35
+ }
36
+ if (!(name.startsWith("@shivaedev/") || name.startsWith(".") || name.startsWith("#"))) {
37
+ return undefined;
38
+ }
39
+ const project = projectOf(from);
40
+ return ts.resolveModuleName(name, from, project.typesOptions, host, project.typesCache).resolvedModule;
32
41
  }),
33
42
  };
34
43
  const program = ts.createProgram([...sources.keys()], options, host);
@@ -0,0 +1,73 @@
1
+ import { Schema } from "effect";
2
+ import ts from "typescript";
3
+
4
+ const RouterOptions = Schema.Struct({
5
+ routeFileIgnorePattern: Schema.optionalKey(Schema.String),
6
+ routeFileIgnorePrefix: Schema.optionalKey(Schema.String),
7
+ routeFilePrefix: Schema.optionalKey(Schema.String),
8
+ routesDirectory: Schema.optionalKey(Schema.NonEmptyString),
9
+ });
10
+
11
+ export type RouterOptions = typeof RouterOptions.Type;
12
+
13
+ const OPTIONS = new Set(["routeFileIgnorePattern", "routeFileIgnorePrefix", "routeFilePrefix", "routesDirectory"]);
14
+ const PLUGINS = new Set(["tanstackRouter", "TanStackRouterVite"]);
15
+ const PACKAGES = new Set(["@tanstack/router-plugin/vite", "@tanstack/router-vite-plugin"]);
16
+
17
+ function pluginNames(source: ts.SourceFile): ReadonlySet<string> {
18
+ return new Set(
19
+ source.statements.flatMap((statement) => {
20
+ if (!(ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier) && PACKAGES.has(statement.moduleSpecifier.text))) {
21
+ return [];
22
+ }
23
+ const clause = statement.importClause;
24
+ const bindings = clause?.namedBindings;
25
+ return [
26
+ ...(clause?.name === undefined ? [] : [clause.name.text]),
27
+ ...(bindings !== undefined && ts.isNamedImports(bindings)
28
+ ? bindings.elements.filter((entry) => PLUGINS.has((entry.propertyName ?? entry.name).text)).map((entry) => entry.name.text)
29
+ : []),
30
+ ];
31
+ }),
32
+ );
33
+ }
34
+
35
+ function literalOptions(node: ts.Expression | undefined): RouterOptions {
36
+ if (node === undefined) {
37
+ return {};
38
+ }
39
+ if (!ts.isObjectLiteralExpression(node)) {
40
+ throw new Error("Use literal TanStack Router options or move them to tsr.config.json so Quality can read the route folder.");
41
+ }
42
+ const entries = node.properties.flatMap((property): readonly (readonly [string, string])[] => {
43
+ if (ts.isSpreadAssignment(property)) {
44
+ throw new Error("Move spread TanStack Router options to tsr.config.json so Quality can read the route folder.");
45
+ }
46
+ const name = property.name;
47
+ if (name === undefined || !(ts.isIdentifier(name) || ts.isStringLiteral(name)) || !OPTIONS.has(name.text)) {
48
+ return [];
49
+ }
50
+ if (!(ts.isPropertyAssignment(property) && ts.isStringLiteralLike(property.initializer))) {
51
+ throw new Error(`TanStack Router ${name.text} must be a literal string for Quality to read it.`);
52
+ }
53
+ return [[name.text, property.initializer.text]];
54
+ });
55
+ return Schema.decodeUnknownSync(RouterOptions)(Object.fromEntries(entries));
56
+ }
57
+
58
+ export function tanstackRoutes(path: string, text: string): readonly RouterOptions[] {
59
+ if (path.endsWith("tsr.config.json")) {
60
+ return [Schema.decodeUnknownSync(Schema.fromJsonString(RouterOptions))(text)];
61
+ }
62
+ const source = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
63
+ const names = pluginNames(source);
64
+ const options: RouterOptions[] = [];
65
+ function visit(node: ts.Node): void {
66
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && names.has(node.expression.text)) {
67
+ options.push(literalOptions(node.arguments[0]));
68
+ }
69
+ ts.forEachChild(node, visit);
70
+ }
71
+ visit(source);
72
+ return options;
73
+ }
@@ -0,0 +1,78 @@
1
+ import * as NodePath from "@effect/platform-node/NodePath";
2
+ import { Effect, Path } from "effect";
3
+ import { type RouterOptions, tanstackRoutes } from "#adapters/tanstackRoutes.ts";
4
+ import { SetupFailure } from "#failure.ts";
5
+ import { readRequiredText } from "./filesystem.ts";
6
+ import { posix as portable } from "./ignoreScope.ts";
7
+ import { walk } from "./walk.ts";
8
+
9
+ const CONFIG = /^(?:tsr\.config\.json|vite\.config\.[cm]?[jt]s)$/u;
10
+ const CODE = /\.[jt]sx?$/u;
11
+
12
+ interface RouteFolder {
13
+ readonly directory: string;
14
+ readonly ignorePattern: RegExp | undefined;
15
+ readonly ignorePrefix: string;
16
+ readonly prefix: string | undefined;
17
+ }
18
+
19
+ function owns(file: string, folder: RouteFolder): boolean {
20
+ if (!(CODE.test(file) && file.startsWith(`${folder.directory}/`))) {
21
+ return false;
22
+ }
23
+ const parts = file.slice(folder.directory.length + 1).split("/");
24
+ return parts.every(
25
+ (part) =>
26
+ !(part.startsWith(".") || (folder.ignorePrefix !== "" && part.startsWith(folder.ignorePrefix)) || folder.ignorePattern?.test(part))
27
+ && (folder.prefix === undefined || part.startsWith(folder.prefix)),
28
+ );
29
+ }
30
+
31
+ export const routeFiles = Effect.fn("Inventory.routeFiles")(function* (root: string) {
32
+ const { basename, dirname, relative, resolve } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
33
+ const paths = yield* walk(root);
34
+ const configs = paths
35
+ .filter((path) => CONFIG.test(basename(path)))
36
+ .sort((left, right) => Number(basename(right) === "tsr.config.json") - Number(basename(left) === "tsr.config.json"));
37
+ const byApp = new Map<string, RouterOptions>();
38
+ for (const path of configs) {
39
+ const text = yield* readRequiredText(path);
40
+ const options = yield* Effect.try({
41
+ catch: (cause) => new SetupFailure({ cause, message: `cannot read routes from ${path}: ${String(cause)}` }),
42
+ try: () => tanstackRoutes(path, text),
43
+ });
44
+ for (const option of options) {
45
+ const base = dirname(path);
46
+ byApp.set(base, { ...byApp.get(base), ...option });
47
+ }
48
+ }
49
+ const folders = yield* Effect.try({
50
+ catch: (cause) => new SetupFailure({ cause, message: `cannot resolve TanStack Router folders: ${String(cause)}` }),
51
+ try: () =>
52
+ [...byApp].map(
53
+ ([base, options]): RouteFolder => ({
54
+ directory: portable(relative(root, resolve(base, options.routesDirectory ?? "src/routes"))),
55
+ ignorePattern:
56
+ options.routeFileIgnorePattern === undefined || options.routeFileIgnorePattern === ""
57
+ ? undefined
58
+ : new RegExp(options.routeFileIgnorePattern, "u"),
59
+ ignorePrefix: options.routeFileIgnorePrefix ?? "-",
60
+ prefix: options.routeFilePrefix,
61
+ }),
62
+ ),
63
+ });
64
+ const files = new Set<string>();
65
+ const ownedFolders = new Set<string>();
66
+ for (const absolute of paths) {
67
+ const file = portable(relative(root, absolute));
68
+ const folder = folders.find((candidate) => owns(file, candidate));
69
+ if (folder === undefined) {
70
+ continue;
71
+ }
72
+ files.add(file);
73
+ for (let current = dirname(file); current.startsWith(`${folder.directory}/`) || current === folder.directory; current = dirname(current)) {
74
+ ownedFolders.add(current);
75
+ }
76
+ }
77
+ return { files, folders: ownedFolders };
78
+ });
@@ -72,7 +72,7 @@ export function shadcnAlias(directory: string, alias: string): string {
72
72
  join(directory, "components.tsx"),
73
73
  {
74
74
  ...options,
75
- customConditions: ["source", ...(options.customConditions ?? [])],
75
+ customConditions: ["@shivaedev/source", ...(options.customConditions ?? [])],
76
76
  moduleResolution: ts.ModuleResolutionKind.Bundler,
77
77
  },
78
78
  {
@@ -2,6 +2,7 @@ import { posix } from "node:path";
2
2
  import { Effect, Order, Schema } from "effect";
3
3
  import { type IgnoreMatcher, ignorePatterns } from "#adapters/ignore.ts";
4
4
  import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
5
+ import { routeFiles } from "#inventory/routeFiles.ts";
5
6
  import { nativeNames } from "#naming/nativeNames.ts";
6
7
  import { packageLayout } from "#naming/packageLayout.ts";
7
8
  import { KEBAB, PASCAL } from "#naming/words.ts";
@@ -52,14 +53,14 @@ function groupMessage(name: string): string | undefined {
52
53
  interface Context {
53
54
  readonly content: IgnoreMatcher;
54
55
  readonly names: ReadonlyMap<string, string>;
55
- readonly native: ReadonlySet<string>;
56
+ readonly owned: ReadonlySet<string>;
56
57
  readonly stems: ReadonlySet<string>;
57
58
  readonly toolOwned: IgnoreMatcher;
58
59
  }
59
60
 
60
61
  function messageFor(folder: string, context: Context): string | undefined {
61
62
  const name = posix.basename(folder);
62
- if (context.native.has(folder) || context.toolOwned.ignores(`${folder}/`) || isModule(folder, context.stems)) {
63
+ if (context.owned.has(folder) || context.toolOwned.ignores(`${folder}/`) || isModule(folder, context.stems)) {
63
64
  return undefined;
64
65
  }
65
66
  const packageName = context.names.get(folder);
@@ -73,13 +74,14 @@ function messageFor(folder: string, context: Context): string | undefined {
73
74
  }
74
75
 
75
76
  export const folderNames = defineRule({
76
- check: ({ files, options, readText }) =>
77
+ check: ({ files, options, readText, root }) =>
77
78
  Effect.gen(function* () {
78
79
  const layout = yield* packageLayout({ files, readText });
80
+ const routes = yield* routeFiles(root);
79
81
  const context: Context = {
80
82
  content: ignorePatterns([...globPatterns(options.content)]),
81
83
  names: layout.names,
82
- native: nativeNames(files).folders,
84
+ owned: new Set([...nativeNames(files).folders, ...routes.folders]),
83
85
  stems: stemsIn(files),
84
86
  toolOwned: ignorePatterns([...globPatterns(options.toolOwned)]),
85
87
  };
@@ -89,7 +91,7 @@ export const folderNames = defineRule({
89
91
  });
90
92
  }),
91
93
  description:
92
- "A package folder is named after its package, a module folder after its main file, a content folder in snake_case and every other folder in kebab-case.",
94
+ "A package folder is named after its package, a module folder after its main file, a content folder in snake_case and every other folder in kebab-case. TanStack Router configuration owns route folder names.",
93
95
  id: "files/folder-names",
94
96
  options: Schema.toStandardSchemaV1(FolderNamesOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
95
97
  validate: validateGlobs,
@@ -2,6 +2,7 @@ import { posix } from "node:path";
2
2
  import { Effect, Schema } from "effect";
3
3
  import { ignorePatterns } from "#adapters/ignore.ts";
4
4
  import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
5
+ import { routeFiles } from "#inventory/routeFiles.ts";
5
6
  import { exportFits } from "#naming/exportFits.ts";
6
7
  import { mainExport } from "#naming/mainExport.ts";
7
8
  import { isMigrationFile } from "#naming/migrationFile.ts";
@@ -89,16 +90,17 @@ function findingsOf(file: SourceFile, layout: PackageLayout): readonly Finding[]
89
90
  }
90
91
 
91
92
  export const namedAfterExport = defineRule({
92
- check: ({ files, options, readText, sources }) =>
93
+ check: ({ files, options, readText, root, sources }) =>
93
94
  Effect.gen(function* () {
94
95
  const layout = yield* packageLayout({ files, readText });
96
+ const routes = yield* routeFiles(root);
95
97
  const toolOwned = ignorePatterns([...DEFAULT_TOOL_OWNED, ...globPatterns(options.toolOwned)]);
96
98
  return sources
97
- .filter((file) => !(TEST.test(file.path) || isMigrationFile(file.path) || toolOwned.ignores(file.path)))
99
+ .filter((file) => !(TEST.test(file.path) || isMigrationFile(file.path) || routes.files.has(file.path) || toolOwned.ignores(file.path)))
98
100
  .flatMap((file) => findingsOf(file, layout));
99
101
  }),
100
102
  description:
101
- "A file is named after its main export or a module-level constant, including a private constant, with its folders as the prefix; module client/admin and server/admin files may repeat names from above the admin folder. A file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
103
+ "A file is named after its main export or a module-level constant, including a private constant, with its folders as the prefix; module client/admin and server/admin files may repeat names from above the admin folder. TanStack Router configuration owns route filenames. A file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
102
104
  id: "files/named-after-export",
103
105
  options: Schema.toStandardSchemaV1(NamedAfterExportOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
104
106
  validate: validateGlobs,
@@ -18,7 +18,8 @@ function standardPattern(key: string, value: unknown): boolean {
18
18
  }
19
19
  const subpath = key.slice("./".length);
20
20
  const stem = subpath.slice(0, -".ts".length);
21
- const conditions = { default: `./dist/${stem}.js`, source: `./src/${subpath}`, types: `./dist/${stem}.d.ts` };
21
+ const source = "@shivaedev/source" in value ? "@shivaedev/source" : "source";
22
+ const conditions = { default: `./dist/${stem}.js`, [source]: `./src/${subpath}`, types: `./dist/${stem}.d.ts` };
22
23
  return (
23
24
  Object.keys(value).length === Object.keys(conditions).length
24
25
  && Object.entries(conditions).every(([condition, target]) => value[condition] === target)
@@ -3,19 +3,18 @@ import { manifestEntry, manifestFiles } from "#adapters/manifestInventory.ts";
3
3
  import { defineRule, type Finding } from "#rule.ts";
4
4
  import { itemsOf, type Json, member, parseJsonc } from "#rules/suppressions/biome/json.ts";
5
5
 
6
- const CONDITION = "source";
7
-
8
6
  function misplaced(path: string, field: string, value: unknown, node: Json | undefined): readonly Finding[] {
9
7
  const conditions = typeof value === "object" && value !== null && !Array.isArray(value) ? Object.entries(value) : [];
10
8
  const first = conditions[0]?.[0];
9
+ const condition = ["@shivaedev/source", "source"].find((name) => conditions.some(([key]) => key === name));
11
10
  const own: readonly Finding[] =
12
- first === CONDITION || !conditions.some(([key]) => key === CONDITION)
11
+ condition === undefined || first === condition
13
12
  ? []
14
13
  : [
15
14
  {
16
15
  file: path,
17
16
  line: node?.line,
18
- message: `Lists the "${CONDITION}" condition after "${first}" in ${field}. TypeScript takes the first condition that matches, so once built output exists it reads that instead of the sources the "${CONDITION}" condition names. Move "${CONDITION}" to the top of this condition block.`,
17
+ message: `Lists the "${condition}" condition after "${first}" in ${field}. TypeScript takes the first condition that matches, so once built output exists it reads that instead of the sources the "${condition}" condition names. Move "${condition}" to the top of this condition block.`,
19
18
  subject: field,
20
19
  },
21
20
  ];
@@ -47,7 +46,7 @@ export const manifestsSourceFirst = defineRule({
47
46
  return findings.flat();
48
47
  }),
49
48
  description:
50
- 'Every package.json condition block that names the "source" condition lists it first in exports and imports, so TypeScript reads the sources whether or not built output exists.',
49
+ 'Every package.json condition block that names a "@shivaedev/source" or "source" condition lists it first in exports and imports, so TypeScript reads the sources whether or not built output exists.',
51
50
  id: "manifests/source-first",
52
51
  registrable: false,
53
52
  });
@@ -2,11 +2,11 @@ import { Effect } from "effect";
2
2
  import ts from "typescript";
3
3
  import { fakeApi, fakeReferences } from "#adapters/imports/fakeReferences.ts";
4
4
  import { type FakeModule, fakeTargets } from "#adapters/imports/fakeTargets.ts";
5
+ import { storyProgram } from "#adapters/storyProgram.ts";
5
6
  import { importGraph } from "#imports/graph.ts";
6
7
  import { isTestCode } from "#naming/testName.ts";
7
8
  import { defineRule, type Finding } from "#rule.ts";
8
9
  import { fakeReplacements } from "./fakeReplacements.ts";
9
- import { storyProgram } from "./program.ts";
10
10
 
11
11
  function internal(path: string): boolean {
12
12
  return !path.split("/").includes("adapters");
@@ -1,10 +1,10 @@
1
1
  import { join } from "node:path";
2
2
  import ts from "typescript";
3
+ import { storyProgram } from "#adapters/storyProgram.ts";
3
4
  import type { ImportGraph } from "#imports/graph.ts";
4
5
  import type { RuleInputs } from "#rule.ts";
5
6
  import { iterationOrigin, type Origin } from "./collectionOrigins.ts";
6
7
  import { importFrom, importOrigin } from "./importOrigin.ts";
7
- import { storyProgram } from "./program.ts";
8
8
  import { returnValues } from "./returnValues.ts";
9
9
  import { memberName } from "./syntax.ts";
10
10
 
@@ -15,7 +15,7 @@ export interface Run {
15
15
 
16
16
  const SOURCE = import.meta.url.endsWith(".ts");
17
17
  const CLI = fileURLToPath(new URL(SOURCE ? "../../cli.ts" : "../../cli.js", import.meta.url));
18
- const OPTIONS = SOURCE ? ["--conditions=source"] : [];
18
+ const OPTIONS = SOURCE ? ["--conditions=@shivaedev/source"] : [];
19
19
 
20
20
  export const CLI_TIMEOUT = 60_000;
21
21
 
@@ -25,7 +25,7 @@ const CHECKS_LOG = "checks.log";
25
25
 
26
26
  const SOURCE_EXPORTS = {
27
27
  "./*.ts": Object.fromEntries([
28
- ["source", "./src/*.ts"],
28
+ ["@shivaedev/source", "./src/*.ts"],
29
29
  ["types", "./dist/*.d.ts"],
30
30
  ["default", "./dist/*.js"],
31
31
  ]),
@@ -4,7 +4,7 @@ import type { SeedFile } from "./tree.ts";
4
4
  export const LIBRARY_MANIFEST = "modules/library/package.json";
5
5
 
6
6
  export const FILE_PATH_EXPORTS = {
7
- "./*.ts": { default: "./dist/*.js", source: "./src/*.ts", types: "./dist/*.d.ts" },
7
+ "./*.ts": { "@shivaedev/source": "./src/*.ts", default: "./dist/*.js", types: "./dist/*.d.ts" },
8
8
  "./package.json": "./package.json",
9
9
  };
10
10
 
@@ -14,10 +14,13 @@ export const exportsWorkspace: SeedFile = {
14
14
  };
15
15
 
16
16
  function sourceFirst(_key: string, value: unknown): unknown {
17
- if (typeof value !== "object" || value === null || !("source" in value)) {
17
+ if (typeof value !== "object" || value === null || !("@shivaedev/source" in value)) {
18
18
  return value;
19
19
  }
20
- return Object.fromEntries([["source", value.source], ...Object.entries(value).filter(([key]) => key !== "source")]);
20
+ return Object.fromEntries([
21
+ ["@shivaedev/source", value["@shivaedev/source"]],
22
+ ...Object.entries(value).filter(([key]) => key !== "@shivaedev/source"),
23
+ ]);
21
24
  }
22
25
 
23
26
  export function packageExports(exports: unknown, path = LIBRARY_MANIFEST): SeedFile {
@@ -1 +0,0 @@
1
- {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/rules/stories/program.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI3C,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE,CAAC,OAAO,CA6B/E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"program.js","sourceRoot":"","sources":["../../../src/rules/stories/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAqC,CAAC;AAElE,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,KAAkB;IAClE,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjG,MAAM,OAAO,GAAG,IAAI,GAAG,CACtB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5B,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAChI,CACD,CAAC;IACF,MAAM,OAAO,GAAuB,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAC9E,MAAM,IAAI,GAAoB;QAC7B,GAAG,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC;QACjC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACvC,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/B,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACvG,CAAC;QACD,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACrC,kBAAkB,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACnC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAChG,CAAC,CAAC;KACH,CAAC;IACF,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACrE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC;AAChB,CAAC"}