@sdxc/kit 2026.10.24 → 2026.10.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -15
- package/changelog.jsonl +125 -4
- package/dist/architecture/graph.d.ts +16 -3
- package/dist/architecture/graph.js +37 -19
- package/dist/architecture/layers.d.ts +10 -3
- package/dist/architecture/layers.js +38 -9
- package/dist/commands/destroy.d.ts +1 -1
- package/dist/commands/make.d.ts +5 -5
- package/dist/commands/make.js +11 -8
- package/dist/commands/scaffold.d.ts +1 -1
- package/dist/contract.d.ts +3 -3
- package/dist/doctor/checks.d.ts +2 -2
- package/dist/doctor/checks.js +14 -2
- package/dist/doctor/constant-names.d.ts +17 -0
- package/dist/doctor/constant-names.js +106 -0
- package/dist/doctor/dependencies.d.ts +3 -3
- package/dist/doctor/dependencies.js +3 -3
- package/dist/doctor/fan-out.d.ts +3 -2
- package/dist/doctor/fan-out.js +4 -3
- package/dist/doctor/fetch-param.d.ts +15 -0
- package/dist/doctor/fetch-param.js +37 -0
- package/dist/doctor/files.d.ts +2 -0
- package/dist/doctor/files.js +4 -0
- package/dist/doctor/local-const.d.ts +15 -0
- package/dist/doctor/local-const.js +54 -0
- package/dist/doctor/logger.d.ts +15 -0
- package/dist/doctor/logger.js +41 -0
- package/dist/doctor/orphans.d.ts +3 -3
- package/dist/doctor/orphans.js +33 -7
- package/dist/doctor/process-env.d.ts +15 -0
- package/dist/doctor/process-env.js +39 -0
- package/dist/doctor/project.js +17 -13
- package/dist/doctor/result-throws.d.ts +5 -4
- package/dist/doctor/result-throws.js +6 -5
- package/dist/doctor/source-rule.d.ts +35 -0
- package/dist/doctor/source-rule.js +52 -0
- package/dist/doctor/stack-imports.d.ts +15 -0
- package/dist/doctor/stack-imports.js +60 -0
- package/dist/doctor/syntax.d.ts +31 -0
- package/dist/doctor/syntax.js +56 -0
- package/dist/make/binding.d.ts +13 -8
- package/dist/make/binding.js +96 -64
- package/dist/make/from-model.js +2 -7
- package/dist/make/index.js +2 -7
- package/dist/package-manager.d.ts +6 -0
- package/dist/package-manager.js +25 -2
- package/dist/scaffold/index.js +25 -19
- package/dist/ui/commands.js +2 -5
- package/dist/ui/registry.d.ts +2 -2
- package/dist/ui/registry.js +1 -1
- package/dist/upgrade/changelog.d.ts +2 -0
- package/dist/upgrade/changelog.js +2 -0
- package/dist/upgrade/project.d.ts +2 -2
- package/dist/upgrade/prompt.d.ts +3 -2
- package/dist/upgrade/prompt.js +43 -2
- package/package.json +5 -5
- package/registry/ui/youtube-embed.json +3 -3
- package/stubs/scaffold.test-mcp.stub +5 -1
- package/templates/app/AGENTS.md +3 -1
- package/templates/app/app/commands/db/fresh.ts +20 -13
- package/templates/app/app/commands/db/migrate.ts +42 -32
- package/templates/app/app/http/controllers/api/openapi.test.ts +29 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +8 -2
- package/templates/app/app/http/controllers/health.test.ts +35 -0
- package/templates/app/app/http/controllers/health.ts +16 -0
- package/templates/app/app/http/controllers/mcp.test.ts +16 -0
- package/templates/app/app/http/middleware/access.ts +6 -3
- package/templates/app/app/http/middleware/page.ts +3 -4
- package/templates/app/app/http/middleware/server-timing.test.ts +1 -1
- package/templates/app/app/initializers/database.test.ts +6 -1
- package/templates/app/app/initializers/health.ts +17 -0
- package/templates/app/app/initializers/openapi.ts +5 -4
- package/templates/app/app/initializers/router.test.ts +1 -1
- package/templates/app/app/initializers/router.tsx +5 -6
- package/templates/app/app/test/cloudflare-workers.test.ts +27 -0
- package/templates/app/app/test/cloudflare-workers.ts +17 -4
- package/templates/app/app/test/database.ts +33 -0
- package/templates/app/app/test/mcp.ts +96 -0
- package/templates/app/package.json +1 -0
- package/templates/app/resources/layouts/document.tsx +2 -3
- package/templates/app/routes/api.ts +17 -7
- package/templates/app/app/http/controllers/api/health.tsx +0 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `dependencies` check: import cycles and Clean Architecture breaches against the
|
|
3
|
-
* layers
|
|
4
|
-
*
|
|
2
|
+
* The `dependencies` check: static import cycles and Clean Architecture breaches against the
|
|
3
|
+
* app-layout layers, so models stay inward of services and http. A `lazy()` mapping or another
|
|
4
|
+
* deferred `import()` loads after startup, so it closes no cycle and breaches no layer.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
package/dist/doctor/fan-out.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `fan-out` check: no module imports more distinct project modules than
|
|
2
|
+
* The `fan-out` check: no module statically imports more distinct project modules than
|
|
3
3
|
* `doctor.fanOut.max` (default 15), so one file cannot become a hub that couples half the app.
|
|
4
|
+
* A `lazy()` mapping is a deferred import, so a router grows with its routes freely.
|
|
4
5
|
*
|
|
5
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
7
|
* @copyright Sergio Xalambrí 2026
|
|
7
8
|
*/
|
|
8
9
|
import type { Check } from "./check.js";
|
|
9
10
|
/**
|
|
10
|
-
* Warns on each module whose distinct import targets exceed the configured maximum.
|
|
11
|
+
* Warns on each module whose distinct static import targets exceed the configured maximum.
|
|
11
12
|
*/
|
|
12
13
|
export declare const fanOutCheck: Check;
|
package/dist/doctor/fan-out.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `fan-out` check: no module imports more distinct project modules than
|
|
2
|
+
* The `fan-out` check: no module statically imports more distinct project modules than
|
|
3
3
|
* `doctor.fanOut.max` (default 15), so one file cannot become a hub that couples half the app.
|
|
4
|
+
* A `lazy()` mapping is a deferred import, so a router grows with its routes freely.
|
|
4
5
|
*
|
|
5
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
7
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -8,7 +9,7 @@
|
|
|
8
9
|
import { projectGraph } from "../architecture/graph.js";
|
|
9
10
|
import { passed, skipped } from "./check.js";
|
|
10
11
|
/**
|
|
11
|
-
* Warns on each module whose distinct import targets exceed the configured maximum.
|
|
12
|
+
* Warns on each module whose distinct static import targets exceed the configured maximum.
|
|
12
13
|
*/
|
|
13
14
|
export const fanOutCheck = {
|
|
14
15
|
name: "fan-out",
|
|
@@ -18,7 +19,7 @@ export const fanOutCheck = {
|
|
|
18
19
|
if (graph.modules.length === 0)
|
|
19
20
|
return skipped("No app source to measure fan-out");
|
|
20
21
|
let counts = new Map();
|
|
21
|
-
for (let edge of graph.edges) {
|
|
22
|
+
for (let edge of graph.edges.filter((candidate) => !candidate.deferred)) {
|
|
22
23
|
let set = counts.get(edge.from) ?? new Set();
|
|
23
24
|
set.add(edge.to);
|
|
24
25
|
counts.set(edge.from, set);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `fetch-param` check: code calls the global `fetch`, and tests intercept it with MSW. A
|
|
3
|
+
* `typeof fetch` parameter or option threads a second way to reach the network through every
|
|
4
|
+
* caller, and lets a test pass against a stub that answers differently from the real client.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { SourceFinding, SourceRule } from "./source-rule.js";
|
|
10
|
+
/** Every `typeof fetch` type in app code, the shape an injected fetch is declared with. */
|
|
11
|
+
export declare const FETCH_PARAM_RULE: SourceRule;
|
|
12
|
+
/** Warns on each `typeof fetch` in app code. */
|
|
13
|
+
export declare const fetchParamCheck: import("./check.js").Check;
|
|
14
|
+
/** Each `typeof fetch` type query in `source`. */
|
|
15
|
+
export declare function findFetchParams(file: string, source: string): SourceFinding[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `fetch-param` check: code calls the global `fetch`, and tests intercept it with MSW. A
|
|
3
|
+
* `typeof fetch` parameter or option threads a second way to reach the network through every
|
|
4
|
+
* caller, and lets a test pass against a stub that answers differently from the real client.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { sourceCheck } from "./source-rule.js";
|
|
10
|
+
import { isNode, lineAt, parseModule, walk } from "./syntax.js";
|
|
11
|
+
/** Every `typeof fetch` type in app code, the shape an injected fetch is declared with. */
|
|
12
|
+
export const FETCH_PARAM_RULE = {
|
|
13
|
+
name: "fetch-param",
|
|
14
|
+
tests: false,
|
|
15
|
+
find: findFetchParams,
|
|
16
|
+
passed: "App code calls the global fetch",
|
|
17
|
+
noun: ["injected fetch", "injected fetches"],
|
|
18
|
+
fix: "Call the global fetch directly and mock it in tests with MSW",
|
|
19
|
+
};
|
|
20
|
+
/** Warns on each `typeof fetch` in app code. */
|
|
21
|
+
export const fetchParamCheck = sourceCheck(FETCH_PARAM_RULE);
|
|
22
|
+
/** Each `typeof fetch` type query in `source`. */
|
|
23
|
+
export function findFetchParams(file, source) {
|
|
24
|
+
let parsed = parseModule(file, source);
|
|
25
|
+
if (parsed === null)
|
|
26
|
+
return [];
|
|
27
|
+
let findings = [];
|
|
28
|
+
walk(parsed.program, (node) => {
|
|
29
|
+
if (node.type !== "TSTypeQuery")
|
|
30
|
+
return;
|
|
31
|
+
let name = node.exprName;
|
|
32
|
+
if (!isNode(name) || name.type !== "Identifier" || name.name !== "fetch")
|
|
33
|
+
return;
|
|
34
|
+
findings.push({ line: lineAt(source, node.start), message: "typeof fetch" });
|
|
35
|
+
});
|
|
36
|
+
return findings;
|
|
37
|
+
}
|
package/dist/doctor/files.d.ts
CHANGED
|
@@ -10,5 +10,7 @@
|
|
|
10
10
|
* lists nothing.
|
|
11
11
|
*/
|
|
12
12
|
export declare function listFiles(root: string, folder: string): Promise<string[]>;
|
|
13
|
+
/** Whether `path` is a module, tests included and declaration files left out. */
|
|
14
|
+
export declare function isModule(path: string): boolean;
|
|
13
15
|
/** Whether `path` is a module the app runs, its tests and declaration files left out. */
|
|
14
16
|
export declare function isAppSource(path: string): boolean;
|
package/dist/doctor/files.js
CHANGED
|
@@ -28,6 +28,10 @@ export async function listFiles(root, folder) {
|
|
|
28
28
|
.map((path) => `${folder}/${path}`)
|
|
29
29
|
.sort();
|
|
30
30
|
}
|
|
31
|
+
/** Whether `path` is a module, tests included and declaration files left out. */
|
|
32
|
+
export function isModule(path) {
|
|
33
|
+
return SOURCE.test(path) && !/\.d\.[cm]?ts$/.test(path);
|
|
34
|
+
}
|
|
31
35
|
/** Whether `path` is a module the app runs, its tests and declaration files left out. */
|
|
32
36
|
export function isAppSource(path) {
|
|
33
37
|
return SOURCE.test(path) && !NOT_APP_CODE.test(path);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `local-const` check: `const` declares module-level constants only, and every binding inside
|
|
3
|
+
* a function or block is `let`. A reader then knows a `const` is shared by the whole module and
|
|
4
|
+
* named for it, and a local binding reads the same whether or not it is reassigned.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { SourceFinding, SourceRule } from "./source-rule.js";
|
|
10
|
+
/** Every `const` below the module's top level, tests included; ambient declarations are left out. */
|
|
11
|
+
export declare const LOCAL_CONST_RULE: SourceRule;
|
|
12
|
+
/** Warns on each `const` declared inside a function or block. */
|
|
13
|
+
export declare const localConstCheck: import("./check.js").Check;
|
|
14
|
+
/** Each `const` declaration nested in a function, class or block of `source`. */
|
|
15
|
+
export declare function findLocalConsts(file: string, source: string): SourceFinding[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `local-const` check: `const` declares module-level constants only, and every binding inside
|
|
3
|
+
* a function or block is `let`. A reader then knows a `const` is shared by the whole module and
|
|
4
|
+
* named for it, and a local binding reads the same whether or not it is reassigned.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { sourceCheck } from "./source-rule.js";
|
|
10
|
+
import { lineAt, parseModule, walk } from "./syntax.js";
|
|
11
|
+
/** Every `const` below the module's top level, tests included; ambient declarations are left out. */
|
|
12
|
+
export const LOCAL_CONST_RULE = {
|
|
13
|
+
name: "local-const",
|
|
14
|
+
tests: true,
|
|
15
|
+
find: findLocalConsts,
|
|
16
|
+
passed: "Every const is a module-level constant",
|
|
17
|
+
noun: ["const inside a function or block", "consts inside a function or block"],
|
|
18
|
+
fix: "Declare it with let, or move a true constant to the module's top level in UPPER_SNAKE_CASE",
|
|
19
|
+
};
|
|
20
|
+
/** Warns on each `const` declared inside a function or block. */
|
|
21
|
+
export const localConstCheck = sourceCheck(LOCAL_CONST_RULE);
|
|
22
|
+
/** Each `const` declaration nested in a function, class or block of `source`. */
|
|
23
|
+
export function findLocalConsts(file, source) {
|
|
24
|
+
let parsed = parseModule(file, source);
|
|
25
|
+
if (parsed === null)
|
|
26
|
+
return [];
|
|
27
|
+
let findings = [];
|
|
28
|
+
walk(parsed.program, (node, ancestors) => {
|
|
29
|
+
if (node.type !== "VariableDeclaration" || node.kind !== "const")
|
|
30
|
+
return;
|
|
31
|
+
if (node.declare === true || ancestors.some(isAmbient) || ancestors.every(isTopLevel))
|
|
32
|
+
return;
|
|
33
|
+
findings.push({
|
|
34
|
+
line: lineAt(source, node.start),
|
|
35
|
+
message: "const inside a function or block",
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
return findings;
|
|
39
|
+
}
|
|
40
|
+
/** Nodes that keep a declaration at module level: a namespace's members are module members too. */
|
|
41
|
+
const MODULE_LEVEL = new Set([
|
|
42
|
+
"Program",
|
|
43
|
+
"ExportNamedDeclaration",
|
|
44
|
+
"TSModuleDeclaration",
|
|
45
|
+
"TSModuleBlock",
|
|
46
|
+
]);
|
|
47
|
+
/** A node that keeps a declaration at module level. */
|
|
48
|
+
function isTopLevel(node) {
|
|
49
|
+
return MODULE_LEVEL.has(node.type);
|
|
50
|
+
}
|
|
51
|
+
/** A `declare` module or namespace, whose members describe types rather than run. */
|
|
52
|
+
function isAmbient(node) {
|
|
53
|
+
return node.type === "TSModuleDeclaration" && node.declare === true;
|
|
54
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `logger` check: the app builds its loggers in `app/initializers/`, and the router and job
|
|
3
|
+
* dispatcher attach that one instance to each invocation, so every line carries the request's
|
|
4
|
+
* trace and a handler logs through `ctx.log` or `currentLog()`.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { SourceFinding, SourceRule } from "./source-rule.js";
|
|
10
|
+
/** Every `createLogger()` call in app code outside `app/initializers/`. */
|
|
11
|
+
export declare const LOGGER_RULE: SourceRule;
|
|
12
|
+
/** Warns on each `createLogger()` call outside `app/initializers/`. */
|
|
13
|
+
export declare const loggerCheck: import("./check.js").Check;
|
|
14
|
+
/** Each `createLogger()` call in `source`, unless `file` is an initializer. */
|
|
15
|
+
export declare function findLoggerInstances(file: string, source: string): SourceFinding[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `logger` check: the app builds its loggers in `app/initializers/`, and the router and job
|
|
3
|
+
* dispatcher attach that one instance to each invocation, so every line carries the request's
|
|
4
|
+
* trace and a handler logs through `ctx.log` or `currentLog()`.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { sourceCheck } from "./source-rule.js";
|
|
10
|
+
import { isNode, lineAt, parseModule, walk } from "./syntax.js";
|
|
11
|
+
/** The folder that owns the app's single instances. */
|
|
12
|
+
const INITIALIZERS = "app/initializers/";
|
|
13
|
+
/** Every `createLogger()` call in app code outside `app/initializers/`. */
|
|
14
|
+
export const LOGGER_RULE = {
|
|
15
|
+
name: "logger",
|
|
16
|
+
tests: false,
|
|
17
|
+
find: findLoggerInstances,
|
|
18
|
+
passed: "Loggers are built in app/initializers",
|
|
19
|
+
noun: ["logger built outside app/initializers", "loggers built outside app/initializers"],
|
|
20
|
+
fix: "Log through ctx.log, or currentLog() from @sdxc/logger, and build the logger in app/initializers/logger.ts",
|
|
21
|
+
};
|
|
22
|
+
/** Warns on each `createLogger()` call outside `app/initializers/`. */
|
|
23
|
+
export const loggerCheck = sourceCheck(LOGGER_RULE);
|
|
24
|
+
/** Each `createLogger()` call in `source`, unless `file` is an initializer. */
|
|
25
|
+
export function findLoggerInstances(file, source) {
|
|
26
|
+
if (file.startsWith(INITIALIZERS) || file.includes(`/${INITIALIZERS}`))
|
|
27
|
+
return [];
|
|
28
|
+
let parsed = parseModule(file, source);
|
|
29
|
+
if (parsed === null)
|
|
30
|
+
return [];
|
|
31
|
+
let findings = [];
|
|
32
|
+
walk(parsed.program, (node) => {
|
|
33
|
+
if (node.type !== "CallExpression")
|
|
34
|
+
return;
|
|
35
|
+
let callee = node.callee;
|
|
36
|
+
if (!isNode(callee) || callee.type !== "Identifier" || callee.name !== "createLogger")
|
|
37
|
+
return;
|
|
38
|
+
findings.push({ line: lineAt(source, node.start), message: "calls createLogger()" });
|
|
39
|
+
});
|
|
40
|
+
return findings;
|
|
41
|
+
}
|
package/dist/doctor/orphans.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `orphans` check: every app-source module is imported by another
|
|
3
|
-
* loads from outside the graph (bootstrap,
|
|
4
|
-
* agent leftovers show up as unreferenced files.
|
|
2
|
+
* The `orphans` check: every app-source module is imported by another module or a test, named
|
|
3
|
+
* by a root config file, or is an entry the layout loads from outside the graph (bootstrap,
|
|
4
|
+
* routes, initializers, declarations). Dead agent leftovers show up as unreferenced files.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
package/dist/doctor/orphans.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `orphans` check: every app-source module is imported by another
|
|
3
|
-
* loads from outside the graph (bootstrap,
|
|
4
|
-
* agent leftovers show up as unreferenced files.
|
|
2
|
+
* The `orphans` check: every app-source module is imported by another module or a test, named
|
|
3
|
+
* by a root config file, or is an entry the layout loads from outside the graph (bootstrap,
|
|
4
|
+
* routes, initializers, declarations). Dead agent leftovers show up as unreferenced files.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
9
12
|
import { projectGraph } from "../architecture/graph.js";
|
|
13
|
+
import { isDeclaration } from "../architecture/layers.js";
|
|
10
14
|
import { passed, skipped } from "./check.js";
|
|
11
15
|
/** Prefixes that may have no importers inside the project graph. */
|
|
12
16
|
const ENTRY_PREFIXES = [
|
|
@@ -26,9 +30,10 @@ export const orphansCheck = {
|
|
|
26
30
|
let graph = await projectGraph(context.root);
|
|
27
31
|
if (graph.modules.length === 0)
|
|
28
32
|
return skipped("No app source to find orphans");
|
|
29
|
-
let imported = new Set(graph.edges.map((edge) => edge.to));
|
|
33
|
+
let imported = new Set([...graph.edges, ...graph.testEdges].map((edge) => edge.to));
|
|
34
|
+
let configured = await rootConfigText(context.root);
|
|
30
35
|
let findings = graph.modules
|
|
31
|
-
.filter((module) => !imported.has(module) && !isEntry(module))
|
|
36
|
+
.filter((module) => !imported.has(module) && !isEntry(module) && !configured.includes(module))
|
|
32
37
|
.sort()
|
|
33
38
|
.map((module) => `${module}: nothing in the project imports it`);
|
|
34
39
|
if (findings.length === 0) {
|
|
@@ -44,7 +49,28 @@ export const orphansCheck = {
|
|
|
44
49
|
};
|
|
45
50
|
},
|
|
46
51
|
};
|
|
47
|
-
/**
|
|
52
|
+
/** A tool's config file at the project root, such as `vite.config.ts`. */
|
|
53
|
+
const ROOT_CONFIG = /\.config\.[cm]?[jt]s$/;
|
|
54
|
+
/**
|
|
55
|
+
* Whether `path` is an entry the layout loads without a same-project importer, or a declaration
|
|
56
|
+
* module `sdxc make` imports into its initializer with the first handler it maps.
|
|
57
|
+
*/
|
|
48
58
|
function isEntry(path) {
|
|
49
|
-
return ENTRY_PREFIXES.some((prefix) => path.startsWith(prefix));
|
|
59
|
+
return ENTRY_PREFIXES.some((prefix) => path.startsWith(prefix)) || isDeclaration(path);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The text of every tool config at the project root, joined, so a module a config names by
|
|
63
|
+
* path, as `vite.config.ts` names a test stand-in for a runtime module, counts as used.
|
|
64
|
+
*/
|
|
65
|
+
async function rootConfigText(root) {
|
|
66
|
+
let entries = await wrap(() => readdir(root));
|
|
67
|
+
if (isFailure(entries))
|
|
68
|
+
return "";
|
|
69
|
+
let texts = [];
|
|
70
|
+
for (let name of entries.data.filter((entry) => ROOT_CONFIG.test(entry))) {
|
|
71
|
+
let text = await wrap(() => readFile(join(root, name), "utf8"));
|
|
72
|
+
if (!isFailure(text))
|
|
73
|
+
texts.push(text.data);
|
|
74
|
+
}
|
|
75
|
+
return texts.join("\n");
|
|
50
76
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `process-env` check: app code reads its bindings and secrets from `env` in
|
|
3
|
+
* `cloudflare:workers`, which `cloudflare.config.ts` declares and typegen types. `process.env`
|
|
4
|
+
* holds none of them in a deployed Worker.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { SourceFinding, SourceRule } from "./source-rule.js";
|
|
10
|
+
/** Every `process.env` read in app code; tests set up their environment as they need. */
|
|
11
|
+
export declare const PROCESS_ENV_RULE: SourceRule;
|
|
12
|
+
/** Warns on each `process.env` read in app code. */
|
|
13
|
+
export declare const processEnvCheck: import("./check.js").Check;
|
|
14
|
+
/** Each `process.env` member access in `source`. */
|
|
15
|
+
export declare function findProcessEnv(file: string, source: string): SourceFinding[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `process-env` check: app code reads its bindings and secrets from `env` in
|
|
3
|
+
* `cloudflare:workers`, which `cloudflare.config.ts` declares and typegen types. `process.env`
|
|
4
|
+
* holds none of them in a deployed Worker.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { sourceCheck } from "./source-rule.js";
|
|
10
|
+
import { isNode, lineAt, parseModule, walk } from "./syntax.js";
|
|
11
|
+
/** Every `process.env` read in app code; tests set up their environment as they need. */
|
|
12
|
+
export const PROCESS_ENV_RULE = {
|
|
13
|
+
name: "process-env",
|
|
14
|
+
tests: false,
|
|
15
|
+
find: findProcessEnv,
|
|
16
|
+
passed: "App code reads env from cloudflare:workers",
|
|
17
|
+
noun: ["process.env read", "process.env reads"],
|
|
18
|
+
fix: 'Read the binding from env, imported from "cloudflare:workers"',
|
|
19
|
+
};
|
|
20
|
+
/** Warns on each `process.env` read in app code. */
|
|
21
|
+
export const processEnvCheck = sourceCheck(PROCESS_ENV_RULE);
|
|
22
|
+
/** Each `process.env` member access in `source`. */
|
|
23
|
+
export function findProcessEnv(file, source) {
|
|
24
|
+
let parsed = parseModule(file, source);
|
|
25
|
+
if (parsed === null)
|
|
26
|
+
return [];
|
|
27
|
+
let findings = [];
|
|
28
|
+
walk(parsed.program, (node) => {
|
|
29
|
+
if (node.type !== "MemberExpression")
|
|
30
|
+
return;
|
|
31
|
+
let { object, property } = node;
|
|
32
|
+
if (!isNode(object) || object.type !== "Identifier" || object.name !== "process")
|
|
33
|
+
return;
|
|
34
|
+
if (!isNode(property) || property.name !== "env")
|
|
35
|
+
return;
|
|
36
|
+
findings.push({ line: lineAt(source, node.start), message: "reads process.env" });
|
|
37
|
+
});
|
|
38
|
+
return findings;
|
|
39
|
+
}
|
package/dist/doctor/project.js
CHANGED
|
@@ -63,19 +63,23 @@ const context = Object.freeze({
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
async files(folder) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
const found = [];
|
|
67
|
+
const visit = async (dir) => {
|
|
68
|
+
let entries;
|
|
69
|
+
try {
|
|
70
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
71
|
+
} catch {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
for (const entry of entries) {
|
|
75
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
76
|
+
const full = join(dir, entry.name);
|
|
77
|
+
if (entry.isDirectory()) await visit(full);
|
|
78
|
+
else if (entry.isFile()) found.push(relative(root, full).split(sep).join("/"));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
await visit(inside(folder));
|
|
82
|
+
return found.sort();
|
|
79
83
|
},
|
|
80
84
|
});
|
|
81
85
|
const NAME = new RegExp(input.namePattern);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `result-throws` check: app source
|
|
3
|
-
*
|
|
2
|
+
* The `result-throws` check: app source returns `@sdxc/result` failures so handlers stay typed.
|
|
3
|
+
* Entry points in `bootstrap/` answer the runtime that calls them, whose callbacks report a
|
|
4
|
+
* failure by throwing, so they are left out.
|
|
4
5
|
*
|
|
5
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
7
|
* @copyright Sergio Xalambrí 2026
|
|
7
8
|
*/
|
|
8
9
|
import type { Check } from "./check.js";
|
|
9
10
|
/**
|
|
10
|
-
* Warns on each `throw` statement in app source
|
|
11
|
-
* {@link isAppSource}.
|
|
11
|
+
* Warns on each `throw` statement in app source outside `bootstrap/`. Tests and declaration
|
|
12
|
+
* files are left out by {@link isAppSource}.
|
|
12
13
|
*/
|
|
13
14
|
export declare const resultThrowsCheck: Check;
|
|
14
15
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `result-throws` check: app source
|
|
3
|
-
*
|
|
2
|
+
* The `result-throws` check: app source returns `@sdxc/result` failures so handlers stay typed.
|
|
3
|
+
* Entry points in `bootstrap/` answer the runtime that calls them, whose callbacks report a
|
|
4
|
+
* failure by throwing, so they are left out.
|
|
4
5
|
*
|
|
5
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
7
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -13,15 +14,15 @@ import { PROJECT_FOLDERS } from "../stats.js";
|
|
|
13
14
|
import { passed, skipped } from "./check.js";
|
|
14
15
|
import { isAppSource, listFiles } from "./files.js";
|
|
15
16
|
/**
|
|
16
|
-
* Warns on each `throw` statement in app source
|
|
17
|
-
* {@link isAppSource}.
|
|
17
|
+
* Warns on each `throw` statement in app source outside `bootstrap/`. Tests and declaration
|
|
18
|
+
* files are left out by {@link isAppSource}.
|
|
18
19
|
*/
|
|
19
20
|
export const resultThrowsCheck = {
|
|
20
21
|
name: "result-throws",
|
|
21
22
|
async run(context) {
|
|
22
23
|
let findings = [];
|
|
23
24
|
let files = 0;
|
|
24
|
-
for (let folder of PROJECT_FOLDERS) {
|
|
25
|
+
for (let folder of PROJECT_FOLDERS.filter((name) => name !== "bootstrap")) {
|
|
25
26
|
for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
|
|
26
27
|
files += 1;
|
|
27
28
|
let source = await wrap(() => readFile(join(context.root, file), "utf8"));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A source rule: one convention the project's modules follow, found per file by `find`, and the
|
|
3
|
+
* `sdxc doctor` check that reads every module in the app layout's folders for it. A rule is plain
|
|
4
|
+
* data, so a monorepo check can run the same `find` over folders outside one app.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Check } from "./check.js";
|
|
10
|
+
/** One place a module breaks a rule. */
|
|
11
|
+
export interface SourceFinding {
|
|
12
|
+
/** The 1-based line it starts on. */
|
|
13
|
+
line: number;
|
|
14
|
+
/** What breaks the rule, short enough to follow `file:line:` in the report. */
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
/** A convention every module of the project follows. */
|
|
18
|
+
export interface SourceRule {
|
|
19
|
+
/** The check's name in the report and for `--only` and `--skip`. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Whether tests follow the rule too; app code always does. */
|
|
22
|
+
tests: boolean;
|
|
23
|
+
/** Each place `source` breaks the rule; a module oxc cannot parse yields none. */
|
|
24
|
+
find(file: string, source: string): SourceFinding[];
|
|
25
|
+
/** The report's message when no module breaks the rule. */
|
|
26
|
+
passed: string;
|
|
27
|
+
/** The noun for one finding and for many, as in "Found 2 local consts". */
|
|
28
|
+
noun: [one: string, many: string];
|
|
29
|
+
/** The edit that clears a finding. */
|
|
30
|
+
fix: string;
|
|
31
|
+
}
|
|
32
|
+
/** Whether `rule` reads `file`: a module, and app code unless the rule covers tests. */
|
|
33
|
+
export declare function appliesTo(rule: SourceRule, file: string): boolean;
|
|
34
|
+
/** The `sdxc doctor` check that warns on every finding of `rule` across the app layout's folders. */
|
|
35
|
+
export declare function sourceCheck(rule: SourceRule): Check;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A source rule: one convention the project's modules follow, found per file by `find`, and the
|
|
3
|
+
* `sdxc doctor` check that reads every module in the app layout's folders for it. A rule is plain
|
|
4
|
+
* data, so a monorepo check can run the same `find` over folders outside one app.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
12
|
+
import { PROJECT_FOLDERS } from "../stats.js";
|
|
13
|
+
import { passed, skipped } from "./check.js";
|
|
14
|
+
import { isAppSource, isModule, listFiles } from "./files.js";
|
|
15
|
+
/** Whether `rule` reads `file`: a module, and app code unless the rule covers tests. */
|
|
16
|
+
export function appliesTo(rule, file) {
|
|
17
|
+
return rule.tests ? isModule(file) : isAppSource(file);
|
|
18
|
+
}
|
|
19
|
+
/** The `sdxc doctor` check that warns on every finding of `rule` across the app layout's folders. */
|
|
20
|
+
export function sourceCheck(rule) {
|
|
21
|
+
return {
|
|
22
|
+
name: rule.name,
|
|
23
|
+
async run(context) {
|
|
24
|
+
let findings = [];
|
|
25
|
+
let files = 0;
|
|
26
|
+
for (let folder of PROJECT_FOLDERS) {
|
|
27
|
+
for (let file of await listFiles(context.root, folder)) {
|
|
28
|
+
if (!appliesTo(rule, file))
|
|
29
|
+
continue;
|
|
30
|
+
files += 1;
|
|
31
|
+
let source = await wrap(() => readFile(join(context.root, file), "utf8"));
|
|
32
|
+
if (isFailure(source))
|
|
33
|
+
continue;
|
|
34
|
+
for (let found of rule.find(file, source.data)) {
|
|
35
|
+
findings.push(`${file}:${found.line}: ${found.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (files === 0)
|
|
40
|
+
return skipped("No app source to read");
|
|
41
|
+
if (findings.length === 0)
|
|
42
|
+
return passed(rule.passed);
|
|
43
|
+
let [one, many] = rule.noun;
|
|
44
|
+
return {
|
|
45
|
+
status: "warn",
|
|
46
|
+
message: `Found ${findings.length} ${findings.length === 1 ? one : many}`,
|
|
47
|
+
findings,
|
|
48
|
+
fix: rule.fix,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `stack-imports` check: the project imports the library its stack settled on for each
|
|
3
|
+
* concern, so validation, UI and markup each have one way to be written: `remix/data-schema`
|
|
4
|
+
* for schemas, `remix/component` JSX for UI and server HTML, and `css()` mixins for styles.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { SourceFinding, SourceRule } from "./source-rule.js";
|
|
10
|
+
/** Every import, re-export or dynamic `import()` of a replaced library, tests included. */
|
|
11
|
+
export declare const STACK_IMPORTS_RULE: SourceRule;
|
|
12
|
+
/** Warns on each import of a library the stack replaces. */
|
|
13
|
+
export declare const stackImportsCheck: import("./check.js").Check;
|
|
14
|
+
/** Each place `source` loads a replaced library, with the library to use instead. */
|
|
15
|
+
export declare function findStackImports(file: string, source: string): SourceFinding[];
|