@nitra/cursor 1.13.13 → 1.13.15

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
@@ -4,6 +4,36 @@
4
4
 
5
5
  Формат — [Keep a Changelog](https://keepachangelog.com/uk/1.1.0/), нумерація — [SemVer](https://semver.org/lang/uk/).
6
6
 
7
+ ## [1.13.15] - 2026-05-17
8
+
9
+ ### Added
10
+
11
+ - `npm-module` rule template/ міграція (Phase 5): усі 4 policy концерни — `emit_types_config` (fragment, 2-level walker), `root_package_json` (fragment, snippet-array `workspaces`), `npm_package_json` (partial — `files` whitelist у template, regex `types` + `devDependencies`-must-be-empty лишаються у rego), `npm_publish_yml` (full-canon workflow з per-concern field-by-field rego).
12
+ - 3 нові `*_test.rego` (раніше тестів не було для `emit_types_config`, `root_package_json`, `npm_publish_yml`) — кожен покриває canonical + 4-6 негативних + drift.
13
+
14
+ ### Changed
15
+
16
+ - `emit_types_config.rego` — generic 2-level snippet walker (як `bun.bunfig` / `ga.vscode_settings`).
17
+ - `root_package_json.rego` — generic snippet-array subset-of walker (під `workspaces` і потенційні наступні масиви).
18
+ - `npm_package_json.rego` — `files` whitelist тепер subset-of через `data.template.snippet`; `types` regex + `devDependencies`-must-be-empty лишаються у rego як inverse-patterns.
19
+ - `npm_publish_yml.rego` — повний канон workflow у `template/npm-publish.yml.snippet.yml` (як ga workflow concerns), expected paths/branches/permissions/uses-marker читаються з `data.template.snippet.<path>`.
20
+ - `npm-module.mdc` — inline `npm-publish.yml` блок (35 рядків) замінено на template-link; додано окрему секцію «Канонічні конфіги» з лінками на `root_package_json`, `npm_package_json`, `emit_types_config` template-файли.
21
+ - `docs/adr/template-dir-concern-inventory.md` — усі 4 `npm-module.*` концерни позначено ✓; додано Phase 5 у прогрес; tally: 19/39 (49%).
22
+
23
+ ## [1.13.14] - 2026-05-17
24
+
25
+ ### Added
26
+
27
+ - `bun` rule template/ міграція (Phase 4): 2 концерни — `bunfig` (snippet-walker 2-level, `[install].linker = "hoisted"`) + `package_json` (partial — top-level deny-fields у template).
28
+ - `bunfig_test.rego` створено з нуля (раніше тестів не було) — 5 позитивних/негативних + drift.
29
+
30
+ ### Changed
31
+
32
+ - `bun.bunfig.rego` — використовує той самий 2-level snippet-walker, що `ga.vscode_settings` (leaf-by-leaf + guard на non-object section).
33
+ - `bun.package_json.rego` — top-level deny-fields (`packageManager`, `dependencies`) тепер читаються з `data.template.deny`. Сентинельний value у `object.get(input, field, "__bun_missing__")` зберігає behavior «field present навіть якщо порожній обʼєкт». Логіка `@nitra/*`-only у devDependencies та lint-aggregator (cross-script) лишається у rego — це inverse-patterns, які не виносяться у template.
34
+ - `bun.mdc` — inline `bunfig.toml` snippet замінено на template-link; додано посилання на `package.json.deny.json` для документації заборонених top-level полів.
35
+ - `docs/adr/template-dir-concern-inventory.md` — `bun.*` концерни позначено ✓; додано Phase 4 у прогрес-секцію; tally: 15/39 (38%).
36
+
7
37
  ## [1.13.13] - 2026-05-17
8
38
 
9
39
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/cursor",
3
- "version": "1.13.13",
3
+ "version": "1.13.15",
4
4
  "description": "CLI для завантаження cursor-правил (префікс n-) у локальний репозиторій",
5
5
  "keywords": [
6
6
  "cli",
package/rules/bun/bun.mdc CHANGED
@@ -34,10 +34,7 @@ Lockfile у репозиторії: `bun.lock`.
34
34
 
35
35
  У корені репозиторію має бути **`bunfig.toml`** з **hoisted** лінкером (пласке `node_modules`, сумісне з інструментами, які не розуміють ізольований layout Bun):
36
36
 
37
- ```toml title="bunfig.toml"
38
- [install]
39
- linker = "hoisted"
40
- ```
37
+ - Канон `bunfig.toml`: [bunfig.toml.snippet.toml](./policy/bunfig/template/bunfig.toml.snippet.toml)
41
38
 
42
39
  Для Bun monorepo:
43
40
 
@@ -45,9 +42,9 @@ linker = "hoisted"
45
42
  - Якщо залежність потрібна лише одному пакету, додавати її в директорії цього пакета.
46
43
  - У CI та локально запускати скрипти через `bun run`.
47
44
 
48
- В кореневому в package.json не повинно бути `dependencies`, а в `devDependencies` — тільки модулі `@nitra/*`
45
+ В кореневому в package.json не повинно бути `dependencies`, а в `devDependencies` — тільки модулі `@nitra/*`. Якщо в package.json є поля `packageManager`, то прибрати їх, також прибрати всі директорії та файли для yarn.
49
46
 
50
- Якщо в package.json є поля `packageManager`, то прибрати їх, також прибрати всі директорії та файли для yarn
47
+ - Заборонені top-level поля у root `package.json` причинами): [package.json.deny.json](./policy/package_json/template/package.json.deny.json)
51
48
 
52
49
  Коли зміна відбувається в Dockerfile, то використовувати
53
50
 
@@ -1,33 +1,29 @@
1
- # Порт перевірки `checkBunfigHoisted` з `npm/scripts/check-bun.mjs` (bun.mdc).
1
+ # Перевірка `bunfig.toml` для bun (bun.mdc).
2
2
  #
3
- # Запуск (локально):
4
- # conftest test bunfig.toml -p npm/policy/bun --namespace bun.bunfig
5
- #
6
- # Conftest парсить `.toml` нативно: секція `[install]` стає обʼєктом `input.install`.
7
- # FS-перевірки (наявність самого `bunfig.toml`, `bun.lock`, заборонені lockfile-и
8
- # `package-lock.json` тощо, директорія `.yarn/`) живуть у `check-bun.mjs` — Rego
9
- # працює лише з вже завантаженим input.
10
- #
11
- # Структура каталогу збігається зі шляхом пакету (regal: directory-package-mismatch).
12
- # Конвенція проєкту — `import rego.v1` + multi-value `deny contains msg if { … }`
13
- # (.cursor/rules/conftest.mdc). Лінт — `bun run lint-rego` (regal).
3
+ # Канон надходить через --data: { "template": { "snippet": ... } }
4
+ # Структура --data сформована з template/bunfig.toml.snippet.toml.
5
+ # Snippet — 2-рівнева мапа (section → key → expected). Walker такий самий,
6
+ # як для ga.vscode_settings: leaf-by-leaf коли section-обʼєкт існує + окремий
7
+ # deny коли section відсутній / не обʼєкт.
14
8
  package bun.bunfig
15
9
 
16
10
  import rego.v1
17
11
 
12
+ # Leaf-by-leaf: section присутня й обʼєкт.
18
13
  deny contains msg if {
19
- # `object.get(…, false)` дає визначене значення, коли поля немає, інакше
20
- # `not is_object(input.install)` повернув би `undefined`, і правило мовчки
21
- # не спрацювало б (той самий патерн, що й у `ga.workflow_common`).
22
- not is_object(object.get(input, "install", false))
23
- msg := "bunfig.toml: відсутня секція [install] (bun.mdc)"
14
+ some section, expected_inner in data.template.snippet
15
+ inner := object.get(input, section, {})
16
+ is_object(inner)
17
+ some leaf_key, expected_value in expected_inner
18
+ actual := object.get(inner, leaf_key, null)
19
+ actual != expected_value
20
+ msg := sprintf("bunfig.toml: у секції [%s] має бути %s = %q (bun.mdc)", [section, leaf_key, expected_value])
24
21
  }
25
22
 
23
+ # Section відсутня (null) або не обʼєкт.
26
24
  deny contains msg if {
27
- is_object(object.get(input, "install", false))
28
-
29
- # `object.get(…, null)` робить значення визначеним, інакше при відсутньому
30
- # `linker` порівняння `!= "hoisted"` дало б `undefined`, не `true`.
31
- object.get(input.install, "linker", null) != "hoisted"
32
- msg := "bunfig.toml: у секції [install] має бути linker = \"hoisted\" (bun.mdc)"
25
+ some section in object.keys(data.template.snippet)
26
+ raw := object.get(input, section, null)
27
+ not is_object(raw)
28
+ msg := sprintf("bunfig.toml: відсутня секція [%s] (bun.mdc)", [section])
33
29
  }
@@ -0,0 +1,2 @@
1
+ [install]
2
+ linker = "hoisted"
@@ -1,47 +1,38 @@
1
- # Порт структурних перевірок `package.json` з `npm/scripts/check-bun.mjs` (bun.mdc).
1
+ # Перевірка кореневого `package.json` для bun (bun.mdc).
2
2
  #
3
- # Запуск (локально, КОРЕНЕВИЙ package.json):
4
- # conftest test package.json -p npm/policy/bun --namespace bun.package_json
3
+ # Канон надходить через --data: { "template": { "deny": ... } }
4
+ # Структура --data сформована з template/package.json.deny.json
5
+ # (top-level fields заборонені у root).
5
6
  #
6
- # Перевіряє: відсутність `packageManager`, відсутність кореневих `dependencies`,
7
- # у `devDependencies` лише `@nitra/*`, агрегований `lint`-скрипт (якщо є `lint-*`
8
- # скрипти): покриває всі lint-* через `bun run`, закінчується на `&& oxfmt .`.
7
+ # Логіка, що ЛИШАЄТЬСЯ у rego (inverse-patterns, не виносяться у template):
8
+ # - `devDependencies` лише `@nitra/*` (inverse-pattern: every dep must match)
9
+ # - Агрегований `lint` скрипт (cross-script aggregation logic)
9
10
  #
10
11
  # Перевірки, які ЗАЛИШИЛИСЬ у JS (потребують FS / cross-file):
11
12
  # - `lint-docker` / `lint-k8s` коли `.n-cursor.json:rules` містить відповідне
12
13
  # правило (потрібен другий файл-вхід — у Rego без `--combine` не зробити).
13
- #
14
- # Структура каталогу збігається зі шляхом пакету (regal: directory-package-mismatch).
15
- # Конвенція проєкту — `import rego.v1` + multi-value `deny contains msg if { … }`
16
- # (.cursor/rules/conftest.mdc). Лінт — `bun run lint-rego` (regal).
17
14
  package bun.package_json
18
15
 
19
16
  import rego.v1
20
17
 
21
18
  # ── Шаблони повідомлень ────────────────────────────────────────────────────
22
19
 
23
- # Через `concat` — дотримуємося regal style/line-length.
24
20
  lint_aggregate_missing_template := concat(" ", [
25
21
  "У package.json є скрипти %v, але немає агрегованого `lint`.",
26
22
  "Додай скрипт, який запускає їх через `bun run` (bun.mdc)",
27
23
  ])
28
24
 
29
- # ── deny: заборонені поля ──────────────────────────────────────────────────
30
-
31
- deny contains msg if {
32
- pm := object.get(input, "packageManager", "")
33
- pm != ""
34
- msg := sprintf("package.json містить поле packageManager: %q — видали його (bun.mdc)", [pm])
35
- }
25
+ # ── deny: заборонені top-level поля (template-driven) ─────────────────────
36
26
 
37
- # `dependencies` не повинно бути взагалі навіть пусте `{}`. Сентинельний рядок
38
- # дозволяє відрізнити «поле відсутнє» від «поле є з будь-яким значенням».
27
+ # Сентинельний value відрізняє «поле відсутнє» від «поле є з будь-яким значенням»
28
+ # (наприклад `dependencies: {}` присутнє але порожнє теж заборонено).
39
29
  deny contains msg if {
40
- object.get(input, "dependencies", "__bun_missing__") != "__bun_missing__"
41
- msg := "Кореневий package.json не повинен містити поле dependencies — додай залежності в workspace-пакети (bun.mdc)"
30
+ some field, reason in data.template.deny
31
+ object.get(input, field, "__bun_missing__") != "__bun_missing__"
32
+ msg := sprintf("package.json: поле %s — %s", [field, reason])
42
33
  }
43
34
 
44
- # ── deny: devDependencies — лише `@nitra/*` ───────────────────────────────
35
+ # ── deny: devDependencies — лише `@nitra/*` (inverse pattern; не виноситься у template) ─
45
36
 
46
37
  deny contains msg if {
47
38
  is_object(input.devDependencies)
@@ -50,11 +41,7 @@ deny contains msg if {
50
41
  msg := sprintf("Кореневі devDependencies: дозволені лише @nitra/* — прибери або перенеси: %s (bun.mdc)", [name])
51
42
  }
52
43
 
53
- # ── deny: агрегований lint-скрипт ─────────────────────────────────────────
54
- #
55
- # Якщо в `scripts` є хоч один `lint-*`, має бути скрипт `lint`, у якому
56
- # через `bun run <ім'я>` викликається кожен такий скрипт; рядок завершується
57
- # на `&& oxfmt .`.
44
+ # ── deny: агрегований lint-скрипт (cross-script aggregation logic) ───────
58
45
 
59
46
  deny contains msg if {
60
47
  count(lint_prefixed_scripts) > 0
@@ -73,22 +60,17 @@ deny contains msg if {
73
60
  deny contains msg if {
74
61
  count(lint_prefixed_scripts) > 0
75
62
  lint_script != ""
76
-
77
- # Перевіряємо, що рядок завершується `&& oxfmt .` (з можливими пробілами/табами).
78
- # Trim не потрібен — пробіли/таби в кінці допускаємо в самому regex (`[ \t]*$`).
79
63
  not regex.match(`&&[ \t]+oxfmt[ \t]+\.[ \t]*$`, lint_script)
80
64
  msg := "Скрипт `lint` має закінчуватися на `&& oxfmt .` (bun.mdc)"
81
65
  }
82
66
 
83
67
  # ── helpers ────────────────────────────────────────────────────────────────
84
68
 
85
- # Ключі скриптів, що починаються з `lint-` (наприклад `lint-js`, `lint-ga`).
86
69
  lint_prefixed_scripts := [name |
87
70
  some name, _ in object.get(input, "scripts", {})
88
71
  startswith(name, "lint-")
89
72
  ]
90
73
 
91
- # Значення `scripts.lint` як рядок (порожній, якщо поля немає або тип не string).
92
74
  default lint_script := ""
93
75
 
94
76
  lint_script := input.scripts.lint if is_string(input.scripts.lint)
@@ -0,0 +1,4 @@
1
+ {
2
+ "packageManager": "видали поле — Bun не потребує packageManager (bun.mdc)",
3
+ "dependencies": "кореневий package.json не повинен містити dependencies — додай у workspace-пакети (bun.mdc)"
4
+ }
@@ -75,39 +75,10 @@ bunx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly
75
75
 
76
76
  **`npm-publish.yml`:** push у **`main`**, **`on.push.paths`** з **`npm/**`**, **`JS-DevTools/npm-publish@v4.1.5`**, **`with.package: npm/package.json`**, **`permissions.id-token: write`** (OIDC на npm).
77
77
 
78
- ```yaml title=".github/workflows/npm-publish.yml"
79
- name: npm-publish
80
-
81
- on:
82
- push:
83
- paths:
84
- - 'npm/**'
85
- branches:
86
- - main
87
-
88
- concurrency:
89
- group: ${{ github.ref }}-${{ github.workflow }}
90
- cancel-in-progress: true
91
-
92
- jobs:
93
- publish:
94
- runs-on: ubuntu-latest
95
- permissions:
96
- contents: read
97
- id-token: write # КРИТИЧНО для OIDC!
98
-
99
- steps:
100
- - uses: actions/checkout@v6
101
- with:
102
- persist-credentials: false
103
-
104
- - uses: actions/setup-node@v6
105
- with:
106
- node-version: '24' # includes npm@11.6.0
107
- registry-url: 'https://registry.npmjs.org'
108
-
109
- - name: Publish package
110
- uses: JS-DevTools/npm-publish@v4.1.5
111
- with:
112
- package: npm/package.json
113
- ```
78
+ - Канон: [npm-publish.yml.snippet.yml](./policy/npm_publish_yml/template/npm-publish.yml.snippet.yml)
79
+
80
+ ## Канонічні конфіги
81
+
82
+ - Кореневий `package.json` (workspaces): [package.json.snippet.json](./policy/root_package_json/template/package.json.snippet.json)
83
+ - `npm/package.json` (whitelist `files` обовʼязково має містити `types`): [package.json.snippet.json](./policy/npm_package_json/template/package.json.snippet.json)
84
+ - `npm/tsconfig.emit-types.json` (canonical `compilerOptions` для emit-types): [tsconfig.emit-types.json.snippet.json](./policy/emit_types_config/template/tsconfig.emit-types.json.snippet.json)
@@ -1,37 +1,28 @@
1
- # Порт перевірок `npm/tsconfig.emit-types.json` з `npm/scripts/check-npm-module.mjs`
2
- # (npm-module.mdc).
1
+ # Перевірка `npm/tsconfig.emit-types.json` (npm-module.mdc).
3
2
  #
4
- # Запуск (локально):
5
- # conftest test npm/tsconfig.emit-types.json -p npm/policy/npm_module \
6
- # --namespace npm_module.emit_types_config
7
- #
8
- # Перевіряє: `compilerOptions.{allowJs, declaration, emitDeclarationOnly, outDir,
9
- # skipLibCheck}` мають канонічні значення (true/true/true/"types"/true). FS-перевірки
10
- # (наявність самого `tsconfig.emit-types.json`, активність layout-варіанта) — у JS.
11
- #
12
- # Структура каталогу збігається зі шляхом пакету (regal: directory-package-mismatch).
13
- # Конвенція проєкту — `import rego.v1` + multi-value `deny contains msg if { … }`
14
- # (.cursor/rules/conftest.mdc). Лінт — `bun run lint-rego` (regal).
3
+ # Канон надходить через --data: { "template": { "snippet": ... } }
4
+ # Структура --data сформована з template/tsconfig.emit-types.json.snippet.json.
5
+ # Snippet — 2-рівнева мапа (section → key → expected). Walker такий самий,
6
+ # як для ga.vscode_settings / bun.bunfig.
15
7
  package npm_module.emit_types_config
16
8
 
17
9
  import rego.v1
18
10
 
19
- required_compiler_options := {
20
- "allowJs": true,
21
- "declaration": true,
22
- "emitDeclarationOnly": true,
23
- "outDir": "types",
24
- "skipLibCheck": true,
25
- }
26
-
11
+ # Leaf-by-leaf: коли section присутня й обʼєкт.
27
12
  deny contains msg if {
28
- not is_object(object.get(input, "compilerOptions", null))
29
- msg := "npm/tsconfig.emit-types.json: відсутній compilerOptions (npm-module.mdc)"
13
+ some section, expected_inner in data.template.snippet
14
+ inner := object.get(input, section, {})
15
+ is_object(inner)
16
+ some leaf_key, expected_value in expected_inner
17
+ actual := object.get(inner, leaf_key, null)
18
+ actual != expected_value
19
+ msg := sprintf("npm/tsconfig.emit-types.json: %s.%s має бути %v (npm-module.mdc)", [section, leaf_key, expected_value])
30
20
  }
31
21
 
22
+ # Section відсутня (null) або не обʼєкт.
32
23
  deny contains msg if {
33
- is_object(input.compilerOptions)
34
- some key, expected in required_compiler_options
35
- object.get(input.compilerOptions, key, null) != expected
36
- msg := sprintf("npm/tsconfig.emit-types.json: compilerOptions.%s має бути %v (npm-module.mdc)", [key, expected])
24
+ some section in object.keys(data.template.snippet)
25
+ raw := object.get(input, section, null)
26
+ not is_object(raw)
27
+ msg := sprintf("npm/tsconfig.emit-types.json: відсутній %s (npm-module.mdc)", [section])
37
28
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "outDir": "types",
7
+ "skipLibCheck": true
8
+ }
9
+ }
@@ -1,44 +1,29 @@
1
- # Порт перевірок `npm/package.json` з `npm/scripts/check-npm-module.mjs`
2
- # (npm-module.mdc).
1
+ # Порт перевірок `npm/package.json` (npm-module.mdc).
3
2
  #
4
- # Запуск (локально):
5
- # conftest test npm/package.json -p npm/policy/npm_module \
6
- # --namespace npm_module.npm_package_json
3
+ # Канон надходить через --data: { "template": { "snippet": ... } }
4
+ # Структура --data сформована з template/package.json.snippet.json
5
+ # (snippet-array subset-of для whitelist `files`).
7
6
  #
8
- # Перевіряє:
9
- # - поле `types` має один із двох канонічних патернів: `./types/index.d.ts`
10
- # (layout `npm/src` з `.js`) або `./types/<…>.d.ts`/`.d.mts` (emit-types);
11
- # - масив `files` присутній, непорожній і містить `"types"` (whitelist
12
- # обовʼязковий — без нього npm пакує майже все);
13
- # - `devDependencies` відсутні або порожні: dev-інструментарій тримаємо у
14
- # кореневому `package.json` монорепо, щоб `npm install @nitra/<pkg>` його
15
- # не тягнув (npm-module.mdc: компактний пакет).
7
+ # Логіка, що ЛИШАЄТЬСЯ у rego (inverse-patterns, не виносяться у template):
8
+ # - форма поля `types` (regex pattern: `./types/index.d.ts` або `./types/<…>.d.ts|.d.mts`);
9
+ # - `devDependencies` мають бути відсутні або порожні (inverse-pattern — заборона будь-яких).
16
10
  #
17
- # Те, який саме типовий layout активний (наявність `.js` під `npm/src`),
18
- # існування файлу зі шляху `types` і скан тест-патернів у tarball — у
19
- # JS-перевірці (`check-npm-module.mjs`: cross-file / FS-access / AST).
20
- #
21
- # Структура каталогу збігається зі шляхом пакету (regal: directory-package-mismatch).
22
- # Конвенція проєкту — `import rego.v1` + multi-value `deny contains msg if { … }`
23
- # (.cursor/rules/conftest.mdc). Лінт — `bun run lint-rego` (regal).
11
+ # FS-перевірки (наявність файлу зі шляху `types`, скан tarball на тест-патерни) — у JS.
24
12
  package npm_module.npm_package_json
25
13
 
26
14
  import rego.v1
27
15
 
28
- # Шаблон повідомлення про неканонічне поле `types` — через `concat` для
29
- # regal style/line-length.
30
16
  types_field_template := concat(" ", [
31
17
  "npm/package.json: поле \"types\" має бути \"./types/index.d.ts\"",
32
18
  "або \"./types/<…>.d.ts|.d.mts\" (зараз: %v) (npm-module.mdc)",
33
19
  ])
34
20
 
35
- # Шаблон повідомлення про присутність `devDependencies`.
36
21
  dev_deps_template := concat(" ", [
37
22
  "npm/package.json: \"devDependencies\" не публікуються користувачам пакета —",
38
23
  "перенеси у кореневий package.json: %v (npm-module.mdc: компактний пакет)",
39
24
  ])
40
25
 
41
- # ── deny: types ────────────────────────────────────────────────────────────
26
+ # ── deny: types (regex — лишається в rego) ───────────────────────────────
42
27
 
43
28
  deny contains msg if {
44
29
  types_field := object.get(input, "types", "")
@@ -46,7 +31,7 @@ deny contains msg if {
46
31
  msg := sprintf(types_field_template, [types_field])
47
32
  }
48
33
 
49
- # ── deny: files має існувати, бути непорожнім, містити "types" ────────────
34
+ # ── deny: files має існувати та бути масивом ─────────────────────────────
50
35
 
51
36
  deny contains msg if {
52
37
  not is_array(object.get(input, "files", null))
@@ -59,14 +44,19 @@ deny contains msg if {
59
44
  msg := "npm/package.json: масив \"files\" не повинен бути порожнім (npm-module.mdc: компактний пакет)"
60
45
  }
61
46
 
47
+ # ── deny: files subset-of з template (template-driven) ──────────────────
48
+
62
49
  deny contains msg if {
63
- is_array(input.files)
64
- count(input.files) > 0
65
- not "types" in {f | some f in input.files}
66
- msg := "npm/package.json: масив \"files\" має містити \"types\" (npm-module.mdc)"
50
+ some field, expected_values in data.template.snippet
51
+ is_array(object.get(input, field, null))
52
+ count(input[field]) > 0
53
+ actual_set := {v | some v in input[field]}
54
+ some required in expected_values
55
+ not required in actual_set
56
+ msg := sprintf("npm/package.json: масив \"%s\" має містити %q (npm-module.mdc)", [field, required])
67
57
  }
68
58
 
69
- # ── deny: жодних devDependencies у npm/package.json ───────────────────────
59
+ # ── deny: devDependencies (inverse-pattern, лишається в rego) ────────────
70
60
 
71
61
  deny contains msg if {
72
62
  dev := object.get(input, "devDependencies", {})
@@ -1,20 +1,12 @@
1
- # Порт перевірок `.github/workflows/npm-publish.yml` з `npm/scripts/check-npm-module.mjs`
2
- # (npm-module.mdc).
1
+ # Перевірка `.github/workflows/npm-publish.yml` (npm-module.mdc).
3
2
  #
4
- # Запуск (локально):
5
- # conftest test .github/workflows/npm-publish.yml -p npm/policy/npm_module \
6
- # --namespace npm_module.npm_publish_yml
7
- #
8
- # Перевіряє: `on.push.paths` містить glob з `npm/**`, `on.push.branches` містить
9
- # `main`, у jobs є `permissions.id-token: write` (OIDC), є крок з
10
- # `uses: JS-DevTools/npm-publish` і `with.package: npm/package.json`.
3
+ # Канон надходить через --data: { "template": { "snippet": ... } }
4
+ # Структура --data сформована з template/npm-publish.yml.snippet.yml.
5
+ # Per-concern field-by-field: path/substring-маркери з expected_uses_set читаються
6
+ # зі steps template, експектації branches/paths — subset-of.
11
7
  #
12
8
  # Універсальні workflow-перевірки (concurrency, заборонені setup-bun/cache/install,
13
9
  # shell line-continuation) — у `ga.workflow_common`.
14
- #
15
- # Структура каталогу збігається зі шляхом пакету (regal: directory-package-mismatch).
16
- # Конвенція проєкту — `import rego.v1` + multi-value `deny contains msg if { … }`
17
- # (.cursor/rules/conftest.mdc). Лінт — `bun run lint-rego` (regal).
18
10
  package npm_module.npm_publish_yml
19
11
 
20
12
  import rego.v1
@@ -22,58 +14,74 @@ import rego.v1
22
14
  # YAML 1.1 quirk: ключ `on:` → boolean true → у конфтесті ключ "true".
23
15
  gha_on := input["true"]
24
16
 
25
- # Шаблон повідомлення про відсутній JS-DevTools/npm-publish крок — через `concat`
26
- # для regal style/line-length.
27
- npm_publish_step_template := concat(" ", [
28
- "npm-publish.yml: очікується `uses: JS-DevTools/npm-publish`",
29
- `with.package: npm/package.json` (npm-module.mdc)",
30
- ])
17
+ # Required marker substring у `uses` для ідентифікації npm-publish кроку.
18
+ publish_action_marker := "JS-DevTools/npm-publish"
19
+
20
+ # Очікувані літерали з template.
21
+ expected_paths := {p | some p in data.template.snippet.on.push.paths}
31
22
 
32
- # ── deny: paths/branches ──────────────────────────────────────────────────
23
+ expected_branches := {b | some b in data.template.snippet.on.push.branches}
24
+
25
+ expected_permissions := data.template.snippet.jobs.publish.permissions
26
+
27
+ # Required publish-step (за маркером): expected `with.package` value з template.
28
+ expected_publish_with_package := s.with.package if {
29
+ some s in data.template.snippet.jobs.publish.steps
30
+ contains(object.get(s, "uses", ""), publish_action_marker)
31
+ }
32
+
33
+ # ── deny: paths містить кожне з expected_paths (subset-of) ───────────────
33
34
 
34
35
  deny contains msg if {
35
- not push_paths_have_npm_glob
36
- msg := "npm-publish.yml: у on.push.paths має бути `npm/**` (npm-module.mdc)"
36
+ some required_path in expected_paths
37
+ not path_present(required_path)
38
+ msg := sprintf("npm-publish.yml: у on.push.paths має бути `%s` (npm-module.mdc)", [required_path])
37
39
  }
38
40
 
41
+ # ── deny: branches містить кожне з expected_branches (subset-of) ─────────
42
+
39
43
  deny contains msg if {
40
- not push_branches_have_main
41
- msg := "npm-publish.yml: on.push.branches має містити `main` (npm-module.mdc)"
44
+ some required_branch in expected_branches
45
+ not required_branch in {b | some b in gha_on.push.branches}
46
+ msg := sprintf("npm-publish.yml: on.push.branches має містити `%s` (npm-module.mdc)", [required_branch])
42
47
  }
43
48
 
44
49
  # ── deny: id-token: write у permissions хоч одного job ────────────────────
45
50
 
46
51
  deny contains msg if {
47
- not any_job_has_id_token_write
48
- msg := "npm-publish.yml: permissions має містити `id-token: write` (OIDC) (npm-module.mdc)"
52
+ required := expected_permissions["id-token"]
53
+ not any_job_has_id_token(required)
54
+ msg := sprintf("npm-publish.yml: permissions має містити `id-token: %s` (OIDC) (npm-module.mdc)", [required])
49
55
  }
50
56
 
51
- # ── deny: крок з uses JS-DevTools/npm-publish та with.package ─────────────
57
+ # ── deny: крок з uses-маркером npm-publish та канонічним with.package ────
52
58
 
53
- deny contains npm_publish_step_template if {
59
+ deny contains msg if {
54
60
  not has_npm_publish_step
61
+ msg := sprintf(
62
+ "npm-publish.yml: очікується `uses: %s` з `with.package: %s` (npm-module.mdc)",
63
+ [publish_action_marker, expected_publish_with_package],
64
+ )
55
65
  }
56
66
 
57
67
  # ── helpers ────────────────────────────────────────────────────────────────
58
68
 
59
- push_paths_have_npm_glob if {
69
+ # Path присутній, якщо хоч один шлях у actual містить required як substring
70
+ # (npm/** glob у workflow може бути записаний як `npm/**` або `'npm/**'`).
71
+ path_present(required) if {
60
72
  some p in gha_on.push.paths
61
73
  is_string(p)
62
- contains(p, "npm/**")
63
- }
64
-
65
- push_branches_have_main if {
66
- "main" in {b | some b in gha_on.push.branches}
74
+ contains(p, required)
67
75
  }
68
76
 
69
- any_job_has_id_token_write if {
77
+ any_job_has_id_token(required) if {
70
78
  some job in object.get(input, "jobs", {})
71
- job.permissions["id-token"] == "write"
79
+ job.permissions["id-token"] == required
72
80
  }
73
81
 
74
82
  has_npm_publish_step if {
75
83
  some job in object.get(input, "jobs", {})
76
84
  some step in object.get(job, "steps", [])
77
- contains(object.get(step, "uses", ""), "JS-DevTools/npm-publish")
78
- step.with.package == "npm/package.json"
85
+ contains(object.get(step, "uses", ""), publish_action_marker)
86
+ step.with.package == expected_publish_with_package
79
87
  }
@@ -0,0 +1,34 @@
1
+ name: npm-publish
2
+
3
+ on:
4
+ push:
5
+ paths:
6
+ - 'npm/**'
7
+ branches:
8
+ - main
9
+
10
+ concurrency:
11
+ group: ${{ github.ref }}-${{ github.workflow }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ publish:
16
+ runs-on: ubuntu-latest
17
+ permissions:
18
+ contents: read
19
+ id-token: write # КРИТИЧНО для OIDC!
20
+
21
+ steps:
22
+ - uses: actions/checkout@v6
23
+ with:
24
+ persist-credentials: false
25
+
26
+ - uses: actions/setup-node@v6
27
+ with:
28
+ node-version: '24' # includes npm@11.6.0
29
+ registry-url: 'https://registry.npmjs.org'
30
+
31
+ - name: Publish package
32
+ uses: JS-DevTools/npm-publish@v4.1.5
33
+ with:
34
+ package: npm/package.json
@@ -1,28 +1,28 @@
1
- # Порт перевірки кореневого `package.json` з `npm/scripts/check-npm-module.mjs`
2
- # (npm-module.mdc) — масив `workspaces` має містити "npm".
3
- #
4
- # Запуск (локально):
5
- # conftest test package.json -p npm/policy/npm_module \
6
- # --namespace npm_module.root_package_json
1
+ # Перевірка кореневого `package.json` для npm-module (npm-module.mdc).
7
2
  #
3
+ # Канон надходить через --data: { "template": { "snippet": ... } }
4
+ # Структура --data сформована з template/package.json.snippet.json.
5
+ # Snippet-array subset-of: кожне значення з template-масиву має бути у input-масиві.
8
6
  # Решта кореневих `package.json`-перевірок (заборонені поля, devDeps лише @nitra/*)
9
- # — у `bun.package_json`. FS-перевірки (наявність каталогу `npm/`,
10
- # `npm/package.json`) — у JS.
11
- #
12
- # Структура каталогу збігається зі шляхом пакету (regal: directory-package-mismatch).
13
- # Конвенція проєкту — `import rego.v1` + multi-value `deny contains msg if { … }`
14
- # (.cursor/rules/conftest.mdc). Лінт — `bun run lint-rego` (regal).
7
+ # — у `bun.package_json`. FS-перевірки (наявність каталогу `npm/`, `npm/package.json`)
8
+ # — у JS.
15
9
  package npm_module.root_package_json
16
10
 
17
11
  import rego.v1
18
12
 
13
+ # Поле має бути масивом — інакше окрема deny.
19
14
  deny contains msg if {
20
- not is_array(object.get(input, "workspaces", null))
21
- msg := "package.json: масив workspaces відсутній — має містити \"npm\" (npm-module.mdc)"
15
+ some field in object.keys(data.template.snippet)
16
+ not is_array(object.get(input, field, null))
17
+ msg := sprintf("package.json: масив %s відсутній або не масив (npm-module.mdc)", [field])
22
18
  }
23
19
 
20
+ # Subset-of: кожне значення з template має бути в input-масиві.
24
21
  deny contains msg if {
25
- is_array(input.workspaces)
26
- not "npm" in {w | some w in input.workspaces}
27
- msg := "package.json: workspaces має містити \"npm\" (npm-module.mdc)"
22
+ some field, expected_values in data.template.snippet
23
+ is_array(object.get(input, field, null))
24
+ actual_set := {v | some v in input[field]}
25
+ some required in expected_values
26
+ not required in actual_set
27
+ msg := sprintf("package.json: %s має містити %q (npm-module.mdc)", [field, required])
28
28
  }