@angular-modernizer/adapter-mcp 1.2.0 → 2.0.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/CHANGELOG.md +662 -0
- package/README.md +84 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -0
- package/dist/scan-host/scan-host.d.ts +7 -0
- package/dist/scan-host/scan-host.js +73 -10
- package/dist/scan-host/scan-protocol.d.ts +2 -0
- package/dist/scan-host/scan-worker.js +14 -8
- package/dist/server/limited-stdio-transport.d.ts +6 -3
- package/dist/server/limited-stdio-transport.js +26 -9
- package/dist/server/mcp-server.js +1 -1
- package/dist/server/sdk-server.d.ts +14 -3
- package/dist/server/sdk-server.js +54 -6
- package/dist/server/tool-registry.d.ts +3 -1
- package/dist/server/tool-registry.js +8 -3
- package/dist/streaming/progress-store.d.ts +19 -7
- package/dist/streaming/progress-store.js +19 -8
- package/dist/tools/analyze-build-impact.d.ts +7 -4
- package/dist/tools/analyze-build-impact.js +8 -3
- package/dist/tools/analyze-core-to-shared.d.ts +10 -6
- package/dist/tools/analyze-core-to-shared.js +63 -60
- package/dist/tools/analyze-parser-performance.d.ts +57 -13
- package/dist/tools/analyze-parser-performance.js +67 -6
- package/dist/tools/analyze-project.d.ts +30 -4
- package/dist/tools/analyze-project.js +99 -15
- package/dist/tools/check-incremental-compatibility.d.ts +30 -41
- package/dist/tools/check-incremental-compatibility.js +32 -264
- package/dist/tools/collect-feedback.js +15 -2
- package/dist/tools/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.js +3 -2
- package/dist/tools/find-component-hosts.js +3 -2
- package/dist/tools/find-usages.js +21 -12
- package/dist/tools/get-call-graph.js +15 -2
- package/dist/tools/get-operation-progress-tool.d.ts +1 -1
- package/dist/tools/get-operation-progress-tool.js +2 -2
- package/dist/tools/get-operation-progress.d.ts +4 -1
- package/dist/tools/get-operation-progress.js +6 -2
- package/dist/tools/helpers/analysis-output.d.ts +32 -1
- package/dist/tools/helpers/analysis-output.js +22 -1
- package/dist/tools/helpers/build-cache.d.ts +27 -0
- package/dist/tools/helpers/build-cache.js +86 -0
- package/dist/tools/helpers/class-filter.d.ts +18 -0
- package/dist/tools/helpers/class-filter.js +30 -0
- package/dist/tools/helpers/cli-arguments.d.ts +23 -0
- package/dist/tools/helpers/cli-arguments.js +35 -0
- package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
- package/dist/tools/helpers/feedback-catalog.js +196 -0
- package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
- package/dist/tools/helpers/feedback-sidecar.js +381 -0
- package/dist/tools/helpers/file-type-check.d.ts +34 -0
- package/dist/tools/helpers/file-type-check.js +56 -0
- package/dist/tools/helpers/output-contract.d.ts +42 -0
- package/dist/tools/helpers/output-contract.js +54 -0
- package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
- package/dist/tools/helpers/pattern-anonymizer.js +159 -0
- package/dist/tools/helpers/project-cache.d.ts +5 -4
- package/dist/tools/helpers/project-cache.js +21 -16
- package/dist/tools/helpers/project-decorators.d.ts +11 -4
- package/dist/tools/helpers/project-decorators.js +13 -6
- package/dist/tools/helpers/refresh-apply.d.ts +94 -0
- package/dist/tools/helpers/refresh-apply.js +460 -0
- package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
- package/dist/tools/helpers/refresh-inventory.js +610 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +74 -5
- package/dist/tools/helpers/scan-cache.js +134 -6
- package/dist/tools/helpers/scan-engine.d.ts +30 -6
- package/dist/tools/helpers/scan-engine.js +131 -22
- package/dist/tools/helpers/scan-plan.js +16 -2
- package/dist/tools/helpers/source-map-loader.d.ts +55 -0
- package/dist/tools/helpers/source-map-loader.js +226 -0
- package/dist/tools/helpers/template-check.d.ts +76 -0
- package/dist/tools/helpers/template-check.js +158 -0
- package/dist/tools/helpers/tool-cache.d.ts +7 -2
- package/dist/tools/helpers/tool-cache.js +9 -3
- package/dist/tools/helpers/tool-context.d.ts +18 -0
- package/dist/tools/helpers/tool-context.js +29 -0
- package/dist/tools/helpers/transform-safety.d.ts +151 -1
- package/dist/tools/helpers/transform-safety.js +357 -4
- package/dist/tools/inspect-form-group.js +5 -0
- package/dist/tools/inspect-i18n.d.ts +1 -1
- package/dist/tools/inspect-template.js +8 -2
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/orchestrate-migration.d.ts +19 -1
- package/dist/tools/orchestrate-migration.js +52 -10
- package/dist/tools/parse-stack-trace.d.ts +48 -1
- package/dist/tools/parse-stack-trace.js +108 -9
- package/dist/tools/plan-migration.js +22 -10
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.js +10 -3
- package/dist/tools/review-feedback.d.ts +42 -7
- package/dist/tools/review-feedback.js +24 -17
- package/dist/tools/rollback-changes.d.ts +5 -0
- package/dist/tools/rollback-changes.js +7 -2
- package/dist/tools/run-angular-cli.js +36 -22
- package/dist/tools/run-build.d.ts +33 -28
- package/dist/tools/run-build.js +136 -438
- package/dist/tools/run-schematic.d.ts +8 -2
- package/dist/tools/run-schematic.js +80 -50
- package/dist/tools/scan-all.d.ts +31 -15
- package/dist/tools/scan-all.js +75 -109
- package/dist/tools/scan-angular.d.ts +27 -14
- package/dist/tools/scan-angular.js +70 -92
- package/dist/tools/scan-architecture.d.ts +29 -12
- package/dist/tools/scan-architecture.js +205 -135
- package/dist/tools/scan-solid.d.ts +27 -14
- package/dist/tools/scan-solid.js +73 -89
- package/dist/tools/search-codebase.d.ts +6 -1
- package/dist/tools/search-codebase.js +13 -7
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.js +3 -2
- package/dist/tools/transform-code-batch.d.ts +9 -9
- package/dist/tools/transform-code.d.ts +161 -12
- package/dist/tools/transform-code.js +715 -206
- package/dist/tools/validate-before-transform.js +2 -1
- package/dist/tools/validate-project-compatibility.d.ts +28 -55
- package/dist/tools/validate-project-compatibility.js +33 -225
- package/dist/tools/validate-transformation.d.ts +40 -26
- package/dist/tools/validate-transformation.js +115 -294
- package/dist/tools/verify-citations.js +8 -2
- package/dist/types.d.ts +9 -9
- package/dist/utils/format-tool-response.d.ts +3 -1
- package/dist/utils/format-tool-response.js +8 -3
- package/package.json +14 -13
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply side of refresh-state: plans that a report hands out and the removal of planned items. An item is removed
|
|
3
|
+
* only while a fresh inventory (with the retention of the report) still lists it for the same reason and it is
|
|
4
|
+
* unchanged since the report: a cache entry or file keeps its size and mtime (a folder: bytes, file count, newest
|
|
5
|
+
* mtime) and its real path is itself below the folder of its store; a backup group keeps the same files with the
|
|
6
|
+
* same sizes and mtimes, and exactly those files go; a snapshot ref still points at the commit of the report, which
|
|
7
|
+
* git checks on deletion (`update-ref -d <ref> <old>`). Symbolic links are never followed and never removed. Feedback
|
|
8
|
+
* items are never removed: their session file keeps its SHA-256 of the report, and its marks go into the sidecar
|
|
9
|
+
* (`feedback-sidecar.ts`); session files are only read.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
12
|
+
import { lstatSync, readFileSync, readdirSync, realpathSync, rmSync, unlinkSync, } from 'node:fs';
|
|
13
|
+
import { dirname, join, sep } from 'node:path';
|
|
14
|
+
import { BACKUP_DIR, CACHE_DIR, FEEDBACK_DIR, LEGACY_STORE_DIR, backupGroupMembers, runGit, } from './refresh-inventory.js';
|
|
15
|
+
import { writeFeedbackMarks } from './feedback-sidecar.js';
|
|
16
|
+
/** Time a plan stays valid after its report. */
|
|
17
|
+
export const PLAN_TTL_MS = 10 * 60 * 1000;
|
|
18
|
+
/** Plans kept at a time; the oldest goes first. */
|
|
19
|
+
const MAX_PLANS = 20;
|
|
20
|
+
/** Every part apply accepts. */
|
|
21
|
+
export const REFRESH_PARTS = ['caches', 'backups', 'refs', 'feedback'];
|
|
22
|
+
/** Stores and reasons each part removes. */
|
|
23
|
+
const PART_SCOPE = {
|
|
24
|
+
caches: {
|
|
25
|
+
stores: ['scan-cache', 'legacy-cache'],
|
|
26
|
+
reasons: ['orphan', 'expired', 'unreadable', 'legacy-layout', 'legacy-store'],
|
|
27
|
+
},
|
|
28
|
+
backups: {
|
|
29
|
+
stores: ['backups'],
|
|
30
|
+
reasons: ['retention', 'missing-metadata'],
|
|
31
|
+
},
|
|
32
|
+
refs: {
|
|
33
|
+
stores: ['snapshot-refs'],
|
|
34
|
+
reasons: ['retention', 'ref-without-backup'],
|
|
35
|
+
},
|
|
36
|
+
feedback: {
|
|
37
|
+
stores: ['feedback'],
|
|
38
|
+
reasons: ['duplicate-records', 'outdated-records'],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
/** Folders below the project root that the caches part may remove from. */
|
|
42
|
+
const CACHE_ROOTS = [CACHE_DIR, LEGACY_STORE_DIR];
|
|
43
|
+
/** Plans of one tool instance, kept in memory only. */
|
|
44
|
+
export class RefreshPlans {
|
|
45
|
+
now;
|
|
46
|
+
git;
|
|
47
|
+
plans = new Map();
|
|
48
|
+
/**
|
|
49
|
+
* @param now clock
|
|
50
|
+
* @param git git runner (snapshot refs are read and deleted through it)
|
|
51
|
+
*/
|
|
52
|
+
constructor(now, git = runGit) {
|
|
53
|
+
this.now = now;
|
|
54
|
+
this.git = git;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Records the items of a report with their fingerprints and the retention the report used.
|
|
58
|
+
*
|
|
59
|
+
* @param projectRoot real path of the project root
|
|
60
|
+
* @returns the plan id and when it expires (ms)
|
|
61
|
+
*/
|
|
62
|
+
create(projectRoot, items, retention) {
|
|
63
|
+
const now = this.now();
|
|
64
|
+
for (const [id, plan] of this.plans) {
|
|
65
|
+
if (plan.expiresAt <= now) {
|
|
66
|
+
this.plans.delete(id);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
while (this.plans.size >= MAX_PLANS) {
|
|
70
|
+
const oldest = this.plans.keys().next().value;
|
|
71
|
+
if (oldest === undefined) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
this.plans.delete(oldest);
|
|
75
|
+
}
|
|
76
|
+
const planned = [];
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
if (inAnyPart(item)) {
|
|
79
|
+
planned.push(this.plan(projectRoot, item));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const planId = randomUUID();
|
|
83
|
+
const expiresAt = now + PLAN_TTL_MS;
|
|
84
|
+
this.plans.set(planId, { projectRoot, retention: { ...retention }, expiresAt, items: planned });
|
|
85
|
+
return { planId, expiresAt };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Removes the planned items of `parts` that a fresh inventory still lists and that are unchanged. The inventory
|
|
89
|
+
* runs with the retention of the report. The plan is used up by the call, whatever the outcome.
|
|
90
|
+
*
|
|
91
|
+
* @param projectRoot real path of the project root
|
|
92
|
+
* @throws when the plan is unknown, expired or belongs to another project
|
|
93
|
+
*/
|
|
94
|
+
apply(planId, projectRoot, parts, inventory, tools) {
|
|
95
|
+
const plan = this.plans.get(planId);
|
|
96
|
+
if (plan === undefined) {
|
|
97
|
+
throw new Error(`Unknown planId ${planId}: run refresh-state with mode 'report' and pass the planId of that report`);
|
|
98
|
+
}
|
|
99
|
+
this.plans.delete(planId);
|
|
100
|
+
if (plan.expiresAt <= this.now()) {
|
|
101
|
+
throw new Error(`planId ${planId} expired (plans are valid for ${PLAN_TTL_MS / 60000} minutes): run a new report`);
|
|
102
|
+
}
|
|
103
|
+
if (plan.projectRoot !== projectRoot) {
|
|
104
|
+
throw new Error(`planId ${planId} belongs to ${plan.projectRoot}, not to ${projectRoot}`);
|
|
105
|
+
}
|
|
106
|
+
const listed = new Set(inventory(plan.retention).map(key));
|
|
107
|
+
const outcome = { removed: [], marked: [], skipped: [] };
|
|
108
|
+
// Feedback items are marked together at the end: one sidecar write for every session file
|
|
109
|
+
const toMark = [];
|
|
110
|
+
for (const planned of plan.items) {
|
|
111
|
+
const { item } = planned;
|
|
112
|
+
if (!parts.some((part) => inPart(item, part))) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
let result;
|
|
116
|
+
if (!listed.has(key(item))) {
|
|
117
|
+
result = { cause: 'no-longer-listed' };
|
|
118
|
+
}
|
|
119
|
+
else if (planned.fingerprint === undefined) {
|
|
120
|
+
result = { cause: planned.cause };
|
|
121
|
+
}
|
|
122
|
+
else if (planned.fingerprint.kind === 'hash') {
|
|
123
|
+
toMark.push({ item, sha256: planned.fingerprint.sha256 });
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
result = this.remove(projectRoot, item, planned.fingerprint);
|
|
128
|
+
}
|
|
129
|
+
if ('cause' in result) {
|
|
130
|
+
outcome.skipped.push({
|
|
131
|
+
store: item.store,
|
|
132
|
+
reason: item.reason,
|
|
133
|
+
path: item.path,
|
|
134
|
+
cause: result.cause,
|
|
135
|
+
...(result.detail === undefined ? {} : { detail: result.detail }),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
outcome.removed.push({
|
|
140
|
+
store: item.store,
|
|
141
|
+
reason: item.reason,
|
|
142
|
+
path: item.path,
|
|
143
|
+
bytes: result.bytes,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (toMark.length > 0) {
|
|
148
|
+
this.mark(projectRoot, planId, toMark, tools, outcome);
|
|
149
|
+
}
|
|
150
|
+
return outcome;
|
|
151
|
+
}
|
|
152
|
+
/** Writes the sidecar marks of the planned session files that are still unchanged. */
|
|
153
|
+
mark(projectRoot, planId, toMark, tools, outcome) {
|
|
154
|
+
const fileOf = (item) => item.path.slice(item.path.lastIndexOf('/') + 1);
|
|
155
|
+
const planned = new Map(toMark.map(({ item, sha256 }) => [fileOf(item), sha256]));
|
|
156
|
+
const result = writeFeedbackMarks(projectRoot, join(projectRoot, FEEDBACK_DIR), planned, tools, planId, this.now());
|
|
157
|
+
for (const { item } of toMark) {
|
|
158
|
+
const file = fileOf(item);
|
|
159
|
+
const skip = (cause, detail) => {
|
|
160
|
+
outcome.skipped.push({
|
|
161
|
+
store: item.store,
|
|
162
|
+
reason: item.reason,
|
|
163
|
+
path: item.path,
|
|
164
|
+
cause,
|
|
165
|
+
...(detail === undefined ? {} : { detail }),
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
if ('error' in result) {
|
|
169
|
+
skip(result.outsideFolder ? 'outside-feedback-folder' : 'failed', result.error);
|
|
170
|
+
}
|
|
171
|
+
else if (result.missing.includes(file)) {
|
|
172
|
+
skip('missing');
|
|
173
|
+
}
|
|
174
|
+
else if (result.changed.includes(file)) {
|
|
175
|
+
skip('changed');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const records = result.marked.find((m) => m.file === file)?.records ?? 0;
|
|
179
|
+
outcome.marked.push({ store: item.store, reason: item.reason, path: item.path, records });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Fingerprint of an item at report time, or why it can never be removed. */
|
|
184
|
+
plan(projectRoot, item) {
|
|
185
|
+
if (item.store === 'snapshot-refs') {
|
|
186
|
+
const sha = refTarget(this.git, projectRoot, item.path);
|
|
187
|
+
return sha === undefined
|
|
188
|
+
? { item, fingerprint: undefined, cause: 'missing' }
|
|
189
|
+
: { item, fingerprint: { kind: 'ref', sha } };
|
|
190
|
+
}
|
|
191
|
+
if (item.store === 'feedback') {
|
|
192
|
+
return feedbackFingerprint(projectRoot, item);
|
|
193
|
+
}
|
|
194
|
+
if (item.store === 'backups' && item.reason === 'retention') {
|
|
195
|
+
const members = groupStamps(projectRoot, item.path);
|
|
196
|
+
return 'cause' in members
|
|
197
|
+
? { item, fingerprint: undefined, cause: members.cause }
|
|
198
|
+
: { item, fingerprint: { kind: 'group', members } };
|
|
199
|
+
}
|
|
200
|
+
const path = join(projectRoot, item.path);
|
|
201
|
+
const fingerprint = fingerprintOf(path);
|
|
202
|
+
if (fingerprint !== undefined) {
|
|
203
|
+
return { item, fingerprint };
|
|
204
|
+
}
|
|
205
|
+
return { item, fingerprint: undefined, cause: lstat(path) === undefined ? 'missing' : 'symbolic-link' };
|
|
206
|
+
}
|
|
207
|
+
/** Removes one listed item when it is unchanged against its fingerprint. */
|
|
208
|
+
remove(projectRoot, item, planned) {
|
|
209
|
+
switch (planned.kind) {
|
|
210
|
+
case 'ref':
|
|
211
|
+
return removeRef(this.git, projectRoot, item.path, planned.sha);
|
|
212
|
+
case 'group':
|
|
213
|
+
return removeGroup(projectRoot, item.path, planned.members);
|
|
214
|
+
case 'path':
|
|
215
|
+
return removePath(projectRoot, item, planned);
|
|
216
|
+
case 'hash':
|
|
217
|
+
// Feedback items are marked in apply(), never removed
|
|
218
|
+
return { cause: 'failed', detail: 'feedback records are marked, not removed' };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/** SHA-256 of a session file at report time; a link or a file outside the sessions folder is never marked. */
|
|
223
|
+
function feedbackFingerprint(projectRoot, item) {
|
|
224
|
+
const path = join(projectRoot, item.path);
|
|
225
|
+
const s = lstat(path);
|
|
226
|
+
if (s === undefined) {
|
|
227
|
+
return { item, fingerprint: undefined, cause: 'missing' };
|
|
228
|
+
}
|
|
229
|
+
if (s.isSymbolicLink()) {
|
|
230
|
+
return { item, fingerprint: undefined, cause: 'symbolic-link' };
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
if (realpathSync(path) !== path || dirname(path) !== join(projectRoot, FEEDBACK_DIR)) {
|
|
234
|
+
return { item, fingerprint: undefined, cause: 'outside-feedback-folder' };
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
item,
|
|
238
|
+
fingerprint: { kind: 'hash', sha256: createHash('sha256').update(readFileSync(path)).digest('hex') },
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return { item, fingerprint: undefined, cause: 'missing' };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function key(item) {
|
|
246
|
+
return `${item.store}\0${item.reason}\0${item.path}`;
|
|
247
|
+
}
|
|
248
|
+
function inPart(item, part) {
|
|
249
|
+
const scope = PART_SCOPE[part];
|
|
250
|
+
return scope.stores.includes(item.store) && scope.reasons.includes(item.reason);
|
|
251
|
+
}
|
|
252
|
+
function inAnyPart(item) {
|
|
253
|
+
return REFRESH_PARTS.some((part) => inPart(item, part));
|
|
254
|
+
}
|
|
255
|
+
function lstat(path) {
|
|
256
|
+
try {
|
|
257
|
+
return lstatSync(path);
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function errorText(error) {
|
|
264
|
+
return error instanceof Error ? error.message : String(error);
|
|
265
|
+
}
|
|
266
|
+
/** Object a ref points at, `undefined` when the ref does not exist. */
|
|
267
|
+
function refTarget(git, projectRoot, ref) {
|
|
268
|
+
const sha = git(projectRoot, ['rev-parse', '--verify', '--quiet', ref])?.trim();
|
|
269
|
+
return sha === undefined || sha === '' ? undefined : sha;
|
|
270
|
+
}
|
|
271
|
+
/** Deletes `ref` only while it still points at `sha` (git compares and deletes in one step). */
|
|
272
|
+
function removeRef(git, projectRoot, ref, sha) {
|
|
273
|
+
if (git(projectRoot, ['update-ref', '-d', ref, sha]) !== undefined) {
|
|
274
|
+
return { bytes: 0 };
|
|
275
|
+
}
|
|
276
|
+
const now = refTarget(git, projectRoot, ref);
|
|
277
|
+
if (now === undefined) {
|
|
278
|
+
return { cause: 'missing' };
|
|
279
|
+
}
|
|
280
|
+
return { cause: now === sha ? 'failed' : 'changed' };
|
|
281
|
+
}
|
|
282
|
+
/** The backup folder, when it is a real folder at its own path. */
|
|
283
|
+
function backupFolder(projectRoot) {
|
|
284
|
+
const dir = join(projectRoot, BACKUP_DIR);
|
|
285
|
+
try {
|
|
286
|
+
return realpathSync(dir) === dir ? dir : undefined;
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** Size and mtime of each file of a backup group, sorted by name, or why the group cannot be removed. */
|
|
293
|
+
function groupStamps(projectRoot, groupId) {
|
|
294
|
+
const dir = backupFolder(projectRoot);
|
|
295
|
+
if (dir === undefined) {
|
|
296
|
+
return { cause: lstat(join(projectRoot, BACKUP_DIR)) === undefined ? 'missing' : 'outside-backup-folder' };
|
|
297
|
+
}
|
|
298
|
+
const names = backupGroupMembers(projectRoot).get(groupId);
|
|
299
|
+
if (names === undefined) {
|
|
300
|
+
return { cause: 'missing' };
|
|
301
|
+
}
|
|
302
|
+
const stamps = [];
|
|
303
|
+
for (const name of [...names].sort()) {
|
|
304
|
+
const s = lstat(join(dir, name));
|
|
305
|
+
if (s === undefined) {
|
|
306
|
+
return { cause: 'changed' };
|
|
307
|
+
}
|
|
308
|
+
if (s.isSymbolicLink()) {
|
|
309
|
+
return { cause: 'symbolic-link' };
|
|
310
|
+
}
|
|
311
|
+
if (!s.isFile()) {
|
|
312
|
+
return { cause: 'changed' };
|
|
313
|
+
}
|
|
314
|
+
stamps.push({ name, size: s.size, mtimeMs: s.mtimeMs });
|
|
315
|
+
}
|
|
316
|
+
return stamps;
|
|
317
|
+
}
|
|
318
|
+
/** Removes exactly the files of the group the report saw, while the group still has exactly those files unchanged. */
|
|
319
|
+
function removeGroup(projectRoot, groupId, planned) {
|
|
320
|
+
const now = groupStamps(projectRoot, groupId);
|
|
321
|
+
if ('cause' in now) {
|
|
322
|
+
return now;
|
|
323
|
+
}
|
|
324
|
+
const stampKey = (stamps) => stamps.map((stamp) => `${stamp.name}\0${stamp.size}\0${stamp.mtimeMs}`).join('\n');
|
|
325
|
+
if (stampKey(now) !== stampKey(planned)) {
|
|
326
|
+
return { cause: 'changed' };
|
|
327
|
+
}
|
|
328
|
+
const dir = join(projectRoot, BACKUP_DIR);
|
|
329
|
+
let removed = 0;
|
|
330
|
+
for (const stamp of planned) {
|
|
331
|
+
try {
|
|
332
|
+
unlinkSync(join(dir, stamp.name));
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
return {
|
|
336
|
+
cause: 'failed',
|
|
337
|
+
detail: `${removed} of ${planned.length} files removed; ${stamp.name}: ${errorText(error)}`,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
removed++;
|
|
341
|
+
}
|
|
342
|
+
return { bytes: planned.reduce((sum, stamp) => sum + stamp.size, 0) };
|
|
343
|
+
}
|
|
344
|
+
/** Removes a cache entry, legacy cache folder or backup file without metadata. */
|
|
345
|
+
function removePath(projectRoot, item, planned) {
|
|
346
|
+
const path = join(projectRoot, item.path);
|
|
347
|
+
const check = checkRemovable(projectRoot, path, planned, item.store);
|
|
348
|
+
if (check !== undefined) {
|
|
349
|
+
return { cause: check };
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
if (planned.directory) {
|
|
353
|
+
rmSync(path, { recursive: true });
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
unlinkSync(path);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
return { cause: 'failed', detail: errorText(error) };
|
|
361
|
+
}
|
|
362
|
+
return { bytes: planned.bytes };
|
|
363
|
+
}
|
|
364
|
+
/** Fingerprint of a file or folder; `undefined` when missing or a link. */
|
|
365
|
+
function fingerprintOf(path) {
|
|
366
|
+
const s = lstat(path);
|
|
367
|
+
if (s === undefined || s.isSymbolicLink()) {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
if (!s.isDirectory()) {
|
|
371
|
+
return { kind: 'path', directory: false, bytes: s.size, files: 1, newestMtimeMs: s.mtimeMs };
|
|
372
|
+
}
|
|
373
|
+
const tree = walk(path);
|
|
374
|
+
return tree.links > 0
|
|
375
|
+
? undefined
|
|
376
|
+
: { kind: 'path', directory: true, bytes: tree.bytes, files: tree.files, newestMtimeMs: tree.newest };
|
|
377
|
+
}
|
|
378
|
+
function walk(dir) {
|
|
379
|
+
let bytes = 0;
|
|
380
|
+
let files = 0;
|
|
381
|
+
let newest = 0;
|
|
382
|
+
let links = 0;
|
|
383
|
+
let names;
|
|
384
|
+
try {
|
|
385
|
+
names = readdirSync(dir);
|
|
386
|
+
}
|
|
387
|
+
catch {
|
|
388
|
+
return { bytes, files, newest, links };
|
|
389
|
+
}
|
|
390
|
+
for (const name of names) {
|
|
391
|
+
const path = join(dir, name);
|
|
392
|
+
const s = lstat(path);
|
|
393
|
+
if (s === undefined) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (s.isSymbolicLink()) {
|
|
397
|
+
links++;
|
|
398
|
+
}
|
|
399
|
+
else if (s.isDirectory()) {
|
|
400
|
+
const sub = walk(path);
|
|
401
|
+
bytes += sub.bytes;
|
|
402
|
+
files += sub.files;
|
|
403
|
+
newest = Math.max(newest, sub.newest);
|
|
404
|
+
links += sub.links;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
bytes += s.size;
|
|
408
|
+
files++;
|
|
409
|
+
newest = Math.max(newest, s.mtimeMs);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return { bytes, files, newest, links };
|
|
413
|
+
}
|
|
414
|
+
/** Below a cache folder, or the legacy store folder itself; never the cache folder itself. */
|
|
415
|
+
function insideCacheFolder(projectRoot, real) {
|
|
416
|
+
return (real === join(projectRoot, LEGACY_STORE_DIR) ||
|
|
417
|
+
CACHE_ROOTS.some((dir) => real.startsWith(join(projectRoot, dir) + sep)));
|
|
418
|
+
}
|
|
419
|
+
/** Why `path` must stay, or `undefined` when it may be removed. */
|
|
420
|
+
function checkRemovable(projectRoot, path, planned, store) {
|
|
421
|
+
const s = lstat(path);
|
|
422
|
+
if (s === undefined) {
|
|
423
|
+
return 'missing';
|
|
424
|
+
}
|
|
425
|
+
if (s.isSymbolicLink()) {
|
|
426
|
+
return 'symbolic-link';
|
|
427
|
+
}
|
|
428
|
+
let real;
|
|
429
|
+
try {
|
|
430
|
+
real = realpathSync(path);
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return 'missing';
|
|
434
|
+
}
|
|
435
|
+
// A real path other than the path itself means a linked folder on the way
|
|
436
|
+
if (store === 'backups') {
|
|
437
|
+
// A backup file without metadata lies directly in the backup folder
|
|
438
|
+
if (real !== path || dirname(real) !== join(projectRoot, BACKUP_DIR)) {
|
|
439
|
+
return 'outside-backup-folder';
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
else if (real !== path || !insideCacheFolder(projectRoot, real)) {
|
|
443
|
+
return 'outside-cache-folder';
|
|
444
|
+
}
|
|
445
|
+
if (s.isDirectory() !== planned.directory) {
|
|
446
|
+
return 'changed';
|
|
447
|
+
}
|
|
448
|
+
if (planned.directory && walk(path).links > 0) {
|
|
449
|
+
return 'symbolic-link';
|
|
450
|
+
}
|
|
451
|
+
const now = fingerprintOf(path);
|
|
452
|
+
if (now === undefined ||
|
|
453
|
+
now.bytes !== planned.bytes ||
|
|
454
|
+
now.files !== planned.files ||
|
|
455
|
+
now.newestMtimeMs !== planned.newestMtimeMs) {
|
|
456
|
+
return 'changed';
|
|
457
|
+
}
|
|
458
|
+
return undefined;
|
|
459
|
+
}
|
|
460
|
+
//# sourceMappingURL=refresh-apply.js.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type CatalogTool } from './feedback-catalog.js';
|
|
2
|
+
/** Platform cache folder in the project root. */
|
|
3
|
+
export declare const CACHE_DIR = ".angular-modernizer-cache";
|
|
4
|
+
/** Transform backup folder in the project root. */
|
|
5
|
+
export declare const BACKUP_DIR = ".angular-modernizer-backups";
|
|
6
|
+
/** Feedback session folder in the project root. */
|
|
7
|
+
export declare const FEEDBACK_DIR: string;
|
|
8
|
+
/** Folder of the deprecated CacheCoordinator (no writer left). */
|
|
9
|
+
export declare const LEGACY_STORE_DIR: string;
|
|
10
|
+
/** Ref namespace of the git snapshots transform-code keeps (core `SNAPSHOT_REF_PREFIX`). */
|
|
11
|
+
export declare const SNAPSHOT_REFS = "refs/angular-modernizer/snapshots/";
|
|
12
|
+
/** Age after which a scan cache entry is no longer used (core CacheManager `maxAge`). */
|
|
13
|
+
export declare const CACHE_MAX_AGE_MS: number;
|
|
14
|
+
/** Default retention of backup groups and snapshot refs in days. */
|
|
15
|
+
export declare const DEFAULT_RETENTION_DAYS = 30;
|
|
16
|
+
/** Default number of newest backup groups that are never proposed. */
|
|
17
|
+
export declare const DEFAULT_KEEP_NEWEST = 5;
|
|
18
|
+
/** Store of the platform state an item belongs to. */
|
|
19
|
+
export type RefreshStore = 'scan-cache' | 'legacy-cache' | 'health-snapshot' | 'pattern-knowledge' | 'backups' | 'snapshot-refs' | 'feedback' | 'ngm-cache';
|
|
20
|
+
/** Why an item is listed. */
|
|
21
|
+
export type RefreshReason = 'orphan' | 'expired' | 'unreadable' | 'legacy-layout' | 'legacy-store' | 'retention' | 'missing-metadata' | 'ref-without-backup' | 'duplicate-records' | 'outdated-records' | 'stale-date';
|
|
22
|
+
/** What a later apply would do with the item. */
|
|
23
|
+
export type RefreshAction = 'remove' | 'mark' | 'regenerate';
|
|
24
|
+
/** One stale, orphaned or duplicated piece of platform state. */
|
|
25
|
+
export interface RefreshItem {
|
|
26
|
+
/** Store the item belongs to. */
|
|
27
|
+
store: RefreshStore;
|
|
28
|
+
/** Why it is listed. */
|
|
29
|
+
reason: RefreshReason;
|
|
30
|
+
/** What apply would do: remove it, mark records (feedback) or regenerate it (NGM-CACHE). */
|
|
31
|
+
action: RefreshAction;
|
|
32
|
+
/** Path relative to the project root (`/`-separated), a backup group id or a ref name. */
|
|
33
|
+
path: string;
|
|
34
|
+
/** Bytes on disk (0 for refs and marks). */
|
|
35
|
+
bytes: number;
|
|
36
|
+
/** Age in whole days. */
|
|
37
|
+
ageDays?: number;
|
|
38
|
+
/** Extra detail: source file of a cache entry, file count of a group, duplicate count. */
|
|
39
|
+
detail?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Overview of one store. */
|
|
42
|
+
export interface StoreReport {
|
|
43
|
+
/** Store name. */
|
|
44
|
+
store: RefreshStore;
|
|
45
|
+
/** Whether anything of the store exists. */
|
|
46
|
+
present: boolean;
|
|
47
|
+
/** Entries (cache files, backup groups, refs, feedback records, 1 for single files). */
|
|
48
|
+
entries: number;
|
|
49
|
+
/** Bytes on disk. */
|
|
50
|
+
bytes: number;
|
|
51
|
+
/** Number of listed items of this store. */
|
|
52
|
+
listed: number;
|
|
53
|
+
/** Bytes of the listed items. */
|
|
54
|
+
listedBytes: number;
|
|
55
|
+
/** Age of the newest entry in days. */
|
|
56
|
+
newestAgeDays?: number;
|
|
57
|
+
/** Age of the oldest entry in days. */
|
|
58
|
+
oldestAgeDays?: number;
|
|
59
|
+
/** Remark, such as a skipped symbolic link or no git repository. */
|
|
60
|
+
note?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Retention applied to backup groups and snapshot refs. */
|
|
63
|
+
export interface RefreshRetention {
|
|
64
|
+
/** Backup groups and refs older than this many days are listed. */
|
|
65
|
+
days: number;
|
|
66
|
+
/** Newest backup groups that are never listed. */
|
|
67
|
+
keepNewest: number;
|
|
68
|
+
}
|
|
69
|
+
/** Inventory result. */
|
|
70
|
+
export interface RefreshInventory {
|
|
71
|
+
/** Real path of the project root. */
|
|
72
|
+
projectRoot: string;
|
|
73
|
+
/** Time of the inventory (ISO). */
|
|
74
|
+
generatedAt: string;
|
|
75
|
+
/** Retention used for backups and refs. */
|
|
76
|
+
retention: RefreshRetention;
|
|
77
|
+
/** One entry per store, in a fixed order. */
|
|
78
|
+
stores: StoreReport[];
|
|
79
|
+
/** Listed items, store order, then path. */
|
|
80
|
+
items: RefreshItem[];
|
|
81
|
+
}
|
|
82
|
+
/** Runs git with arguments in a folder and returns stdout, or `undefined` when git fails. */
|
|
83
|
+
export type GitRunner = (cwd: string, args: string[]) => string | undefined;
|
|
84
|
+
/** Settings of {@link inventoryPlatformState}. */
|
|
85
|
+
export interface InventoryOptions {
|
|
86
|
+
/** Days after which a backup group or snapshot ref is listed. */
|
|
87
|
+
retentionDays?: number;
|
|
88
|
+
/** Newest backup groups that are never listed; at least 1 (a lower value counts as 1). */
|
|
89
|
+
keepNewest?: number;
|
|
90
|
+
/** Clock, for tests. */
|
|
91
|
+
now?: () => number;
|
|
92
|
+
/** git, for tests. */
|
|
93
|
+
git?: GitRunner;
|
|
94
|
+
/** Registered tools for the outdated check of feedback records; without them tools are not checked. */
|
|
95
|
+
tools?: readonly CatalogTool[];
|
|
96
|
+
}
|
|
97
|
+
/** {@link GitRunner} on the real git binary; `undefined` when git fails or is missing. */
|
|
98
|
+
export declare const runGit: GitRunner;
|
|
99
|
+
/** Collects the platform state of `projectRoot`; changes nothing. */
|
|
100
|
+
export declare function inventoryPlatformState(projectRoot: string, options?: InventoryOptions): RefreshInventory;
|
|
101
|
+
/**
|
|
102
|
+
* Files of each backup group in `.angular-modernizer-backups` of `projectRoot`, by group id (`group`, else
|
|
103
|
+
* `backupId`, of the metadata), as names in that folder. Grouped exactly like the inventory groups them.
|
|
104
|
+
*/
|
|
105
|
+
export declare function backupGroupMembers(projectRoot: string): Map<string, string[]>;
|
|
106
|
+
//# sourceMappingURL=refresh-inventory.d.ts.map
|