@appland/scanner 1.82.1 → 1.83.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
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@appland/scanner-v1.83.0](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.82.1...@appland/scanner-v1.83.0) (2023-09-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Clean up telemetry ([c7d0a92](https://github.com/getappmap/appmap-js/commit/c7d0a928661351bc10e51c0531689caa3ff98b1f))
|
|
7
|
+
|
|
1
8
|
# [@appland/scanner-v1.82.1](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.82.0...@appland/scanner-v1.82.1) (2023-08-25)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -19,19 +19,11 @@ const findings_1 = require("../../findings");
|
|
|
19
19
|
const findingsReport_1 = __importDefault(require("../../report/findingsReport"));
|
|
20
20
|
const summaryReport_1 = __importDefault(require("../../report/summaryReport"));
|
|
21
21
|
const formatReport_1 = require("./formatReport");
|
|
22
|
-
const telemetry_1 = __importDefault(require("../../telemetry"));
|
|
23
|
-
const scanResults_1 = require("../../report/scanResults");
|
|
24
22
|
const util_1 = require("../../rules/lib/util");
|
|
25
23
|
const validateFile_1 = __importDefault(require("../validateFile"));
|
|
26
24
|
function singleScan(options) {
|
|
27
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
26
|
const { appmapFile, appmapDir, configuration, reportAllFindings, appId, ide, reportFile } = options;
|
|
29
|
-
telemetry_1.default.sendEvent({
|
|
30
|
-
name: 'scan:started',
|
|
31
|
-
properties: {
|
|
32
|
-
ide,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
27
|
const skipErrors = appmapDir !== undefined;
|
|
36
28
|
const files = yield (0, util_1.collectAppMapFiles)(appmapFile, appmapDir);
|
|
37
29
|
yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () { return (0, validateFile_1.default)('file', file); })));
|
|
@@ -59,13 +51,6 @@ function singleScan(options) {
|
|
|
59
51
|
const elapsed = Date.now() - startTime;
|
|
60
52
|
const numChecks = scanResults.checks.length * scanResults.summary.numAppMaps;
|
|
61
53
|
console.log(`Performed ${numChecks} checks in ${elapsed}ms (${Math.floor(numChecks / (elapsed / 1000.0))} checks/sec)`);
|
|
62
|
-
(0, scanResults_1.sendScanResultsTelemetry)({
|
|
63
|
-
ruleIds: scanResults.summary.rules,
|
|
64
|
-
numAppMaps: scanResults.summary.numAppMaps,
|
|
65
|
-
numFindings: scanResults.summary.numFindings,
|
|
66
|
-
elapsedMs: elapsed,
|
|
67
|
-
appmapDir: options.appmapDir,
|
|
68
|
-
});
|
|
69
54
|
});
|
|
70
55
|
}
|
|
71
56
|
exports.default = singleScan;
|
|
@@ -47,7 +47,6 @@ const scanner_1 = __importDefault(require("./scanner"));
|
|
|
47
47
|
const configurationProvider_1 = require("../../configuration/configurationProvider");
|
|
48
48
|
const telemetry_1 = __importDefault(require("../../telemetry"));
|
|
49
49
|
const events_1 = __importDefault(require("events"));
|
|
50
|
-
const watchScanTelemetry_1 = require("./watchScanTelemetry");
|
|
51
50
|
const isAncestorPath_1 = __importDefault(require("../../util/isAncestorPath"));
|
|
52
51
|
const util_1 = require("util");
|
|
53
52
|
const console_1 = require("console");
|
|
@@ -80,15 +79,11 @@ class Watcher {
|
|
|
80
79
|
// passing plain async function doesn't work (?)
|
|
81
80
|
this.queue = (0, async_1.queue)((0, node_util_1.callbackify)(this.scan.bind(this)), 2);
|
|
82
81
|
this.processing = new Set();
|
|
83
|
-
watchScanTelemetry_1.WatchScanTelemetry.watch(this.scanEventEmitter, options.appmapDir);
|
|
84
82
|
this.queue.error((error, task) => console.warn(`Problem processing ${task}:\n`, error));
|
|
85
83
|
}
|
|
86
84
|
watch() {
|
|
87
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
86
|
yield this.reloadConfig();
|
|
89
|
-
telemetry_1.default.sendEvent({
|
|
90
|
-
name: 'scan:started',
|
|
91
|
-
});
|
|
92
87
|
this.configWatcher = chokidar.watch(this.options.configFile, {
|
|
93
88
|
ignoreInitial: true,
|
|
94
89
|
});
|
|
@@ -1,39 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
36
|
-
const telemetry_1 = __importStar(require("../telemetry"));
|
|
3
|
+
exports.ScanResults = void 0;
|
|
37
4
|
class DistinctItems {
|
|
38
5
|
constructor() {
|
|
39
6
|
this.members = {};
|
|
@@ -118,24 +85,3 @@ class ScanResults {
|
|
|
118
85
|
}
|
|
119
86
|
}
|
|
120
87
|
exports.ScanResults = ScanResults;
|
|
121
|
-
function sendScanResultsTelemetry(telemetry) {
|
|
122
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
const gitState = telemetry_1.GitState[yield telemetry_1.Git.state(telemetry.appmapDir)];
|
|
124
|
-
const contributors = (yield telemetry_1.Git.contributors(60, telemetry.appmapDir)).length;
|
|
125
|
-
telemetry_1.default.sendEvent({
|
|
126
|
-
name: 'scan:completed',
|
|
127
|
-
properties: {
|
|
128
|
-
rules: telemetry.ruleIds.sort().join(', '),
|
|
129
|
-
git_state: gitState,
|
|
130
|
-
},
|
|
131
|
-
metrics: {
|
|
132
|
-
duration: telemetry.elapsedMs / 1000,
|
|
133
|
-
numRules: telemetry.ruleIds.length,
|
|
134
|
-
numAppMaps: telemetry.numAppMaps,
|
|
135
|
-
numFindings: telemetry.numFindings,
|
|
136
|
-
contributors: contributors,
|
|
137
|
-
},
|
|
138
|
-
}, { includeEnvironment: true });
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
exports.sendScanResultsTelemetry = sendScanResultsTelemetry;
|
package/built/telemetry.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.Git = exports.GitState = void 0;
|
|
38
|
+
exports.Git = exports.GitCommitEnvKeys = exports.GitBranchEnvKeys = exports.GitRepositoryEnvKeys = exports.GitState = void 0;
|
|
39
39
|
const os_1 = require("os");
|
|
40
40
|
const crypto_1 = require("crypto");
|
|
41
41
|
const os = __importStar(require("os"));
|
|
@@ -238,6 +238,26 @@ var GitState;
|
|
|
238
238
|
GitState[GitState["NoRepository"] = 1] = "NoRepository";
|
|
239
239
|
GitState[GitState["Ok"] = 2] = "Ok";
|
|
240
240
|
})(GitState = exports.GitState || (exports.GitState = {}));
|
|
241
|
+
exports.GitRepositoryEnvKeys = [
|
|
242
|
+
'GITHUB_REPOSITORY',
|
|
243
|
+
'CIRCLE_REPOSITORY_URL',
|
|
244
|
+
'GIT_URL',
|
|
245
|
+
'CI_REPOSITORY_URL', // GitLab
|
|
246
|
+
];
|
|
247
|
+
exports.GitBranchEnvKeys = [
|
|
248
|
+
'GITHUB_REF_NAME',
|
|
249
|
+
'CIRCLE_BRANCH',
|
|
250
|
+
'GIT_BRANCH',
|
|
251
|
+
'TRAVIS_BRANCH',
|
|
252
|
+
'CI_COMMIT_REF_NAME', // GitLab
|
|
253
|
+
];
|
|
254
|
+
exports.GitCommitEnvKeys = [
|
|
255
|
+
'GITHUB_SHA',
|
|
256
|
+
'CIRCLE_SHA1',
|
|
257
|
+
'GIT_COMMIT',
|
|
258
|
+
'TRAVIS_COMMIT',
|
|
259
|
+
'CI_COMMIT_SHA', // GitLab
|
|
260
|
+
];
|
|
241
261
|
class GitProperties {
|
|
242
262
|
static contributors(sinceDaysAgo, cwd) {
|
|
243
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -267,6 +287,54 @@ class GitProperties {
|
|
|
267
287
|
}
|
|
268
288
|
});
|
|
269
289
|
}
|
|
290
|
+
// Returns the repository URL, first by checking the environment, then by
|
|
291
|
+
// shelling out to git.
|
|
292
|
+
static repository(cwd) {
|
|
293
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
+
const envKey = exports.GitRepositoryEnvKeys.find((key) => process.env[key]);
|
|
295
|
+
if (envKey)
|
|
296
|
+
return process.env[envKey];
|
|
297
|
+
try {
|
|
298
|
+
const { stdout } = yield exec(['git', cwd && `-C ${cwd.toString()}`, 'config', '--get', 'remote.origin.url'].join(' '));
|
|
299
|
+
return stdout.trim();
|
|
300
|
+
}
|
|
301
|
+
catch (_a) {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
// Returns the branch, first by checking the environment, then by
|
|
307
|
+
// shelling out to git.
|
|
308
|
+
static branch(cwd) {
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
const envKey = exports.GitBranchEnvKeys.find((key) => process.env[key]);
|
|
311
|
+
if (envKey)
|
|
312
|
+
return process.env[envKey];
|
|
313
|
+
try {
|
|
314
|
+
const { stdout } = yield exec(['git', cwd && `-C ${cwd.toString()}`, 'rev-parse', '--abbrev-ref', 'HEAD'].join(' '));
|
|
315
|
+
return stdout.trim();
|
|
316
|
+
}
|
|
317
|
+
catch (_a) {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
// Returns the commit SHA, first by checking the environment, then by
|
|
323
|
+
// shelling out to git.
|
|
324
|
+
static commit(cwd) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
+
const envKey = exports.GitCommitEnvKeys.find((key) => process.env[key]);
|
|
327
|
+
if (envKey)
|
|
328
|
+
return process.env[envKey];
|
|
329
|
+
try {
|
|
330
|
+
const { stdout } = yield exec(['git', cwd && `-C ${cwd.toString()}`, 'rev-parse', 'HEAD'].join(' '));
|
|
331
|
+
return stdout.trim();
|
|
332
|
+
}
|
|
333
|
+
catch (_a) {
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
270
338
|
static state(cwd) {
|
|
271
339
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
340
|
return new Promise((resolve) => {
|
|
@@ -295,6 +363,9 @@ class GitProperties {
|
|
|
295
363
|
});
|
|
296
364
|
});
|
|
297
365
|
}
|
|
366
|
+
static clearCache() {
|
|
367
|
+
gitCache.clear();
|
|
368
|
+
}
|
|
298
369
|
}
|
|
299
370
|
const gitCache = new Map();
|
|
300
371
|
// GitProperties is available externally as Git.
|
package/package.json
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WatchScanTelemetry = void 0;
|
|
7
|
-
const eventAggregator_1 = __importDefault(require("../../util/eventAggregator"));
|
|
8
|
-
const scanResults_1 = require("../../report/scanResults");
|
|
9
|
-
class WatchScanTelemetry {
|
|
10
|
-
constructor(scanEvents, appmapDir) {
|
|
11
|
-
this.appmapDir = appmapDir;
|
|
12
|
-
this.cancelFn = new eventAggregator_1.default((events) => {
|
|
13
|
-
const scanEvents = events.map((e) => e.arg);
|
|
14
|
-
this.sendTelemetry(scanEvents);
|
|
15
|
-
}).attach(scanEvents, 'scan');
|
|
16
|
-
}
|
|
17
|
-
cancel() {
|
|
18
|
-
if (this.cancelFn)
|
|
19
|
-
this.cancelFn();
|
|
20
|
-
this.cancelFn = undefined;
|
|
21
|
-
}
|
|
22
|
-
static watch(scanEvents, appmapDir) {
|
|
23
|
-
const telemetry = new WatchScanTelemetry(scanEvents, appmapDir);
|
|
24
|
-
return () => telemetry.cancel();
|
|
25
|
-
}
|
|
26
|
-
sendTelemetry(scanEvents) {
|
|
27
|
-
const ruleIds = new Set();
|
|
28
|
-
let elapsed = 0;
|
|
29
|
-
const telemetryScanResults = new scanResults_1.ScanResults();
|
|
30
|
-
for (const scanEvent of scanEvents) {
|
|
31
|
-
telemetryScanResults.aggregate(scanEvent.scanResults);
|
|
32
|
-
elapsed += scanEvent.elapsed;
|
|
33
|
-
}
|
|
34
|
-
telemetryScanResults.summary.rules.forEach((rule) => ruleIds.add(rule));
|
|
35
|
-
(0, scanResults_1.sendScanResultsTelemetry)({
|
|
36
|
-
ruleIds: [...ruleIds],
|
|
37
|
-
numAppMaps: telemetryScanResults.summary.numAppMaps,
|
|
38
|
-
numFindings: telemetryScanResults.summary.numFindings,
|
|
39
|
-
elapsedMs: elapsed,
|
|
40
|
-
appmapDir: this.appmapDir,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.WatchScanTelemetry = WatchScanTelemetry;
|