@nitpicker/report-google-sheets 0.19.0 → 0.20.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/lib/data/create-discrepancies.d.ts +10 -12
- package/lib/data/create-discrepancies.js +27 -31
- package/lib/data/create-image-list.d.ts +26 -6
- package/lib/data/create-image-list.js +65 -39
- package/lib/data/create-links.d.ts +18 -1
- package/lib/data/create-links.js +91 -55
- package/lib/data/create-page-list.d.ts +24 -24
- package/lib/data/create-page-list.js +177 -225
- package/lib/data/create-referrers-relational-table.d.ts +13 -7
- package/lib/data/create-referrers-relational-table.js +57 -47
- package/lib/data/create-resources-relational-table.d.ts +7 -0
- package/lib/data/create-resources-relational-table.js +41 -33
- package/lib/data/create-resources.d.ts +24 -124
- package/lib/data/create-resources.js +100 -264
- package/lib/data/create-violations.d.ts +7 -6
- package/lib/data/create-violations.js +34 -19
- package/lib/dedupe-progress-message.d.ts +17 -0
- package/lib/dedupe-progress-message.js +26 -0
- package/lib/format-progress-count.d.ts +19 -0
- package/lib/format-progress-count.js +22 -0
- package/lib/open-report-archive.d.ts +54 -0
- package/lib/open-report-archive.js +76 -0
- package/lib/report.d.ts +16 -12
- package/lib/report.js +101 -94
- package/lib/reports/get-plugin-reports.d.ts +14 -6
- package/lib/reports/get-plugin-reports.js +14 -34
- package/lib/sheets/create-sheets.d.ts +66 -36
- package/lib/sheets/create-sheets.js +228 -362
- package/lib/sheets/estimate-cell-budget.d.ts +55 -0
- package/lib/sheets/estimate-cell-budget.js +56 -0
- package/lib/sheets/types.d.ts +111 -91
- package/lib/test-helpers/assert-no-lazy-cells.d.ts +16 -0
- package/lib/test-helpers/assert-no-lazy-cells.js +23 -0
- package/lib/test-helpers/cell-inspection.d.ts +20 -0
- package/lib/test-helpers/cell-inspection.js +21 -0
- package/lib/test-helpers/create-mock-sheet.d.ts +30 -0
- package/lib/test-helpers/create-mock-sheet.js +71 -0
- package/lib/test-helpers/one-chunk.d.ts +8 -0
- package/lib/test-helpers/one-chunk.js +11 -0
- package/lib/utils/join-urls-for-note.d.ts +27 -0
- package/lib/utils/join-urls-for-note.js +48 -0
- package/lib/utils/truncate-note-text.d.ts +15 -0
- package/lib/utils/truncate-note-text.js +23 -0
- package/package.json +7 -9
- package/lib/archive.d.ts +0 -29
- package/lib/archive.js +0 -49
- package/lib/sheets/run-finalize-resources.d.ts +0 -40
- package/lib/sheets/run-finalize-resources.js +0 -44
- package/lib/types.d.ts +0 -11
- package/lib/types.js +0 -1
- package/lib/utils/canonicalize-url.d.ts +0 -53
- package/lib/utils/canonicalize-url.js +0 -105
- package/lib/utils/has-prop-filter.d.ts +0 -18
- package/lib/utils/has-prop-filter.js +0 -19
- package/lib/utils/sort-resources-by-url.d.ts +0 -69
- package/lib/utils/sort-resources-by-url.js +0 -223
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
2
|
+
/**
|
|
3
|
+
* Result of opening an archive for reporting.
|
|
4
|
+
*
|
|
5
|
+
* Implements `Symbol.asyncDispose` so callers can obtain one via
|
|
6
|
+
* `await using` instead of remembering to call both
|
|
7
|
+
* `removeSignalHandlers()` and closing the manager by hand.
|
|
8
|
+
*/
|
|
9
|
+
export interface ReportArchiveHandle extends AsyncDisposable {
|
|
10
|
+
/** Read-only accessor for query functions — the only interface `report` code may depend on. */
|
|
11
|
+
readonly accessor: ArchiveAccessor;
|
|
12
|
+
/** Removes the registered signal handlers. Call this when the archive is no longer in use. */
|
|
13
|
+
readonly removeSignalHandlers: () => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Opens a `.nitpicker` archive for reporting, via `@nitpicker/query`'s
|
|
17
|
+
* `ArchiveManager` (the same tar-extraction cache `viewer`/`query` CLI use)
|
|
18
|
+
* instead of `@nitpicker/crawler`'s `Archive.open` — report used to
|
|
19
|
+
* re-extract the full tar on every run; `ArchiveManager` reuses the cache
|
|
20
|
+
* across runs and returns a read-only `ArchiveAccessor`, matching report's
|
|
21
|
+
* actual access pattern (it never writes back to the archive).
|
|
22
|
+
*
|
|
23
|
+
* Rejects anything that is not a completed `.nitpicker` file: `ArchiveManager`
|
|
24
|
+
* itself accepts a live-crawl tmpDir as `mode: 'stub'` (that is a valid mode
|
|
25
|
+
* for `viewer`/`query`, which must keep working during a live crawl), but a
|
|
26
|
+
* stub directory has no viewer read model and no finished write-model data
|
|
27
|
+
* to report on, so `report` treats it as a caller error rather than a
|
|
28
|
+
* degraded-but-working mode.
|
|
29
|
+
*
|
|
30
|
+
* Only `accessor` — never a raw `Archive` writer instance — is exposed:
|
|
31
|
+
* `ArchiveManager.open()`'s `OpenResult.archive` is populated only on the
|
|
32
|
+
* legacy `NITPICKER_DISABLE_TAR_CACHE=1` writer path and is `undefined` on
|
|
33
|
+
* the normal cached-read path this function always takes, so code that
|
|
34
|
+
* reached for it would work in one environment and silently misbehave in
|
|
35
|
+
* another. `report` has no legitimate use for write access in the first
|
|
36
|
+
* place — it is a read-only consumer by design.
|
|
37
|
+
*
|
|
38
|
+
* `ArchiveManager.closeAll()` is used (not `close(archiveId)`) for the
|
|
39
|
+
* SIGINT handler and `Symbol.asyncDispose` because it is naturally
|
|
40
|
+
* idempotent — the manager holds exactly one archive per report run, and a
|
|
41
|
+
* second `closeAll()` call iterates an already-empty id list as a no-op.
|
|
42
|
+
* `close(archiveId)` throws on a second call ("Archive not found"), which
|
|
43
|
+
* would turn the ordinary SIGINT-then-asyncDispose double-teardown into an
|
|
44
|
+
* unhandled rejection.
|
|
45
|
+
* @param filePath - Path to the `.nitpicker` archive file.
|
|
46
|
+
* @param onExtractProgress - Forwarded to `ArchiveManager` — called during
|
|
47
|
+
* the untar step with bytes read so far and the archive's total size
|
|
48
|
+
* (issue #294: a large archive's extraction can take tens of seconds with
|
|
49
|
+
* no other signal it isn't hung). Never called on a cache hit.
|
|
50
|
+
* @returns A {@link ReportArchiveHandle}.
|
|
51
|
+
* @throws {Error} If `filePath` does not resolve to a completed `.nitpicker`
|
|
52
|
+
* archive (e.g. it is a live-crawl directory).
|
|
53
|
+
*/
|
|
54
|
+
export declare function openReportArchive(filePath: string, onExtractProgress?: (readBytes: number, totalBytes: number) => void): Promise<ReportArchiveHandle>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ArchiveManager } from '@nitpicker/query';
|
|
2
|
+
import { archiveLog } from './debug.js';
|
|
3
|
+
/**
|
|
4
|
+
* Opens a `.nitpicker` archive for reporting, via `@nitpicker/query`'s
|
|
5
|
+
* `ArchiveManager` (the same tar-extraction cache `viewer`/`query` CLI use)
|
|
6
|
+
* instead of `@nitpicker/crawler`'s `Archive.open` — report used to
|
|
7
|
+
* re-extract the full tar on every run; `ArchiveManager` reuses the cache
|
|
8
|
+
* across runs and returns a read-only `ArchiveAccessor`, matching report's
|
|
9
|
+
* actual access pattern (it never writes back to the archive).
|
|
10
|
+
*
|
|
11
|
+
* Rejects anything that is not a completed `.nitpicker` file: `ArchiveManager`
|
|
12
|
+
* itself accepts a live-crawl tmpDir as `mode: 'stub'` (that is a valid mode
|
|
13
|
+
* for `viewer`/`query`, which must keep working during a live crawl), but a
|
|
14
|
+
* stub directory has no viewer read model and no finished write-model data
|
|
15
|
+
* to report on, so `report` treats it as a caller error rather than a
|
|
16
|
+
* degraded-but-working mode.
|
|
17
|
+
*
|
|
18
|
+
* Only `accessor` — never a raw `Archive` writer instance — is exposed:
|
|
19
|
+
* `ArchiveManager.open()`'s `OpenResult.archive` is populated only on the
|
|
20
|
+
* legacy `NITPICKER_DISABLE_TAR_CACHE=1` writer path and is `undefined` on
|
|
21
|
+
* the normal cached-read path this function always takes, so code that
|
|
22
|
+
* reached for it would work in one environment and silently misbehave in
|
|
23
|
+
* another. `report` has no legitimate use for write access in the first
|
|
24
|
+
* place — it is a read-only consumer by design.
|
|
25
|
+
*
|
|
26
|
+
* `ArchiveManager.closeAll()` is used (not `close(archiveId)`) for the
|
|
27
|
+
* SIGINT handler and `Symbol.asyncDispose` because it is naturally
|
|
28
|
+
* idempotent — the manager holds exactly one archive per report run, and a
|
|
29
|
+
* second `closeAll()` call iterates an already-empty id list as a no-op.
|
|
30
|
+
* `close(archiveId)` throws on a second call ("Archive not found"), which
|
|
31
|
+
* would turn the ordinary SIGINT-then-asyncDispose double-teardown into an
|
|
32
|
+
* unhandled rejection.
|
|
33
|
+
* @param filePath - Path to the `.nitpicker` archive file.
|
|
34
|
+
* @param onExtractProgress - Forwarded to `ArchiveManager` — called during
|
|
35
|
+
* the untar step with bytes read so far and the archive's total size
|
|
36
|
+
* (issue #294: a large archive's extraction can take tens of seconds with
|
|
37
|
+
* no other signal it isn't hung). Never called on a cache hit.
|
|
38
|
+
* @returns A {@link ReportArchiveHandle}.
|
|
39
|
+
* @throws {Error} If `filePath` does not resolve to a completed `.nitpicker`
|
|
40
|
+
* archive (e.g. it is a live-crawl directory).
|
|
41
|
+
*/
|
|
42
|
+
export async function openReportArchive(filePath, onExtractProgress) {
|
|
43
|
+
archiveLog('Open file: %s', filePath);
|
|
44
|
+
const manager = new ArchiveManager({ onExtractProgress });
|
|
45
|
+
const { accessor, mode } = await manager.open(filePath);
|
|
46
|
+
if (mode !== 'archive') {
|
|
47
|
+
await manager.closeAll();
|
|
48
|
+
throw new Error(`report: "${filePath}" is not a completed .nitpicker archive (detected mode: "${mode}"). ` +
|
|
49
|
+
'report only works against a finished archive file, not a live crawl directory.');
|
|
50
|
+
}
|
|
51
|
+
archiveLog('File open succeeded');
|
|
52
|
+
const signals = ['SIGINT', 'SIGBREAK', 'SIGHUP', 'SIGABRT'];
|
|
53
|
+
const close = async () => {
|
|
54
|
+
await manager.closeAll();
|
|
55
|
+
process.exit();
|
|
56
|
+
};
|
|
57
|
+
archiveLog('Bind close method to SIGINT, SIGBREAK, SIGHUP, SIGABRT events');
|
|
58
|
+
for (const signal of signals) {
|
|
59
|
+
process.on(signal, close);
|
|
60
|
+
}
|
|
61
|
+
const removeSignalHandlers = () => {
|
|
62
|
+
for (const signal of signals) {
|
|
63
|
+
process.removeListener(signal, close);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
accessor,
|
|
68
|
+
removeSignalHandlers,
|
|
69
|
+
async [Symbol.asyncDispose]() {
|
|
70
|
+
archiveLog('Closes file');
|
|
71
|
+
removeSignalHandlers();
|
|
72
|
+
await manager.closeAll();
|
|
73
|
+
archiveLog('Closed');
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/lib/report.d.ts
CHANGED
|
@@ -10,8 +10,6 @@ export interface ReportParams {
|
|
|
10
10
|
readonly credentialFilePath: string;
|
|
11
11
|
/** Path to the nitpicker config file, or `null` for defaults. */
|
|
12
12
|
readonly configPath: string | null;
|
|
13
|
-
/** Batch size for `getPagesWithRefs()` pagination (default: 100,000). */
|
|
14
|
-
readonly limit: number;
|
|
15
13
|
/** When `true`, generate all sheets without interactive prompt. */
|
|
16
14
|
readonly all?: boolean;
|
|
17
15
|
/** When `true`, suppress progress display output. */
|
|
@@ -22,8 +20,11 @@ export interface ReportParams {
|
|
|
22
20
|
* one row per `(canonical URL, status, contentType)` combination,
|
|
23
21
|
* with an added `Count` column. Useful for archives where tracking
|
|
24
22
|
* pixels generate millions of per-request unique URLs that would
|
|
25
|
-
* otherwise exceed Google Sheets' 10M-cell document limit.
|
|
26
|
-
*
|
|
23
|
+
* otherwise exceed Google Sheets' 10M-cell document limit. This field
|
|
24
|
+
* has no default of its own (omitting it maps to raw mode, like
|
|
25
|
+
* `false`) — the CLI's `report`/`pipeline` commands default their
|
|
26
|
+
* `--dedupe-resources` flag to `true` and always pass an explicit
|
|
27
|
+
* value here.
|
|
27
28
|
*/
|
|
28
29
|
readonly dedupeResources?: boolean;
|
|
29
30
|
/**
|
|
@@ -31,8 +32,7 @@ export interface ReportParams {
|
|
|
31
32
|
* the archive's total size (issue #294: a large archive's extraction can
|
|
32
33
|
* take tens of seconds with no other signal it isn't hung). This
|
|
33
34
|
* package stays UI-agnostic — the caller (the CLI's `report` command)
|
|
34
|
-
* owns turning this into a
|
|
35
|
-
* lets the caller own the rate-limit countdown display below.
|
|
35
|
+
* owns turning this into a display.
|
|
36
36
|
*/
|
|
37
37
|
readonly onExtractProgress?: (readBytes: number, totalBytes: number) => void;
|
|
38
38
|
}
|
|
@@ -43,15 +43,20 @@ export interface ReportParams {
|
|
|
43
43
|
* It orchestrates the full reporting pipeline:
|
|
44
44
|
*
|
|
45
45
|
* 1. Authenticates with Google Sheets API using OAuth2 credentials.
|
|
46
|
-
* 2. Opens the `.nitpicker` archive
|
|
46
|
+
* 2. Opens the `.nitpicker` archive (read-only, via `openReportArchive` —
|
|
47
|
+
* see that function's docs for why this replaced `Archive.open`).
|
|
47
48
|
* 3. Loads analyze plugin reports from the archive.
|
|
48
49
|
* 4. Presents an interactive multi-select prompt for the user to
|
|
49
50
|
* choose which sheets to generate.
|
|
50
|
-
* 5. Delegates to `createSheets()` for
|
|
51
|
+
* 5. Delegates to `createSheets()` for cell-budget-aware, priority-ordered
|
|
52
|
+
* data generation and upload, including its `TaskList` progress display
|
|
53
|
+
* and Google Sheets API rate-limit (429/403/5xx/ECONNRESET) backoff
|
|
54
|
+
* display — see `create-sheets.ts`'s docs.
|
|
51
55
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
56
|
+
* Cell-budget truncation warnings from `createSheets` are collected and
|
|
57
|
+
* printed via `console.error` only after `createSheets` (and its internal
|
|
58
|
+
* `TaskList` display) has finished, mirroring this file's `console.log`
|
|
59
|
+
* calls, which likewise only ever run outside that active display window.
|
|
55
60
|
* @param params - レポート生成に必要なパラメータ
|
|
56
61
|
* @example
|
|
57
62
|
* ```ts
|
|
@@ -60,7 +65,6 @@ export interface ReportParams {
|
|
|
60
65
|
* sheetUrl: 'https://docs.google.com/spreadsheets/d/xxx/edit',
|
|
61
66
|
* credentialFilePath: './credentials.json',
|
|
62
67
|
* configPath: './nitpicker.config.json',
|
|
63
|
-
* limit: 100_000,
|
|
64
68
|
* });
|
|
65
69
|
* ```
|
|
66
70
|
*/
|
package/lib/report.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { Lanes } from '@d-zero/dealer';
|
|
2
1
|
import { authentication } from '@d-zero/google-auth';
|
|
3
2
|
import { Sheets } from '@d-zero/google-sheets';
|
|
4
|
-
import c from 'ansi-colors';
|
|
5
3
|
import enquirer from 'enquirer';
|
|
6
|
-
import { getArchive } from './archive.js';
|
|
7
|
-
import { addToSummary } from './data/add-to-summary.js';
|
|
8
4
|
import { createDiscrepancies } from './data/create-discrepancies.js';
|
|
9
5
|
import { createImageList } from './data/create-image-list.js';
|
|
10
6
|
import { createLinks } from './data/create-links.js';
|
|
@@ -15,8 +11,28 @@ import { createResources } from './data/create-resources.js';
|
|
|
15
11
|
import { createViolations } from './data/create-violations.js';
|
|
16
12
|
import { log } from './debug.js';
|
|
17
13
|
import { loadConfig } from './load-config.js';
|
|
14
|
+
import { openReportArchive } from './open-report-archive.js';
|
|
18
15
|
import { getPluginReports } from './reports/get-plugin-reports.js';
|
|
19
16
|
import { createSheets } from './sheets/create-sheets.js';
|
|
17
|
+
/**
|
|
18
|
+
* Every generatable sheet name, in **priority order** — the order
|
|
19
|
+
* `createSheetList` is built in below, which `create-sheets.ts`'s Phase 2
|
|
20
|
+
* treats as the cell-budget allocation priority (see that file's docs).
|
|
21
|
+
* User-visible, more universally useful sheets first; the two relational
|
|
22
|
+
* tables last since their row counts (one row per edge, not per page) are
|
|
23
|
+
* the most likely to explode past the Google Sheets 10M-cell limit.
|
|
24
|
+
*/
|
|
25
|
+
const SHEET_PRIORITY_ORDER = [
|
|
26
|
+
'Page List',
|
|
27
|
+
'Links',
|
|
28
|
+
'Violations',
|
|
29
|
+
'Discrepancies',
|
|
30
|
+
'Resources',
|
|
31
|
+
'Images',
|
|
32
|
+
'Referrers Relational Table',
|
|
33
|
+
'Resources Relational Table',
|
|
34
|
+
'Summary',
|
|
35
|
+
];
|
|
20
36
|
/**
|
|
21
37
|
* Generates a Google Sheets report from a `.nitpicker` archive file.
|
|
22
38
|
*
|
|
@@ -24,15 +40,20 @@ import { createSheets } from './sheets/create-sheets.js';
|
|
|
24
40
|
* It orchestrates the full reporting pipeline:
|
|
25
41
|
*
|
|
26
42
|
* 1. Authenticates with Google Sheets API using OAuth2 credentials.
|
|
27
|
-
* 2. Opens the `.nitpicker` archive
|
|
43
|
+
* 2. Opens the `.nitpicker` archive (read-only, via `openReportArchive` —
|
|
44
|
+
* see that function's docs for why this replaced `Archive.open`).
|
|
28
45
|
* 3. Loads analyze plugin reports from the archive.
|
|
29
46
|
* 4. Presents an interactive multi-select prompt for the user to
|
|
30
47
|
* choose which sheets to generate.
|
|
31
|
-
* 5. Delegates to `createSheets()` for
|
|
48
|
+
* 5. Delegates to `createSheets()` for cell-budget-aware, priority-ordered
|
|
49
|
+
* data generation and upload, including its `TaskList` progress display
|
|
50
|
+
* and Google Sheets API rate-limit (429/403/5xx/ECONNRESET) backoff
|
|
51
|
+
* display — see `create-sheets.ts`'s docs.
|
|
32
52
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
53
|
+
* Cell-budget truncation warnings from `createSheets` are collected and
|
|
54
|
+
* printed via `console.error` only after `createSheets` (and its internal
|
|
55
|
+
* `TaskList` display) has finished, mirroring this file's `console.log`
|
|
56
|
+
* calls, which likewise only ever run outside that active display window.
|
|
36
57
|
* @param params - レポート生成に必要なパラメータ
|
|
37
58
|
* @example
|
|
38
59
|
* ```ts
|
|
@@ -41,12 +62,11 @@ import { createSheets } from './sheets/create-sheets.js';
|
|
|
41
62
|
* sheetUrl: 'https://docs.google.com/spreadsheets/d/xxx/edit',
|
|
42
63
|
* credentialFilePath: './credentials.json',
|
|
43
64
|
* configPath: './nitpicker.config.json',
|
|
44
|
-
* limit: 100_000,
|
|
45
65
|
* });
|
|
46
66
|
* ```
|
|
47
67
|
*/
|
|
48
68
|
export async function report(params) {
|
|
49
|
-
const { filePath, sheetUrl, credentialFilePath, configPath,
|
|
69
|
+
const { filePath, sheetUrl, credentialFilePath, configPath, all, silent, dedupeResources, onExtractProgress, } = params;
|
|
50
70
|
log('Initialization');
|
|
51
71
|
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
|
|
52
72
|
log('Authenticating');
|
|
@@ -55,8 +75,8 @@ export async function report(params) {
|
|
|
55
75
|
});
|
|
56
76
|
log('Authentication succeeded');
|
|
57
77
|
log('Opening archive: %s', filePath);
|
|
58
|
-
await using archiveHandle = await
|
|
59
|
-
const {
|
|
78
|
+
await using archiveHandle = await openReportArchive(filePath, onExtractProgress);
|
|
79
|
+
const { accessor } = archiveHandle;
|
|
60
80
|
log('Archive opened');
|
|
61
81
|
log('Loading config');
|
|
62
82
|
const config = await loadConfig(configPath);
|
|
@@ -66,25 +86,14 @@ export async function report(params) {
|
|
|
66
86
|
: undefined;
|
|
67
87
|
log('Loaded plugins: %O', plugins);
|
|
68
88
|
log('Loading plugin reports');
|
|
69
|
-
const reports = await getPluginReports(
|
|
89
|
+
const reports = await getPluginReports(accessor);
|
|
70
90
|
log('Plugin reports loaded: %d', reports.length);
|
|
71
91
|
const sheets = new Sheets(sheetUrl, auth);
|
|
72
92
|
log('Reporting starts');
|
|
73
|
-
const sheetNames = [
|
|
74
|
-
'Page List',
|
|
75
|
-
'Links',
|
|
76
|
-
'Resources',
|
|
77
|
-
'Images',
|
|
78
|
-
'Violations',
|
|
79
|
-
'Discrepancies',
|
|
80
|
-
'Summary',
|
|
81
|
-
'Referrers Relational Table',
|
|
82
|
-
'Resources Relational Table',
|
|
83
|
-
];
|
|
84
93
|
let selectedSheetNames;
|
|
85
94
|
if (all) {
|
|
86
95
|
log('All sheets selected (--all or non-TTY)');
|
|
87
|
-
selectedSheetNames =
|
|
96
|
+
selectedSheetNames = [...SHEET_PRIORITY_ORDER];
|
|
88
97
|
}
|
|
89
98
|
else {
|
|
90
99
|
log('Choice creating data');
|
|
@@ -94,7 +103,7 @@ export async function report(params) {
|
|
|
94
103
|
message: 'What do you report?',
|
|
95
104
|
name: 'sheetName',
|
|
96
105
|
type: 'multiselect',
|
|
97
|
-
choices:
|
|
106
|
+
choices: [...SHEET_PRIORITY_ORDER],
|
|
98
107
|
},
|
|
99
108
|
])
|
|
100
109
|
.catch(() => {
|
|
@@ -110,82 +119,80 @@ export async function report(params) {
|
|
|
110
119
|
selectedSheetNames = chosenSheets.sheetName;
|
|
111
120
|
}
|
|
112
121
|
log('Chosen sheets: %O', selectedSheetNames);
|
|
122
|
+
const warnings = [];
|
|
123
|
+
// Priority order is the fixed SHEET_PRIORITY_ORDER, not the user's
|
|
124
|
+
// selection-click order — createSheets's Phase 2 treats array order as
|
|
125
|
+
// the cell-budget allocation priority (see that file's docs).
|
|
113
126
|
const createSheetList = [];
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
for (const name of SHEET_PRIORITY_ORDER) {
|
|
128
|
+
if (!selectedSheetNames.includes(name)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
switch (name) {
|
|
132
|
+
case 'Page List': {
|
|
133
|
+
createSheetList.push(createPageList);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'Links': {
|
|
137
|
+
createSheetList.push(createLinks);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case 'Violations': {
|
|
141
|
+
createSheetList.push(createViolations);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case 'Discrepancies': {
|
|
145
|
+
createSheetList.push(createDiscrepancies);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case 'Resources': {
|
|
149
|
+
createSheetList.push(createResources({ dedupe: dedupeResources }));
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'Images': {
|
|
153
|
+
createSheetList.push(createImageList);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case 'Referrers Relational Table': {
|
|
157
|
+
createSheetList.push(createReferrersRelationalTable);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 'Resources Relational Table': {
|
|
161
|
+
createSheetList.push(createResourcesRelationalTable);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case 'Summary': {
|
|
165
|
+
// No-op: the Summary sheet has no generator yet (out of scope
|
|
166
|
+
// for the report rewrite — see `data/add-to-summary.ts`). Warn
|
|
167
|
+
// so a user who explicitly picked it (or ran --all) isn't left
|
|
168
|
+
// wondering why the tab never showed up.
|
|
169
|
+
warnings.push('Warning: "Summary" was selected but is not implemented yet — no Summary sheet will be generated.\n');
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
137
173
|
}
|
|
138
174
|
if (!silent) {
|
|
139
175
|
// eslint-disable-next-line no-console
|
|
140
176
|
console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
|
|
141
177
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
waitingCount++;
|
|
154
|
-
const id = `rateLimit_${countdownSeq++}`;
|
|
155
|
-
const label = message.message === 'TooManyRequestError'
|
|
156
|
-
? 'Too Many Requests (429)'
|
|
157
|
-
: message.message === 'UserRateLimitExceededError'
|
|
158
|
-
? 'Rate Limit Exceeded (403)'
|
|
159
|
-
: message.message === 'ServerError'
|
|
160
|
-
? `Server Error (${message.code ?? '5xx'})`
|
|
161
|
-
: 'Connection Reset';
|
|
162
|
-
lanes.update(RATE_LIMIT_LANE, c.yellow(`${label}: waiting %countdown(${message.waitTime}, ${id}, s)%s`));
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
waitingCount--;
|
|
166
|
-
if (waitingCount <= 0) {
|
|
167
|
-
waitingCount = 0;
|
|
168
|
-
lanes.delete(RATE_LIMIT_LANE);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
log('Reporting starts (limit: %d)', limit);
|
|
174
|
-
await createSheets({
|
|
175
|
-
sheets,
|
|
176
|
-
archive,
|
|
177
|
-
reports,
|
|
178
|
-
limit,
|
|
179
|
-
createSheetList,
|
|
180
|
-
options: lanes ? { lanes } : undefined,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
178
|
+
log('Reporting starts');
|
|
179
|
+
await createSheets({
|
|
180
|
+
sheets,
|
|
181
|
+
accessor,
|
|
182
|
+
reports,
|
|
183
|
+
createSheetList,
|
|
184
|
+
options: {
|
|
185
|
+
onWarn: (message) => warnings.push(message),
|
|
186
|
+
silent,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
183
189
|
log('Reporting done');
|
|
190
|
+
for (const warning of warnings) {
|
|
191
|
+
// eslint-disable-next-line no-console
|
|
192
|
+
console.error(warning);
|
|
193
|
+
}
|
|
184
194
|
if (!silent) {
|
|
185
195
|
// eslint-disable-next-line no-console
|
|
186
196
|
console.log('\nReport complete.');
|
|
187
197
|
}
|
|
188
|
-
if (selectedSheetNames.includes('Summary')) {
|
|
189
|
-
await addToSummary( /*sheets, archive, reports*/);
|
|
190
|
-
}
|
|
191
198
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
2
2
|
import type { Report } from '@nitpicker/types';
|
|
3
3
|
/**
|
|
4
|
-
* Retrieves analyze plugin reports stored in the archive
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Retrieves analyze plugin reports stored in the archive's `analysis/report`
|
|
5
|
+
* namespace file — the `pageData`/`discrepancies` source for the Page List
|
|
6
|
+
* and Discrepancies sheets. Returns an empty array if none is found.
|
|
7
|
+
*
|
|
8
|
+
* Violations are deliberately NOT loaded here (unlike the pre-rewrite
|
|
9
|
+
* version, which pre-fetched every `getViolations` page into a synthetic
|
|
10
|
+
* `{ name: 'violations', violations }` report entry): the Violations sheet
|
|
11
|
+
* now calls `getViolations` directly inside its own `run()`, streaming
|
|
12
|
+
* pages as it sends rows instead of holding the full violation set in
|
|
13
|
+
* memory before the first row goes out.
|
|
14
|
+
* @param accessor - The opened archive to read plugin reports from.
|
|
15
|
+
* @returns An array of plugin report data (0 or 1 entries).
|
|
8
16
|
*/
|
|
9
|
-
export declare function getPluginReports(
|
|
17
|
+
export declare function getPluginReports(accessor: ArchiveAccessor): Promise<Report[]>;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import { getViolations } from '@nitpicker/query';
|
|
2
1
|
import { reportLog } from '../debug.js';
|
|
3
|
-
const VIOLATION_CHUNK_SIZE = 5000;
|
|
4
2
|
/**
|
|
5
|
-
* Retrieves analyze plugin reports stored in the archive
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3
|
+
* Retrieves analyze plugin reports stored in the archive's `analysis/report`
|
|
4
|
+
* namespace file — the `pageData`/`discrepancies` source for the Page List
|
|
5
|
+
* and Discrepancies sheets. Returns an empty array if none is found.
|
|
6
|
+
*
|
|
7
|
+
* Violations are deliberately NOT loaded here (unlike the pre-rewrite
|
|
8
|
+
* version, which pre-fetched every `getViolations` page into a synthetic
|
|
9
|
+
* `{ name: 'violations', violations }` report entry): the Violations sheet
|
|
10
|
+
* now calls `getViolations` directly inside its own `run()`, streaming
|
|
11
|
+
* pages as it sends rows instead of holding the full violation set in
|
|
12
|
+
* memory before the first row goes out.
|
|
13
|
+
* @param accessor - The opened archive to read plugin reports from.
|
|
14
|
+
* @returns An array of plugin report data (0 or 1 entries).
|
|
9
15
|
*/
|
|
10
|
-
export async function getPluginReports(
|
|
16
|
+
export async function getPluginReports(accessor) {
|
|
11
17
|
const reports = [];
|
|
12
18
|
reportLog('Load');
|
|
13
19
|
try {
|
|
14
|
-
const report = await
|
|
20
|
+
const report = await accessor.getData('analysis/report');
|
|
15
21
|
if (report) {
|
|
16
22
|
reports.push(report);
|
|
17
23
|
}
|
|
@@ -19,31 +25,5 @@ export async function getPluginReports(archive) {
|
|
|
19
25
|
catch {
|
|
20
26
|
reportLog('Failed: report is not found');
|
|
21
27
|
}
|
|
22
|
-
try {
|
|
23
|
-
const violations = [];
|
|
24
|
-
let offset = 0;
|
|
25
|
-
let total = 0;
|
|
26
|
-
do {
|
|
27
|
-
const page = await getViolations(archive, {
|
|
28
|
-
limit: VIOLATION_CHUNK_SIZE,
|
|
29
|
-
offset,
|
|
30
|
-
});
|
|
31
|
-
total = page.total;
|
|
32
|
-
violations.push(...page.items);
|
|
33
|
-
if (page.items.length === 0) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
offset += page.items.length;
|
|
37
|
-
} while (offset < total);
|
|
38
|
-
if (violations.length > 0) {
|
|
39
|
-
reports.push({
|
|
40
|
-
name: 'violations',
|
|
41
|
-
violations,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
reportLog('Failed: violations are not found');
|
|
47
|
-
}
|
|
48
28
|
return reports;
|
|
49
29
|
}
|