@se-studio/site-check 2.25.6 → 2.25.13

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 CHANGED
@@ -1,5 +1,54 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.25.13
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [b8ecf76]
8
+ - @se-studio/core-ui@1.56.0
9
+
10
+ ## 2.25.12
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [d9463b7]
15
+ - @se-studio/core-ui@1.55.0
16
+
17
+ ## 2.25.11
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [8e93a52]
22
+ - @se-studio/core-ui@1.54.0
23
+
24
+ ## 2.25.10
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [3f48438]
29
+ - @se-studio/core-ui@1.53.0
30
+
31
+ ## 2.25.9
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [4744235]
36
+ - @se-studio/core-ui@1.52.0
37
+
38
+ ## 2.25.8
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies [c749645]
43
+ - @se-studio/core-ui@1.51.0
44
+ - @se-studio/contentful-rest-api@2.10.0
45
+
46
+ ## 2.25.7
47
+
48
+ ### Patch Changes
49
+
50
+ - 75ab028: Add `check-proxy-preview`: fails a site that hand-writes the proxy trailing-slash / CMS-redirect logic instead of importing it from `@se-studio/core-ui/proxy`, or a `/preview` page that does not use `createPreviewPage`. Per-file allowances live in `proxy-preview.config.json` and need a reason.
51
+
3
52
  ## 2.25.6
4
53
 
5
54
  ### Patch Changes
package/README.md CHANGED
@@ -432,6 +432,35 @@ Allowed: `biome-ignore`, `@ts-expect-error`, `@ts-ignore`; `se-exception: <reaso
432
432
 
433
433
  `--diff` needs the base ref. Locally a missing base prints a warning and skips; with `CI` set it fails, so check out with `fetch-depth: 0` (or `git fetch origin develop`).
434
434
 
435
+ ## Proxy and preview guard (`check-proxy-preview`)
436
+
437
+ Fails when a site hand-writes what `@se-studio/core-ui` already provides.
438
+
439
+ ```bash
440
+ pnpm exec check-proxy-preview # script: "check:proxy-preview": "check-proxy-preview"
441
+ ```
442
+
443
+ - `proxy-own-redirect-logic`: a proxy or middleware file (`src/proxy.ts`, `src/middleware.ts`, `proxy.ts`, `middleware.ts`, `packages/*/src/middleware/**`) defines `pagePathNeedingTrailingSlashRedirect`, `applyCmsRedirects`, `lookupRedirectRule` or `redirectDestination`, or has an inline trailing-slash 308 (`lastSegment.includes('.')`). Import `applyTrailingSlashRedirect` and `applyCmsRedirects` from `@se-studio/core-ui/proxy`.
444
+ - `preview-not-create-preview-page`: a `src/app/**/preview/page.tsx` that does not import and call `createPreviewPage` from `@se-studio/core-ui/server`.
445
+
446
+ Site-local steps under other names (Eagle's `legacyRedirectForPath`) pass. A deliberate exception needs a reason, either `// se-exception: <reason>` on or above the line (anywhere in a preview page), or an entry in `proxy-preview.config.json` at the app root:
447
+
448
+ ```json
449
+ {
450
+ "files": ["src/lib/pointMeEdge.ts"],
451
+ "allow": [
452
+ {
453
+ "file": "src/lib/pointMeEdge.ts",
454
+ "rule": "proxy-own-redirect-logic",
455
+ "names": ["lookupRedirectRule"],
456
+ "reason": "PointMe exact-match CMS lookup"
457
+ }
458
+ ]
459
+ }
460
+ ```
461
+
462
+ `files` adds extra files to scan; `rule` and `names` narrow an allowance (omitted means everything in that file). An allowance without a reason fails. Not part of customer CI until a site opts in.
463
+
435
464
  ## Class string gaps (`check-class-gaps`)
436
465
 
437
466
  Fails when a class token in a class-string template literal runs straight into a `${` or a `}` runs straight into a class token with no space between. The separating space then lives (or not) inside the expression, and an edit to the expression glues two classes into one.
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
3
+ import { join, relative, sep } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ /**
7
+ * Guard: proxy redirect logic and /preview pages come from @se-studio/core-ui, not from
8
+ * a hand-written copy in the site.
9
+ *
10
+ * Rule `proxy-own-redirect-logic`: src/proxy.ts, src/middleware.ts, proxy.ts, middleware.ts,
11
+ * packages/*\/src/middleware/**, and any file in config `files`, must not define
12
+ * `pagePathNeedingTrailingSlashRedirect`, `applyCmsRedirects`, `lookupRedirectRule` or
13
+ * `redirectDestination`, nor carry an inline trailing-slash 308 (a `.includes('.')` test
14
+ * on a path segment in a file that issues a 308). Import `applyTrailingSlashRedirect` and
15
+ * `applyCmsRedirects` from `@se-studio/core-ui/proxy` instead. Site-local steps with other
16
+ * names (a legacy redirect map, a pre-lookup) are fine.
17
+ *
18
+ * Rule `preview-not-create-preview-page`: every src/app/**\/preview/page.tsx must import and
19
+ * call `createPreviewPage` from `@se-studio/core-ui/server`. A render-callback preview that
20
+ * still calls `createPreviewPage` passes.
21
+ *
22
+ * Escapes (a reason is required):
23
+ * - a line comment `se-exception: <reason>` on the offending line (or the line above);
24
+ * for the preview rule, anywhere in the page file
25
+ * - `proxy-preview.config.json` at the app root:
26
+ * { "files": ["src/lib/edge.ts"],
27
+ * "allow": [{ "file": "src/proxy.ts", "rule": "proxy-own-redirect-logic",
28
+ * "names": ["lookupRedirectRule"], "reason": "exact-match CMS lookup" }] }
29
+ * `rule` is optional (omitted = both rules); `names` limits a proxy allowance to those
30
+ * identifiers (omitted = all of them).
31
+ *
32
+ * Filesystem only. Run from the app root: pnpm exec check-proxy-preview
33
+ */
34
+
35
+ export const RULE_PROXY = 'proxy-own-redirect-logic';
36
+ export const RULE_PREVIEW = 'preview-not-create-preview-page';
37
+ export const CONFIG_NAME = 'proxy-preview.config.json';
38
+
39
+ export const FORBIDDEN_NAMES = [
40
+ 'pagePathNeedingTrailingSlashRedirect',
41
+ 'applyCmsRedirects',
42
+ 'lookupRedirectRule',
43
+ 'redirectDestination',
44
+ ];
45
+
46
+ const PROXY_FILES = ['src/proxy.ts', 'src/middleware.ts', 'proxy.ts', 'middleware.ts'];
47
+ const SOURCE_FILE = /\.(?:ts|tsx|mts|js|mjs)$/;
48
+ const EXCEPTION = /se-exception:\s*\S/;
49
+ const MIN_REASON = 8;
50
+
51
+ const definition = (name) =>
52
+ new RegExp(
53
+ `(?:\\b(?:function\\*?|const|let|var|class)\\s+${name}\\b|\\b(?:export\\s+)?(?:async\\s+)?${name}\\s*[:=]\\s*(?:async\\s*)?(?:function\\b|\\([^)]*\\)\\s*(?::[^=]+)?=>))`,
54
+ );
55
+
56
+ const SEGMENT_DOT = /\b\w*[sS]egment\w*\s*\.\s*includes\(\s*(['"`])\.\1\s*\)/;
57
+ const STATUS_308 = /\b308\b/;
58
+
59
+ function stripComments(line) {
60
+ return line.replace(/^\s*(?:\/\/.*|\*.*|\/\*.*)$/, '');
61
+ }
62
+
63
+ function toPosix(p) {
64
+ return p.split(sep).join('/');
65
+ }
66
+
67
+ function lineAllowed(lines, index) {
68
+ return EXCEPTION.test(lines[index]) || (index > 0 && EXCEPTION.test(lines[index - 1]));
69
+ }
70
+
71
+ /** Violations in one proxy/middleware source. */
72
+ export function checkProxySource(file, source) {
73
+ const lines = source.split('\n');
74
+ const out = [];
75
+ lines.forEach((raw, i) => {
76
+ const line = stripComments(raw);
77
+ if (!line.trim() || lineAllowed(lines, i)) return;
78
+ for (const name of FORBIDDEN_NAMES) {
79
+ if (definition(name).test(line)) {
80
+ out.push({
81
+ file,
82
+ line: i + 1,
83
+ rule: RULE_PROXY,
84
+ name,
85
+ message: `defines its own \`${name}\`; import applyTrailingSlashRedirect / applyCmsRedirects from '@se-studio/core-ui/proxy' instead`,
86
+ });
87
+ }
88
+ }
89
+ });
90
+ if (STATUS_308.test(lines.map(stripComments).join('\n'))) {
91
+ lines.forEach((raw, i) => {
92
+ if (lineAllowed(lines, i)) return;
93
+ if (SEGMENT_DOT.test(stripComments(raw))) {
94
+ out.push({
95
+ file,
96
+ line: i + 1,
97
+ rule: RULE_PROXY,
98
+ name: 'inline-trailing-slash-308',
99
+ message:
100
+ "inline trailing-slash 308 (segment `.includes('.')` test); use applyTrailingSlashRedirect from '@se-studio/core-ui/proxy' instead",
101
+ });
102
+ }
103
+ });
104
+ }
105
+ return out;
106
+ }
107
+
108
+ /** Violations in one preview page source. */
109
+ export function checkPreviewSource(file, source) {
110
+ if (EXCEPTION.test(source)) return [];
111
+ const imported =
112
+ /import\s*\{[^}]*\bcreatePreviewPage\b[^}]*\}\s*from\s*['"]@se-studio\/core-ui\/server['"]/.test(
113
+ source,
114
+ );
115
+ const called = /\bcreatePreviewPage\s*\(/.test(source);
116
+ if (imported && called) return [];
117
+ return [
118
+ {
119
+ file,
120
+ line: 1,
121
+ rule: RULE_PREVIEW,
122
+ name: 'createPreviewPage',
123
+ message:
124
+ "hand-written /preview page; build it with createPreviewPage from '@se-studio/core-ui/server' (pass mode: 'render' for a custom shell)",
125
+ },
126
+ ];
127
+ }
128
+
129
+ function walk(dir, visit) {
130
+ if (!existsSync(dir)) return;
131
+ for (const entry of readdirSync(dir)) {
132
+ if (entry === 'node_modules' || entry === '.next' || entry === 'generated') continue;
133
+ const full = join(dir, entry);
134
+ const info = statSync(full);
135
+ if (info.isDirectory()) walk(full, visit);
136
+ else visit(full);
137
+ }
138
+ }
139
+
140
+ export function readConfig(root) {
141
+ const path = join(root, CONFIG_NAME);
142
+ if (!existsSync(path)) return { files: [], allow: [], errors: [] };
143
+ const errors = [];
144
+ let raw;
145
+ try {
146
+ raw = JSON.parse(readFileSync(path, 'utf8'));
147
+ } catch (e) {
148
+ return { files: [], allow: [], errors: [`${CONFIG_NAME}: invalid JSON (${e.message})`] };
149
+ }
150
+ const files = Array.isArray(raw.files) ? raw.files.filter((f) => typeof f === 'string') : [];
151
+ const allow = [];
152
+ for (const [i, a] of (Array.isArray(raw.allow) ? raw.allow : []).entries()) {
153
+ if (!a || typeof a.file !== 'string') {
154
+ errors.push(`${CONFIG_NAME}: allow[${i}] needs a "file"`);
155
+ continue;
156
+ }
157
+ if (typeof a.reason !== 'string' || a.reason.trim().length < MIN_REASON) {
158
+ errors.push(
159
+ `${CONFIG_NAME}: allow[${i}] (${a.file}) needs a "reason" of at least ${MIN_REASON} characters`,
160
+ );
161
+ continue;
162
+ }
163
+ if (a.rule !== undefined && a.rule !== RULE_PROXY && a.rule !== RULE_PREVIEW) {
164
+ errors.push(`${CONFIG_NAME}: allow[${i}] has unknown rule "${a.rule}"`);
165
+ continue;
166
+ }
167
+ allow.push({
168
+ file: a.file.replace(/^\.\//, ''),
169
+ rule: a.rule,
170
+ names: Array.isArray(a.names) ? a.names : undefined,
171
+ });
172
+ }
173
+ return { files, allow, errors };
174
+ }
175
+
176
+ function isAllowed(v, allow) {
177
+ return allow.some(
178
+ (a) =>
179
+ a.file === v.file &&
180
+ (a.rule === undefined || a.rule === v.rule) &&
181
+ (a.names === undefined || v.rule !== RULE_PROXY || a.names.includes(v.name)),
182
+ );
183
+ }
184
+
185
+ /** Run both rules against an app root. Returns { violations, errors }. */
186
+ export function checkRoot(root) {
187
+ const config = readConfig(root);
188
+ const violations = [];
189
+
190
+ const proxyFiles = new Set(PROXY_FILES.filter((f) => existsSync(join(root, f))));
191
+ for (const f of config.files)
192
+ if (existsSync(join(root, f))) proxyFiles.add(f.replace(/^\.\//, ''));
193
+ walk(join(root, 'packages'), (full) => {
194
+ const rel = toPosix(relative(root, full));
195
+ if (/^packages\/[^/]+\/src\/middleware\//.test(rel) && SOURCE_FILE.test(rel))
196
+ proxyFiles.add(rel);
197
+ });
198
+ for (const file of proxyFiles) {
199
+ violations.push(...checkProxySource(file, readFileSync(join(root, file), 'utf8')));
200
+ }
201
+
202
+ walk(join(root, 'src', 'app'), (full) => {
203
+ const rel = toPosix(relative(root, full));
204
+ if (/(?:^|\/)preview\/page\.(?:tsx|jsx|ts|js)$/.test(rel)) {
205
+ violations.push(...checkPreviewSource(rel, readFileSync(full, 'utf8')));
206
+ }
207
+ });
208
+
209
+ return {
210
+ violations: violations.filter((v) => !isAllowed(v, config.allow)),
211
+ errors: config.errors,
212
+ };
213
+ }
214
+
215
+ function main() {
216
+ const root = process.cwd();
217
+ const { violations, errors } = checkRoot(root);
218
+ for (const e of errors) console.error(`check-proxy-preview: ${e}`);
219
+ for (const v of violations) {
220
+ console.error(`${v.file}:${v.line} [${v.rule}] ${v.message}`);
221
+ }
222
+ if (violations.length || errors.length) {
223
+ console.error(
224
+ `\ncheck-proxy-preview: ${violations.length} violation(s). Allow a deliberate site-local exception with a reason in ${CONFIG_NAME} or a \`se-exception: <reason>\` comment.`,
225
+ );
226
+ process.exit(1);
227
+ }
228
+ console.log('check-proxy-preview: ok');
229
+ }
230
+
231
+ const invoked = process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
232
+ if (invoked) main();
package/docs/llms.md CHANGED
@@ -139,6 +139,15 @@ Bin: `check-comments`. Run from the app root: `pnpm exec check-comments` (whole
139
139
 
140
140
  Allowed: `biome-ignore`, `@ts-expect-error`, `@ts-ignore`, `se-exception: <reason>`, `why-external: <system and constraint>`, licence headers (`@license`, `Copyright`, `SPDX-License`, `@generated`), a comment with an http(s) link, `/// <reference`, and a `/**` doc block directly above an `export`. Everything else is a violation. A missing `--diff` base fails in CI (`fetch-depth: 0` needed) and is skipped locally.
141
141
 
142
+ ### check-proxy-preview
143
+
144
+ Bin: `check-proxy-preview`. Run from the app root: `pnpm exec check-proxy-preview` (script `check:proxy-preview`; `apps/example-empty` wires it into `validate`). Filesystem only. **Customer sites do not run this in CI until they opt in.**
145
+
146
+ - `proxy-own-redirect-logic`: `src/proxy.ts`, `src/middleware.ts`, `proxy.ts`, `middleware.ts`, `packages/*/src/middleware/**` (and `files` in the config) must not define `pagePathNeedingTrailingSlashRedirect`, `applyCmsRedirects`, `lookupRedirectRule` or `redirectDestination`, or carry an inline trailing-slash 308 (`lastSegment.includes('.')`). Import `applyTrailingSlashRedirect` / `applyCmsRedirects` from `@se-studio/core-ui/proxy`. Site-local steps with other names (Eagle `legacyRedirectForPath`) pass.
147
+ - `preview-not-create-preview-page`: every `src/app/**/preview/page.tsx` must import and call `createPreviewPage` from `@se-studio/core-ui/server` (render-callback previews that still call it pass).
148
+
149
+ Escapes need a reason: `// se-exception: <reason>` on or above the line (anywhere in the file for a preview page), or `proxy-preview.config.json` with `allow: [{ "file", "rule"?, "names"?, "reason" }]` and `files: [...]` for extra files to scan. Example for PointMe: `{ "files": ["src/lib/pointMeEdge.ts"], "allow": [{ "file": "src/lib/pointMeEdge.ts", "rule": "proxy-own-redirect-logic", "names": ["lookupRedirectRule"], "reason": "exact-match CMS lookup" }] }`.
150
+
142
151
  ### check-no-context-workarounds
143
152
 
144
153
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/site-check",
3
- "version": "2.25.6",
3
+ "version": "2.25.13",
4
4
  "description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,6 +67,7 @@
67
67
  "check-publish-state": "./check-publish-state.mjs",
68
68
  "check-cms-driven": "./check-cms-driven.mjs",
69
69
  "check-comments": "./check-comments.mjs",
70
+ "check-proxy-preview": "./check-proxy-preview.mjs",
70
71
  "check-class-gaps": "./check-class-gaps.mjs",
71
72
  "site-type-audit": "./dist/site-type-audit/cli.js"
72
73
  },
@@ -90,6 +91,7 @@
90
91
  "check-publish-state.mjs",
91
92
  "check-cms-driven.mjs",
92
93
  "check-comments.mjs",
94
+ "check-proxy-preview.mjs",
93
95
  "check-class-gaps.mjs",
94
96
  "cms-driven-baseline.mjs",
95
97
  "screaming-frog"
@@ -110,9 +112,9 @@
110
112
  "url": "https://github.com/Something-Else-Studio/se-core-product/issues"
111
113
  },
112
114
  "dependencies": {
113
- "@se-studio/contentful-rest-api": "2.9.5",
115
+ "@se-studio/contentful-rest-api": "2.10.0",
114
116
  "@se-studio/core-data-types": "2.3.0",
115
- "@se-studio/core-ui": "1.50.0"
117
+ "@se-studio/core-ui": "1.56.0"
116
118
  },
117
119
  "devDependencies": {
118
120
  "@biomejs/biome": "^2.6.8",
@@ -125,6 +127,6 @@
125
127
  "type-check": "tsc --noEmit",
126
128
  "lint": "biome lint .",
127
129
  "clean": "rm -rf dist .turbo *.tsbuildinfo",
128
- "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/screaming-frog-config.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/smoke-coverage.test.mjs scripts/smoke-followups.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/check-cms-driven.test.mjs scripts/check-comments.test.mjs scripts/check-class-gaps.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs scripts/site-type-audit.test.mjs scripts/develop-published-gate.test.mjs scripts/fetch-timeout.test.mjs scripts/xml-entities.test.mjs scripts/compare-bypass.test.mjs"
130
+ "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/screaming-frog-config.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/smoke-coverage.test.mjs scripts/smoke-followups.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/check-cms-driven.test.mjs scripts/check-comments.test.mjs scripts/check-proxy-preview.test.mjs scripts/check-class-gaps.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs scripts/site-type-audit.test.mjs scripts/develop-published-gate.test.mjs scripts/fetch-timeout.test.mjs scripts/xml-entities.test.mjs scripts/compare-bypass.test.mjs"
129
131
  }
130
132
  }