spooder 3.2.5 → 3.2.7
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/package.json +1 -1
- package/src/api.ts +13 -3
- package/src/config.ts +7 -7
- package/src/dispatch.ts +6 -6
- package/src/utils.d.ts +0 -2
- package/src/utils.ts +0 -5
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -6,17 +6,27 @@ import fs from 'node:fs/promises';
|
|
|
6
6
|
export class ErrorWithMetadata extends Error {
|
|
7
7
|
constructor(message: string, public metadata: Record<string, unknown>) {
|
|
8
8
|
super(message);
|
|
9
|
+
|
|
10
|
+
if (this.stack)
|
|
11
|
+
this.stack = this.stack.split('\n').slice(1).join('\n');
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
async resolve_metadata(): Promise<object> {
|
|
12
15
|
const metadata = Object.assign({}, this.metadata);
|
|
13
16
|
for (const [key, value] of Object.entries(metadata)) {
|
|
17
|
+
let resolved_value = value;
|
|
18
|
+
|
|
14
19
|
if (value instanceof Promise)
|
|
15
|
-
|
|
20
|
+
resolved_value = await value;
|
|
16
21
|
else if (typeof value === 'function')
|
|
17
|
-
|
|
22
|
+
resolved_value = value();
|
|
18
23
|
else if (value instanceof ReadableStream)
|
|
19
|
-
|
|
24
|
+
resolved_value = await new Response(value).text();
|
|
25
|
+
|
|
26
|
+
if (typeof resolved_value === 'string' && resolved_value.includes('\n'))
|
|
27
|
+
resolved_value = resolved_value.split(/\r?\n/);
|
|
28
|
+
|
|
29
|
+
metadata[key] = resolved_value;
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
return metadata;
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { log } from './utils';
|
|
3
3
|
|
|
4
4
|
const internal_config = {
|
|
5
5
|
run: 'bun run index.ts',
|
|
@@ -27,7 +27,7 @@ function validate_config_option(source: ConfigObject, target: ConfigObject, root
|
|
|
27
27
|
const actual_type = typeof value;
|
|
28
28
|
|
|
29
29
|
if (actual_type !== expected_type) {
|
|
30
|
-
|
|
30
|
+
log('ignoring invalid configuration value `%s` (expected %s, got %s)', key_name, expected_type, actual_type);
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -37,14 +37,14 @@ function validate_config_option(source: ConfigObject, target: ConfigObject, root
|
|
|
37
37
|
|
|
38
38
|
if (is_default_array) {
|
|
39
39
|
if (!is_actual_array) {
|
|
40
|
-
|
|
40
|
+
log('ignoring invalid configuration value `%s` (expected array)', key_name);
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
source[key as keyof Config] = value as Config[keyof Config];
|
|
45
45
|
} else {
|
|
46
46
|
if (is_actual_array) {
|
|
47
|
-
|
|
47
|
+
log('ignoring invalid configuration value `%s` (expected object)', key_name);
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -54,7 +54,7 @@ function validate_config_option(source: ConfigObject, target: ConfigObject, root
|
|
|
54
54
|
source[key as keyof Config] = value as Config[keyof Config];
|
|
55
55
|
}
|
|
56
56
|
} else {
|
|
57
|
-
|
|
57
|
+
log('ignoring unknown configuration key `%s`', key_name);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -65,13 +65,13 @@ export async function get_config(): Promise<Config> {
|
|
|
65
65
|
const json = await config_file.json();
|
|
66
66
|
|
|
67
67
|
if (json.spooder === null || typeof json.spooder !== 'object') {
|
|
68
|
-
|
|
68
|
+
log('failed to parse spooder configuration in package.json, using defaults');
|
|
69
69
|
return internal_config;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
validate_config_option(internal_config, json.spooder, 'spooder');
|
|
73
73
|
} catch (e) {
|
|
74
|
-
|
|
74
|
+
log('failed to read package.json, using configuration defaults');
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
return internal_config;
|
package/src/dispatch.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App } from '@octokit/app';
|
|
2
2
|
import { get_config } from './config';
|
|
3
|
-
import {
|
|
3
|
+
import { log } from './utils';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import os from 'node:os';
|
|
@@ -93,9 +93,9 @@ async function check_cache_table(key: string, repository: string, expiry: number
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
} catch (e) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
log('Failed to read canary cache file ' + cache_file_path);
|
|
97
|
+
log('Error: ' + (e as Error).message);
|
|
98
|
+
log('You should resolve this issue to prevent spamming GitHub with canary reports.');
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
if (cache_table.has(key_hash)) {
|
|
@@ -158,7 +158,7 @@ export async function dispatch_report(report_title: string, report_body: Array<u
|
|
|
158
158
|
|
|
159
159
|
const is_cached = await check_cache_table(report_title, canary_repostiory, config.canary.throttle);
|
|
160
160
|
if (is_cached) {
|
|
161
|
-
|
|
161
|
+
log('Throttled canary report: ' + report_title);
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -218,6 +218,6 @@ export async function dispatch_report(report_title: string, report_body: Array<u
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
} catch (e) {
|
|
221
|
-
|
|
221
|
+
log('Failed to dispatch canary report: ' + (e as Error)?.message ?? 'unspecified error');
|
|
222
222
|
}
|
|
223
223
|
}
|
package/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/** Logs a message to stdout with the prefix `[spooder] ` */
|
|
2
2
|
export declare function log(message: string, ...args: unknown[]): void;
|
|
3
|
-
/** Logs a message to stderr with the prefix `[spooder] ` */
|
|
4
|
-
export declare function warn(message: string, ...args: unknown[]): void;
|
|
5
3
|
/** Strips ANSI color codes from a string */
|
|
6
4
|
export declare function strip_color_codes(str: string): string;
|
|
7
5
|
/** Converts a command line string into an array of arguments */
|
package/src/utils.ts
CHANGED
|
@@ -3,11 +3,6 @@ export function log(message: string, ...args: unknown[]): void {
|
|
|
3
3
|
console.log('[spooder] ' + message, ...args);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
/** Logs a message to stderr with the prefix `[spooder] ` */
|
|
7
|
-
export function warn(message: string, ...args: unknown[]): void {
|
|
8
|
-
console.error('[spooder] ' + message, ...args);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
6
|
/** Strips ANSI color codes from a string */
|
|
12
7
|
export function strip_color_codes(str: string): string {
|
|
13
8
|
return str.replace(/\x1b\[[0-9;]*m/g, '');
|