@nitpicker/report-google-sheets 0.12.0 → 0.14.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/README.md +6 -50
- package/lib/data/create-page-list.js +30 -0
- package/lib/data/create-resources.js +7 -2
- package/lib/reports/get-plugin-reports.js +28 -0
- package/lib/sheets/run-finalize-resources.d.ts +9 -0
- package/lib/sheets/run-finalize-resources.js +9 -0
- package/lib/utils/sort-resources-by-url.d.ts +5 -2
- package/lib/utils/sort-resources-by-url.js +5 -2
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -1,58 +1,14 @@
|
|
|
1
1
|
# @nitpicker/report-google-sheets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`.nitpicker` アーカイブのクロール結果と分析結果をGoogle Sheetsへ出力する内部パッケージです。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
通常は [@nitpicker/cli](../cli/README.md) の `report` コマンドから利用します。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 関連リンク
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- **5 フェーズ構成**: `Phase 1 (シート作成)` → `Phase 2 (ページ反復) / Phase 3 (リソース反復) / Phase 4 (プラグインデータ)` 並列 → `Phase 5 (フォーマット)`。詳細は [ARCHITECTURE.md §8](../../../ARCHITECTURE.md#8-report-の詳細)。
|
|
14
|
-
- **ストリーミング送信**: 各シートの行生成は `sheet.appendRow(...rows)` でストリーミング送信。`@d-zero/google-sheets` が内部で 2500 行ごとに自動 flush するため、呼び出し元のメモリ滞留はチャンクサイズ分に抑えられる。
|
|
15
|
-
- **Resources シートの dedupe モード**: `--dedupe-resources` で canonical URL ごとに集約。広告・解析タグで per-request unique なクエリが爆発するサイトで、Google Sheets の **1 ドキュメント 10,000,000 セル上限** を回避するための機能(実例: 1.6M raw → 63K rows、96% 削減)。
|
|
16
|
-
- **Phase 3 finalize での進捗表示**: 集約後の大量行を `appendRow(...finalRows)` で一括送信する間も、`Sheet.onProgress` を購読して chunk flush ごとに Lanes に `Sending N/total` を反映する。実装は [`src/sheets/run-finalize-resources.ts`](./src/sheets/run-finalize-resources.ts)。
|
|
17
|
-
|
|
18
|
-
## 拡張ポイント(新規シート追加時)
|
|
19
|
-
|
|
20
|
-
新しいシートを追加するときの典型パターン:
|
|
21
|
-
|
|
22
|
-
| やりたいこと | 使う hook |
|
|
23
|
-
| ---------------------------------------------- | ----------------------------------------------------------- |
|
|
24
|
-
| ページごとに行を生成 | `eachPage` |
|
|
25
|
-
| ページ反復前に状態を蓄積(例: 親子関係マップ) | `preEachPage` |
|
|
26
|
-
| リソースごとに行を生成 | `eachResource` |
|
|
27
|
-
| リソース反復の終端で集約結果を 1 回だけ送信 | `eachResource` で Map に蓄積 → `finalizeResources` で flush |
|
|
28
|
-
| プラグインデータ等、反復不要で一括送信 | `addRows`(Phase 2/3 と並列実行) |
|
|
29
|
-
| データ送信後にフォーマット適用 | `updateSheet` |
|
|
30
|
-
|
|
31
|
-
> **集約系シートで `eachResource` 内の `num`/`total` を見て最後だけ emit する設計は禁止**。Phase 3 が将来並列化されると壊れる。必ず `finalizeResources` hook を使うこと([ARCHITECTURE.md の説明](../../../ARCHITECTURE.md#行送信戦略))。
|
|
32
|
-
|
|
33
|
-
## トラブルシューティング
|
|
34
|
-
|
|
35
|
-
| 症状 | 原因と対処 |
|
|
36
|
-
| ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
-
| `Error: This document is too large to continue editing.` | Google Sheets の 10M セル上限到達。`--dedupe-resources` を有効にして Resources を集約する。 |
|
|
38
|
-
| Phase 3 で「Sending N/total」の N が止まったまま | 進捗表示は `Sheet.onProgress` 駆動。`@d-zero/google-sheets` を 0.9.0 以上に保つ必要がある。 |
|
|
39
|
-
| `RangeError: Maximum call stack size exceeded` (Phase 3 finalize) | `appendRow(...finalRows)` のスプレッドが V8 引数上限(実用上 6.5 万件付近)を超えた。`finalizeResources` の戻り値件数が更に増えた場合は chunk 単位で複数回 `appendRow` を呼ぶよう書き換える。[ARCHITECTURE.md の既知の制約セクション](../../../ARCHITECTURE.md#行送信戦略)を参照。 |
|
|
40
|
-
| sort に長時間ブロックされて HTTPS が EPIPE で落ちる | `sortResourcesByUrl` は Pool `strnatcmp` の派生文字列ゼロ実装。`Intl.Collator.compare` や Schwartzian transform への書き換えは禁止(過去にやって両方とも本番障害を起こした)。詳細は [ARCHITECTURE.md](../../../ARCHITECTURE.md#行送信戦略)。 |
|
|
41
|
-
|
|
42
|
-
## テスト
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
yarn vitest run packages/@nitpicker/report-google-sheets
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
E2E は `yarn vitest run --config vitest.e2e.config.ts` でリポジトリ全体一括(Google Sheets API モックは未整備のため、本番送信パスは手動検証)。
|
|
49
|
-
|
|
50
|
-
## 参照
|
|
51
|
-
|
|
52
|
-
- [ARCHITECTURE.md §8 Report の詳細](../../../ARCHITECTURE.md#8-report-の詳細) — フェーズ詳細、行送信戦略、sort 実装の根拠
|
|
53
|
-
- [`@d-zero/google-sheets`](https://www.npmjs.com/package/@d-zero/google-sheets) — Sheet ストリーミング送信 API
|
|
54
|
-
- [Google Sheets API 制限](https://developers.google.com/sheets/api/limits) — 10M セル上限、batchUpdate サイズ
|
|
55
|
-
- [Martin Pool, "Natural Order String Comparison"](https://sourcefrog.net/projects/natsort/) — sort 実装の出典
|
|
9
|
+
- [Nitpicker README](../../../README.md)
|
|
10
|
+
- [CLI report docs](../cli/docs/report.md)
|
|
11
|
+
- [ARCHITECTURE.md](../../../ARCHITECTURE.md)
|
|
56
12
|
|
|
57
13
|
## ライセンス
|
|
58
14
|
|
|
@@ -111,6 +111,19 @@ export const createPageList = (reports) => {
|
|
|
111
111
|
'og:article:published_time',
|
|
112
112
|
'jsonld_count',
|
|
113
113
|
'tags_providers',
|
|
114
|
+
'main_content_selector',
|
|
115
|
+
'main_content_word_count',
|
|
116
|
+
'main_content_body_word_count',
|
|
117
|
+
'main_content_heading_count',
|
|
118
|
+
'main_content_image_count',
|
|
119
|
+
'main_content_table_count',
|
|
120
|
+
'main_content_button_count',
|
|
121
|
+
'main_content_iframe_count',
|
|
122
|
+
'main_content_video_count',
|
|
123
|
+
'main_content_audio_count',
|
|
124
|
+
'main_content_canvas_count',
|
|
125
|
+
'scroll_height_desktop',
|
|
126
|
+
'scroll_height_mobile',
|
|
114
127
|
];
|
|
115
128
|
for (const report of reports) {
|
|
116
129
|
if (report.pageData) {
|
|
@@ -258,6 +271,23 @@ export const createPageList = (reports) => {
|
|
|
258
271
|
// for native Google Sheets list rendering.
|
|
259
272
|
createCellData({ value: page.jsonldCount }, defaultCellFormat),
|
|
260
273
|
createCellData({ value: page.tagsProvidersCsv }, defaultCellFormat),
|
|
274
|
+
// beholder MainContentsData / ScrollHeightData denormalised
|
|
275
|
+
// aggregates. `null` (page never fully rendered) or `0` (rendered,
|
|
276
|
+
// no main region / no elements of that kind found) render as
|
|
277
|
+
// blank / 0 respectively — no special-casing needed here.
|
|
278
|
+
createCellData({ value: page.mainContentSelector }, defaultCellFormat),
|
|
279
|
+
createCellData({ value: page.mainContentWordCount }, defaultCellFormat),
|
|
280
|
+
createCellData({ value: page.mainContentBodyWordCount }, defaultCellFormat),
|
|
281
|
+
createCellData({ value: page.mainContentHeadingCount }, defaultCellFormat),
|
|
282
|
+
createCellData({ value: page.mainContentImageCount }, defaultCellFormat),
|
|
283
|
+
createCellData({ value: page.mainContentTableCount }, defaultCellFormat),
|
|
284
|
+
createCellData({ value: page.mainContentButtonCount }, defaultCellFormat),
|
|
285
|
+
createCellData({ value: page.mainContentIframeCount }, defaultCellFormat),
|
|
286
|
+
createCellData({ value: page.mainContentVideoCount }, defaultCellFormat),
|
|
287
|
+
createCellData({ value: page.mainContentAudioCount }, defaultCellFormat),
|
|
288
|
+
createCellData({ value: page.mainContentCanvasCount }, defaultCellFormat),
|
|
289
|
+
createCellData({ value: page.scrollHeightDesktop }, defaultCellFormat),
|
|
290
|
+
createCellData({ value: page.scrollHeightMobile }, defaultCellFormat),
|
|
261
291
|
];
|
|
262
292
|
for (const report of reportPageData) {
|
|
263
293
|
const tableData = report.pageData.data[page.url.href];
|
|
@@ -278,7 +278,12 @@ export function createResources(options) {
|
|
|
278
278
|
skipSortResources: true,
|
|
279
279
|
createHeaders: () => [...DEDUPE_HEADERS],
|
|
280
280
|
async eachResource(resource) {
|
|
281
|
-
|
|
281
|
+
// A blob-routed resource (identity is a large `data:` URI, not a
|
|
282
|
+
// URL — see `create-entity-tables.ts`'s `resource_items url /
|
|
283
|
+
// blob mutual-exclusion CHECK`) has `url === null`; group all
|
|
284
|
+
// such resources under one degenerate empty-string key rather
|
|
285
|
+
// than crashing the report.
|
|
286
|
+
const canonical = canonicalizeUrl(resource.url ?? '');
|
|
282
287
|
const key = dedupeKey(canonical, resource.status, resource.contentType);
|
|
283
288
|
let entry = entries.get(key);
|
|
284
289
|
if (entry) {
|
|
@@ -299,7 +304,7 @@ export function createResources(options) {
|
|
|
299
304
|
entries.set(key, entry);
|
|
300
305
|
}
|
|
301
306
|
entry.count++;
|
|
302
|
-
for (const { key: paramKey, value } of extractQueryPairs(resource.url)) {
|
|
307
|
+
for (const { key: paramKey, value } of extractQueryPairs(resource.url ?? '')) {
|
|
303
308
|
recordParamValue(entry, paramKey, value);
|
|
304
309
|
}
|
|
305
310
|
reportLog(`Read: Resource referrers (Search: ${resource.url})`);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getViolations } from '@nitpicker/query';
|
|
1
2
|
import { reportLog } from '../debug.js';
|
|
3
|
+
const VIOLATION_CHUNK_SIZE = 5000;
|
|
2
4
|
/**
|
|
3
5
|
* Retrieves analyze plugin reports stored in the archive.
|
|
4
6
|
* Returns an empty array if no reports are found.
|
|
@@ -17,5 +19,31 @@ export async function getPluginReports(archive) {
|
|
|
17
19
|
catch {
|
|
18
20
|
reportLog('Failed: report is not found');
|
|
19
21
|
}
|
|
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
|
+
}
|
|
20
48
|
return reports;
|
|
21
49
|
}
|
|
@@ -26,6 +26,15 @@ export interface RunFinalizeResourcesParams {
|
|
|
26
26
|
* - Always resets `sheet.onProgress` in a `finally` block, even when
|
|
27
27
|
* `appendRow` throws — preventing a stale handler from leaking into
|
|
28
28
|
* a different sheet's lane.
|
|
29
|
+
*
|
|
30
|
+
* Known limitation (V8 argument cap): the aggregated rows are spread into
|
|
31
|
+
* `sheet.appendRow(...finalRows)`, so an array longer than V8's practical
|
|
32
|
+
* argument limit (~65k) throws `RangeError: Maximum call stack size
|
|
33
|
+
* exceeded`. Verified working at 1.6M raw resources → 63k aggregated rows.
|
|
34
|
+
* If aggregates ever exceed ~60k, switch to chunked calls (e.g. 10k per
|
|
35
|
+
* `appendRow`) — the Sheet's internal 2500-row buffer is call-count
|
|
36
|
+
* agnostic, so outer chunking preserves ordering and total send count.
|
|
37
|
+
* The spec pins behaviour at 100 rows to stay clear of the V8 limit.
|
|
29
38
|
* @param params - Hook invocation context (see {@link RunFinalizeResourcesParams}).
|
|
30
39
|
*/
|
|
31
40
|
export declare function runFinalizeResources(params: RunFinalizeResourcesParams): Promise<void>;
|
|
@@ -9,6 +9,15 @@ import { sheetLog } from '../debug.js';
|
|
|
9
9
|
* - Always resets `sheet.onProgress` in a `finally` block, even when
|
|
10
10
|
* `appendRow` throws — preventing a stale handler from leaking into
|
|
11
11
|
* a different sheet's lane.
|
|
12
|
+
*
|
|
13
|
+
* Known limitation (V8 argument cap): the aggregated rows are spread into
|
|
14
|
+
* `sheet.appendRow(...finalRows)`, so an array longer than V8's practical
|
|
15
|
+
* argument limit (~65k) throws `RangeError: Maximum call stack size
|
|
16
|
+
* exceeded`. Verified working at 1.6M raw resources → 63k aggregated rows.
|
|
17
|
+
* If aggregates ever exceed ~60k, switch to chunked calls (e.g. 10k per
|
|
18
|
+
* `appendRow`) — the Sheet's internal 2500-row buffer is call-count
|
|
19
|
+
* agnostic, so outer chunking preserves ordering and total send count.
|
|
20
|
+
* The spec pins behaviour at 100 rows to stay clear of the V8 limit.
|
|
12
21
|
* @param params - Hook invocation context (see {@link RunFinalizeResourcesParams}).
|
|
13
22
|
*/
|
|
14
23
|
export async function runFinalizeResources(params) {
|
|
@@ -49,7 +49,10 @@ export declare function naturalCompare(a: string, b: string): number;
|
|
|
49
49
|
* intermediate strings, so the only extra memory is V8's TimSort
|
|
50
50
|
* auxiliary buffer — O(N) pointer-sized entries, not O(N × URL length).
|
|
51
51
|
* @param resources - The list of resources to sort. Only the `url`
|
|
52
|
-
* field is read.
|
|
52
|
+
* field is read. A `null` url (a blob-routed resource whose identity
|
|
53
|
+
* is a large `data:` URI — see `create-entity-tables.ts`'s
|
|
54
|
+
* `resource_items url / blob mutual-exclusion CHECK`) sorts as if it
|
|
55
|
+
* were the empty string, placing it first.
|
|
53
56
|
* @returns A new array sorted by URL in natural order.
|
|
54
57
|
* @example
|
|
55
58
|
* ```ts
|
|
@@ -62,5 +65,5 @@ export declare function naturalCompare(a: string, b: string): number;
|
|
|
62
65
|
* ```
|
|
63
66
|
*/
|
|
64
67
|
export declare function sortResourcesByUrl<T extends {
|
|
65
|
-
readonly url: string;
|
|
68
|
+
readonly url: string | null;
|
|
66
69
|
}>(resources: readonly T[]): T[];
|
|
@@ -203,7 +203,10 @@ export function naturalCompare(a, b) {
|
|
|
203
203
|
* intermediate strings, so the only extra memory is V8's TimSort
|
|
204
204
|
* auxiliary buffer — O(N) pointer-sized entries, not O(N × URL length).
|
|
205
205
|
* @param resources - The list of resources to sort. Only the `url`
|
|
206
|
-
* field is read.
|
|
206
|
+
* field is read. A `null` url (a blob-routed resource whose identity
|
|
207
|
+
* is a large `data:` URI — see `create-entity-tables.ts`'s
|
|
208
|
+
* `resource_items url / blob mutual-exclusion CHECK`) sorts as if it
|
|
209
|
+
* were the empty string, placing it first.
|
|
207
210
|
* @returns A new array sorted by URL in natural order.
|
|
208
211
|
* @example
|
|
209
212
|
* ```ts
|
|
@@ -216,5 +219,5 @@ export function naturalCompare(a, b) {
|
|
|
216
219
|
* ```
|
|
217
220
|
*/
|
|
218
221
|
export function sortResourcesByUrl(resources) {
|
|
219
|
-
return resources.toSorted((a, b) => naturalCompare(a.url, b.url));
|
|
222
|
+
return resources.toSorted((a, b) => naturalCompare(a.url ?? '', b.url ?? ''));
|
|
220
223
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitpicker/report-google-sheets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Nitpicker reporter that outputs crawl and analysis results to Google Sheets",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -27,12 +27,13 @@
|
|
|
27
27
|
"clean": "tsc --build --clean"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@d-zero/dealer": "1.9.
|
|
31
|
-
"@d-zero/google-auth": "0.7.
|
|
32
|
-
"@d-zero/google-sheets": "0.9.
|
|
33
|
-
"@d-zero/shared": "0.22.
|
|
34
|
-
"@nitpicker/crawler": "0.
|
|
35
|
-
"@nitpicker/
|
|
30
|
+
"@d-zero/dealer": "1.9.4",
|
|
31
|
+
"@d-zero/google-auth": "0.7.5",
|
|
32
|
+
"@d-zero/google-sheets": "0.9.4",
|
|
33
|
+
"@d-zero/shared": "0.22.2",
|
|
34
|
+
"@nitpicker/crawler": "0.14.0",
|
|
35
|
+
"@nitpicker/query": "0.14.0",
|
|
36
|
+
"@nitpicker/types": "0.14.0",
|
|
36
37
|
"ansi-colors": "4.1.3",
|
|
37
38
|
"debug": "4.4.3",
|
|
38
39
|
"enquirer": "2.4.1",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"@types/debug": "4.1.13",
|
|
43
44
|
"@types/jsdom": "28.0.3",
|
|
44
45
|
"googleapis": "173.0.0",
|
|
45
|
-
"vitest": "4.1.
|
|
46
|
+
"vitest": "4.1.10"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "d6e1894a29aa29ca94785d9db0acfc3acc74764b"
|
|
48
49
|
}
|