@7n/rules 1.19.0 → 1.19.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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.19.1] - 2026-07-18
4
+
5
+ ### Changed
6
+
7
+ - експортовано `parseNRulesCmd` і `relevantDomains` з `scripts/lib/lint-surface/ci-plan.mjs` — спільні хелпери для fix-хендлерів автоміграції service-канону (ci-azure, ci-github), усунуто jscpd-дублікат
8
+
3
9
  ## [1.19.0] - 2026-07-18
4
10
 
5
11
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7n/rules",
3
- "version": "1.19.0",
3
+ "version": "1.19.1",
4
4
  "description": "CLI еталонних правил і skills (префікс n-): синк у репозиторій, дельта-lint, конформність",
5
5
  "keywords": [
6
6
  "cli",
@@ -14,7 +14,8 @@
14
14
  * `--base`-ref) — warning і ВСІ домени true (запускаємо більше, ніколи не
15
15
  * скіпаємо мовчки).
16
16
  */
17
- import { appendFileSync } from 'node:fs'
17
+ import { appendFileSync, existsSync, statSync } from 'node:fs'
18
+ import { resolve } from 'node:path'
18
19
  import { env } from 'node:process'
19
20
 
20
21
  import picomatch from 'picomatch'
@@ -29,6 +30,59 @@ const TEST_FILE_GLOBS = ['**/*.test.*', '**/*.spec.*', '**/test_*.py', '**/*_tes
29
30
  /** Зарезервовані ключі outputs — домен із таким ключем був би колізією. */
30
31
  const RESERVED_OUTPUT_KEYS = new Set(['any', 'has_tests', 'domains'])
31
32
 
33
+ const WS_RE = /\s+/u
34
+
35
+ /**
36
+ * Розбирає команду `n-rules lint …`/`n-rules ci plan …` токенами (без regex —
37
+ * стійко до багаторядкових script-ів і без бектрекінгу). Спільне для
38
+ * fix-хендлерів автоміграції service-канону (ci-azure, ci-github).
39
+ * @param {string} cmd повний текст команди кроку.
40
+ * @param {string} marker підрядок-початок (`n-rules lint` | `n-rules ci plan`).
41
+ * @returns {{ domain: string|null, path: string|null }|null} розбір або null, якщо маркера немає.
42
+ */
43
+ export function parseNRulesCmd(cmd, marker) {
44
+ const at = cmd.indexOf(marker)
45
+ if (at === -1) return null
46
+ const tokens = cmd
47
+ .slice(at + marker.length)
48
+ .split(WS_RE)
49
+ .filter(Boolean)
50
+ let domain = null
51
+ let path = null
52
+ for (let i = 0; i < tokens.length; i++) {
53
+ const t = tokens[i]
54
+ if (t === '--path') {
55
+ path = tokens[i + 1] ?? null
56
+ i++
57
+ continue
58
+ }
59
+ if (!t.startsWith('-') && domain === null && path === null) domain = t
60
+ }
61
+ return { domain, path }
62
+ }
63
+
64
+ /**
65
+ * Релевантні домени сервісу: enabled-правила, чиї per-file glob-и матчать
66
+ * бодай один файл піддерева (та сама таблиця, що `ci plan` по не-дельті).
67
+ * Спільне для fix-хендлерів автоміграції service-канону (ci-azure, ci-github).
68
+ * @param {string} cwd корінь consumer-репо.
69
+ * @param {string} servicePath каталог сервісу.
70
+ * @returns {Promise<string[]>} відсортовані rule-id.
71
+ */
72
+ export async function relevantDomains(cwd, servicePath) {
73
+ const abs = resolve(cwd, servicePath)
74
+ if (!existsSync(abs) || !statSync(abs).isDirectory()) return []
75
+ const files = await collectPathScopedFiles(cwd, servicePath)
76
+ const { byRule, enabledSet } = await loadEnabledLintRules({ cwd })
77
+ const active = computeActiveDomains(byRule, enabledSet, files)
78
+ return active
79
+ .entries()
80
+ .filter(([, st]) => st.triggered)
81
+ .map(([id]) => id)
82
+ .toArray()
83
+ .toSorted((a, b) => a.localeCompare(b))
84
+ }
85
+
32
86
  /**
33
87
  * Rule-id → ключ output-змінної: `-` → `_` (GA/Azure не люблять дефіси в
34
88
  * іменах змінних; `npm-module` → `npm_module`). Експортовано для fix-хендлерів
@@ -3,7 +3,7 @@ type: JS Module
3
3
  title: ci-plan.mjs
4
4
  resource: npm/scripts/lib/lint-surface/ci-plan.mjs
5
5
  docgen:
6
- crc: ce7f2a96
6
+ crc: 7df6d5b8
7
7
  model: openai-codex/gpt-5.4-mini
8
8
  score: 90
9
9
  issues: internal-name:computeActiveDomains,judge:inaccurate:0.99