@alxwlw/stack 1.1.1 → 1.2.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.
@@ -10,9 +10,9 @@
10
10
  "dependency-cruiser": "18.1.0",
11
11
  "vitest": "4.1.10",
12
12
  "@playwright/test": "1.62.0",
13
- "@alxwlw/stack": "1.1.1",
14
- "@alxwlw/oxlint-config": "1.1.1",
15
- "@alxwlw/tsconfig": "1.1.1"
13
+ "@alxwlw/stack": "1.2.0",
14
+ "@alxwlw/oxlint-config": "1.2.0",
15
+ "@alxwlw/tsconfig": "1.2.0"
16
16
  },
17
17
  "libs": {
18
18
  "@nestjs/core": "12.0.1",
@@ -78,7 +78,8 @@
78
78
  "src": "files/dependabot.template.yml",
79
79
  "dest": ".github/dependabot.yml",
80
80
  "appliesTo": ["node", "contracts"],
81
- "strategy": "create-if-absent"
81
+ "strategy": "create-if-absent",
82
+ "unlessWith": "renovate"
82
83
  },
83
84
  {
84
85
  "src": "files/oxlintrc.template.json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alxwlw/stack",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,6 +21,7 @@
21
21
  "provenance": true
22
22
  },
23
23
  "dependencies": {
24
+ "json5": "^2.2.3",
24
25
  "jsonc-parser": "^3.3.1",
25
26
  "yaml": "^2.9.1"
26
27
  }
package/schema.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "description": "Opt-in canon groups.",
15
15
  "items": {
16
16
  "type": "string",
17
- "enum": ["moon-tasks", "libs", "knip", "depcruise"]
17
+ "enum": ["moon-tasks", "libs", "knip", "depcruise", "renovate"]
18
18
  }
19
19
  },
20
20
  "exceptions": {
package/src/canon.ts CHANGED
@@ -13,6 +13,8 @@ export interface CanonFile {
13
13
  strategy?: SyncStrategy;
14
14
  /** Группа, включаемая через `with` в .stack.jsonc. Без группы файл обязателен всем. */
15
15
  group?: string;
16
+ /** Группа, при включении которой файл НЕ применяется (альтернатива: renovate вместо dependabot). */
17
+ unlessWith?: string;
16
18
  }
17
19
 
18
20
  export type CanonCatalogs = Record<string, Record<string, string>>;
@@ -24,6 +26,8 @@ export interface Canon {
24
26
  catalogs: CanonCatalogs;
25
27
  nodePin: string;
26
28
  pnpmPin: string;
29
+ /** Бот зависимостей репо. renovate добавляет правило renovate-ignore (конфиг Renovate должен отключать `@alxwlw/*`); dependabot-ignore по-прежнему проверяет .github/dependabot.yml, если файл есть. */
30
+ bot?: 'dependabot' | 'renovate';
27
31
  }
28
32
 
29
33
  export function canonDir(): string {
@@ -39,7 +43,10 @@ export function loadManifest(dir: string = canonDir()): CanonFile[] {
39
43
 
40
44
  export function filesFor(cfg: StackConfig, dir: string = canonDir()): CanonFile[] {
41
45
  return loadManifest(dir).filter(
42
- (f) => f.appliesTo.includes(cfg.profile) && (f.group == null || cfg.with.includes(f.group)),
46
+ (f) =>
47
+ f.appliesTo.includes(cfg.profile) &&
48
+ (f.group == null || cfg.with.includes(f.group)) &&
49
+ (f.unlessWith == null || !cfg.with.includes(f.unlessWith)),
43
50
  );
44
51
  }
45
52
 
@@ -69,5 +76,11 @@ export function loadCanon(cfg: StackConfig, dir: string = canonDir()): Canon {
69
76
  // Пин pnpm нужен правилу package-manager: поле packageManager — второй источник версии pnpm.
70
77
  const pnpm = /^pnpm\s*=\s*"([^"]+)"/m.exec(prototools.content);
71
78
  if (!pnpm?.[1]) throw new Error('canon .prototools has no pnpm pin');
72
- return { files, catalogs, nodePin: pin[1], pnpmPin: pnpm[1] };
79
+ return {
80
+ files,
81
+ catalogs,
82
+ nodePin: pin[1],
83
+ pnpmPin: pnpm[1],
84
+ bot: cfg.with.includes('renovate') ? 'renovate' : 'dependabot',
85
+ };
73
86
  }
package/src/catalogs.ts CHANGED
@@ -48,7 +48,9 @@ export function planCatalogs(repoRoot: string, canon: Canon): Drift[] {
48
48
  // double quotes otherwise, so a freshly-synced workspace fails `oxfmt --check`.
49
49
  // ponytail: doc общий на весь план, файл пишется на каждую запись; один flush в
50
50
  // конце, если ~40 записей первого sync станут заметны.
51
- writeFileSync(path, doc.toString({ singleQuote: true }));
51
+ // lineWidth: 0 — без переноса: по умолчанию yaml режет скаляры длиннее 80 колонок во
52
+ // всём документе, и sync переписал бы строки, к каталогам не относящиеся.
53
+ writeFileSync(path, doc.toString({ singleQuote: true, lineWidth: 0 }));
52
54
  },
53
55
  });
54
56
  }
package/src/check.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import type { Canon } from './canon.ts';
2
2
  import { planCatalogs } from './catalogs.ts';
3
3
  import type { Exception } from './config.ts';
4
- import { checkDependabotIgnore, checkEnginesNode, checkInlineVersions } from './deps.ts';
4
+ import {
5
+ checkDependabotIgnore,
6
+ checkEnginesNode,
7
+ checkInlineVersions,
8
+ checkRenovateIgnore,
9
+ } from './deps.ts';
5
10
  import { planFiles } from './files.ts';
6
11
  import { applyExceptions, covers, type Drift, type Finding } from './findings.ts';
7
12
  import { planPackageManager } from './package-manager.ts';
@@ -44,6 +49,7 @@ export function checkRepo(repoRoot: string, canon: Canon, exceptions: Exception[
44
49
  ...checkInlineVersions(repoRoot, canon),
45
50
  ...checkEnginesNode(repoRoot, canon),
46
51
  ...checkDependabotIgnore(repoRoot),
52
+ ...(canon.bot === 'renovate' ? checkRenovateIgnore(repoRoot) : []),
47
53
  ],
48
54
  exceptions,
49
55
  );
package/src/cli.ts CHANGED
@@ -5,6 +5,7 @@ import { parseArgs } from 'node:util';
5
5
  import { loadCanon } from './canon.ts';
6
6
  import { checkRepo, syncRepo } from './check.ts';
7
7
  import { type Profile, PROFILES, readStackConfig, StackConfigError } from './config.ts';
8
+ import { type Finding, isDrift } from './findings.ts';
8
9
  import { initConfig } from './init.ts';
9
10
 
10
11
  function fail(message: string): never {
@@ -29,6 +30,17 @@ function parseCliArgs() {
29
30
  }
30
31
  }
31
32
 
33
+ // Подсказка под находками: stack sync закрывает только Drift; правила deps.ts — отчёт без действия.
34
+ function fixHint(blocking: Finding[]): string {
35
+ const total = blocking.length;
36
+ const bySync = blocking.filter(isDrift).length;
37
+ if (bySync === total) return `${total} finding(s). Fix with: stack sync`;
38
+ if (bySync === 0) {
39
+ return `${total} finding(s). stack sync does not fix these — fix them by hand (see above)`;
40
+ }
41
+ return `${total} finding(s): ${bySync} fixable with: stack sync, ${total - bySync} to fix by hand (see above)`;
42
+ }
43
+
32
44
  const { values, positionals } = parseCliArgs();
33
45
 
34
46
  const repoRoot = values.repo ?? process.cwd();
@@ -61,7 +73,7 @@ try {
61
73
  }
62
74
  for (const f of blocking) console.error(`${f.code}: ${f.target} — ${f.message}`);
63
75
  if (blocking.length) {
64
- console.error(`\n${blocking.length} finding(s). Fix with: stack sync`);
76
+ console.error(`\n${fixHint(blocking)}`);
65
77
  process.exit(1);
66
78
  }
67
79
  console.log('canon: no drift');
package/src/deps.ts CHANGED
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
 
4
4
  import { Glob } from 'bun';
5
+ import JSON5 from 'json5';
5
6
  import { parse as parseYaml } from 'yaml';
6
7
 
7
8
  import type { Canon } from './canon.ts';
@@ -112,3 +113,71 @@ export function checkDependabotIgnore(repoRoot: string): Finding[] {
112
113
  }
113
114
  return ignoresAlxwlw(doc) ? [] : [finding];
114
115
  }
116
+
117
+ // Имена и порядок поиска — как у самого Renovate (renovate.json{,c,5} для каждого места; первый
118
+ // найденный файл и есть конфиг), без устаревшего package.json#renovate. JSON5.parse читает и JSONC.
119
+ const RENOVATE_CONFIGS = [
120
+ 'renovate.json',
121
+ 'renovate.jsonc',
122
+ 'renovate.json5',
123
+ '.github/renovate.json',
124
+ '.github/renovate.jsonc',
125
+ '.github/renovate.json5',
126
+ '.gitlab/renovate.json',
127
+ '.gitlab/renovate.jsonc',
128
+ '.gitlab/renovate.json5',
129
+ '.renovaterc',
130
+ '.renovaterc.json',
131
+ '.renovaterc.jsonc',
132
+ '.renovaterc.json5',
133
+ ];
134
+ // matchPackageNames — glob'ы: для скоупа одного уровня `@alxwlw/*` и `@alxwlw/**` равносильны.
135
+ const ALXWLW_GLOBS = new Set(['@alxwlw/**', '@alxwlw/*']);
136
+
137
+ function disablesAlxwlw(doc: unknown): boolean {
138
+ const rules = (doc as { packageRules?: unknown } | null)?.packageRules;
139
+ if (!Array.isArray(rules)) return false;
140
+ return rules.some((r) => {
141
+ const rule = r as { enabled?: unknown; matchPackageNames?: unknown } | null;
142
+ return (
143
+ rule?.enabled === false &&
144
+ Array.isArray(rule.matchPackageNames) &&
145
+ rule.matchPackageNames.some((n) => typeof n === 'string' && ALXWLW_GLOBS.has(n))
146
+ );
147
+ });
148
+ }
149
+
150
+ // Группа renovate: версии @alxwlw/* двигает stack sync, бот должен их не трогать — иначе его PR
151
+ // разводят каталог с каноном и check краснеет. Группировка (groupName) не мешает боту — нужен
152
+ // enabled: false.
153
+ export function checkRenovateIgnore(repoRoot: string): Finding[] {
154
+ if (!existsSync(join(repoRoot, 'pnpm-workspace.yaml'))) return [];
155
+ const found = RENOVATE_CONFIGS.find((p) => existsSync(join(repoRoot, p)));
156
+ if (!found) {
157
+ return [
158
+ {
159
+ code: 'renovate-ignore',
160
+ target: 'renovate.json',
161
+ message: `no Renovate config found (${RENOVATE_CONFIGS.join(', ')}) — the renovate group expects one that disables "@alxwlw/*"`,
162
+ },
163
+ ];
164
+ }
165
+ let doc: unknown;
166
+ try {
167
+ doc = JSON5.parse(readFileSync(join(repoRoot, found), 'utf8'));
168
+ } catch {
169
+ return [
170
+ { code: 'unreadable-file', target: found, message: `${found} does not parse as JSON5` },
171
+ ];
172
+ }
173
+ return disablesAlxwlw(doc)
174
+ ? []
175
+ : [
176
+ {
177
+ code: 'renovate-ignore',
178
+ target: found,
179
+ message:
180
+ 'no packageRules entry with matchPackageNames "@alxwlw/**" and enabled: false — the bot will fight the canon rollout',
181
+ },
182
+ ];
183
+ }
package/src/findings.ts CHANGED
@@ -9,6 +9,7 @@ export type FindingCode =
9
9
  | 'engines-node'
10
10
  | 'package-manager'
11
11
  | 'dependabot-ignore'
12
+ | 'renovate-ignore'
12
13
  | 'unreadable-file'
13
14
  | 'stale-exception';
14
15
 
@@ -29,6 +30,11 @@ export interface Drift extends Finding {
29
30
  apply(): void;
30
31
  }
31
32
 
33
+ // Drift — находка, которую закрывает `stack sync` (у неё есть apply); остальное правят руками.
34
+ export function isDrift(f: Finding): f is Drift {
35
+ return typeof (f as Partial<Drift>).apply === 'function';
36
+ }
37
+
32
38
  export function covers(e: Exception, f: Finding): boolean {
33
39
  const a = f.address;
34
40
  if (!a) return false;