@nitpicker/report-google-sheets 0.18.1 → 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.
Files changed (56) hide show
  1. package/lib/data/create-discrepancies.d.ts +10 -12
  2. package/lib/data/create-discrepancies.js +27 -31
  3. package/lib/data/create-image-list.d.ts +26 -6
  4. package/lib/data/create-image-list.js +65 -39
  5. package/lib/data/create-links.d.ts +18 -1
  6. package/lib/data/create-links.js +91 -55
  7. package/lib/data/create-page-list.d.ts +24 -24
  8. package/lib/data/create-page-list.js +178 -224
  9. package/lib/data/create-referrers-relational-table.d.ts +13 -7
  10. package/lib/data/create-referrers-relational-table.js +57 -47
  11. package/lib/data/create-resources-relational-table.d.ts +7 -0
  12. package/lib/data/create-resources-relational-table.js +41 -33
  13. package/lib/data/create-resources.d.ts +24 -124
  14. package/lib/data/create-resources.js +100 -264
  15. package/lib/data/create-violations.d.ts +7 -6
  16. package/lib/data/create-violations.js +34 -19
  17. package/lib/dedupe-progress-message.d.ts +17 -0
  18. package/lib/dedupe-progress-message.js +26 -0
  19. package/lib/format-progress-count.d.ts +19 -0
  20. package/lib/format-progress-count.js +22 -0
  21. package/lib/open-report-archive.d.ts +54 -0
  22. package/lib/open-report-archive.js +76 -0
  23. package/lib/report.d.ts +23 -10
  24. package/lib/report.js +146 -149
  25. package/lib/reports/get-plugin-reports.d.ts +14 -6
  26. package/lib/reports/get-plugin-reports.js +14 -34
  27. package/lib/sheets/create-sheets.d.ts +66 -36
  28. package/lib/sheets/create-sheets.js +228 -362
  29. package/lib/sheets/estimate-cell-budget.d.ts +55 -0
  30. package/lib/sheets/estimate-cell-budget.js +56 -0
  31. package/lib/sheets/types.d.ts +111 -91
  32. package/lib/test-helpers/assert-no-lazy-cells.d.ts +16 -0
  33. package/lib/test-helpers/assert-no-lazy-cells.js +23 -0
  34. package/lib/test-helpers/cell-inspection.d.ts +20 -0
  35. package/lib/test-helpers/cell-inspection.js +21 -0
  36. package/lib/test-helpers/create-mock-sheet.d.ts +30 -0
  37. package/lib/test-helpers/create-mock-sheet.js +71 -0
  38. package/lib/test-helpers/one-chunk.d.ts +8 -0
  39. package/lib/test-helpers/one-chunk.js +11 -0
  40. package/lib/utils/join-urls-for-note.d.ts +27 -0
  41. package/lib/utils/join-urls-for-note.js +48 -0
  42. package/lib/utils/truncate-note-text.d.ts +15 -0
  43. package/lib/utils/truncate-note-text.js +23 -0
  44. package/package.json +13 -12
  45. package/lib/archive.d.ts +0 -20
  46. package/lib/archive.js +0 -34
  47. package/lib/sheets/run-finalize-resources.d.ts +0 -40
  48. package/lib/sheets/run-finalize-resources.js +0 -44
  49. package/lib/types.d.ts +0 -11
  50. package/lib/types.js +0 -1
  51. package/lib/utils/canonicalize-url.d.ts +0 -53
  52. package/lib/utils/canonicalize-url.js +0 -105
  53. package/lib/utils/has-prop-filter.d.ts +0 -18
  54. package/lib/utils/has-prop-filter.js +0 -19
  55. package/lib/utils/sort-resources-by-url.d.ts +0 -69
  56. 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,10 +20,21 @@ 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. Defaults
26
- * to `false` (raw mode).
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;
30
+ /**
31
+ * Called during the archive-open untar step with bytes read so far and
32
+ * the archive's total size (issue #294: a large archive's extraction can
33
+ * take tens of seconds with no other signal it isn't hung). This
34
+ * package stays UI-agnostic — the caller (the CLI's `report` command)
35
+ * owns turning this into a display.
36
+ */
37
+ readonly onExtractProgress?: (readBytes: number, totalBytes: number) => void;
29
38
  }
30
39
  /**
31
40
  * Generates a Google Sheets report from a `.nitpicker` archive file.
@@ -34,15 +43,20 @@ export interface ReportParams {
34
43
  * It orchestrates the full reporting pipeline:
35
44
  *
36
45
  * 1. Authenticates with Google Sheets API using OAuth2 credentials.
37
- * 2. Opens the `.nitpicker` archive and loads its configuration.
46
+ * 2. Opens the `.nitpicker` archive (read-only, via `openReportArchive` —
47
+ * see that function's docs for why this replaced `Archive.open`).
38
48
  * 3. Loads analyze plugin reports from the archive.
39
49
  * 4. Presents an interactive multi-select prompt for the user to
40
50
  * choose which sheets to generate.
41
- * 5. Delegates to `createSheets()` for phased data generation and upload.
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.
42
55
  *
43
- * Rate limiting from the Google Sheets API (429 / 403) is handled
44
- * gracefully via the `Sheets.onLog` callback, which displays a
45
- * countdown timer in the terminal using the `Lanes` progress display.
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.
46
60
  * @param params - レポート生成に必要なパラメータ
47
61
  * @example
48
62
  * ```ts
@@ -51,7 +65,6 @@ export interface ReportParams {
51
65
  * sheetUrl: 'https://docs.google.com/spreadsheets/d/xxx/edit',
52
66
  * credentialFilePath: './credentials.json',
53
67
  * configPath: './nitpicker.config.json',
54
- * limit: 100_000,
55
68
  * });
56
69
  * ```
57
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';
@@ -13,10 +9,30 @@ import { createReferrersRelationalTable } from './data/create-referrers-relation
13
9
  import { createResourcesRelationalTable } from './data/create-resources-relational-table.js';
14
10
  import { createResources } from './data/create-resources.js';
15
11
  import { createViolations } from './data/create-violations.js';
16
- import { archiveLog, log } from './debug.js';
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 and loads its configuration.
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 phased data generation and upload.
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
- * Rate limiting from the Google Sheets API (429 / 403) is handled
34
- * gracefully via the `Sheets.onLog` callback, which displays a
35
- * countdown timer in the terminal using the `Lanes` progress display.
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, limit, all, silent, dedupeResources, } = params;
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,147 +75,124 @@ export async function report(params) {
55
75
  });
56
76
  log('Authentication succeeded');
57
77
  log('Opening archive: %s', filePath);
58
- const { archive, removeSignalHandlers } = await getArchive(filePath);
78
+ await using archiveHandle = await openReportArchive(filePath, onExtractProgress);
79
+ const { accessor } = archiveHandle;
59
80
  log('Archive opened');
60
- try {
61
- log('Loading config');
62
- const config = await loadConfig(configPath);
63
- log('Config loaded');
64
- const plugins = config.plugins?.analyze
65
- ? Object.keys(config.plugins.analyze)
66
- : undefined;
67
- log('Loaded plugins: %O', plugins);
68
- log('Loading plugin reports');
69
- const reports = await getPluginReports(archive /*plugins*/);
70
- log('Plugin reports loaded: %d', reports.length);
71
- const sheets = new Sheets(sheetUrl, auth);
72
- 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
- let selectedSheetNames;
85
- if (all) {
86
- log('All sheets selected (--all or non-TTY)');
87
- selectedSheetNames = sheetNames;
88
- }
89
- else {
81
+ log('Loading config');
82
+ const config = await loadConfig(configPath);
83
+ log('Config loaded');
84
+ const plugins = config.plugins?.analyze
85
+ ? Object.keys(config.plugins.analyze)
86
+ : undefined;
87
+ log('Loaded plugins: %O', plugins);
88
+ log('Loading plugin reports');
89
+ const reports = await getPluginReports(accessor);
90
+ log('Plugin reports loaded: %d', reports.length);
91
+ const sheets = new Sheets(sheetUrl, auth);
92
+ log('Reporting starts');
93
+ let selectedSheetNames;
94
+ if (all) {
95
+ log('All sheets selected (--all or non-TTY)');
96
+ selectedSheetNames = [...SHEET_PRIORITY_ORDER];
97
+ }
98
+ else {
99
+ log('Choice creating data');
100
+ const chosenSheets = await enquirer
101
+ .prompt([
102
+ {
103
+ message: 'What do you report?',
104
+ name: 'sheetName',
105
+ type: 'multiselect',
106
+ choices: [...SHEET_PRIORITY_ORDER],
107
+ },
108
+ ])
109
+ .catch(() => {
110
+ // enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
111
+ // ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
112
+ // 即座に終了して回避する
113
+ process.exit(0);
114
+ });
115
+ if (!chosenSheets) {
90
116
  log('Choice creating data');
91
- const chosenSheets = await enquirer
92
- .prompt([
93
- {
94
- message: 'What do you report?',
95
- name: 'sheetName',
96
- type: 'multiselect',
97
- choices: sheetNames,
98
- },
99
- ])
100
- .catch(() => {
101
- // enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
102
- // ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
103
- // 即座に終了して回避する
104
- process.exit(0);
105
- });
106
- if (!chosenSheets) {
107
- log('Choice creating data');
108
- return;
109
- }
110
- selectedSheetNames = chosenSheets.sheetName;
111
- }
112
- log('Chosen sheets: %O', selectedSheetNames);
113
- const createSheetList = [];
114
- if (selectedSheetNames.includes('Page List')) {
115
- createSheetList.push(createPageList);
116
- }
117
- if (selectedSheetNames.includes('Links')) {
118
- createSheetList.push(createLinks);
119
- }
120
- if (selectedSheetNames.includes('Discrepancies')) {
121
- createSheetList.push(createDiscrepancies);
122
- }
123
- if (selectedSheetNames.includes('Violations')) {
124
- createSheetList.push(createViolations);
125
- }
126
- if (selectedSheetNames.includes('Referrers Relational Table')) {
127
- createSheetList.push(createReferrersRelationalTable);
128
- }
129
- if (selectedSheetNames.includes('Resources Relational Table')) {
130
- createSheetList.push(createResourcesRelationalTable);
131
- }
132
- if (selectedSheetNames.includes('Resources')) {
133
- createSheetList.push(createResources({ dedupe: dedupeResources }));
134
- }
135
- if (selectedSheetNames.includes('Images')) {
136
- createSheetList.push(createImageList);
137
- }
138
- if (!silent) {
139
- // eslint-disable-next-line no-console
140
- console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
141
- }
142
- const lanes = silent
143
- ? null
144
- : new Lanes({ verbose: !process.stdout.isTTY, indent: ' ' });
145
- log('Lanes created (verbose: %s, silent: %s)', !process.stdout.isTTY, !!silent);
146
- const RATE_LIMIT_LANE = 10_000;
147
- let countdownSeq = 0;
148
- let waitingCount = 0;
149
- if (lanes) {
150
- sheets.onLog = (message) => {
151
- if (message.waiting && message.waitTime) {
152
- waitingCount++;
153
- const id = `rateLimit_${countdownSeq++}`;
154
- const label = message.message === 'TooManyRequestError'
155
- ? 'Too Many Requests (429)'
156
- : message.message === 'UserRateLimitExceededError'
157
- ? 'Rate Limit Exceeded (403)'
158
- : message.message === 'ServerError'
159
- ? `Server Error (${message.code ?? '5xx'})`
160
- : 'Connection Reset';
161
- lanes.update(RATE_LIMIT_LANE, c.yellow(`${label}: waiting %countdown(${message.waitTime}, ${id}, s)%s`));
162
- }
163
- else {
164
- waitingCount--;
165
- if (waitingCount <= 0) {
166
- waitingCount = 0;
167
- lanes.delete(RATE_LIMIT_LANE);
168
- }
169
- }
170
- };
171
- }
172
- log('Reporting starts (limit: %d)', limit);
173
- try {
174
- await createSheets({
175
- sheets,
176
- archive,
177
- reports,
178
- limit,
179
- createSheetList,
180
- options: lanes ? { lanes } : undefined,
181
- });
117
+ return;
182
118
  }
183
- finally {
184
- lanes?.close();
185
- }
186
- log('Reporting done');
187
- if (!silent) {
188
- // eslint-disable-next-line no-console
189
- console.log('\nReport complete.');
190
- }
191
- if (selectedSheetNames.includes('Summary')) {
192
- await addToSummary( /*sheets, archive, reports*/);
119
+ selectedSheetNames = chosenSheets.sheetName;
120
+ }
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).
126
+ const createSheetList = [];
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
+ }
193
172
  }
194
173
  }
195
- finally {
196
- archiveLog('Closes file');
197
- removeSignalHandlers();
198
- await archive.close();
199
- log('Done');
174
+ if (!silent) {
175
+ // eslint-disable-next-line no-console
176
+ console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
177
+ }
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
+ });
189
+ log('Reporting done');
190
+ for (const warning of warnings) {
191
+ // eslint-disable-next-line no-console
192
+ console.error(warning);
193
+ }
194
+ if (!silent) {
195
+ // eslint-disable-next-line no-console
196
+ console.log('\nReport complete.');
200
197
  }
201
198
  }
@@ -1,9 +1,17 @@
1
- import type { Archive } from '@nitpicker/crawler';
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
- * Returns an empty array if no reports are found.
6
- * @param archive - The opened archive to read plugin reports from
7
- * @returns An array of plugin report data
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(archive: Archive): Promise<Report[]>;
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
- * Returns an empty array if no reports are found.
7
- * @param archive - The opened archive to read plugin reports from
8
- * @returns An array of plugin report data
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(archive) {
16
+ export async function getPluginReports(accessor) {
11
17
  const reports = [];
12
18
  reportLog('Load');
13
19
  try {
14
- const report = await archive.getData('analysis/report');
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
  }