@mnemonik/shared 7.119.1 → 7.120.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.
- package/dist/codeScanner.d.ts +87 -18
- package/dist/codeScanner.d.ts.map +1 -1
- package/dist/codeScanner.js +229 -74
- package/dist/codeScanner.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/indexClassifier.d.ts +178 -0
- package/dist/indexClassifier.d.ts.map +1 -0
- package/dist/indexClassifier.js +585 -0
- package/dist/indexClassifier.js.map +1 -0
- package/dist/indexJudge.d.ts +50 -0
- package/dist/indexJudge.d.ts.map +1 -0
- package/dist/indexJudge.js +116 -0
- package/dist/indexJudge.js.map +1 -0
- package/package.json +1 -1
- package/src/codeScanner.ts +305 -81
- package/src/index.ts +34 -0
- package/src/indexClassifier.ts +681 -0
- package/src/indexJudge.ts +149 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Judge a stored or pushed path the way the daemon judged it, from the rules
|
|
3
|
+
* the daemon uploaded (`projects.scanner_ignore_patterns`).
|
|
4
|
+
*
|
|
5
|
+
* The daemon walks the disk with every rule file in front of it. The server
|
|
6
|
+
* never sees the disk; it has the root .gitignore / .mnemonikignore lines (the
|
|
7
|
+
* privacy list) plus the tagged nested-ignore and .gitattributes lines the
|
|
8
|
+
* daemon uploads beside them (`indexClassifier.ts`, "Rule upload"). This
|
|
9
|
+
* module rebuilds the same precedence from those lines so the /scan/push
|
|
10
|
+
* backstop, file_push, the dropped-path marker bookkeeping and retirement all
|
|
11
|
+
* reach the daemon's answer:
|
|
12
|
+
*
|
|
13
|
+
* hard built-in directories, secret files, the root ignore patterns
|
|
14
|
+
* (makeIgnoreMatcher - unchanged, never overridable), and a nested
|
|
15
|
+
* ignore file that ignores the path;
|
|
16
|
+
* soft classifyForIndex: `!pattern` and .gitattributes overrides, then the
|
|
17
|
+
* soft defaults - path rules always, content rules when content is
|
|
18
|
+
* supplied.
|
|
19
|
+
*/
|
|
20
|
+
import ignore from 'ignore';
|
|
21
|
+
import { AUTHORITY_FILE_MATCHERS, makeIgnoreMatcher } from './codeScanner.js';
|
|
22
|
+
import { classifyForIndex, decodeIndexRules, parseGitattributes, softDefaultForContent, } from './indexClassifier.js';
|
|
23
|
+
function compile(lines) {
|
|
24
|
+
const cleaned = lines.filter((line) => typeof line === 'string' && line.trim().length > 0);
|
|
25
|
+
if (cleaned.length === 0)
|
|
26
|
+
return null;
|
|
27
|
+
try {
|
|
28
|
+
return ignore().add([...cleaned]);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Deepest layer with an opinion wins, as CodeScanner's walk resolves it. */
|
|
35
|
+
function verdictFor(path, layers) {
|
|
36
|
+
for (let i = layers.length - 1; i >= 0; i--) {
|
|
37
|
+
const layer = layers[i];
|
|
38
|
+
if (!layer)
|
|
39
|
+
continue;
|
|
40
|
+
let sub;
|
|
41
|
+
if (layer.baseRel === '')
|
|
42
|
+
sub = path;
|
|
43
|
+
else if (path.startsWith(`${layer.baseRel}/`))
|
|
44
|
+
sub = path.slice(layer.baseRel.length + 1);
|
|
45
|
+
else
|
|
46
|
+
continue;
|
|
47
|
+
try {
|
|
48
|
+
const res = layer.ig.test(sub);
|
|
49
|
+
if (res.ignored)
|
|
50
|
+
return 'ignored';
|
|
51
|
+
if (res.unignored)
|
|
52
|
+
return 'unignored';
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// `ignore` throws on paths it considers invalid; such a path has no verdict.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return 'unmatched';
|
|
59
|
+
}
|
|
60
|
+
const depth = (baseRel) => (baseRel === '' ? 0 : baseRel.split('/').length);
|
|
61
|
+
export function makeIndexJudge(storedPatterns = []) {
|
|
62
|
+
const rules = decodeIndexRules(storedPatterns);
|
|
63
|
+
// The privacy net is exactly what it was: root patterns, built-in dirs, secrets.
|
|
64
|
+
const isHardIgnored = makeIgnoreMatcher(rules.rootIgnore);
|
|
65
|
+
const layers = [];
|
|
66
|
+
const root = compile(rules.rootIgnore);
|
|
67
|
+
if (root)
|
|
68
|
+
layers.push({ baseRel: '', ig: root });
|
|
69
|
+
const nested = [...rules.nestedIgnore.entries()].sort(([a], [b]) => depth(a) - depth(b));
|
|
70
|
+
for (const [baseRel, lines] of nested) {
|
|
71
|
+
const ig = compile(lines);
|
|
72
|
+
if (ig)
|
|
73
|
+
layers.push({ baseRel, ig });
|
|
74
|
+
}
|
|
75
|
+
const attributes = [...rules.attributes.entries()].map(([baseRel, lines]) => ({ baseRel, rules: parseGitattributes(lines.join('\n')) }));
|
|
76
|
+
const judgePath = (relPath) => {
|
|
77
|
+
const path = relPath.replace(/\\/g, '/');
|
|
78
|
+
if (!path)
|
|
79
|
+
return { excluded: false };
|
|
80
|
+
if (isHardIgnored(path))
|
|
81
|
+
return { excluded: true, kind: 'hard', rule: 'ignore rule' };
|
|
82
|
+
const verdict = verdictFor(path, layers);
|
|
83
|
+
if (verdict === 'ignored') {
|
|
84
|
+
return { excluded: true, kind: 'hard', rule: 'nested ignore file' };
|
|
85
|
+
}
|
|
86
|
+
if (AUTHORITY_FILE_MATCHERS.some((matches) => matches(path))) {
|
|
87
|
+
return { excluded: false, override: 'authority' };
|
|
88
|
+
}
|
|
89
|
+
const classification = classifyForIndex(path, {
|
|
90
|
+
ignoreFileVerdict: verdict,
|
|
91
|
+
attributes,
|
|
92
|
+
});
|
|
93
|
+
if (!classification.include) {
|
|
94
|
+
return {
|
|
95
|
+
excluded: true,
|
|
96
|
+
kind: 'soft',
|
|
97
|
+
reason: classification.reason,
|
|
98
|
+
rule: classification.rule,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return classification.override
|
|
102
|
+
? { excluded: false, override: classification.override }
|
|
103
|
+
: { excluded: false };
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
judgePath,
|
|
107
|
+
judge(relPath, content) {
|
|
108
|
+
const byPath = judgePath(relPath);
|
|
109
|
+
if (byPath.excluded || byPath.override || content === undefined)
|
|
110
|
+
return byPath;
|
|
111
|
+
const byContent = softDefaultForContent(relPath, content);
|
|
112
|
+
return byContent ? { excluded: true, kind: 'soft', ...byContent } : byPath;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=indexJudge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexJudge.js","sourceRoot":"","sources":["../src/indexJudge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,MAAuB,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,GAItB,MAAM,sBAAsB,CAAC;AA+B9B,SAAS,OAAO,CAAC,KAAwB;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3F,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,6EAA6E;AAC7E,SAAS,UAAU,CAAC,IAAY,EAAE,MAA8B;IAC9D,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAA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