@stacksjs/actions 0.70.257 → 0.70.258
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/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/lint/stx-gate.d.ts +36 -0
- package/dist/lint/stx-gate.js +175 -0
- package/package.json +19 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { StxLintConfig, StxLintReport, StxLintResult } from './lint/stx-gate';
|
|
1
2
|
export type { CrudField } from './scaffold-crud';
|
|
2
3
|
export type { DiscoveredPackagesManifest, PackageStacksMeta } from './discover-packages';
|
|
3
4
|
export * from './action';
|
|
@@ -24,6 +25,9 @@ export * from './helpers/index';
|
|
|
24
25
|
// spawning a deep dist path. Exported from ./lint/lint — the pure module — so
|
|
25
26
|
// importing the barrel never pulls the process-exiting ./lint/index script.
|
|
26
27
|
export { formatProject, lintFix, lintProject } from './lint/lint';
|
|
28
|
+
// stx conformance checks behind `buddy lint --stx`. Pure - returns a report
|
|
29
|
+
// and never exits, so the command owns rendering and the exit code.
|
|
30
|
+
export { DEFAULT_STX_LINT_CONFIG, loadStxLintConfig, runStxLint } from './lint/stx-gate';
|
|
27
31
|
export * from './setup/index';
|
|
28
32
|
// makeFactory,
|
|
29
33
|
export {
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./dev";
|
|
|
13
13
|
export * from "./generate";
|
|
14
14
|
export * from "./helpers";
|
|
15
15
|
export { formatProject, lintFix, lintProject } from "./lint/lint";
|
|
16
|
+
export { DEFAULT_STX_LINT_CONFIG, loadStxLintConfig, runStxLint } from "./lint/stx-gate";
|
|
16
17
|
export * from "./setup";
|
|
17
18
|
export {
|
|
18
19
|
createComponent,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Read `config/lint.ts`, falling back to defaults when a project has none. */
|
|
2
|
+
export declare function loadStxLintConfig(root: string): Promise<StxLintConfig>;
|
|
3
|
+
/**
|
|
4
|
+
* Run every check and report.
|
|
5
|
+
*
|
|
6
|
+
* `status` is `fail` when a count sits above its baseline, `loosened` when it
|
|
7
|
+
* sits below one (real progress, but the baseline is now stale), `pass` when
|
|
8
|
+
* they match.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runStxLint(options?: { root?: string, config?: StxLintConfig }): Promise<StxLintReport>;
|
|
11
|
+
export declare const DEFAULT_STX_LINT_CONFIG: StxLintConfig;
|
|
12
|
+
export declare interface StxLintConfig {
|
|
13
|
+
stxGlob: string
|
|
14
|
+
distGlob: string
|
|
15
|
+
baselines: Record<string, number>
|
|
16
|
+
doctypeExempt: string[]
|
|
17
|
+
styleExempt: string[]
|
|
18
|
+
staleRules: Record<string, boolean>
|
|
19
|
+
}
|
|
20
|
+
export declare interface StxLintResult {
|
|
21
|
+
id: string
|
|
22
|
+
label: string
|
|
23
|
+
why?: string
|
|
24
|
+
count: number
|
|
25
|
+
baseline: number
|
|
26
|
+
detail: string[]
|
|
27
|
+
status: 'pass' | 'fail' | 'loosened'
|
|
28
|
+
}
|
|
29
|
+
export declare interface StxLintReport {
|
|
30
|
+
root: string
|
|
31
|
+
results: StxLintResult[]
|
|
32
|
+
distMissing: boolean
|
|
33
|
+
failed: number
|
|
34
|
+
loosened: number
|
|
35
|
+
counts: Record<string, number>
|
|
36
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { Glob } from "bun";
|
|
5
|
+
export const DEFAULT_STX_LINT_CONFIG = {
|
|
6
|
+
stxGlob: "resources/**/*.stx",
|
|
7
|
+
distGlob: "dist/**/*.html",
|
|
8
|
+
baselines: {},
|
|
9
|
+
doctypeExempt: [],
|
|
10
|
+
styleExempt: ["resources/emails/"],
|
|
11
|
+
staleRules: {}
|
|
12
|
+
};
|
|
13
|
+
const REQUIRED_STX_CONFIG_KEYS = [
|
|
14
|
+
["strict", "DOM guard (ch. 12.1) - without it script-validation discards every finding"],
|
|
15
|
+
["root", "pins project topology; absent, resolveStxRoot sniffs it and double-prefixes dirs"],
|
|
16
|
+
["pagesDir", 'must accompany root - resolveStxRoot falls back to a non-existent "pages"']
|
|
17
|
+
];
|
|
18
|
+
export async function loadStxLintConfig(root) {
|
|
19
|
+
const found = ["config/lint.ts", "config/lint.js"].find((c) => existsSync(join(root, c)));
|
|
20
|
+
if (!found)
|
|
21
|
+
return { ...DEFAULT_STX_LINT_CONFIG };
|
|
22
|
+
try {
|
|
23
|
+
const stx = (await import(join(root, found))).default?.stx ?? {};
|
|
24
|
+
return {
|
|
25
|
+
...DEFAULT_STX_LINT_CONFIG,
|
|
26
|
+
...stx,
|
|
27
|
+
baselines: { ...stx.baselines },
|
|
28
|
+
styleExempt: stx.styleExempt ?? DEFAULT_STX_LINT_CONFIG.styleExempt,
|
|
29
|
+
doctypeExempt: stx.doctypeExempt ?? [],
|
|
30
|
+
staleRules: stx.staleRules ?? {}
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw Error(`Could not read ${found}: ${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function scanGlob(pattern, root) {
|
|
37
|
+
const out = [];
|
|
38
|
+
try {
|
|
39
|
+
for await (const f of new Glob(pattern).scan(root))
|
|
40
|
+
out.push(f);
|
|
41
|
+
} catch {}
|
|
42
|
+
return out.sort();
|
|
43
|
+
}
|
|
44
|
+
const ROUTED_ANCHOR = /\bdata-stx-link\b|\bdata-no-router\b/;
|
|
45
|
+
async function grepLines(re, files, root, ignore) {
|
|
46
|
+
const hits = [];
|
|
47
|
+
for (const f of files) {
|
|
48
|
+
let src = "";
|
|
49
|
+
try {
|
|
50
|
+
src = await Bun.file(join(root, f)).text();
|
|
51
|
+
} catch {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
src.split(`
|
|
55
|
+
`).forEach((line, i) => {
|
|
56
|
+
re.lastIndex = 0;
|
|
57
|
+
if (!re.test(line))
|
|
58
|
+
return;
|
|
59
|
+
if (ignore) {
|
|
60
|
+
ignore.lastIndex = 0;
|
|
61
|
+
if (ignore.test(line))
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
hits.push(`${f}:${i + 1} ${line.trim().slice(0, 90)}`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return hits;
|
|
68
|
+
}
|
|
69
|
+
async function scanSources(files, root, config) {
|
|
70
|
+
const { lintStxStrict } = await import("@stacksjs/stx"), { PROHIBITED_DOM_PATTERNS } = await import("@stacksjs/stx/script-validation"), { scanScriptTags } = await import("@stacksjs/stx/signal-processing"), domPatterns = PROHIBITED_DOM_PATTERNS, scan = { domGuard: [], strictLint: [], balance: [], commentLandmine: [], doctype: [] };
|
|
71
|
+
for (const f of files) {
|
|
72
|
+
let src = "";
|
|
73
|
+
try {
|
|
74
|
+
src = await Bun.file(join(root, f)).text();
|
|
75
|
+
} catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
for (const d of lintStxStrict(src, { filePath: f, rules: config.staleRules }) ?? [])
|
|
79
|
+
scan.strictLint.push(`${f}:${d.line}:${d.column} ${d.ruleId} ${d.message}`);
|
|
80
|
+
for (const s of scanScriptTags(src, { skipAttrs: /\bserver\b|\bsrc\s*=/ }))
|
|
81
|
+
for (const { pattern, message, suggestion } of domPatterns) {
|
|
82
|
+
pattern.lastIndex = 0;
|
|
83
|
+
const m = s.body.match(pattern);
|
|
84
|
+
if (m)
|
|
85
|
+
scan.domGuard.push(`${f} ${message} x${m.length} -> ${suggestion}`);
|
|
86
|
+
}
|
|
87
|
+
const open = (src.match(/<script\b/gi) ?? []).length, close = (src.match(/<\/script\s*>/gi) ?? []).length;
|
|
88
|
+
if (open !== close)
|
|
89
|
+
scan.balance.push(`${f} ${open} <script> vs ${close} </script> - a "</script" sits inside a script body`);
|
|
90
|
+
for (const m of src.matchAll(/<!--([\s\S]*?)-->/g))
|
|
91
|
+
if (/<\/?html\b|<!DOCTYPE\b|<\/?script\b/i.test(m[1] ?? "")) {
|
|
92
|
+
const line = src.slice(0, m.index).split(`
|
|
93
|
+
`).length;
|
|
94
|
+
scan.commentLandmine.push(`${f}:${line} banned token inside <!-- -->`);
|
|
95
|
+
}
|
|
96
|
+
const exempt = config.doctypeExempt.some((p) => f.startsWith(p) || f === p);
|
|
97
|
+
if (/<!DOCTYPE\s/i.test(src) && !/@nolayout\b/.test(src) && !exempt)
|
|
98
|
+
scan.doctype.push(`${f} <!DOCTYPE> with no @nolayout - layout resolution is silently skipped`);
|
|
99
|
+
}
|
|
100
|
+
return scan;
|
|
101
|
+
}
|
|
102
|
+
async function missingStxConfigKeys(root) {
|
|
103
|
+
const found = ["config/ui.ts", "config/ui.js"].find((c) => existsSync(join(root, c)));
|
|
104
|
+
if (!found)
|
|
105
|
+
return [];
|
|
106
|
+
let ui;
|
|
107
|
+
try {
|
|
108
|
+
ui = (await import(join(root, found))).default ?? {};
|
|
109
|
+
} catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
return REQUIRED_STX_CONFIG_KEYS.filter(([key]) => ui[key] == null).map(([key, why]) => `${found} is missing "${key}" - ${why}`);
|
|
113
|
+
}
|
|
114
|
+
export async function runStxLint(options = {}) {
|
|
115
|
+
const root = options.root ?? process.cwd(), config = options.config ?? await loadStxLintConfig(root), stxAll = await scanGlob(config.stxGlob, root), dist = await scanGlob(config.distGlob, root), styled = stxAll.filter((f) => !config.styleExempt.some((p) => f.startsWith(p))), scan = await scanSources(stxAll, root, config), configErrors = await missingStxConfigKeys(root), definitions = [
|
|
116
|
+
{
|
|
117
|
+
id: "stx-config-keys",
|
|
118
|
+
label: "stx config sets every key the standards require",
|
|
119
|
+
why: "pinning root/pagesDir changes topology resolution, so it is a deliberate move",
|
|
120
|
+
detail: () => configErrors
|
|
121
|
+
},
|
|
122
|
+
{ id: "style-block", label: "no <style> block in a .stx file (rule 11.1)", detail: () => grepLines(/<style/, stxAll, root) },
|
|
123
|
+
{ id: "doctype-no-nolayout", label: "no <!DOCTYPE> outside the exempt list (rule 2.2)", detail: () => scan.doctype },
|
|
124
|
+
{ id: "script-tag-balance", label: 'no "</script" inside a script body', detail: () => scan.balance },
|
|
125
|
+
{ id: "comment-landmine", label: "no html/DOCTYPE/script token inside an HTML comment", detail: () => scan.commentLandmine },
|
|
126
|
+
{ id: "strict-lint", label: "stx's own strict linter", detail: () => scan.strictLint },
|
|
127
|
+
{
|
|
128
|
+
id: "dom-guard",
|
|
129
|
+
label: "prohibited DOM access in client scripts",
|
|
130
|
+
why: "imperative views clear these as they move to signals",
|
|
131
|
+
detail: () => scan.domGuard
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "inline-style-attr",
|
|
135
|
+
label: 'no style="" attribute (rule 11.5)',
|
|
136
|
+
why: "pre-hydration display:none; the sanctioned form is a :class with literal branches",
|
|
137
|
+
detail: () => grepLines(/style="/, styled, root)
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "plain-internal-anchor",
|
|
141
|
+
label: 'no unrouted internal <a href="/"> (rule 9 - use StxLink)',
|
|
142
|
+
why: "converting marketing pages is usually its own pass",
|
|
143
|
+
detail: () => grepLines(/<a [^>]*href="\//, styled, root, ROUTED_ANCHOR)
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: "unmanaged-timer",
|
|
147
|
+
label: "no bare setTimeout/setInterval (rule 6.7)",
|
|
148
|
+
why: "useTimeout()/useDebounce() unsubscribe on destroy; bare timers outlive the SPA swap",
|
|
149
|
+
detail: () => grepLines(/(^|[^.\w])(setTimeout|setInterval)\s*\(/, stxAll, root)
|
|
150
|
+
},
|
|
151
|
+
{ id: "dist-component-error", label: "no unresolved component in built HTML", detail: () => grepLines(/Error loading component/, dist, root) },
|
|
152
|
+
{ id: "dist-path-leak", label: "no absolute filesystem path in built HTML", detail: () => grepLines(/\/(Users|home)\/[a-z]/i, dist, root) },
|
|
153
|
+
{ id: "dist-layout-published", label: "no layout emitted as a public page", detail: () => dist.filter((f) => f.startsWith("layouts/") || f.includes("/layouts/")) }
|
|
154
|
+
], results = [];
|
|
155
|
+
for (const def of definitions) {
|
|
156
|
+
const detail = await def.detail(), count = detail.length, baseline = config.baselines[def.id] ?? 0;
|
|
157
|
+
results.push({
|
|
158
|
+
id: def.id,
|
|
159
|
+
label: def.label,
|
|
160
|
+
why: def.why,
|
|
161
|
+
count,
|
|
162
|
+
baseline,
|
|
163
|
+
detail,
|
|
164
|
+
status: count > baseline ? "fail" : count < baseline ? "loosened" : "pass"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
root,
|
|
169
|
+
results,
|
|
170
|
+
distMissing: dist.length === 0,
|
|
171
|
+
failed: results.filter((r) => r.status === "fail").length,
|
|
172
|
+
loosened: results.filter((r) => r.status === "loosened").length,
|
|
173
|
+
counts: Object.fromEntries(results.map((r) => [r.id, r.count]))
|
|
174
|
+
};
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/actions",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.70.
|
|
5
|
+
"version": "0.70.258",
|
|
6
6
|
"description": "The Stacks actions.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -59,33 +59,33 @@
|
|
|
59
59
|
"prepublishOnly": "bun run build"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@stacksjs/config": "0.70.
|
|
62
|
+
"@stacksjs/config": "0.70.258",
|
|
63
63
|
"@stacksjs/bumpx": "^0.2.6",
|
|
64
64
|
"@stacksjs/bunpress": "^0.1.18",
|
|
65
65
|
"@stacksjs/logsmith": "^0.2.3",
|
|
66
|
-
"@stacksjs/registry": "0.70.
|
|
66
|
+
"@stacksjs/registry": "0.70.258",
|
|
67
67
|
"@stacksjs/stx": "^0.2.148",
|
|
68
|
-
"@stacksjs/ts-cloud": "^0.7.
|
|
68
|
+
"@stacksjs/ts-cloud": "^0.7.94",
|
|
69
69
|
"@stacksjs/ts-md": "^0.1.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@stacksjs/api": "0.70.
|
|
73
|
-
"@stacksjs/cli": "0.70.
|
|
74
|
-
"@stacksjs/database": "0.70.
|
|
72
|
+
"@stacksjs/api": "0.70.258",
|
|
73
|
+
"@stacksjs/cli": "0.70.258",
|
|
74
|
+
"@stacksjs/database": "0.70.258",
|
|
75
75
|
"@stacksjs/tlsx": "^0.13.2",
|
|
76
76
|
"better-dx": "^0.2.17",
|
|
77
|
-
"@stacksjs/dns": "0.70.
|
|
78
|
-
"@stacksjs/enums": "0.70.
|
|
79
|
-
"@stacksjs/env": "0.70.
|
|
80
|
-
"@stacksjs/error-handling": "0.70.
|
|
81
|
-
"@stacksjs/image": "0.70.
|
|
82
|
-
"@stacksjs/logging": "0.70.
|
|
83
|
-
"@stacksjs/path": "0.70.
|
|
84
|
-
"@stacksjs/security": "0.70.
|
|
85
|
-
"@stacksjs/storage": "0.70.
|
|
86
|
-
"@stacksjs/strings": "0.70.
|
|
87
|
-
"@stacksjs/utils": "0.70.
|
|
88
|
-
"@stacksjs/validation": "0.70.
|
|
77
|
+
"@stacksjs/dns": "0.70.258",
|
|
78
|
+
"@stacksjs/enums": "0.70.258",
|
|
79
|
+
"@stacksjs/env": "0.70.258",
|
|
80
|
+
"@stacksjs/error-handling": "0.70.258",
|
|
81
|
+
"@stacksjs/image": "0.70.258",
|
|
82
|
+
"@stacksjs/logging": "0.70.258",
|
|
83
|
+
"@stacksjs/path": "0.70.258",
|
|
84
|
+
"@stacksjs/security": "0.70.258",
|
|
85
|
+
"@stacksjs/storage": "0.70.258",
|
|
86
|
+
"@stacksjs/strings": "0.70.258",
|
|
87
|
+
"@stacksjs/utils": "0.70.258",
|
|
88
|
+
"@stacksjs/validation": "0.70.258"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"pickier": "^0.1.35"
|