@angular-modernizer/adapter-mcp 2.0.0 → 2.1.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 +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/tools/analyze-project.d.ts +26 -1
- package/dist/tools/analyze-project.js +8 -3
- package/dist/tools/compare-health.d.ts +40 -4
- package/dist/tools/compare-health.js +22 -5
- package/dist/tools/helpers/analysis-output.js +3 -0
- package/dist/tools/helpers/health-delta.d.ts +6 -0
- package/dist/tools/helpers/health-delta.js +4 -1
- package/dist/tools/helpers/library-import-warning.d.ts +33 -0
- package/dist/tools/helpers/library-import-warning.js +38 -0
- package/dist/tools/helpers/library-imports.d.ts +38 -14
- package/dist/tools/helpers/library-imports.js +128 -23
- package/dist/tools/helpers/output-contract.d.ts +22 -0
- package/dist/tools/helpers/output-contract.js +13 -0
- package/dist/tools/helpers/refresh-apply.js +1 -1
- package/dist/tools/helpers/refresh-inventory.d.ts +1 -1
- package/dist/tools/helpers/refresh-inventory.js +24 -3
- package/dist/tools/helpers/scan-cache.d.ts +45 -2
- package/dist/tools/helpers/scan-cache.js +47 -2
- package/dist/tools/helpers/scan-engine.d.ts +13 -0
- package/dist/tools/helpers/scan-engine.js +10 -0
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/refresh-state.js +1 -1
- package/dist/tools/scan-all.d.ts +7 -1
- package/dist/tools/scan-all.js +8 -13
- package/dist/tools/scan-angular.d.ts +7 -1
- package/dist/tools/scan-angular.js +7 -2
- package/dist/tools/scan-architecture.d.ts +8 -0
- package/dist/tools/scan-architecture.js +25 -14
- package/dist/tools/scan-solid.d.ts +7 -1
- package/dist/tools/scan-solid.js +7 -2
- package/package.json +11 -11
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
* program is created.
|
|
27
27
|
*/
|
|
28
28
|
import { isRelativeSpecifier, matchPathPattern, } from '@angular-modernizer/core';
|
|
29
|
+
import { statSync } from 'node:fs';
|
|
29
30
|
import { dirname, join } from 'node:path';
|
|
30
|
-
import { ts } from 'ts-morph';
|
|
31
|
-
|
|
32
|
-
export
|
|
31
|
+
import { Project, ts } from 'ts-morph';
|
|
32
|
+
import { EXAMPLE_PACKAGES, } from './library-import-warning.js';
|
|
33
|
+
export { EXAMPLE_PACKAGES, libraryImportWarning, withLibraryImportWarning, } from './library-import-warning.js';
|
|
33
34
|
/** Module specifiers of the import and re-export declarations of one file. */
|
|
34
35
|
function moduleSpecifiers(sourceFile) {
|
|
35
36
|
const specifiers = [];
|
|
@@ -89,13 +90,11 @@ function packageFolderExists(host, fromFile, pkg) {
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
|
-
* Resolves every distinct library specifier of `
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* @param tsConfigPath - The project's tsconfig; the `package.json` with the
|
|
96
|
-
* declared packages is looked up from its directory upwards.
|
|
93
|
+
* Resolves every distinct library specifier of `files` once against the
|
|
94
|
+
* compiler options and module resolution host of `project` and counts the
|
|
95
|
+
* imports whose specifier does not resolve.
|
|
97
96
|
*/
|
|
98
|
-
|
|
97
|
+
function countUnresolved(project, tsConfigPath, files) {
|
|
99
98
|
const declared = declaredPackages(project.getFileSystem(), dirname(tsConfigPath));
|
|
100
99
|
const options = project.getCompilerOptions();
|
|
101
100
|
const host = project.getModuleResolutionHost();
|
|
@@ -105,12 +104,8 @@ export function findUnresolvedLibraryImports(project, tsConfigPath) {
|
|
|
105
104
|
const resolved = new Map();
|
|
106
105
|
const unresolvedPerPackage = new Map();
|
|
107
106
|
let imports = 0;
|
|
108
|
-
for (const
|
|
109
|
-
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const containingFile = sourceFile.getFilePath();
|
|
113
|
-
for (const specifier of moduleSpecifiers(sourceFile.compilerNode)) {
|
|
107
|
+
for (const { path: containingFile, specifiers } of files) {
|
|
108
|
+
for (const specifier of specifiers) {
|
|
114
109
|
const isLibrary = !isRelativeSpecifier(specifier) &&
|
|
115
110
|
declared.has(packageName(specifier)) &&
|
|
116
111
|
!isAlias(specifier);
|
|
@@ -136,16 +131,126 @@ export function findUnresolvedLibraryImports(project, tsConfigPath) {
|
|
|
136
131
|
.sort(([a, countA], [b, countB]) => countB - countA || a.localeCompare(b))
|
|
137
132
|
.slice(0, EXAMPLE_PACKAGES)
|
|
138
133
|
.map(([name]) => name);
|
|
139
|
-
return {
|
|
134
|
+
return {
|
|
135
|
+
found: { imports, packages: unresolvedPerPackage.size, examples },
|
|
136
|
+
packages: [...unresolvedPerPackage.keys()].sort(),
|
|
137
|
+
};
|
|
140
138
|
}
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
/** Import specifiers of the source files of `project` outside node_modules. */
|
|
140
|
+
function* projectFiles(project) {
|
|
141
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
142
|
+
if (!sourceFile.isInNodeModules()) {
|
|
143
|
+
yield {
|
|
144
|
+
path: sourceFile.getFilePath(),
|
|
145
|
+
specifiers: moduleSpecifiers(sourceFile.compilerNode),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Resolves every distinct library specifier of `project` once and counts the
|
|
152
|
+
* declarations whose specifier does not resolve.
|
|
153
|
+
*
|
|
154
|
+
* @param tsConfigPath - The project's tsconfig; the `package.json` with the
|
|
155
|
+
* declared packages is looked up from its directory upwards.
|
|
156
|
+
*/
|
|
157
|
+
export function findUnresolvedLibraryImports(project, tsConfigPath) {
|
|
158
|
+
return countUnresolved(project, tsConfigPath, projectFiles(project)).found;
|
|
159
|
+
}
|
|
160
|
+
/** Most files whose specifiers {@link fileSpecifiers} keeps. */
|
|
161
|
+
const MAX_REMEMBERED_FILES = 50000;
|
|
162
|
+
/** Specifiers per file path, valid while mtime and size are unchanged. */
|
|
163
|
+
const rememberedSpecifiers = new Map();
|
|
164
|
+
/**
|
|
165
|
+
* Import specifiers of one file, read through `fs`; `undefined` when it
|
|
166
|
+
* cannot be read. Remembered per process by mtime and size, so a repeated
|
|
167
|
+
* scan (a warm run checks its whole scope) only stats the file; a file
|
|
168
|
+
* that cannot be stat'ed (in-memory file systems) is read every time.
|
|
169
|
+
*/
|
|
170
|
+
function fileSpecifiers(fs, path) {
|
|
171
|
+
let stat;
|
|
172
|
+
try {
|
|
173
|
+
stat = statSync(path);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
stat = undefined;
|
|
177
|
+
}
|
|
178
|
+
const known = rememberedSpecifiers.get(path);
|
|
179
|
+
if (stat !== undefined && known?.mtimeMs === stat.mtimeMs && known.size === stat.size) {
|
|
180
|
+
return known.specifiers;
|
|
181
|
+
}
|
|
182
|
+
let text;
|
|
183
|
+
try {
|
|
184
|
+
text = fs.readFileSync(path);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
144
187
|
return undefined;
|
|
145
188
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
189
|
+
// The scanner pass of preProcessFile is several times faster than a parse
|
|
190
|
+
const specifiers = ts.preProcessFile(text, true, false).importedFiles.map((f) => f.fileName);
|
|
191
|
+
if (stat !== undefined) {
|
|
192
|
+
if (rememberedSpecifiers.size >= MAX_REMEMBERED_FILES) {
|
|
193
|
+
rememberedSpecifiers.clear();
|
|
194
|
+
}
|
|
195
|
+
rememberedSpecifiers.set(path, { mtimeMs: stat.mtimeMs, size: stat.size, specifiers });
|
|
196
|
+
}
|
|
197
|
+
return specifiers;
|
|
198
|
+
}
|
|
199
|
+
/** Import specifiers of `filePaths`, read through the project's file system. */
|
|
200
|
+
function* filesOnDisk(project, filePaths) {
|
|
201
|
+
const fs = project.getFileSystem();
|
|
202
|
+
for (const path of filePaths) {
|
|
203
|
+
if (path.split(/[\\/]/).includes('node_modules')) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const specifiers = fileSpecifiers(fs, path);
|
|
207
|
+
if (specifiers !== undefined) {
|
|
208
|
+
yield { path, specifiers };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Like {@link findUnresolvedLibraryImports}, for files that are not (all)
|
|
214
|
+
* in the project: the scans hold only a batch of their scope at a time and
|
|
215
|
+
* none on a warm run. Each file is read and scanned for its imports without
|
|
216
|
+
* a parse; besides import and `export ... from` declarations this also
|
|
217
|
+
* counts `import x = require(...)` and dynamic `import(...)` of a library.
|
|
218
|
+
* Files that cannot be read are skipped; the specifiers of a file are
|
|
219
|
+
* remembered per process until its mtime or size changes.
|
|
220
|
+
*
|
|
221
|
+
* @param project - Gives compiler options, module resolution host and file
|
|
222
|
+
* system of the tsconfig; its source files are not read.
|
|
223
|
+
* @param tsConfigPath - As in {@link findUnresolvedLibraryImports}.
|
|
224
|
+
* @param filePaths - Absolute paths of the files to check.
|
|
225
|
+
*/
|
|
226
|
+
export function findUnresolvedLibraryImportsInFiles(project, tsConfigPath, filePaths) {
|
|
227
|
+
return countUnresolved(project, tsConfigPath, filesOnDisk(project, filePaths)).found;
|
|
228
|
+
}
|
|
229
|
+
/** Files read between two turns of the event loop in {@link checkScanScope}. */
|
|
230
|
+
const FILES_PER_TURN = 50;
|
|
231
|
+
/**
|
|
232
|
+
* Library imports of a scan scope that do not resolve, checked before the
|
|
233
|
+
* scan reads its cache: the packages go into the cache version, so entries
|
|
234
|
+
* written while node_modules was missing or incomplete are not served once
|
|
235
|
+
* it is complete (and the other way round). Runs on the calling thread and
|
|
236
|
+
* yields to the event loop every {@link FILES_PER_TURN} files; repeated
|
|
237
|
+
* calls only stat unchanged files (see {@link findUnresolvedLibraryImportsInFiles}).
|
|
238
|
+
*
|
|
239
|
+
* @param tsConfigPath - tsconfig of the scan; gives compiler options and
|
|
240
|
+
* the `package.json` with the declared packages.
|
|
241
|
+
* @param filePaths - Absolute paths of the scan scope.
|
|
242
|
+
*/
|
|
243
|
+
export async function checkScanScope(tsConfigPath, filePaths) {
|
|
244
|
+
const project = new Project({ tsConfigFilePath: tsConfigPath, skipAddingFilesFromTsConfig: true });
|
|
245
|
+
const files = [];
|
|
246
|
+
let read = 0;
|
|
247
|
+
for (const file of filesOnDisk(project, filePaths)) {
|
|
248
|
+
files.push(file);
|
|
249
|
+
if (++read % FILES_PER_TURN === 0) {
|
|
250
|
+
await new Promise((done) => setImmediate(done));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const { found, packages } = countUnresolved(project, tsConfigPath, files);
|
|
254
|
+
return { unresolved: found, packages };
|
|
150
255
|
}
|
|
151
256
|
//# sourceMappingURL=library-imports.js.map
|
|
@@ -21,6 +21,28 @@ export declare const WARNINGS_OUTPUT_SCHEMA: {
|
|
|
21
21
|
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
/** `unresolvedLibraryImports` entry of an output schema. */
|
|
25
|
+
export declare const UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA: {
|
|
26
|
+
readonly unresolvedLibraryImports: {
|
|
27
|
+
readonly type: "object";
|
|
28
|
+
readonly description: "Library imports of the scanned files that do not resolve (node_modules missing or incomplete); rules that need library types can report less. Absent when all resolve.";
|
|
29
|
+
readonly properties: {
|
|
30
|
+
readonly imports: {
|
|
31
|
+
readonly type: "integer";
|
|
32
|
+
};
|
|
33
|
+
readonly packages: {
|
|
34
|
+
readonly type: "integer";
|
|
35
|
+
};
|
|
36
|
+
readonly examples: {
|
|
37
|
+
readonly type: "array";
|
|
38
|
+
readonly items: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly required: readonly ["imports", "packages", "examples"];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
24
46
|
/**
|
|
25
47
|
* Adds `warnings` to a result and one `Warning:` line per entry to its
|
|
26
48
|
* summary; returns the result unchanged when there are none.
|
|
@@ -18,6 +18,19 @@ export const WARNINGS_OUTPUT_SCHEMA = {
|
|
|
18
18
|
description: 'Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.',
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
+
/** `unresolvedLibraryImports` entry of an output schema. */
|
|
22
|
+
export const UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA = {
|
|
23
|
+
unresolvedLibraryImports: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
description: 'Library imports of the scanned files that do not resolve (node_modules missing or incomplete); rules that need library types can report less. Absent when all resolve.',
|
|
26
|
+
properties: {
|
|
27
|
+
imports: { type: 'integer' },
|
|
28
|
+
packages: { type: 'integer' },
|
|
29
|
+
examples: { type: 'array', items: { type: 'string' } },
|
|
30
|
+
},
|
|
31
|
+
required: ['imports', 'packages', 'examples'],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
21
34
|
/**
|
|
22
35
|
* Adds `warnings` to a result and one `Warning:` line per entry to its
|
|
23
36
|
* summary; returns the result unchanged when there are none.
|
|
@@ -23,7 +23,7 @@ export const REFRESH_PARTS = ['caches', 'backups', 'refs', 'feedback'];
|
|
|
23
23
|
const PART_SCOPE = {
|
|
24
24
|
caches: {
|
|
25
25
|
stores: ['scan-cache', 'legacy-cache'],
|
|
26
|
-
reasons: ['orphan', 'expired', 'unreadable', 'legacy-layout', 'legacy-store'],
|
|
26
|
+
reasons: ['orphan', 'outdated-layout', 'expired', 'unreadable', 'legacy-layout', 'legacy-store'],
|
|
27
27
|
},
|
|
28
28
|
backups: {
|
|
29
29
|
stores: ['backups'],
|
|
@@ -18,7 +18,7 @@ export declare const DEFAULT_KEEP_NEWEST = 5;
|
|
|
18
18
|
/** Store of the platform state an item belongs to. */
|
|
19
19
|
export type RefreshStore = 'scan-cache' | 'legacy-cache' | 'health-snapshot' | 'pattern-knowledge' | 'backups' | 'snapshot-refs' | 'feedback' | 'ngm-cache';
|
|
20
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';
|
|
21
|
+
export type RefreshReason = 'orphan' | 'outdated-layout' | 'expired' | 'unreadable' | 'legacy-layout' | 'legacy-store' | 'retention' | 'missing-metadata' | 'ref-without-backup' | 'duplicate-records' | 'outdated-records' | 'stale-date';
|
|
22
22
|
/** What a later apply would do with the item. */
|
|
23
23
|
export type RefreshAction = 'remove' | 'mark' | 'regenerate';
|
|
24
24
|
/** One stale, orphaned or duplicated piece of platform state. */
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { execFileSync } from 'node:child_process';
|
|
7
7
|
import { closeSync, existsSync, lstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, } from 'node:fs';
|
|
8
|
-
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
8
|
+
import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
9
|
import { gunzipSync } from 'node:zlib';
|
|
10
10
|
import { readSidecar, sameMarks, scanFeedbackSessions } from './feedback-sidecar.js';
|
|
11
|
+
import { SCAN_CACHE_LAYOUTS } from './scan-cache.js';
|
|
11
12
|
/** Platform cache folder in the project root. */
|
|
12
13
|
export const CACHE_DIR = '.angular-modernizer-cache';
|
|
13
14
|
/** Transform backup folder in the project root. */
|
|
@@ -178,6 +179,8 @@ function scanCaches(ctx) {
|
|
|
178
179
|
.filter((p) => stat(p)?.isDirectory() === true),
|
|
179
180
|
];
|
|
180
181
|
for (const toolDir of toolDirs) {
|
|
182
|
+
// Scan cache folders have a layout version; kernel caches (the base folder) do not
|
|
183
|
+
const layout = toolDir === base ? undefined : SCAN_CACHE_LAYOUTS[basename(toolDir)];
|
|
181
184
|
// Former layout <cacheDir>/YYYY/MM/DD/(ast|analysis)/ (replaced 2026-10, bfd5f91c): looked up by the current
|
|
182
185
|
// date only, so nothing reads these folders any more
|
|
183
186
|
for (const name of list(toolDir)) {
|
|
@@ -219,7 +222,7 @@ function scanCaches(ctx) {
|
|
|
219
222
|
}
|
|
220
223
|
entries++;
|
|
221
224
|
bytes += s.size;
|
|
222
|
-
const item = cacheEntryItem(ctx, path, s);
|
|
225
|
+
const item = cacheEntryItem(ctx, path, s, type === 'analysis' ? layout : undefined);
|
|
223
226
|
ages.push(item.age);
|
|
224
227
|
if (item.listed !== undefined) {
|
|
225
228
|
cacheItems.push(item.listed);
|
|
@@ -256,7 +259,12 @@ function scanCaches(ctx) {
|
|
|
256
259
|
legacy: { report: legacy, items: legacyItems },
|
|
257
260
|
};
|
|
258
261
|
}
|
|
259
|
-
|
|
262
|
+
/**
|
|
263
|
+
* @param layout - Current layout version of the scan cache folder the entry
|
|
264
|
+
* is in; an entry of another layout is never read again (`outdated-layout`).
|
|
265
|
+
* Unset for kernel caches.
|
|
266
|
+
*/
|
|
267
|
+
function cacheEntryItem(ctx, path, s, layout) {
|
|
260
268
|
const metadata = readCacheMetadata(path);
|
|
261
269
|
const cachedAt = typeof metadata?.cachedAt === 'number' ? metadata.cachedAt : s.mtimeMs;
|
|
262
270
|
const age = ageDays(ctx, cachedAt);
|
|
@@ -291,6 +299,19 @@ function cacheEntryItem(ctx, path, s) {
|
|
|
291
299
|
},
|
|
292
300
|
};
|
|
293
301
|
}
|
|
302
|
+
// The version is `<layout>+<hash>`; the hash part (config, rules, scope,
|
|
303
|
+
// unresolved packages) belongs to the scan call and is not checked here
|
|
304
|
+
const entryLayout = typeof metadata.version === 'string' ? metadata.version.split('+')[0] : undefined;
|
|
305
|
+
if (layout !== undefined && entryLayout !== layout) {
|
|
306
|
+
return {
|
|
307
|
+
age,
|
|
308
|
+
listed: {
|
|
309
|
+
...base,
|
|
310
|
+
reason: 'outdated-layout',
|
|
311
|
+
detail: `${shown}; written with cache layout ${entryLayout ?? 'unknown'}, the scan reads ${layout}`,
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
294
315
|
if (ctx.now - cachedAt > CACHE_MAX_AGE_MS) {
|
|
295
316
|
return {
|
|
296
317
|
age,
|
|
@@ -12,9 +12,42 @@ import { type CacheManager } from '@angular-modernizer/core';
|
|
|
12
12
|
* layout were filed under each finding's file (the template's `.html` for
|
|
13
13
|
* template rules, never read back) and missing for files without findings;
|
|
14
14
|
* `scan-3` also drops entries whose cross-file findings saw only their batch,
|
|
15
|
-
* `scan-4` entries that hold project rule findings of another file
|
|
15
|
+
* `scan-4` entries that hold project rule findings of another file, `scan-5`
|
|
16
|
+
* entries written before the unresolved library packages were part of the
|
|
17
|
+
* version (a scan without node_modules would be served once it is complete)
|
|
18
|
+
* and entries filtered before a suppression marker in a comment block or
|
|
19
|
+
* inside a decorator counted.
|
|
16
20
|
*/
|
|
17
|
-
export declare const SCAN_TOOL_CACHE_VERSION = "scan-
|
|
21
|
+
export declare const SCAN_TOOL_CACHE_VERSION = "scan-5";
|
|
22
|
+
/**
|
|
23
|
+
* Version of the cache entries scan-all writes. Entries from before the
|
|
24
|
+
* per-analyzed-file layout (findings filed under their template, files without
|
|
25
|
+
* findings missing) would read as complete; `scan-all-3` also drops entries
|
|
26
|
+
* whose cross-file findings saw only their own batch, `scan-all-4` entries
|
|
27
|
+
* that hold project rule findings of another file, `scan-all-5` entries whose
|
|
28
|
+
* solid:circular-dependency findings have no `cycleId` and carry the path of a
|
|
29
|
+
* long cycle on every file, `scan-all-6` entries written before the unresolved
|
|
30
|
+
* library packages were part of the version or filtered before a suppression
|
|
31
|
+
* marker in a comment block or inside a decorator counted.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SCAN_ALL_CACHE_VERSION = "scan-all-6";
|
|
34
|
+
/**
|
|
35
|
+
* Version of the cache entries of scan-architecture's imperative path: one
|
|
36
|
+
* entry per analyzed file with the findings of the file-scope rules. Entries
|
|
37
|
+
* of the earlier layout were filed under each finding's file and held
|
|
38
|
+
* project-wide findings; `scan-architecture-3` drops solid:circular-dependency
|
|
39
|
+
* findings without `cycleId` that carry the path of a long cycle on every
|
|
40
|
+
* file, `scan-architecture-4` entries written before the unresolved library
|
|
41
|
+
* packages were part of the version or filtered before a suppression marker
|
|
42
|
+
* in a comment block or inside a decorator counted.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ARCHITECTURE_CACHE_VERSION = "scan-architecture-4";
|
|
45
|
+
/**
|
|
46
|
+
* Current layout version per scan cache folder under
|
|
47
|
+
* `.angular-modernizer-cache/`; refresh-state lists entries of another
|
|
48
|
+
* layout (`outdated-layout`), which no scan reads any more.
|
|
49
|
+
*/
|
|
50
|
+
export declare const SCAN_CACHE_LAYOUTS: Readonly<Record<string, string>>;
|
|
18
51
|
/**
|
|
19
52
|
* Cache version for a scan of `rootPath`: the layout version plus a hash of
|
|
20
53
|
* the configuration the rules read. Rule options, `parser`, `layers` and the
|
|
@@ -29,6 +62,9 @@ export declare const SCAN_TOOL_CACHE_VERSION = "scan-4";
|
|
|
29
62
|
* the default patterns keeps the version without a scope. Entries are kept
|
|
30
63
|
* per file, so a scan with another version replaces the entries of the files
|
|
31
64
|
* it analyzed, and the next scan with the first version analyzes them again.
|
|
65
|
+
* The packages whose imports do not resolve (`unresolvedPackages`) count too:
|
|
66
|
+
* entries written without a complete node_modules are not served once it is
|
|
67
|
+
* complete, and the other way round.
|
|
32
68
|
*
|
|
33
69
|
* @throws the loader's error for an invalid `.angular-modernizer.json`
|
|
34
70
|
*/
|
|
@@ -42,6 +78,13 @@ export interface ScanCacheScope {
|
|
|
42
78
|
readonly includePatterns?: readonly string[];
|
|
43
79
|
/** Exclude patterns of the scan, unset for the default. */
|
|
44
80
|
readonly excludePatterns?: readonly string[];
|
|
81
|
+
/**
|
|
82
|
+
* Packages whose imports do not resolve in the scope (missing or
|
|
83
|
+
* incomplete node_modules); unset or empty when all resolve. Rules that
|
|
84
|
+
* need library types report differently without them, so entries of one
|
|
85
|
+
* state are not served in the other.
|
|
86
|
+
*/
|
|
87
|
+
readonly unresolvedPackages?: readonly string[];
|
|
45
88
|
}
|
|
46
89
|
/**
|
|
47
90
|
* How a scan uses its cache: `use` serves unchanged files from it, `refresh`
|
|
@@ -15,9 +15,47 @@ import { loadConfig } from '@angular-modernizer/core';
|
|
|
15
15
|
* layout were filed under each finding's file (the template's `.html` for
|
|
16
16
|
* template rules, never read back) and missing for files without findings;
|
|
17
17
|
* `scan-3` also drops entries whose cross-file findings saw only their batch,
|
|
18
|
-
* `scan-4` entries that hold project rule findings of another file
|
|
18
|
+
* `scan-4` entries that hold project rule findings of another file, `scan-5`
|
|
19
|
+
* entries written before the unresolved library packages were part of the
|
|
20
|
+
* version (a scan without node_modules would be served once it is complete)
|
|
21
|
+
* and entries filtered before a suppression marker in a comment block or
|
|
22
|
+
* inside a decorator counted.
|
|
19
23
|
*/
|
|
20
|
-
export const SCAN_TOOL_CACHE_VERSION = 'scan-
|
|
24
|
+
export const SCAN_TOOL_CACHE_VERSION = 'scan-5';
|
|
25
|
+
/**
|
|
26
|
+
* Version of the cache entries scan-all writes. Entries from before the
|
|
27
|
+
* per-analyzed-file layout (findings filed under their template, files without
|
|
28
|
+
* findings missing) would read as complete; `scan-all-3` also drops entries
|
|
29
|
+
* whose cross-file findings saw only their own batch, `scan-all-4` entries
|
|
30
|
+
* that hold project rule findings of another file, `scan-all-5` entries whose
|
|
31
|
+
* solid:circular-dependency findings have no `cycleId` and carry the path of a
|
|
32
|
+
* long cycle on every file, `scan-all-6` entries written before the unresolved
|
|
33
|
+
* library packages were part of the version or filtered before a suppression
|
|
34
|
+
* marker in a comment block or inside a decorator counted.
|
|
35
|
+
*/
|
|
36
|
+
export const SCAN_ALL_CACHE_VERSION = 'scan-all-6';
|
|
37
|
+
/**
|
|
38
|
+
* Version of the cache entries of scan-architecture's imperative path: one
|
|
39
|
+
* entry per analyzed file with the findings of the file-scope rules. Entries
|
|
40
|
+
* of the earlier layout were filed under each finding's file and held
|
|
41
|
+
* project-wide findings; `scan-architecture-3` drops solid:circular-dependency
|
|
42
|
+
* findings without `cycleId` that carry the path of a long cycle on every
|
|
43
|
+
* file, `scan-architecture-4` entries written before the unresolved library
|
|
44
|
+
* packages were part of the version or filtered before a suppression marker
|
|
45
|
+
* in a comment block or inside a decorator counted.
|
|
46
|
+
*/
|
|
47
|
+
export const ARCHITECTURE_CACHE_VERSION = 'scan-architecture-4';
|
|
48
|
+
/**
|
|
49
|
+
* Current layout version per scan cache folder under
|
|
50
|
+
* `.angular-modernizer-cache/`; refresh-state lists entries of another
|
|
51
|
+
* layout (`outdated-layout`), which no scan reads any more.
|
|
52
|
+
*/
|
|
53
|
+
export const SCAN_CACHE_LAYOUTS = {
|
|
54
|
+
all: SCAN_ALL_CACHE_VERSION,
|
|
55
|
+
solid: SCAN_TOOL_CACHE_VERSION,
|
|
56
|
+
angular: SCAN_TOOL_CACHE_VERSION,
|
|
57
|
+
architecture: ARCHITECTURE_CACHE_VERSION,
|
|
58
|
+
};
|
|
21
59
|
/**
|
|
22
60
|
* Cache version for a scan of `rootPath`: the layout version plus a hash of
|
|
23
61
|
* the configuration the rules read. Rule options, `parser`, `layers` and the
|
|
@@ -32,6 +70,9 @@ export const SCAN_TOOL_CACHE_VERSION = 'scan-4';
|
|
|
32
70
|
* the default patterns keeps the version without a scope. Entries are kept
|
|
33
71
|
* per file, so a scan with another version replaces the entries of the files
|
|
34
72
|
* it analyzed, and the next scan with the first version analyzes them again.
|
|
73
|
+
* The packages whose imports do not resolve (`unresolvedPackages`) count too:
|
|
74
|
+
* entries written without a complete node_modules are not served once it is
|
|
75
|
+
* complete, and the other way round.
|
|
35
76
|
*
|
|
36
77
|
* @throws the loader's error for an invalid `.angular-modernizer.json`
|
|
37
78
|
*/
|
|
@@ -49,6 +90,10 @@ export function scanCacheVersion(layout, rootPath, ruleIds, scope = {}) {
|
|
|
49
90
|
hash.update(`${name}:${stableJson([...new Set(patterns)].sort())}`);
|
|
50
91
|
}
|
|
51
92
|
}
|
|
93
|
+
// Empty when all resolve, so a complete node_modules keeps the version
|
|
94
|
+
if (scope.unresolvedPackages !== undefined && scope.unresolvedPackages.length > 0) {
|
|
95
|
+
hash.update(`unresolved:${[...new Set(scope.unresolvedPackages)].sort().join(',')}`);
|
|
96
|
+
}
|
|
52
97
|
const layersSourcePath = layersSourceFile(ruleConfig['layersSource'], rootPath);
|
|
53
98
|
if (layersSourcePath !== undefined) {
|
|
54
99
|
hash.update(readOrEmpty(layersSourcePath));
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* worker killed in the middle leaves nothing half written.
|
|
13
13
|
*/
|
|
14
14
|
import { type ConfigWarning, type UnreadableSourceFile } from '@angular-modernizer/core';
|
|
15
|
+
import { type UnresolvedLibraryImports } from './library-import-warning.js';
|
|
15
16
|
import { type RuleRunResult, type RuleRunnerViolation } from './rule-runner.js';
|
|
16
17
|
/** Plugins a scan runs. */
|
|
17
18
|
export type ScanPluginSet = 'all' | 'solid' | 'angular' | 'architecture' | 'analyzer';
|
|
@@ -64,6 +65,12 @@ export interface ScanSpec {
|
|
|
64
65
|
maxDurationMs?: number;
|
|
65
66
|
/** `runner`: start of the budget (epoch ms). */
|
|
66
67
|
startTime?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Check the library imports of `files` and `contextFiles` for imports that
|
|
70
|
+
* do not resolve (missing or incomplete node_modules); the result carries
|
|
71
|
+
* {@link ScanEngineResult.unresolvedLibraryImports}.
|
|
72
|
+
*/
|
|
73
|
+
libraryImports?: boolean;
|
|
67
74
|
}
|
|
68
75
|
/** A finding as the scans collect it. */
|
|
69
76
|
export interface ScanFinding {
|
|
@@ -118,6 +125,12 @@ export interface ScanEngineResult {
|
|
|
118
125
|
* plugins report into the caller's scope directly.
|
|
119
126
|
*/
|
|
120
127
|
configWarnings?: ConfigWarning[];
|
|
128
|
+
/**
|
|
129
|
+
* Library imports of the scope that do not resolve, only with
|
|
130
|
+
* {@link ScanSpec.libraryImports}; checked before the rules run, so a
|
|
131
|
+
* cancelled in-thread run carries it too, a cancelled worker run not.
|
|
132
|
+
*/
|
|
133
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
121
134
|
}
|
|
122
135
|
/** Cancellation of an in-thread run; a worker is terminated instead. */
|
|
123
136
|
export interface ScanControl {
|
|
@@ -60,6 +60,16 @@ export async function runScanEngine(spec, sink, control = {}) {
|
|
|
60
60
|
projectOptions: { skipAddingFilesFromTsConfig: spec.mode !== 'sequential' },
|
|
61
61
|
});
|
|
62
62
|
await kernel.initialize();
|
|
63
|
+
// Loaded on demand like the plugins: unit tests of the scan tools mock
|
|
64
|
+
// node:fs, under which ts-morph cannot load
|
|
65
|
+
const unresolvedLibraryImports = spec.libraryImports === true
|
|
66
|
+
? (await import('./library-imports.js')).findUnresolvedLibraryImportsInFiles(kernel.getProject(), spec.tsConfigPath, new Set([...spec.files, ...(spec.contextFiles ?? [])]))
|
|
67
|
+
: undefined;
|
|
68
|
+
const result = await runRules(kernel, spec, sink, control);
|
|
69
|
+
return unresolvedLibraryImports === undefined ? result : { ...result, unresolvedLibraryImports };
|
|
70
|
+
}
|
|
71
|
+
/** Selects the rules of the scan and runs them in the mode of `spec`. */
|
|
72
|
+
async function runRules(kernel, spec, sink, control) {
|
|
63
73
|
// The kernel's plugin instances carry the ruleConfigs of .angular-modernizer.json
|
|
64
74
|
const allRules = kernel
|
|
65
75
|
.getAllPlugins()
|
|
@@ -219,7 +219,7 @@ export declare class ListImportsTool implements MCPTool {
|
|
|
219
219
|
type: string;
|
|
220
220
|
};
|
|
221
221
|
};
|
|
222
|
-
required: ("total" | "
|
|
222
|
+
required: ("total" | "unresolved" | "external" | "aliased" | "relative" | "reExports" | "typeOnly")[];
|
|
223
223
|
};
|
|
224
224
|
summary: {
|
|
225
225
|
type: string;
|
|
@@ -179,7 +179,7 @@ export class RefreshStateTool {
|
|
|
179
179
|
items: { type: 'string', enum: [...REFRESH_PARTS] },
|
|
180
180
|
minItems: 1,
|
|
181
181
|
uniqueItems: true,
|
|
182
|
-
description: "Parts to act on (mode 'apply' only). caches: scan cache entries listed as orphan, expired or unreadable, and the legacy cache folders; backups: backup groups listed by retention (exactly the files the report saw) and backup files without metadata; refs: snapshot refs listed by retention or without a backup group (deleted only while they still point at the commit of the report); feedback: session files listed with duplicate or outdated records, marked in .claude-feedback/index/consolidated.json while the file is unchanged (the session files stay as written)",
|
|
182
|
+
description: "Parts to act on (mode 'apply' only). caches: scan cache entries listed as orphan, outdated-layout, expired or unreadable, and the legacy cache folders; backups: backup groups listed by retention (exactly the files the report saw) and backup files without metadata; refs: snapshot refs listed by retention or without a backup group (deleted only while they still point at the commit of the report); feedback: session files listed with duplicate or outdated records, marked in .claude-feedback/index/consolidated.json while the file is unchanged (the session files stay as written)",
|
|
183
183
|
},
|
|
184
184
|
retentionDays: {
|
|
185
185
|
type: 'integer',
|
package/dist/tools/scan-all.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
|
|
|
2
2
|
import { type CancelledExecution } from './helpers/tool-context.js';
|
|
3
3
|
import { type ScanCounts } from './helpers/analysis-output.js';
|
|
4
4
|
import { type ScanCacheMode } from './helpers/scan-cache.js';
|
|
5
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
5
6
|
/** Result of the scan-all tool. */
|
|
6
7
|
export interface ScanAllResult {
|
|
7
8
|
/** The requested page of violations (`maxResults`, `resultOffset`). */
|
|
@@ -93,8 +94,13 @@ export interface ScanAllResult {
|
|
|
93
94
|
};
|
|
94
95
|
};
|
|
95
96
|
};
|
|
96
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Deprecation notices of the call (`orchestration` has no effect) and the
|
|
99
|
+
* warning about library imports that do not resolve.
|
|
100
|
+
*/
|
|
97
101
|
warnings?: string[];
|
|
102
|
+
/** Library imports of the scope that do not resolve; absent when all resolve. */
|
|
103
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
98
104
|
/**
|
|
99
105
|
* @deprecated No longer set: the block claimed a parallel run that never
|
|
100
106
|
* happened. The scan always runs in the scan worker.
|
package/dist/tools/scan-all.js
CHANGED
|
@@ -6,17 +6,8 @@ import { FindingWindow } from './helpers/finding-window.js';
|
|
|
6
6
|
import { cancelledExecution, fileProgressMessage, finalFileProgress, } from './helpers/tool-context.js';
|
|
7
7
|
import { runScan } from '../scan-host/scan-host.js';
|
|
8
8
|
import { describeScan, DEPRECATED_SCAN_ORCHESTRATION_SCHEMA, SCAN_EXECUTION_SCHEMA, SCAN_ORCHESTRATION_NOTICE, scanOutputSchema, } from './helpers/analysis-output.js';
|
|
9
|
-
import { findingsInFileOrder, readCachedFindings, SCAN_CACHE_MODE_SCHEMA, scanCacheMode, scanCacheVersion, } from './helpers/scan-cache.js';
|
|
10
|
-
|
|
11
|
-
* Version of the cache entries scan-all writes. Entries from before the
|
|
12
|
-
* per-analyzed-file layout (findings filed under their template, files without
|
|
13
|
-
* findings missing) would read as complete; `scan-all-3` also drops entries
|
|
14
|
-
* whose cross-file findings saw only their own batch, `scan-all-4` entries
|
|
15
|
-
* that hold project rule findings of another file, `scan-all-5` entries whose
|
|
16
|
-
* solid:circular-dependency findings have no `cycleId` and carry the path of a
|
|
17
|
-
* long cycle on every file.
|
|
18
|
-
*/
|
|
19
|
-
const SCAN_ALL_CACHE_VERSION = 'scan-all-5';
|
|
9
|
+
import { findingsInFileOrder, readCachedFindings, SCAN_CACHE_MODE_SCHEMA, scanCacheMode, scanCacheVersion, SCAN_ALL_CACHE_VERSION, } from './helpers/scan-cache.js';
|
|
10
|
+
import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
|
|
20
11
|
/**
|
|
21
12
|
* MCP tool `scan-all`: one scan with the rules of all analysis plugins.
|
|
22
13
|
*
|
|
@@ -162,11 +153,15 @@ export class ScanAllTool {
|
|
|
162
153
|
// returned no hits and invalidated (deleted) their entries.
|
|
163
154
|
// ============================================================================
|
|
164
155
|
const fileSystem = new RealFileSystemAdapter();
|
|
156
|
+
// Library resolution state before the cache read: it is part of the
|
|
157
|
+
// cache version, so entries of another node_modules state are not served
|
|
158
|
+
const libraryCheck = await (await import('./helpers/library-imports.js')).checkScanScope(tsConfigPath, filesToAnalyze);
|
|
165
159
|
const multiCacheManager = new MultiCacheFallbackManager(fileSystem, ['all'], {
|
|
166
160
|
...createMultiCacheConfig(mergedParams.rootPath),
|
|
167
161
|
version: scanCacheVersion(SCAN_ALL_CACHE_VERSION, mergedParams.rootPath, ruleSelection, {
|
|
168
162
|
includePatterns: mergedParams.includePatterns,
|
|
169
163
|
excludePatterns: mergedParams.excludePatterns,
|
|
164
|
+
unresolvedPackages: libraryCheck.packages,
|
|
170
165
|
}),
|
|
171
166
|
});
|
|
172
167
|
await multiCacheManager.initialize();
|
|
@@ -336,7 +331,7 @@ export class ScanAllTool {
|
|
|
336
331
|
const allRuleIds = engine.ruleIds;
|
|
337
332
|
// Get final cache statistics (Phase 3)
|
|
338
333
|
const finalStats = multiCacheManager.getStats();
|
|
339
|
-
return {
|
|
334
|
+
return withLibraryImportWarning({
|
|
340
335
|
violations: paginatedViolations,
|
|
341
336
|
counts,
|
|
342
337
|
metadata: {
|
|
@@ -367,7 +362,7 @@ export class ScanAllTool {
|
|
|
367
362
|
pagination,
|
|
368
363
|
...(execution === undefined ? {} : { execution }),
|
|
369
364
|
summary: describeScan(counts, paginatedViolations, pagination, [...notices, ...(execution === undefined ? [] : [execution.note])]),
|
|
370
|
-
};
|
|
365
|
+
}, libraryCheck.unresolved);
|
|
371
366
|
}
|
|
372
367
|
/**
|
|
373
368
|
* Load scan-all tool configuration from .angular-modernizer.json file.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
|
|
2
2
|
import { type ScanCounts } from './helpers/analysis-output.js';
|
|
3
3
|
import { type CancelledExecution } from './helpers/tool-context.js';
|
|
4
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
4
5
|
/** Result of the scan-angular tool. */
|
|
5
6
|
export interface ScanAngularResult {
|
|
6
7
|
/** The requested page of violations (`maxResults`, `resultOffset`). */
|
|
@@ -41,8 +42,13 @@ export interface ScanAngularResult {
|
|
|
41
42
|
/** Root path of the scanned project. */
|
|
42
43
|
projectRoot: string;
|
|
43
44
|
};
|
|
44
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Deprecation notices of the call (`orchestration` has no effect) and the
|
|
47
|
+
* warning about library imports that do not resolve.
|
|
48
|
+
*/
|
|
45
49
|
warnings?: string[];
|
|
50
|
+
/** Library imports of the scope that do not resolve; absent when all resolve. */
|
|
51
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
46
52
|
/**
|
|
47
53
|
* @deprecated No longer set: the block claimed a parallel run that never
|
|
48
54
|
* happened. The scan always runs in the scan worker.
|