@appland/scanner 1.74.0 → 1.74.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 CHANGED
@@ -1,3 +1,12 @@
1
+ # [@appland/scanner-v1.74.1](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.74.0...@appland/scanner-v1.74.1) (2022-12-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Disable file watching on "ENOSPC: System limit for number of file watchers reached" ([e51b423](https://github.com/getappmap/appmap-js/commit/e51b4236384ae0ea2cde0bd79b739f7821ca30c1))
7
+ * Enable scan:completed telemetry ([6e20d73](https://github.com/getappmap/appmap-js/commit/6e20d7305fd86bd077c88f674615edb31854a11a))
8
+ * Send telemetry for scan:watcher_error:enospc and index:watcher_error:enospc ([989db4a](https://github.com/getappmap/appmap-js/commit/989db4a40db8338613afe182be25b0315df94316))
9
+
1
10
  # [@appland/scanner-v1.74.0](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.73.1...@appland/scanner-v1.74.0) (2022-12-07)
2
11
 
3
12
 
@@ -47,6 +47,7 @@ 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");
50
51
  function isDir(targetPath) {
51
52
  return __awaiter(this, void 0, void 0, function* () {
52
53
  try {
@@ -77,6 +78,7 @@ class Watcher {
77
78
  // do not remove callbackify, apparently on windows
78
79
  // passing plain async function doesn't work (?)
79
80
  this.queue = (0, async_1.queue)((0, node_util_1.callbackify)(this.scan.bind(this)), 2);
81
+ watchScanTelemetry_1.WatchScanTelemetry.watch(this.scanEventEmitter);
80
82
  }
81
83
  watch() {
82
84
  return __awaiter(this, void 0, void 0, function* () {
@@ -118,8 +120,35 @@ class Watcher {
118
120
  persistent: false,
119
121
  });
120
122
  const enqueue = (filePath) => path_1.default.basename(filePath) === 'mtime' && this.enqueue(filePath);
121
- for (const ch of [this.appmapWatcher, this.appmapPoller])
122
- ch.on('add', enqueue).on('change', enqueue);
123
+ this.appmapPoller.on('add', enqueue).on('change', enqueue);
124
+ this.appmapWatcher
125
+ .on('add', enqueue)
126
+ .on('change', enqueue)
127
+ .on('error', this.watcherErrorFunction.bind(this));
128
+ });
129
+ }
130
+ watcherErrorFunction(error) {
131
+ var _a;
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ if (this.appmapWatcher &&
134
+ error.message.includes('ENOSPC: System limit for number of file watchers reached')) {
135
+ console.warn(error.stack);
136
+ console.warn('Will disable file watching. File polling will stay enabled.');
137
+ yield ((_a = this.appmapWatcher) === null || _a === void 0 ? void 0 : _a.close());
138
+ this.appmapWatcher = undefined;
139
+ console.warn('File watching disabled.');
140
+ telemetry_1.default.sendEvent({
141
+ name: `scan:watcher_error:enospc`,
142
+ properties: {
143
+ errorMessage: error.message,
144
+ errorStack: error.stack,
145
+ },
146
+ });
147
+ }
148
+ else {
149
+ // let it crash if it's some other error, to learn what the error is
150
+ throw error;
151
+ }
123
152
  });
124
153
  }
125
154
  close() {
@@ -8,11 +8,20 @@ const eventAggregator_1 = __importDefault(require("../../lib/eventAggregator"));
8
8
  const scanResults_1 = require("../../report/scanResults");
9
9
  class WatchScanTelemetry {
10
10
  constructor(scanEvents) {
11
- new eventAggregator_1.default((events) => {
11
+ this.cancelFn = new eventAggregator_1.default((events) => {
12
12
  const scanEvents = events.map((e) => e.arg);
13
13
  this.sendTelemetry(scanEvents);
14
14
  }).attach(scanEvents, 'scan');
15
15
  }
16
+ cancel() {
17
+ if (this.cancelFn)
18
+ this.cancelFn();
19
+ this.cancelFn = undefined;
20
+ }
21
+ static watch(scanEvents) {
22
+ const telemetry = new WatchScanTelemetry(scanEvents);
23
+ return () => telemetry.cancel();
24
+ }
16
25
  sendTelemetry(scanEvents) {
17
26
  const ruleIds = new Set();
18
27
  let elapsed = 0;
@@ -30,7 +30,11 @@ class EventAggregator {
30
30
  this.pending = [];
31
31
  }
32
32
  attach(emitter, event) {
33
- emitter.on(event, (...args) => this.push(emitter, event, args[0]));
33
+ const listenerFn = (...args) => {
34
+ this.push(emitter, event, args[0]);
35
+ };
36
+ emitter.addListener(event, listenerFn);
37
+ return () => emitter.removeListener(event, listenerFn);
34
38
  }
35
39
  }
36
40
  exports.default = EventAggregator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appland/scanner",
3
- "version": "1.74.0",
3
+ "version": "1.74.1",
4
4
  "description": "Analyze AppMaps for code flaws",
5
5
  "bin": "built/cli.js",
6
6
  "files": [
@@ -20,7 +20,8 @@
20
20
  "lint": "eslint src --ext .ts",
21
21
  "ci": "yarn lint && yarn build && yarn schema-up-to-date && yarn doc-up-to-date && yarn test",
22
22
  "test": "jest --filter=./test/testFilter.js",
23
- "semantic-release": "semantic-release"
23
+ "semantic-release": "semantic-release",
24
+ "watch": "node bin/preBuild.js && tsc -p tsconfig.build.json --watch"
24
25
  },
25
26
  "author": "AppLand, Inc.",
26
27
  "license": "Commons Clause + MIT",
@@ -61,7 +62,7 @@
61
62
  "dependencies": {
62
63
  "@appland/client": "^1.5.0",
63
64
  "@appland/models": "^1.18.1",
64
- "@appland/openapi": "1.2.0",
65
+ "@appland/openapi": "1.3.0",
65
66
  "@appland/sql-parser": "^1.5.0",
66
67
  "@types/cli-progress": "^3.9.2",
67
68
  "ajv": "^8.8.2",