@se-studio/site-check 2.9.11 → 2.10.1

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a01b598]
8
+ - @se-studio/core-data-types@1.7.0
9
+ - @se-studio/contentful-rest-api@1.17.0
10
+
11
+ ## 2.10.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Add `check-no-context-workarounds` CLI that fails CI when webpack aliases, pnpm overrides, or public-hoist hacks are used for @se-studio/core-ui dual-install workarounds. Escape hatch: ALLOW_CONTEXT_WORKAROUNDS=1 (feature branches only).
16
+
3
17
  ## 2.9.11
4
18
 
5
19
  ### Patch Changes
@@ -0,0 +1,235 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fail CI/validate if a repo uses dodgy dual-package workarounds for React
4
+ * context libraries (especially @se-studio/core-ui).
5
+ *
6
+ * Allowed on feature branches only via ALLOW_CONTEXT_WORKAROUNDS=1.
7
+ * Never allowed on develop / production integration branches.
8
+ *
9
+ * Usage (repo root):
10
+ * check-no-context-workarounds
11
+ * node node_modules/@se-studio/site-check/check-no-context-workarounds.mjs
12
+ *
13
+ * Proper monorepo pattern (allowed):
14
+ * - peerDependencies for @se-studio/core-ui (etc.) on shared packages
15
+ * - dependenciesMeta.injected on the app → shared package
16
+ * - @se-studio/core-ui singleton (package itself)
17
+ */
18
+
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+
22
+ const root = process.cwd();
23
+
24
+ /** Packages that must never be force-aliased / override-pinned for dual-instance hacks. */
25
+ const CONTEXT_PACKAGES = ['@se-studio/core-ui', '@se-studio/ab-testing'];
26
+
27
+ const findings = [];
28
+
29
+ function rel(filePath) {
30
+ return path.relative(root, filePath) || filePath;
31
+ }
32
+
33
+ function addFinding(file, rule, detail) {
34
+ findings.push({ file: rel(file), rule, detail });
35
+ }
36
+
37
+ function walkFiles(dir, predicate, out = []) {
38
+ if (!fs.existsSync(dir)) return out;
39
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
40
+ if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === '.next') {
41
+ continue;
42
+ }
43
+ const full = path.join(dir, entry.name);
44
+ if (entry.isDirectory()) {
45
+ walkFiles(full, predicate, out);
46
+ } else if (entry.isFile() && predicate(full)) {
47
+ out.push(full);
48
+ }
49
+ }
50
+ return out;
51
+ }
52
+
53
+ function read(filePath) {
54
+ return fs.readFileSync(filePath, 'utf8');
55
+ }
56
+
57
+ function scanNextConfigs() {
58
+ const files = walkFiles(root, (f) => /next\.config\.(js|mjs|cjs|ts|mts|cts)$/.test(f));
59
+ for (const file of files) {
60
+ const content = read(file);
61
+ for (const pkg of CONTEXT_PACKAGES) {
62
+ // webpack resolve.alias targeting the package (including $ exact and subpaths)
63
+ const aliasPatterns = [
64
+ new RegExp(`['"\`]${escapeRegExp(pkg)}(?:\\$|/)[^'"\`]*['"\`]\\s*:`),
65
+ new RegExp(`['"\`]${escapeRegExp(pkg)}['"\`]\\s*:`),
66
+ new RegExp(`alias[^\\n]*${escapeRegExp(pkg)}`),
67
+ new RegExp(`resolve\\.alias[^}]*${escapeRegExp(pkg)}`, 's'),
68
+ ];
69
+ for (const re of aliasPatterns) {
70
+ if (re.test(content) && content.includes('alias')) {
71
+ addFinding(
72
+ file,
73
+ 'webpack-alias',
74
+ `webpack/resolve alias for ${pkg} is banned on integration branches. ` +
75
+ 'Use peerDependencies + dependenciesMeta.injected on the shared package instead.',
76
+ );
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ function scanYamlOverrides(file, content) {
85
+ const lines = content.split('\n');
86
+ let inOverrides = false;
87
+ for (const line of lines) {
88
+ if (/^overrides:\s*$/.test(line.trimEnd()) || /^overrides:\s*$/.test(line)) {
89
+ inOverrides = true;
90
+ continue;
91
+ }
92
+ if (inOverrides) {
93
+ // Top-level key ends the overrides block (no leading whitespace)
94
+ if (line.length > 0 && !/^[ \t]/.test(line) && !line.trimStart().startsWith('#')) {
95
+ inOverrides = false;
96
+ }
97
+ }
98
+ if (!inOverrides) continue;
99
+ for (const pkg of CONTEXT_PACKAGES) {
100
+ if (line.includes(pkg)) {
101
+ addFinding(
102
+ file,
103
+ 'pnpm-override',
104
+ `pnpm override for ${pkg} is banned. Use peerDependencies + dependenciesMeta.injected, not overrides.`,
105
+ );
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ function scanPnpmWorkspaceAndPackageJson() {
112
+ const candidates = [
113
+ path.join(root, 'pnpm-workspace.yaml'),
114
+ path.join(root, 'package.json'),
115
+ ...walkFiles(
116
+ root,
117
+ (f) => f.endsWith('package.json') && !f.includes(`${path.sep}node_modules${path.sep}`),
118
+ ),
119
+ ];
120
+ const seen = new Set();
121
+ for (const file of candidates) {
122
+ if (!fs.existsSync(file) || seen.has(file)) continue;
123
+ seen.add(file);
124
+ const content = read(file);
125
+
126
+ if (file.endsWith('.yaml') || file.endsWith('.yml')) {
127
+ scanYamlOverrides(file, content);
128
+ continue;
129
+ }
130
+
131
+ if (file.endsWith('package.json')) {
132
+ try {
133
+ const json = JSON.parse(content);
134
+ const overrides = json.pnpm?.overrides ?? json.overrides;
135
+ if (overrides && typeof overrides === 'object') {
136
+ for (const pkg of CONTEXT_PACKAGES) {
137
+ if (pkg in overrides) {
138
+ addFinding(
139
+ file,
140
+ 'pnpm-override',
141
+ `package.json overrides for ${pkg} is banned (${overrides[pkg]}).`,
142
+ );
143
+ }
144
+ }
145
+ }
146
+ } catch {
147
+ // ignore invalid json
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ function scanNpmrc() {
154
+ const file = path.join(root, '.npmrc');
155
+ if (!fs.existsSync(file)) return;
156
+ const content = read(file);
157
+ const lines = content.split('\n');
158
+ for (const line of lines) {
159
+ const trimmed = line.trim();
160
+ if (!trimmed || trimmed.startsWith('#')) continue;
161
+ if (trimmed.startsWith('public-hoist-pattern')) {
162
+ for (const pkg of CONTEXT_PACKAGES) {
163
+ const short = pkg.replace('@se-studio/', '');
164
+ if (trimmed.includes(pkg) || trimmed.includes(short) || trimmed.includes('core-ui')) {
165
+ addFinding(
166
+ file,
167
+ 'public-hoist',
168
+ `public-hoist-pattern for context packages is banned (${trimmed}). Prefer peerDependencies + injected shared packages.`,
169
+ );
170
+ }
171
+ }
172
+ }
173
+ // Broad hoist of all react is also a smell when used to fix dual core-ui
174
+ if (
175
+ trimmed.startsWith('public-hoist-pattern') &&
176
+ (trimmed.includes('*react*') || trimmed.includes('react-dom'))
177
+ ) {
178
+ addFinding(
179
+ file,
180
+ 'public-hoist',
181
+ `public-hoist-pattern for react is banned as a dual-package workaround (${trimmed}).`,
182
+ );
183
+ }
184
+ }
185
+ }
186
+
187
+ function escapeRegExp(value) {
188
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
189
+ }
190
+
191
+ function main() {
192
+ if (
193
+ (process.env.ALLOW_CONTEXT_WORKAROUNDS ?? '').toLowerCase() === '1' ||
194
+ (process.env.ALLOW_CONTEXT_WORKAROUNDS ?? '').toLowerCase() === 'true'
195
+ ) {
196
+ console.warn(
197
+ 'check-no-context-workarounds: SKIPPED (ALLOW_CONTEXT_WORKAROUNDS is set). ' +
198
+ 'Do not merge this to develop/main without removing the workarounds.',
199
+ );
200
+ process.exit(0);
201
+ }
202
+
203
+ scanNextConfigs();
204
+ scanPnpmWorkspaceAndPackageJson();
205
+ scanNpmrc();
206
+
207
+ if (findings.length === 0) {
208
+ console.log('check-no-context-workarounds: ok');
209
+ process.exit(0);
210
+ }
211
+
212
+ console.error('check-no-context-workarounds: FAILED');
213
+ console.error('');
214
+ console.error(
215
+ 'Banned dual-package workarounds for React context libraries (@se-studio/core-ui, etc.).',
216
+ );
217
+ console.error('These must never land on develop or production.');
218
+ console.error('');
219
+ for (const f of findings) {
220
+ console.error(` [${f.rule}] ${f.file}`);
221
+ console.error(` ${f.detail}`);
222
+ }
223
+ console.error('');
224
+ console.error('Allowed:');
225
+ console.error(' - peerDependencies on shared packages for @se-studio/core-ui (etc.)');
226
+ console.error(' - dependenciesMeta.<shared-pkg>.injected: true on apps');
227
+ console.error(' - @se-studio/core-ui singleton (package release)');
228
+ console.error('');
229
+ console.error(
230
+ 'Feature-branch escape hatch only: ALLOW_CONTEXT_WORKAROUNDS=1 (never on develop/main).',
231
+ );
232
+ process.exit(1);
233
+ }
234
+
235
+ main();
package/docs/llms.md CHANGED
@@ -104,7 +104,23 @@ import { runArticleLinkIntegrityFromSmokeConfig } from '@se-studio/site-check/cm
104
104
 
105
105
  ### Analytics context bundle check
106
106
 
107
- After a production build (or when `.next` already exists for `smoke-test:deploy-check`), `smoke-test-one` scans `.next/static/chunks` for multiple webpack modules that define `AnalyticsProvider` + React context. **More than one module fails the smoke run** — usually duplicate `@se-studio/core-ui` from pnpm peer isolation in monorepos (provider in a workspace package, consumers in the app). Fix with a single physical install (pnpm override / shared resolution), not by disabling the check.
107
+ After a production build (or when `.next` already exists for `smoke-test:deploy-check`), `smoke-test-one` scans `.next/static/chunks` for multiple webpack modules that define `AnalyticsProvider` + React context. **More than one module fails the smoke run** — usually duplicate `@se-studio/core-ui` from pnpm peer isolation in monorepos (provider in a workspace package, consumers in the app).
108
+
109
+ **Proper fix (allowed):** shared package `peerDependencies` for `@se-studio/core-ui` + app `dependenciesMeta.<shared>.injected: true`.
110
+ **Banned on develop/main:** webpack `resolve.alias` for `@se-studio/core-ui`, pnpm `overrides` for it, `public-hoist-pattern` hacks — run `check-no-context-workarounds`.
111
+
112
+ ### check-no-context-workarounds
113
+
114
+ ```bash
115
+ # repo root — wire into root "validate" / CI on develop
116
+ pnpm exec check-no-context-workarounds
117
+ ```
118
+
119
+ | Env | Purpose |
120
+ |-----|---------|
121
+ | `ALLOW_CONTEXT_WORKAROUNDS=1` | Feature-branch only escape hatch — **never** set on develop/main |
122
+
123
+ Fails on: Next webpack aliases for `@se-studio/core-ui` / `@se-studio/ab-testing`, pnpm overrides for those packages, `.npmrc` public-hoist-pattern workarounds.
108
124
 
109
125
  ## Vercel build cache (not smoke)
110
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/site-check",
3
- "version": "2.9.11",
3
+ "version": "2.10.1",
4
4
  "description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,7 +49,8 @@
49
49
  "validate-build-routes": "./validate-build-routes.mjs",
50
50
  "revalidation-matrix-test": "./revalidation-matrix-test.mjs",
51
51
  "develop-sites-timing": "./develop-sites-timing.mjs",
52
- "markdown-accuracy-audit": "./markdown-accuracy-audit.mjs"
52
+ "markdown-accuracy-audit": "./markdown-accuracy-audit.mjs",
53
+ "check-no-context-workarounds": "./check-no-context-workarounds.mjs"
53
54
  },
54
55
  "files": [
55
56
  "dist",
@@ -63,7 +64,8 @@
63
64
  "validate-build-routes.mjs",
64
65
  "revalidation-matrix-test.mjs",
65
66
  "develop-sites-timing.mjs",
66
- "markdown-accuracy-audit.mjs"
67
+ "markdown-accuracy-audit.mjs",
68
+ "check-no-context-workarounds.mjs"
67
69
  ],
68
70
  "keywords": [
69
71
  "sitemap",
@@ -81,8 +83,8 @@
81
83
  "url": "https://github.com/Something-Else-Studio/se-core-product/issues"
82
84
  },
83
85
  "dependencies": {
84
- "@se-studio/core-data-types": "1.6.1",
85
- "@se-studio/contentful-rest-api": "1.16.5"
86
+ "@se-studio/contentful-rest-api": "1.17.0",
87
+ "@se-studio/core-data-types": "1.7.0"
86
88
  },
87
89
  "devDependencies": {
88
90
  "@biomejs/biome": "^2.5.5",
@@ -95,6 +97,6 @@
95
97
  "type-check": "tsc --noEmit",
96
98
  "lint": "biome lint .",
97
99
  "clean": "rm -rf dist .turbo *.tsbuildinfo",
98
- "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/analytics-context-bundle.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs"
100
+ "test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs"
99
101
  }
100
102
  }