@monoes/monodesign 1.2.20 → 1.2.22
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/README.md +2 -2
- package/cli/engine/design-system-checks.mjs +381 -0
- package/cli/engine/design-system-parse.mjs +433 -0
- package/cli/engine/design-system.mjs +20 -736
- package/cli/engine/engines/regex/detect-text-matchers.mjs +371 -0
- package/cli/engine/engines/regex/detect-text-run.mjs +186 -0
- package/cli/engine/engines/regex/detect-text.mjs +11 -523
- package/cli/engine/engines/static-html/css-cascade-color.mjs +219 -0
- package/cli/engine/engines/static-html/css-cascade-static-data.mjs +138 -0
- package/cli/engine/engines/static-html/css-cascade-static-dom.mjs +132 -0
- package/cli/engine/engines/static-html/css-cascade-static-parse.mjs +393 -0
- package/cli/engine/engines/static-html/css-cascade.mjs +24 -837
- package/cli/lib/monodesign-config-consent.mjs +93 -0
- package/cli/lib/monodesign-config-core.mjs +37 -0
- package/cli/lib/monodesign-config-detection.mjs +133 -0
- package/cli/lib/monodesign-config-filter.mjs +198 -0
- package/cli/lib/monodesign-config-ignore-value.mjs +212 -0
- package/cli/lib/monodesign-config.mjs +21 -623
- package/package.json +2 -2
- package/skill/scripts/context-fields.mjs +65 -0
- package/skill/scripts/context-resolve.mjs +425 -0
- package/skill/scripts/context-update.mjs +151 -0
- package/skill/scripts/context-utils.mjs +68 -0
- package/skill/scripts/context-workspace.mjs +245 -0
- package/skill/scripts/context.mjs +17 -891
- package/skill/scripts/hook-admin-config.mjs +152 -0
- package/skill/scripts/hook-admin-ignore.mjs +131 -0
- package/skill/scripts/hook-admin-manifest.mjs +292 -0
- package/skill/scripts/hook-admin.mjs +8 -541
- package/skill/scripts/hook-lib-cache.mjs +145 -0
- package/skill/scripts/hook-lib-config.mjs +292 -0
- package/skill/scripts/hook-lib-detector.mjs +72 -0
- package/skill/scripts/hook-lib-events.mjs +182 -0
- package/skill/scripts/hook-lib-findings.mjs +201 -0
- package/skill/scripts/hook-lib-ignore.mjs +205 -0
- package/skill/scripts/hook-lib-render.mjs +273 -0
- package/skill/scripts/hook-lib-run.mjs +281 -0
- package/skill/scripts/hook-lib-scan-targets.mjs +128 -0
- package/skill/scripts/hook-lib.mjs +71 -1747
- package/skill/scripts/lib/design-parser-colors.mjs +182 -0
- package/skill/scripts/lib/design-parser-extract.mjs +333 -0
- package/skill/scripts/lib/design-parser-sections.mjs +214 -0
- package/skill/scripts/lib/design-parser-yaml.mjs +135 -0
- package/skill/scripts/lib/design-parser.mjs +10 -783
- package/skill/scripts/live/manual-apply-chunk.mjs +151 -0
- package/skill/scripts/live/manual-apply-compact.mjs +122 -0
- package/skill/scripts/live/manual-apply-evidence.mjs +115 -0
- package/skill/scripts/live/manual-apply-log.mjs +179 -0
- package/skill/scripts/live/manual-apply-transaction.mjs +122 -0
- package/skill/scripts/live/manual-apply.mjs +65 -640
- package/skill/scripts/live/svelte-component-accept.mjs +248 -0
- package/skill/scripts/live/svelte-component-css.mjs +230 -0
- package/skill/scripts/live/svelte-component-markup.mjs +104 -0
- package/skill/scripts/live/svelte-component-scaffold.mjs +118 -0
- package/skill/scripts/live/svelte-component-session.mjs +158 -0
- package/skill/scripts/live/svelte-component.mjs +32 -792
- package/skill/scripts/live-accept-mutate.mjs +152 -0
- package/skill/scripts/live-accept-parse.mjs +370 -0
- package/skill/scripts/live-accept-scrub.mjs +59 -0
- package/skill/scripts/live-accept-search.mjs +58 -0
- package/skill/scripts/live-accept.mjs +15 -631
- package/skill/scripts/live-commit-manual-edits-paths.mjs +27 -0
- package/skill/scripts/live-commit-manual-edits-repair.mjs +166 -0
- package/skill/scripts/live-commit-manual-edits-rollback.mjs +231 -0
- package/skill/scripts/live-commit-manual-edits-utils.mjs +167 -0
- package/skill/scripts/live-commit-manual-edits-verify.mjs +356 -0
- package/skill/scripts/live-commit-manual-edits.mjs +24 -881
- package/skill/scripts/live-copy-edit-agent.mjs +16 -551
- package/skill/scripts/live-copy-edit-compact.mjs +137 -0
- package/skill/scripts/live-copy-edit-post-apply.mjs +175 -0
- package/skill/scripts/live-copy-edit-runners.mjs +297 -0
- package/skill/scripts/live-inject-csp.mjs +132 -0
- package/skill/scripts/live-inject-files.mjs +229 -0
- package/skill/scripts/live-inject-tag.mjs +114 -0
- package/skill/scripts/live-inject.mjs +13 -440
- package/skill/scripts/live-server-poll.mjs +232 -0
- package/skill/scripts/live-server-routes.mjs +449 -0
- package/skill/scripts/live-server-state.mjs +361 -0
- package/skill/scripts/live-server.mjs +10 -946
- package/skill/scripts/live-wrap-css.mjs +132 -0
- package/skill/scripts/live-wrap-manual-edit.mjs +153 -0
- package/skill/scripts/live-wrap-search.mjs +247 -0
- package/skill/scripts/live-wrap.mjs +21 -484
- package/skill/scripts/palette-seeds.mjs +401 -0
- package/skill/scripts/palette.mjs +1 -395
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design-hook consent persistence for monodesign-config.mjs: the recorded
|
|
3
|
+
* per-developer accept/decline decision in config.local.json, and keeping
|
|
4
|
+
* that file out of git via `.git/info/exclude`.
|
|
5
|
+
*
|
|
6
|
+
* Split out of monodesign-config.mjs. See that file for context.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
|
|
9
|
+
import { join, dirname, isAbsolute } from 'node:path';
|
|
10
|
+
import { getConfigPath, getLocalConfigPath, hookSection, safeReadJson } from './monodesign-config-core.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The recorded design-hook decision: 'accepted' | 'declined' | undefined.
|
|
14
|
+
* config.local.json (per-developer) overrides config.json.
|
|
15
|
+
*/
|
|
16
|
+
export function getHookConsent(root) {
|
|
17
|
+
let consent;
|
|
18
|
+
for (const filePath of [getConfigPath(root), getLocalConfigPath(root)]) {
|
|
19
|
+
const hook = hookSection(safeReadJson(filePath));
|
|
20
|
+
if (hook && (hook.consent === 'accepted' || hook.consent === 'declined')) consent = hook.consent;
|
|
21
|
+
}
|
|
22
|
+
return consent;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Persist the per-developer decision to config.local.json, preserving any
|
|
27
|
+
* sibling keys, and ensure the file is gitignored.
|
|
28
|
+
*/
|
|
29
|
+
export function setHookConsent(root, value) {
|
|
30
|
+
const filePath = getLocalConfigPath(root);
|
|
31
|
+
const existing = safeReadJson(filePath) || {};
|
|
32
|
+
const hook = hookSection(existing) || {};
|
|
33
|
+
const next = { ...existing, hook: { ...hook, consent: value } };
|
|
34
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
35
|
+
writeFileSync(filePath, `${JSON.stringify(next, null, 2)}\n`);
|
|
36
|
+
ensureConfigGitExclude(root);
|
|
37
|
+
return filePath;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const EXCLUDE_OPEN = '# monodesign-config-ignore-start';
|
|
41
|
+
const EXCLUDE_CLOSE = '# monodesign-config-ignore-end';
|
|
42
|
+
const EXCLUDE_PATTERNS = ['.monodesign/config.local.json'];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Add config.local.json to `.git/info/exclude` so a developer's decision is
|
|
46
|
+
* never committed. Idempotent via marker comments. Best-effort; returns false
|
|
47
|
+
* when there is no resolvable git dir.
|
|
48
|
+
*/
|
|
49
|
+
export function ensureConfigGitExclude(root) {
|
|
50
|
+
try {
|
|
51
|
+
const gitDir = resolveGitDir(root);
|
|
52
|
+
if (!gitDir) return false;
|
|
53
|
+
const target = join(gitDir, 'info', 'exclude');
|
|
54
|
+
const existing = existsSync(target) ? readFileSync(target, 'utf-8') : '';
|
|
55
|
+
const block = [EXCLUDE_OPEN, ...EXCLUDE_PATTERNS, EXCLUDE_CLOSE].join('\n');
|
|
56
|
+
const markerRe = new RegExp(`${escapeRegExp(EXCLUDE_OPEN)}[\\s\\S]*?${escapeRegExp(EXCLUDE_CLOSE)}`);
|
|
57
|
+
let updated;
|
|
58
|
+
if (markerRe.test(existing)) {
|
|
59
|
+
updated = existing.replace(markerRe, block);
|
|
60
|
+
} else {
|
|
61
|
+
const prefix = existing.length === 0 ? '' : existing.endsWith('\n') ? existing : `${existing}\n`;
|
|
62
|
+
updated = `${prefix}${block}\n`;
|
|
63
|
+
}
|
|
64
|
+
if (updated !== existing) {
|
|
65
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
66
|
+
writeFileSync(target, updated);
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveGitDir(root) {
|
|
75
|
+
const dotGit = join(root, '.git');
|
|
76
|
+
if (!existsSync(dotGit)) return null;
|
|
77
|
+
try {
|
|
78
|
+
if (statSync(dotGit).isDirectory()) return dotGit;
|
|
79
|
+
// A `.git` file (worktree/submodule) points elsewhere: "gitdir: <path>".
|
|
80
|
+
const match = readFileSync(dotGit, 'utf-8').match(/gitdir:\s*(.+)/);
|
|
81
|
+
if (match) {
|
|
82
|
+
const resolved = match[1].trim();
|
|
83
|
+
return isAbsolute(resolved) ? resolved : join(root, resolved);
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
/* fall through */
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function escapeRegExp(value) {
|
|
92
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
93
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config-file path layout and raw JSON section readers shared by the
|
|
3
|
+
* monodesign-config.mjs sibling modules.
|
|
4
|
+
*
|
|
5
|
+
* Split out of monodesign-config.mjs. See that file for context.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
export function getConfigPath(root) {
|
|
11
|
+
return join(root, '.monodesign', 'config.json');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getLocalConfigPath(root) {
|
|
15
|
+
return join(root, '.monodesign', 'config.local.json');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function safeReadJson(filePath) {
|
|
19
|
+
try {
|
|
20
|
+
const raw = JSON.parse(readFileSync(filePath, 'utf-8'));
|
|
21
|
+
return raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function hookSection(raw) {
|
|
28
|
+
return raw?.hook && typeof raw.hook === 'object' && !Array.isArray(raw.hook) ? raw.hook : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function detectorSection(raw) {
|
|
32
|
+
return raw?.detector && typeof raw.detector === 'object' && !Array.isArray(raw.detector) ? raw.detector : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function uniqueStrings(values) {
|
|
36
|
+
return Array.from(new Set(values.map(String)));
|
|
37
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading and writing the detector-filter subtree (`detector.*`, with
|
|
3
|
+
* back-compat fallback to legacy `hook.*`) of the unified `.monodesign`
|
|
4
|
+
* config for monodesign-config.mjs.
|
|
5
|
+
*
|
|
6
|
+
* Split out of monodesign-config.mjs. See that file for context.
|
|
7
|
+
*/
|
|
8
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { dirname } from 'node:path';
|
|
10
|
+
import { detectorSection, getConfigPath, getLocalConfigPath, hookSection, safeReadJson, uniqueStrings } from './monodesign-config-core.mjs';
|
|
11
|
+
import { mergeIgnoreValues, normalizeIgnoreRule, normalizeIgnoreValueEntries } from './monodesign-config-ignore-value.mjs';
|
|
12
|
+
import { ensureConfigGitExclude } from './monodesign-config-consent.mjs';
|
|
13
|
+
|
|
14
|
+
const DETECTOR_CONFIG_KEYS = new Set(['ignoreRules', 'ignoreFiles', 'ignoreValues', 'designSystem']);
|
|
15
|
+
|
|
16
|
+
const DEFAULT_DETECTION_CONFIG = Object.freeze({
|
|
17
|
+
ignoreRules: [],
|
|
18
|
+
ignoreFiles: [],
|
|
19
|
+
ignoreValues: [],
|
|
20
|
+
designSystem: { enabled: true },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function cloneDetectionConfig() {
|
|
24
|
+
return {
|
|
25
|
+
ignoreRules: [],
|
|
26
|
+
ignoreFiles: [],
|
|
27
|
+
ignoreValues: [],
|
|
28
|
+
designSystem: { ...DEFAULT_DETECTION_CONFIG.designSystem },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cloneRawDetectionConfig() {
|
|
33
|
+
return {
|
|
34
|
+
ignoreRules: [],
|
|
35
|
+
ignoreFiles: [],
|
|
36
|
+
ignoreValues: [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function applyDetectionConfigSource(config, raw) {
|
|
41
|
+
if (!raw || typeof raw !== 'object') return config;
|
|
42
|
+
if (raw.designSystem && typeof raw.designSystem === 'object' && !Array.isArray(raw.designSystem)) {
|
|
43
|
+
config.designSystem = {
|
|
44
|
+
...config.designSystem,
|
|
45
|
+
enabled: raw.designSystem.enabled !== false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(raw.ignoreRules)) {
|
|
49
|
+
config.ignoreRules = uniqueStrings([...config.ignoreRules, ...raw.ignoreRules]);
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(raw.ignoreFiles)) {
|
|
52
|
+
config.ignoreFiles = uniqueStrings([...config.ignoreFiles, ...raw.ignoreFiles]);
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(raw.ignoreValues)) {
|
|
55
|
+
config.ignoreValues = mergeIgnoreValues(config.ignoreValues, raw.ignoreValues);
|
|
56
|
+
}
|
|
57
|
+
return config;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Detector filters shared by `monomind design detect` and the design hook.
|
|
62
|
+
* `hook.enabled` remains hook lifecycle state; manual CLI scans still run when
|
|
63
|
+
* the hook is disabled, but they honor the same ignore rules and design-system
|
|
64
|
+
* toggle.
|
|
65
|
+
*/
|
|
66
|
+
export function readDetectionConfig(root) {
|
|
67
|
+
const config = cloneDetectionConfig();
|
|
68
|
+
for (const filePath of [getConfigPath(root), getLocalConfigPath(root)]) {
|
|
69
|
+
const raw = safeReadJson(filePath);
|
|
70
|
+
// Back-compat: old builds stored detector filters under hook.*.
|
|
71
|
+
applyDetectionConfigSource(config, hookSection(raw));
|
|
72
|
+
applyDetectionConfigSource(config, detectorSection(raw));
|
|
73
|
+
}
|
|
74
|
+
return config;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function readRawDetectionConfig(root, opts = {}) {
|
|
78
|
+
const raw = safeReadJson(opts.local ? getLocalConfigPath(root) : getConfigPath(root));
|
|
79
|
+
const config = cloneRawDetectionConfig();
|
|
80
|
+
applyDetectionConfigSource(config, hookSection(raw));
|
|
81
|
+
applyDetectionConfigSource(config, detectorSection(raw));
|
|
82
|
+
return config;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function writeDetectionConfig(root, detectorConfig, opts = {}) {
|
|
86
|
+
const filePath = opts.local ? getLocalConfigPath(root) : getConfigPath(root);
|
|
87
|
+
if (opts.local) ensureConfigGitExclude(root);
|
|
88
|
+
const existing = safeReadJson(filePath) || {};
|
|
89
|
+
const existingHook = hookSection(existing);
|
|
90
|
+
const nextHook = stripDetectorKeys(existingHook);
|
|
91
|
+
const nextDetector = {
|
|
92
|
+
...(detectorSection(existing) || {}),
|
|
93
|
+
...normalizeDetectionConfigForWrite(detectorConfig),
|
|
94
|
+
};
|
|
95
|
+
const next = {
|
|
96
|
+
...existing,
|
|
97
|
+
detector: nextDetector,
|
|
98
|
+
};
|
|
99
|
+
if (nextHook && Object.keys(nextHook).length > 0) {
|
|
100
|
+
next.hook = nextHook;
|
|
101
|
+
} else {
|
|
102
|
+
delete next.hook;
|
|
103
|
+
}
|
|
104
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
105
|
+
writeFileSync(filePath, `${JSON.stringify(next, null, 2)}\n`);
|
|
106
|
+
return filePath;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function normalizeDetectionConfigForWrite(config) {
|
|
110
|
+
const out = {};
|
|
111
|
+
if (Array.isArray(config?.ignoreRules)) {
|
|
112
|
+
out.ignoreRules = uniqueStrings(config.ignoreRules.map((rule) => normalizeIgnoreRule(rule)).filter(Boolean));
|
|
113
|
+
}
|
|
114
|
+
if (Array.isArray(config?.ignoreFiles)) {
|
|
115
|
+
out.ignoreFiles = uniqueStrings(config.ignoreFiles.filter(v => typeof v === 'string' && v.trim()).map(v => v.trim()));
|
|
116
|
+
}
|
|
117
|
+
out.ignoreValues = normalizeIgnoreValueEntries(config?.ignoreValues || []);
|
|
118
|
+
if (config?.designSystem && typeof config.designSystem === 'object' && !Array.isArray(config.designSystem)) {
|
|
119
|
+
out.designSystem = {
|
|
120
|
+
enabled: config.designSystem.enabled !== false,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function stripDetectorKeys(raw) {
|
|
127
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
128
|
+
const out = {};
|
|
129
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
130
|
+
if (!DETECTOR_CONFIG_KEYS.has(key)) out[key] = value;
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detection findings/ignore-file filtering for monodesign-config.mjs: glob
|
|
3
|
+
* matching against `detector.ignoreFiles`, and matching findings against
|
|
4
|
+
* `detector.ignoreValues` entries (including scoped-to-file wildcards).
|
|
5
|
+
*
|
|
6
|
+
* Split out of monodesign-config.mjs. See that file for context.
|
|
7
|
+
*/
|
|
8
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
9
|
+
import {
|
|
10
|
+
ignoreValueMatches,
|
|
11
|
+
normalizeIgnoreRule,
|
|
12
|
+
normalizeIgnoreValue,
|
|
13
|
+
normalizeIgnoreValueEntries,
|
|
14
|
+
} from './monodesign-config-ignore-value.mjs';
|
|
15
|
+
|
|
16
|
+
// Glob -> RegExp. Supports `**`, `*`, `?`, and `{a,b}` alternation.
|
|
17
|
+
function globToRegex(glob) {
|
|
18
|
+
let re = '^';
|
|
19
|
+
let i = 0;
|
|
20
|
+
while (i < glob.length) {
|
|
21
|
+
const c = glob[i];
|
|
22
|
+
if (c === '*') {
|
|
23
|
+
if (glob[i + 1] === '*') {
|
|
24
|
+
re += '.*';
|
|
25
|
+
i += 2;
|
|
26
|
+
if (glob[i] === '/') i += 1;
|
|
27
|
+
} else {
|
|
28
|
+
re += '[^/]*';
|
|
29
|
+
i += 1;
|
|
30
|
+
}
|
|
31
|
+
} else if (c === '?') {
|
|
32
|
+
re += '[^/]';
|
|
33
|
+
i += 1;
|
|
34
|
+
} else if (c === '{') {
|
|
35
|
+
const end = glob.indexOf('}', i);
|
|
36
|
+
if (end === -1) { re += '\\{'; i += 1; continue; }
|
|
37
|
+
const parts = glob.slice(i + 1, end).split(',').map((p) => p.replace(/[.+^$()|[\]\\]/g, '\\$&'));
|
|
38
|
+
re += `(?:${parts.join('|')})`;
|
|
39
|
+
i = end + 1;
|
|
40
|
+
} else if (/[.+^$()|[\]\\]/.test(c)) {
|
|
41
|
+
re += `\\${c}`;
|
|
42
|
+
i += 1;
|
|
43
|
+
} else {
|
|
44
|
+
re += c;
|
|
45
|
+
i += 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
re += '$';
|
|
49
|
+
return new RegExp(re);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function matchesAnyGlob(filePath, globs) {
|
|
53
|
+
if (!Array.isArray(globs) || globs.length === 0) return false;
|
|
54
|
+
const normalized = String(filePath || '').split(sep).join('/');
|
|
55
|
+
for (const glob of globs) {
|
|
56
|
+
try {
|
|
57
|
+
const re = globToRegex(String(glob));
|
|
58
|
+
if (re.test(normalized)) return true;
|
|
59
|
+
const base = normalized.split('/').pop();
|
|
60
|
+
if (re.test(base)) return true;
|
|
61
|
+
} catch {
|
|
62
|
+
/* malformed glob, skip */
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function shouldIgnoreDetectionFile(filePath, root, config) {
|
|
69
|
+
const globs = config?.ignoreFiles || [];
|
|
70
|
+
if (!Array.isArray(globs) || globs.length === 0) return false;
|
|
71
|
+
const raw = String(filePath || '').trim();
|
|
72
|
+
if (!raw) return false;
|
|
73
|
+
if (matchesAnyGlob(raw, globs)) return true;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const abs = isAbsolute(raw) ? raw : resolve(root, raw);
|
|
77
|
+
if (matchesAnyGlob(abs, globs)) return true;
|
|
78
|
+
const rel = relative(root, abs);
|
|
79
|
+
if (rel && !rel.startsWith('..') && !isAbsolute(rel)) {
|
|
80
|
+
return matchesAnyGlob(rel, globs);
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
/* ignore */
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function filterDetectionFindings(findings, config) {
|
|
89
|
+
if (!Array.isArray(findings) || findings.length === 0) return [];
|
|
90
|
+
const ignoreRules = new Set((config?.ignoreRules || []).map((rule) => normalizeIgnoreRule(rule)));
|
|
91
|
+
const ignoreValues = normalizeIgnoreValueEntries(config?.ignoreValues || []);
|
|
92
|
+
return findings.filter((finding) => {
|
|
93
|
+
if (!finding || typeof finding !== 'object') return false;
|
|
94
|
+
if (ignoreRules.has(normalizeIgnoreRule(finding.antipattern))) return false;
|
|
95
|
+
if (isIgnoredFindingValue(finding, ignoreValues)) return false;
|
|
96
|
+
return true;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isIgnoredFindingValue(finding, ignoreValues) {
|
|
101
|
+
if (!Array.isArray(ignoreValues) || ignoreValues.length === 0) return false;
|
|
102
|
+
const rule = normalizeIgnoreRule(finding.antipattern);
|
|
103
|
+
if (!rule) return false;
|
|
104
|
+
// File-scoped wildcards suppress rules with no extractable value, such as side-tab.
|
|
105
|
+
const value = extractFindingIgnoreValue(finding);
|
|
106
|
+
return ignoreValues.some((entry) => {
|
|
107
|
+
if (entry.rule !== rule) return false;
|
|
108
|
+
const wildcardValue = entry.value === '*';
|
|
109
|
+
if (!wildcardValue && (!value || !ignoreValueMatches(rule, entry.value, value))) return false;
|
|
110
|
+
if (!Array.isArray(entry.files) || entry.files.length === 0) return !wildcardValue;
|
|
111
|
+
return findingMatchesScopedIgnoreFile(finding, entry.files);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function findingMatchesScopedIgnoreFile(finding, globs) {
|
|
116
|
+
const filePath = String(finding?.file || '').trim();
|
|
117
|
+
if (!filePath) return false;
|
|
118
|
+
if (matchesAnyGlob(filePath, globs)) return true;
|
|
119
|
+
|
|
120
|
+
const normalized = filePath.split(sep).join('/');
|
|
121
|
+
const parts = normalized.split('/').filter(Boolean);
|
|
122
|
+
for (let i = 0; i < parts.length; i++) {
|
|
123
|
+
const suffix = parts.slice(i).join('/');
|
|
124
|
+
if (matchesAnyGlob(suffix, globs)) return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function extractFindingIgnoreValue(finding) {
|
|
130
|
+
if (!finding || typeof finding !== 'object') return '';
|
|
131
|
+
const rule = normalizeIgnoreRule(finding.antipattern);
|
|
132
|
+
const directValueRules = new Set([
|
|
133
|
+
'overused-font',
|
|
134
|
+
'bounce-easing',
|
|
135
|
+
'design-system-font',
|
|
136
|
+
'design-system-color',
|
|
137
|
+
'design-system-radius',
|
|
138
|
+
]);
|
|
139
|
+
if (!directValueRules.has(rule)) return '';
|
|
140
|
+
return normalizeIgnoreValue(extractFindingIgnoreValueRaw(finding, rule));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function extractFindingIgnoreValueRaw(finding, rule = normalizeIgnoreRule(finding?.antipattern)) {
|
|
144
|
+
const direct = cleanIgnoreValueDisplay(finding.ignoreValue || finding.value || '');
|
|
145
|
+
if (direct) return direct;
|
|
146
|
+
|
|
147
|
+
const candidates = [finding.detail, finding.snippet].filter((v) => typeof v === 'string' && v);
|
|
148
|
+
for (const text of candidates) {
|
|
149
|
+
if (rule === 'bounce-easing') {
|
|
150
|
+
const motion = extractMotionIgnoreValue(text);
|
|
151
|
+
if (motion) return motion;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const primary = text.match(/Primary font:\s*([^()\n;]+)/i);
|
|
156
|
+
if (primary) return cleanIgnoreValueDisplay(primary[1]);
|
|
157
|
+
|
|
158
|
+
const family = text.match(/font-family\s*:\s*["']?([^'",;\n]+)/i);
|
|
159
|
+
if (family) return cleanIgnoreValueDisplay(family[1]);
|
|
160
|
+
|
|
161
|
+
const google = text.match(/[?&]family=([^&:;\n]+)/i);
|
|
162
|
+
if (google) {
|
|
163
|
+
try {
|
|
164
|
+
return cleanIgnoreValueDisplay(decodeURIComponent(google[1]));
|
|
165
|
+
} catch {
|
|
166
|
+
return cleanIgnoreValueDisplay(google[1]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function extractMotionIgnoreValue(text) {
|
|
175
|
+
const tailwind = text.match(/\banimate-bounce\b/i);
|
|
176
|
+
if (tailwind) return cleanIgnoreValueDisplay(tailwind[0]);
|
|
177
|
+
|
|
178
|
+
const bezier = text.match(/cubic-bezier\([^)]+\)/i);
|
|
179
|
+
if (bezier) return cleanIgnoreValueDisplay(bezier[0]);
|
|
180
|
+
|
|
181
|
+
const animation = text.match(/animation(?:-name)?\s*:\s*([^;\n]+)/i);
|
|
182
|
+
if (animation) {
|
|
183
|
+
const token = animation[1]
|
|
184
|
+
.split(/[,\s]+/)
|
|
185
|
+
.find((part) => /bounce|elastic|wobble|jiggle|spring/i.test(part));
|
|
186
|
+
if (token) return cleanIgnoreValueDisplay(token);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function cleanIgnoreValueDisplay(value) {
|
|
193
|
+
return String(value || '')
|
|
194
|
+
.trim()
|
|
195
|
+
.replace(/^["']|["']$/g, '')
|
|
196
|
+
.replace(/\+/g, ' ')
|
|
197
|
+
.replace(/\s+/g, ' ');
|
|
198
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ignore-value normalization for monodesign-config.mjs: canonicalizing rule
|
|
3
|
+
* ids and finding values (including CSS color parsing, so
|
|
4
|
+
* `design-system-color` ignores match regardless of color-function syntax).
|
|
5
|
+
*
|
|
6
|
+
* Split out of monodesign-config.mjs. See that file for context.
|
|
7
|
+
*/
|
|
8
|
+
import { uniqueStrings } from './monodesign-config-core.mjs';
|
|
9
|
+
|
|
10
|
+
export function normalizeIgnoreValue(value) {
|
|
11
|
+
return String(value || '')
|
|
12
|
+
.trim()
|
|
13
|
+
.replace(/^["']|["']$/g, '')
|
|
14
|
+
.replace(/\+/g, ' ')
|
|
15
|
+
.replace(/\s+/g, ' ')
|
|
16
|
+
.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function normalizeIgnoreRule(rule) {
|
|
20
|
+
return String(rule || '').trim().toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function colorIgnoreKey(value) {
|
|
24
|
+
const color = parseIgnoreColor(value);
|
|
25
|
+
if (!color) return '';
|
|
26
|
+
return `${color.r},${color.g},${color.b},${Math.round(color.a * 255)}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parseIgnoreColor(value) {
|
|
30
|
+
const text = String(value || '').trim().toLowerCase();
|
|
31
|
+
if (!text) return null;
|
|
32
|
+
|
|
33
|
+
const hex = text.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);
|
|
34
|
+
if (hex) return parseHexIgnoreColor(hex[1]);
|
|
35
|
+
|
|
36
|
+
const rgb = text.match(/^rgba?\((.*)\)$/i);
|
|
37
|
+
if (rgb) {
|
|
38
|
+
const parts = splitColorArgs(rgb[1]);
|
|
39
|
+
if (parts.length < 3 || parts.length > 4) return null;
|
|
40
|
+
const r = parseRgbChannel(parts[0]);
|
|
41
|
+
const g = parseRgbChannel(parts[1]);
|
|
42
|
+
const b = parseRgbChannel(parts[2]);
|
|
43
|
+
const a = parts[3] === undefined ? 1 : parseAlphaChannel(parts[3]);
|
|
44
|
+
if ([r, g, b, a].some((v) => v === null)) return null;
|
|
45
|
+
return { r, g, b, a };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const hsl = text.match(/^hsla?\((.*)\)$/i);
|
|
49
|
+
if (hsl) {
|
|
50
|
+
const parts = splitColorArgs(hsl[1]);
|
|
51
|
+
if (parts.length < 3 || parts.length > 4) return null;
|
|
52
|
+
const h = parseHueChannel(parts[0]);
|
|
53
|
+
const s = parsePercentChannel(parts[1]);
|
|
54
|
+
const l = parsePercentChannel(parts[2]);
|
|
55
|
+
const a = parts[3] === undefined ? 1 : parseAlphaChannel(parts[3]);
|
|
56
|
+
if ([h, s, l, a].some((v) => v === null)) return null;
|
|
57
|
+
return hslToRgb(h, s, l, a);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parseHexIgnoreColor(hex) {
|
|
64
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
65
|
+
const r = parseInt(hex[0] + hex[0], 16);
|
|
66
|
+
const g = parseInt(hex[1] + hex[1], 16);
|
|
67
|
+
const b = parseInt(hex[2] + hex[2], 16);
|
|
68
|
+
const a = hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1;
|
|
69
|
+
return { r, g, b, a };
|
|
70
|
+
}
|
|
71
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
72
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
73
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
74
|
+
const a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
|
|
75
|
+
return { r, g, b, a };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function splitColorArgs(body) {
|
|
79
|
+
const text = String(body || '').trim();
|
|
80
|
+
if (!text) return [];
|
|
81
|
+
if (text.includes(',')) {
|
|
82
|
+
const parts = text.split(',').map((part) => part.trim()).filter(Boolean);
|
|
83
|
+
const last = parts[parts.length - 1];
|
|
84
|
+
if (last?.includes('/')) {
|
|
85
|
+
const split = last.split('/').map((part) => part.trim()).filter(Boolean);
|
|
86
|
+
return [...parts.slice(0, -1), ...split];
|
|
87
|
+
}
|
|
88
|
+
return parts;
|
|
89
|
+
}
|
|
90
|
+
return text.replace(/\s*\/\s*/g, ' / ').split(/\s+/).filter((part) => part && part !== '/');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function parseRgbChannel(raw) {
|
|
94
|
+
const text = String(raw || '').trim();
|
|
95
|
+
const match = text.match(/^(-?\d*\.?\d+)(%)?$/);
|
|
96
|
+
if (!match) return null;
|
|
97
|
+
const value = Number.parseFloat(match[1]);
|
|
98
|
+
if (!Number.isFinite(value)) return null;
|
|
99
|
+
const scaled = match[2] ? value * 2.55 : value;
|
|
100
|
+
if (scaled < 0 || scaled > 255) return null;
|
|
101
|
+
return Math.round(scaled);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseAlphaChannel(raw) {
|
|
105
|
+
const text = String(raw || '').trim();
|
|
106
|
+
const match = text.match(/^(-?\d*\.?\d+)(%)?$/);
|
|
107
|
+
if (!match) return null;
|
|
108
|
+
const value = Number.parseFloat(match[1]);
|
|
109
|
+
if (!Number.isFinite(value)) return null;
|
|
110
|
+
const alpha = match[2] ? value / 100 : value;
|
|
111
|
+
return alpha >= 0 && alpha <= 1 ? alpha : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function parseHueChannel(raw) {
|
|
115
|
+
const text = String(raw || '').trim();
|
|
116
|
+
const match = text.match(/^(-?\d*\.?\d+)(deg|rad|turn|grad)?$/);
|
|
117
|
+
if (!match) return null;
|
|
118
|
+
const value = Number.parseFloat(match[1]);
|
|
119
|
+
if (!Number.isFinite(value)) return null;
|
|
120
|
+
const unit = match[2] || 'deg';
|
|
121
|
+
if (unit === 'turn') return value * 360;
|
|
122
|
+
if (unit === 'rad') return value * (180 / Math.PI);
|
|
123
|
+
if (unit === 'grad') return value * 0.9;
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function parsePercentChannel(raw) {
|
|
128
|
+
const text = String(raw || '').trim();
|
|
129
|
+
const match = text.match(/^(-?\d*\.?\d+)%$/);
|
|
130
|
+
if (!match) return null;
|
|
131
|
+
const value = Number.parseFloat(match[1]);
|
|
132
|
+
if (!Number.isFinite(value)) return null;
|
|
133
|
+
return value >= 0 && value <= 100 ? value / 100 : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function hslToRgb(hue, saturation, lightness, alpha) {
|
|
137
|
+
const h = (((hue % 360) + 360) % 360) / 360;
|
|
138
|
+
if (saturation === 0) {
|
|
139
|
+
const gray = clampByte(Math.round(lightness * 255));
|
|
140
|
+
return { r: gray, g: gray, b: gray, a: alpha };
|
|
141
|
+
}
|
|
142
|
+
const q = lightness < 0.5
|
|
143
|
+
? lightness * (1 + saturation)
|
|
144
|
+
: lightness + saturation - lightness * saturation;
|
|
145
|
+
const p = 2 * lightness - q;
|
|
146
|
+
const toRgb = (t) => {
|
|
147
|
+
let channel = t;
|
|
148
|
+
if (channel < 0) channel += 1;
|
|
149
|
+
if (channel > 1) channel -= 1;
|
|
150
|
+
if (channel < 1 / 6) return p + (q - p) * 6 * channel;
|
|
151
|
+
if (channel < 1 / 2) return q;
|
|
152
|
+
if (channel < 2 / 3) return p + (q - p) * (2 / 3 - channel) * 6;
|
|
153
|
+
return p;
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
r: clampByte(Math.round(toRgb(h + 1 / 3) * 255)),
|
|
157
|
+
g: clampByte(Math.round(toRgb(h) * 255)),
|
|
158
|
+
b: clampByte(Math.round(toRgb(h - 1 / 3) * 255)),
|
|
159
|
+
a: alpha,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function clampByte(value) {
|
|
164
|
+
return Math.min(255, Math.max(0, value));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function ignoreValueMatches(rule, entryValue, findingValue) {
|
|
168
|
+
if (entryValue === findingValue) return true;
|
|
169
|
+
if (rule !== 'design-system-color') return false;
|
|
170
|
+
const entryColor = colorIgnoreKey(entryValue);
|
|
171
|
+
return Boolean(entryColor && entryColor === colorIgnoreKey(findingValue));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function normalizeIgnoreValueEntries(entries) {
|
|
175
|
+
if (!Array.isArray(entries)) return [];
|
|
176
|
+
const out = [];
|
|
177
|
+
for (const entry of entries) {
|
|
178
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
179
|
+
const rule = normalizeIgnoreRule(entry.rule);
|
|
180
|
+
const value = normalizeIgnoreValue(entry.value);
|
|
181
|
+
if (!rule || !value) continue;
|
|
182
|
+
const normalized = { rule, value };
|
|
183
|
+
const files = uniqueStrings([
|
|
184
|
+
...(typeof entry.file === 'string' && entry.file.trim() ? [entry.file.trim()] : []),
|
|
185
|
+
...(Array.isArray(entry.files) ? entry.files.filter(v => typeof v === 'string' && v.trim()).map(v => v.trim()) : []),
|
|
186
|
+
]);
|
|
187
|
+
if (files.length > 0) normalized.files = files;
|
|
188
|
+
if (typeof entry.reason === 'string' && entry.reason.trim()) {
|
|
189
|
+
normalized.reason = entry.reason.trim();
|
|
190
|
+
}
|
|
191
|
+
if (typeof entry.createdAt === 'string' && entry.createdAt.trim()) {
|
|
192
|
+
normalized.createdAt = entry.createdAt.trim();
|
|
193
|
+
}
|
|
194
|
+
out.push(normalized);
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function mergeIgnoreValues(existing, incoming) {
|
|
200
|
+
const map = new Map();
|
|
201
|
+
for (const entry of normalizeIgnoreValueEntries(existing)) {
|
|
202
|
+
map.set(`${entry.rule}\0${entry.value}\0${ignoreValueFilesKey(entry.files)}`, entry);
|
|
203
|
+
}
|
|
204
|
+
for (const entry of normalizeIgnoreValueEntries(incoming)) {
|
|
205
|
+
map.set(`${entry.rule}\0${entry.value}\0${ignoreValueFilesKey(entry.files)}`, entry);
|
|
206
|
+
}
|
|
207
|
+
return Array.from(map.values());
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function ignoreValueFilesKey(files) {
|
|
211
|
+
return Array.isArray(files) && files.length > 0 ? files.join('\x1f') : '';
|
|
212
|
+
}
|