@appland/scanner 1.70.0 → 1.70.1
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 +7 -0
- package/built/cli/scan/scanner.js +2 -2
- package/built/cli/scan/singleScan.js +2 -1
- package/built/cli/scan.js +60 -25
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@appland/scanner-v1.70.1](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.70.0...@appland/scanner-v1.70.1) (2022-09-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Skip bad files when running scanner on a directory ([d6d1e4e](https://github.com/applandinc/appmap-js/commit/d6d1e4e4eeac40424802169414b170961dfccc25))
|
|
7
|
+
|
|
1
8
|
# [@appland/scanner-v1.70.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.69.1...@appland/scanner-v1.70.0) (2022-08-31)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -35,10 +35,10 @@ class ScannerBase {
|
|
|
35
35
|
this.configuration = configuration;
|
|
36
36
|
this.files = files;
|
|
37
37
|
}
|
|
38
|
-
scan() {
|
|
38
|
+
scan(skipErrors = false) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
const checks = yield (0, configurationProvider_1.loadConfig)(this.configuration);
|
|
41
|
-
const { appMapMetadata, findings } = yield (0, scan_1.default)(this.files, checks);
|
|
41
|
+
const { appMapMetadata, findings } = yield (0, scan_1.default)(this.files, checks, skipErrors);
|
|
42
42
|
return new scanResults_1.ScanResults(this.configuration, appMapMetadata, findings, checks);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -25,6 +25,7 @@ const validateFile_1 = __importDefault(require("../validateFile"));
|
|
|
25
25
|
function singleScan(options) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
const { appmapFile, appmapDir, configuration, reportAllFindings, appId, ide, reportFile } = options;
|
|
28
|
+
const skipErrors = appmapDir !== undefined;
|
|
28
29
|
const files = yield (0, util_1.collectAppMapFiles)(appmapFile, appmapDir);
|
|
29
30
|
yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () { return (0, validateFile_1.default)('file', file); })));
|
|
30
31
|
const scanner = yield (0, scanner_1.default)(reportAllFindings, configuration, files).catch((error) => {
|
|
@@ -32,7 +33,7 @@ function singleScan(options) {
|
|
|
32
33
|
});
|
|
33
34
|
const startTime = Date.now();
|
|
34
35
|
const [rawScanResults, findingStatuses] = yield Promise.all([
|
|
35
|
-
scanner.scan(),
|
|
36
|
+
scanner.scan(skipErrors),
|
|
36
37
|
scanner.fetchFindingStatus(appId, appmapDir),
|
|
37
38
|
]);
|
|
38
39
|
// Always report the raw data
|
package/built/cli/scan.js
CHANGED
|
@@ -18,6 +18,7 @@ const promises_1 = require("fs/promises");
|
|
|
18
18
|
const models_1 = require("@appland/models");
|
|
19
19
|
const ruleChecker_1 = __importDefault(require("../ruleChecker"));
|
|
20
20
|
const appMapIndex_1 = __importDefault(require("../appMapIndex"));
|
|
21
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
21
22
|
function batch(items, size, process) {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
const left = [...items];
|
|
@@ -25,7 +26,37 @@ function batch(items, size, process) {
|
|
|
25
26
|
yield Promise.all(left.splice(0, size).map(process));
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
class Progress {
|
|
30
|
+
constructor(numFiles, numChecks) {
|
|
31
|
+
this.numFiles = numFiles;
|
|
32
|
+
this.numChecks = numChecks;
|
|
33
|
+
this.checks = 0;
|
|
34
|
+
if (process.stdout.isTTY)
|
|
35
|
+
this.bar = new cli_progress_1.default.SingleBar({ format: `Scanning [{bar}] {percentage}% | {value}/{total}` }, cli_progress_1.default.Presets.shades_classic);
|
|
36
|
+
else {
|
|
37
|
+
this.start = this.check = this.file = this.stop = () => { };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
start() {
|
|
41
|
+
var _a;
|
|
42
|
+
(_a = this.bar) === null || _a === void 0 ? void 0 : _a.start(this.numFiles * this.numChecks, 0);
|
|
43
|
+
}
|
|
44
|
+
check() {
|
|
45
|
+
var _a;
|
|
46
|
+
this.checks += 1;
|
|
47
|
+
(_a = this.bar) === null || _a === void 0 ? void 0 : _a.increment();
|
|
48
|
+
}
|
|
49
|
+
file() {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = this.bar) === null || _a === void 0 ? void 0 : _a.increment(this.numChecks - this.checks);
|
|
52
|
+
this.checks = 0;
|
|
53
|
+
}
|
|
54
|
+
stop() {
|
|
55
|
+
var _a;
|
|
56
|
+
(_a = this.bar) === null || _a === void 0 ? void 0 : _a.stop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function scan(files, checks, skipErrors = true) {
|
|
29
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
61
|
// TODO: Improve this by respecting .gitignore, or similar.
|
|
31
62
|
// For now, this addresses the main problem of encountering appmap-js and its appmap.json files
|
|
@@ -34,33 +65,37 @@ function scan(files, checks) {
|
|
|
34
65
|
const checker = new ruleChecker_1.default();
|
|
35
66
|
const appMapMetadata = {};
|
|
36
67
|
const findings = [];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
increment: () => { },
|
|
43
|
-
start: () => { },
|
|
44
|
-
stop: () => { },
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const progress = newProgress();
|
|
48
|
-
progress.start(files.length * checks.length, 0);
|
|
68
|
+
const progress = new Progress(files.length, checks.length);
|
|
69
|
+
let lastError = null;
|
|
70
|
+
let anySuccess = false;
|
|
49
71
|
yield batch(files, 2, (file) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
yield
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
try {
|
|
73
|
+
console.log(`scanning ${file}`);
|
|
74
|
+
const appMapData = yield (0, promises_1.readFile)(file, 'utf8');
|
|
75
|
+
const appMap = (0, models_1.buildAppMap)(appMapData).normalize().build();
|
|
76
|
+
const appMapIndex = new appMapIndex_1.default(appMap);
|
|
77
|
+
appMapMetadata[file] = appMap.metadata;
|
|
78
|
+
yield Promise.all(checks.map((check) => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const matchCount = findings.length;
|
|
80
|
+
yield checker.check(file, appMapIndex, check, findings);
|
|
81
|
+
progress.check();
|
|
82
|
+
const newMatches = findings.slice(matchCount, findings.length);
|
|
83
|
+
newMatches.forEach((match) => (match.appMapFile = file));
|
|
84
|
+
})));
|
|
85
|
+
anySuccess = true;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
(0, node_assert_1.default)(error instanceof Error);
|
|
89
|
+
lastError = new Error(`Error processing "${file}"`, { cause: error });
|
|
90
|
+
if (!skipErrors)
|
|
91
|
+
throw lastError;
|
|
92
|
+
console.warn(lastError);
|
|
93
|
+
}
|
|
94
|
+
progress.file();
|
|
62
95
|
}));
|
|
63
96
|
progress.stop();
|
|
97
|
+
if (!anySuccess && lastError)
|
|
98
|
+
throw lastError;
|
|
64
99
|
return { appMapMetadata, findings };
|
|
65
100
|
});
|
|
66
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appland/scanner",
|
|
3
|
-
"version": "1.70.
|
|
3
|
+
"version": "1.70.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"bin": "built/cli.js",
|
|
6
6
|
"files": [
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"prettier": "^2.3.2",
|
|
50
50
|
"semantic-release": "^19.0.2",
|
|
51
51
|
"sinon": "^13.0.1",
|
|
52
|
+
"tmp-promise": "^3.0.3",
|
|
52
53
|
"ts-jest": "^27.1.4",
|
|
53
54
|
"ts-json-schema-generator": "^0.97.0",
|
|
54
55
|
"ts-node": "^10.2.1",
|