@nitra/cursor 1.8.170 → 1.8.173
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 +24 -0
- package/README.md +14 -0
- package/bin/auto-rules.md +1 -1
- package/mdc/abie.mdc +2 -14
- package/package.json +1 -1
- package/schemas/n-cursor.json +1 -1
- package/scripts/auto-rules.mjs +2 -8
- package/scripts/check-abie.mjs +18 -104
- package/scripts/check-docker.mjs +12 -5
- package/scripts/check-graphql.mjs +15 -9
- package/scripts/check-hasura.mjs +14 -8
- package/scripts/check-image.mjs +15 -9
- package/scripts/check-js-bun-db.mjs +25 -15
- package/scripts/check-js-mssql.mjs +27 -17
- package/scripts/check-js-run.mjs +26 -16
- package/scripts/check-k8s.mjs +22 -13
- package/scripts/check-nginx-default-tpl.mjs +26 -16
- package/scripts/check-npm-module.mjs +13 -7
- package/scripts/check-vue.mjs +27 -17
- package/scripts/rename-yaml-extensions.mjs +35 -29
- package/scripts/run-docker.mjs +11 -5
- package/scripts/run-k8s.mjs +14 -8
- package/scripts/utils/load-cursor-config.mjs +53 -0
- package/scripts/utils/walkDir.mjs +49 -8
package/scripts/run-k8s.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import { spawnSync } from 'node:child_process'
|
|
|
16
16
|
import { basename, dirname } from 'node:path'
|
|
17
17
|
|
|
18
18
|
import { isRunAsCli } from './cli-entry.mjs'
|
|
19
|
+
import { loadCursorIgnorePaths } from './utils/load-cursor-config.mjs'
|
|
19
20
|
import { resolveCmd } from './utils/resolve-cmd.mjs'
|
|
20
21
|
import { walkDir } from './utils/walkDir.mjs'
|
|
21
22
|
|
|
@@ -60,15 +61,19 @@ export function k8sRootFromFile(absFile) {
|
|
|
60
61
|
* @param {string} root корінь репозиторію
|
|
61
62
|
* @returns {Promise<string[]>} відсортовані абсолютні шляхи до каталогів `k8s`
|
|
62
63
|
*/
|
|
63
|
-
export async function findK8sRoots(root) {
|
|
64
|
+
export async function findK8sRoots(root, ignorePaths = []) {
|
|
64
65
|
/** @type {Set<string>} */
|
|
65
66
|
const roots = new Set()
|
|
66
|
-
await walkDir(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
await walkDir(
|
|
68
|
+
root,
|
|
69
|
+
p => {
|
|
70
|
+
if (!pathHasK8sSegment(p)) return
|
|
71
|
+
if (!YAML_EXT_RE.test(p)) return
|
|
72
|
+
const k8sRoot = k8sRootFromFile(p)
|
|
73
|
+
if (k8sRoot) roots.add(k8sRoot)
|
|
74
|
+
},
|
|
75
|
+
ignorePaths
|
|
76
|
+
)
|
|
72
77
|
return [...roots].toSorted((a, b) => a.localeCompare(b))
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -134,7 +139,8 @@ function runKubescape(dirs) {
|
|
|
134
139
|
*/
|
|
135
140
|
async function main() {
|
|
136
141
|
const root = process.cwd()
|
|
137
|
-
const
|
|
142
|
+
const ignorePaths = await loadCursorIgnorePaths(root)
|
|
143
|
+
const dirs = await findK8sRoots(root, ignorePaths)
|
|
138
144
|
|
|
139
145
|
if (dirs.length === 0) {
|
|
140
146
|
console.log('run-k8s: немає *.yaml під k8s — kubeconform і kubescape пропущено')
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Утиліта читання `.n-cursor.json` у корені репозиторію.
|
|
3
|
+
*
|
|
4
|
+
* Зараз експортує `loadCursorIgnorePaths(root)` — список абсолютних posix-шляхів каталогів,
|
|
5
|
+
* які check-скрипти повністю виключають з обходу (поле `ignore` у конфізі).
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from 'node:fs'
|
|
8
|
+
import { readFile } from 'node:fs/promises'
|
|
9
|
+
import { isAbsolute, join, resolve, sep } from 'node:path'
|
|
10
|
+
|
|
11
|
+
const CONFIG_FILE = '.n-cursor.json'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Нормалізує шлях до абсолютного posix-формату без trailing-slash.
|
|
15
|
+
* Відносні шляхи розв'язуються від `root`.
|
|
16
|
+
* @param {string} root абсолютний корінь репозиторію
|
|
17
|
+
* @param {string} p шлях з конфігу (відносний або абсолютний)
|
|
18
|
+
* @returns {string} абсолютний posix-шлях
|
|
19
|
+
*/
|
|
20
|
+
function toAbsPosix(root, p) {
|
|
21
|
+
const trimmed = String(p).trim()
|
|
22
|
+
const abs = isAbsolute(trimmed) ? trimmed : resolve(root, trimmed)
|
|
23
|
+
return abs.split(sep).join('/').replace(/\/+$/, '')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Читає `.n-cursor.json` з кореня та повертає нормалізовані ignore-шляхи.
|
|
28
|
+
* Якщо файлу нема, поле `ignore` відсутнє чи має невалідний формат — повертає порожній масив.
|
|
29
|
+
* Сам конфіг не валідується (це робить v8r/окрема перевірка) — лише поле `ignore`.
|
|
30
|
+
* @param {string} root абсолютний корінь репозиторію
|
|
31
|
+
* @returns {Promise<string[]>} абсолютні posix-шляхи без trailing-slash
|
|
32
|
+
*/
|
|
33
|
+
export async function loadCursorIgnorePaths(root) {
|
|
34
|
+
const file = join(root, CONFIG_FILE)
|
|
35
|
+
if (!existsSync(file)) return []
|
|
36
|
+
let raw
|
|
37
|
+
try {
|
|
38
|
+
raw = JSON.parse(await readFile(file, 'utf8'))
|
|
39
|
+
} catch {
|
|
40
|
+
return []
|
|
41
|
+
}
|
|
42
|
+
const list = raw?.ignore
|
|
43
|
+
if (!Array.isArray(list)) return []
|
|
44
|
+
/** @type {string[]} */
|
|
45
|
+
const out = []
|
|
46
|
+
for (const item of list) {
|
|
47
|
+
if (typeof item !== 'string') continue
|
|
48
|
+
const v = item.trim()
|
|
49
|
+
if (v.length === 0) continue
|
|
50
|
+
out.push(toAbsPosix(root, v))
|
|
51
|
+
}
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
@@ -2,19 +2,60 @@
|
|
|
2
2
|
* Рекурсивний обхід каталогів для скриптів перевірки (Dockerfile, k8s YAML тощо).
|
|
3
3
|
*
|
|
4
4
|
* Обходить дерево від заданого кореня; для кожного звичайного файлу викликає переданий callback.
|
|
5
|
-
* Каталоги node_modules, .git, dist, coverage, .turbo, .next не заходяться.
|
|
6
|
-
*
|
|
5
|
+
* Каталоги node_modules, .git, dist, coverage, .turbo, .next не заходяться.
|
|
6
|
+
* Додатково можна передати `ignorePaths` — повні шляхи каталогів (абсолютні posix), які слід
|
|
7
|
+
* пропускати разом з усім вмістом (поле `ignore` у `.n-cursor.json`). Якщо readdir для каталогу
|
|
8
|
+
* не вдається — тихо виходить без throw.
|
|
7
9
|
*/
|
|
8
10
|
import { readdir } from 'node:fs/promises'
|
|
9
|
-
import { join } from 'node:path'
|
|
11
|
+
import { isAbsolute, join, resolve, sep } from 'node:path'
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
14
|
+
* Перетворює довільний шлях у абсолютний posix-формат без trailing-slash.
|
|
15
|
+
* @param {string} p шлях
|
|
16
|
+
* @returns {string} абсолютний posix-шлях
|
|
17
|
+
*/
|
|
18
|
+
function toAbsPosix(p) {
|
|
19
|
+
const abs = isAbsolute(p) ? p : resolve(p)
|
|
20
|
+
return abs.split(sep).join('/').replace(/\/+$/, '')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Чи каталог `dirAbsPosix` входить у список ignore (точний збіг або префікс з '/').
|
|
25
|
+
* Часткові збіги басенейму не враховуються (postgres-master-test ≠ postgres-master).
|
|
26
|
+
* @param {string} dirAbsPosix абсолютний posix-шлях каталогу
|
|
27
|
+
* @param {string[]} ignorePosix вже нормалізовані ignore-шляхи
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
function isIgnoredDir(dirAbsPosix, ignorePosix) {
|
|
31
|
+
for (const ig of ignorePosix) {
|
|
32
|
+
if (dirAbsPosix === ig) return true
|
|
33
|
+
if (dirAbsPosix.startsWith(`${ig}/`)) return true
|
|
34
|
+
}
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Рекурсивно обходить каталог, пропускає типові артефакти збірки/залежностей та `ignorePaths`.
|
|
13
40
|
* @param {string} dir абсолютний шлях
|
|
14
41
|
* @param {(filePath: string) => void} onFile виклик для кожного файлу
|
|
42
|
+
* @param {string[]} [ignorePaths=[]] шляхи каталогів (відносні від cwd або абсолютні), що повністю виключаються з обходу
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
*/
|
|
45
|
+
export async function walkDir(dir, onFile, ignorePaths = []) {
|
|
46
|
+
const ignorePosix = ignorePaths.map(toAbsPosix)
|
|
47
|
+
await walkDirInner(dir, onFile, ignorePosix)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Внутрішній рекурсор. ignorePosix вже нормалізовано — не нормалізуємо повторно на кожному рівні.
|
|
52
|
+
* @param {string} dir
|
|
53
|
+
* @param {(filePath: string) => void} onFile
|
|
54
|
+
* @param {string[]} ignorePosix
|
|
15
55
|
* @returns {Promise<void>}
|
|
16
56
|
*/
|
|
17
|
-
|
|
57
|
+
async function walkDirInner(dir, onFile, ignorePosix) {
|
|
58
|
+
if (ignorePosix.length > 0 && isIgnoredDir(toAbsPosix(dir), ignorePosix)) return
|
|
18
59
|
let entries
|
|
19
60
|
try {
|
|
20
61
|
entries = await readdir(dir, { withFileTypes: true })
|
|
@@ -31,9 +72,9 @@ export async function walkDir(dir, onFile) {
|
|
|
31
72
|
e.name === 'coverage' ||
|
|
32
73
|
e.name === '.turbo' ||
|
|
33
74
|
e.name === '.next'
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
75
|
+
if (skipDir) continue
|
|
76
|
+
if (ignorePosix.length > 0 && isIgnoredDir(toAbsPosix(p), ignorePosix)) continue
|
|
77
|
+
await walkDirInner(p, onFile, ignorePosix)
|
|
37
78
|
} else if (e.isFile()) {
|
|
38
79
|
onFile(p)
|
|
39
80
|
}
|