@nitpicker/crawler 0.25.0 → 0.25.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/README.md +2 -2
- package/lib/crawler/crawler.js +1 -1
- package/lib/crawler/dedupe/build-dedupe-cap-observation.d.ts +2 -2
- package/lib/crawler/dedupe/build-dedupe-cap-observation.js +2 -2
- package/lib/crawler/fetch-robots-txt.js +1 -3
- package/lib/crawler/scan-js-resource-for-license-comment.js +3 -1
- package/lib/crawler-orchestrator.js +16 -11
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @nitpicker/crawler
|
|
2
2
|
|
|
3
|
-
ヘッドレスブラウザでWebサイトをクロールし、`.nitpicker
|
|
3
|
+
ヘッドレスブラウザでWebサイトをクロールし、`.nitpicker`アーカイブを生成・更新する内部パッケージです。アーカイブ自体の読み書き(スキーマ・マイグレーション・concat/split 等)は[@nitpicker/archive](../archive/README.md)が担い、このパッケージはクロールの制御(puppeteer/beholder/dealer)だけを持ちます。
|
|
4
4
|
|
|
5
|
-
通常は
|
|
5
|
+
通常は[@nitpicker/cli](../cli/README.md)の`crawl`コマンドから利用します。
|
|
6
6
|
|
|
7
7
|
## 関連リンク
|
|
8
8
|
|
package/lib/crawler/crawler.js
CHANGED
|
@@ -1996,7 +1996,7 @@ export default class Crawler extends EventEmitter {
|
|
|
1996
1996
|
* @param headCheckResult - Optional HEAD result to pass to the scraper, avoiding a redundant request
|
|
1997
1997
|
* @returns The scrape result from beholder
|
|
1998
1998
|
*/
|
|
1999
|
-
//
|
|
1999
|
+
// Intentional `private` (vs `#`) so tests can spyOn the prototype to drive the puppeteer-fallback cascade-guard branches without a full browser mock; see JSDoc above.
|
|
2000
2000
|
async _launchBrowserAndScrape(url, update, isExternal, metadataOnly, headCheckResult) {
|
|
2001
2001
|
update('Launching browser%dots%');
|
|
2002
2002
|
if (this.#options.executablePath) {
|
|
@@ -13,8 +13,8 @@ import type { DedupeCapObservationRow } from '@nitpicker/archive/types';
|
|
|
13
13
|
* its threshold when the previous session ended would restart at count 0.
|
|
14
14
|
*
|
|
15
15
|
* Mirrors the exact exclusions the live crawl-time observation site applies
|
|
16
|
-
* (`Crawler`'s `'page'` handler, gated on
|
|
17
|
-
* html.length > 0`): `listDedupeCapObservations` already narrows to that
|
|
16
|
+
* (`Crawler`'s `'page'` handler, gated on
|
|
17
|
+
* `!isExternal && !isMetadataOnly && html.length > 0`): `listDedupeCapObservations` already narrows to that
|
|
18
18
|
* same population at the SQL layer, so this function only needs to redo
|
|
19
19
|
* the two per-row signal computations that can independently yield "no
|
|
20
20
|
* signal" — `computeShapeKey` (a URL that fails to decompose) and
|
|
@@ -14,8 +14,8 @@ import { resolveOgUrlMismatch } from './resolve-og-url-mismatch.js';
|
|
|
14
14
|
* its threshold when the previous session ended would restart at count 0.
|
|
15
15
|
*
|
|
16
16
|
* Mirrors the exact exclusions the live crawl-time observation site applies
|
|
17
|
-
* (`Crawler`'s `'page'` handler, gated on
|
|
18
|
-
* html.length > 0`): `listDedupeCapObservations` already narrows to that
|
|
17
|
+
* (`Crawler`'s `'page'` handler, gated on
|
|
18
|
+
* `!isExternal && !isMetadataOnly && html.length > 0`): `listDedupeCapObservations` already narrows to that
|
|
19
19
|
* same population at the SQL layer, so this function only needs to redo
|
|
20
20
|
* the two per-row signal computations that can independently yield "no
|
|
21
21
|
* signal" — `computeShapeKey` (a URL that fails to decompose) and
|
|
@@ -24,9 +24,7 @@ export async function fetchRobotsTxt(origin, userAgent) {
|
|
|
24
24
|
return new Promise((resolve) => {
|
|
25
25
|
const protocol = robotsUrl.startsWith('https') ? redirects.https : redirects.http;
|
|
26
26
|
const req = protocol.get(robotsUrl, {
|
|
27
|
-
headers: {
|
|
28
|
-
...(userAgent ? { 'User-Agent': userAgent } : {}),
|
|
29
|
-
},
|
|
27
|
+
headers: userAgent ? { 'User-Agent': userAgent } : {},
|
|
30
28
|
timeout: 10_000,
|
|
31
29
|
}, (res) => {
|
|
32
30
|
if (res.statusCode !== 200) {
|
|
@@ -103,7 +103,9 @@ async function readLeadingBytes(url, byteLimit, timeout, userAgent) {
|
|
|
103
103
|
clearTimeout(timeoutHandle);
|
|
104
104
|
destroyed = true;
|
|
105
105
|
req.destroy();
|
|
106
|
-
|
|
106
|
+
// A single chunk can straddle the cap (the socket may deliver far more
|
|
107
|
+
// than `byteLimit` at once), so trim to the cap or a match beyond it leaks in.
|
|
108
|
+
resolve(Buffer.concat(chunks).subarray(0, byteLimit));
|
|
107
109
|
}
|
|
108
110
|
});
|
|
109
111
|
res.on('end', () => {
|
|
@@ -178,7 +178,6 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
178
178
|
get archive() {
|
|
179
179
|
return this.#archive;
|
|
180
180
|
}
|
|
181
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
182
181
|
constructor(archive, options) {
|
|
183
182
|
super();
|
|
184
183
|
this.#fromList = !!options?.list;
|
|
@@ -496,7 +495,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
496
495
|
networkOutageSummaryCounter.confirmedCount++;
|
|
497
496
|
networkOutageSummaryCounter.totalDurationMs += durationMs;
|
|
498
497
|
crawlerLog('Network outage recovered: id=%d endedAt=%d', id, endedAt);
|
|
499
|
-
//
|
|
498
|
+
// oxlint-disable-next-line no-console -- see the confirmed handler above
|
|
500
499
|
console.error(`[network] recovered after ${Math.round(durationMs / 1000)}s`);
|
|
501
500
|
return this.#archive.closeNetworkOutage(id, endedAt);
|
|
502
501
|
})
|
|
@@ -833,7 +832,9 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
833
832
|
// few lines below, and a test-mocked `Archive` may return
|
|
834
833
|
// `{ scraped, pending }` without the field (production's real
|
|
835
834
|
// `getCrawlingState()` always includes it).
|
|
836
|
-
const { scraped, pending,
|
|
835
|
+
const { scraped, pending,
|
|
836
|
+
// oxlint-disable-next-line typescript/no-useless-default-assignment -- the type is never nullish, the default only serves mocked archives
|
|
837
|
+
pendingMetadataOnly = [], } = await this.#archive.getCrawlingState();
|
|
837
838
|
if (pending.length === 0) {
|
|
838
839
|
return;
|
|
839
840
|
}
|
|
@@ -878,7 +879,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
878
879
|
this.#lanes.header(`[auto-retry] ${pending.length} pending page(s) remain — retry ${attempt}/${this.#maxAutoRetry} in %countdown(${delayMs},autoRetry,s)%s`);
|
|
879
880
|
}
|
|
880
881
|
else {
|
|
881
|
-
//
|
|
882
|
+
// oxlint-disable-next-line no-console -- see comment above
|
|
882
883
|
console.error(`[auto-retry] ${pending.length} pending page(s) remain — waiting ${Math.round(delayMs / 1000)}s before retry ${attempt}/${this.#maxAutoRetry}`);
|
|
883
884
|
}
|
|
884
885
|
await delayOrAbort(delayMs, this.#crawler.signal);
|
|
@@ -1134,7 +1135,9 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
1134
1135
|
// to `withoutHashAndAuth` before comparing, matching how
|
|
1135
1136
|
// `pendingMetadataOnly` entries are normalised (see the
|
|
1136
1137
|
// list-mode `resume`'s identical comment).
|
|
1137
|
-
const { scraped, pending,
|
|
1138
|
+
const { scraped, pending,
|
|
1139
|
+
// oxlint-disable-next-line typescript/no-useless-default-assignment -- the type is never nullish, the default only serves mocked archives
|
|
1140
|
+
pendingMetadataOnly = [], } = await archive.getCrawlingState();
|
|
1138
1141
|
const mergedRootKeys = new Set(mergedRoots
|
|
1139
1142
|
.map((root) => parseUrl(root, mergedConfig)?.withoutHashAndAuth)
|
|
1140
1143
|
.filter((root) => root !== undefined));
|
|
@@ -1331,7 +1334,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
1331
1334
|
setupProgress.onLog(message);
|
|
1332
1335
|
}
|
|
1333
1336
|
else {
|
|
1334
|
-
//
|
|
1337
|
+
// oxlint-disable-next-line no-console -- --silent has no TaskList row to report through
|
|
1335
1338
|
console.warn(message);
|
|
1336
1339
|
}
|
|
1337
1340
|
}
|
|
@@ -1656,7 +1659,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
1656
1659
|
setupProgress.onLog(message);
|
|
1657
1660
|
}
|
|
1658
1661
|
else {
|
|
1659
|
-
//
|
|
1662
|
+
// oxlint-disable-next-line no-console -- --silent has no TaskList row to report through
|
|
1660
1663
|
console.warn(message);
|
|
1661
1664
|
}
|
|
1662
1665
|
}
|
|
@@ -1673,7 +1676,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
1673
1676
|
setupProgress.onLog(message);
|
|
1674
1677
|
}
|
|
1675
1678
|
else {
|
|
1676
|
-
//
|
|
1679
|
+
// oxlint-disable-next-line no-console -- --silent has no TaskList row to report through
|
|
1677
1680
|
console.warn(message);
|
|
1678
1681
|
}
|
|
1679
1682
|
}
|
|
@@ -1713,7 +1716,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
1713
1716
|
setupProgress.onLog(summaryMessage);
|
|
1714
1717
|
}
|
|
1715
1718
|
else {
|
|
1716
|
-
//
|
|
1719
|
+
// oxlint-disable-next-line no-console -- --silent has no TaskList row to report through
|
|
1717
1720
|
console.warn(summaryMessage);
|
|
1718
1721
|
}
|
|
1719
1722
|
const { htmlSeeds, nonHtmlSeeds } = await CrawlerOrchestrator.#ingestNovelSeeds({
|
|
@@ -2231,7 +2234,9 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
2231
2234
|
throw new Error(`URL (${_url}) is invalid`);
|
|
2232
2235
|
}
|
|
2233
2236
|
setupProgress?.onPhase?.(PHASE_LOADING_CRAWL_STATE);
|
|
2234
|
-
const { scraped, pending,
|
|
2237
|
+
const { scraped, pending,
|
|
2238
|
+
// oxlint-disable-next-line typescript/no-useless-default-assignment -- the type is never nullish, the default only serves mocked archives
|
|
2239
|
+
pendingMetadataOnly = [], } = await archive.getCrawlingState();
|
|
2235
2240
|
// Unlike `append`/`inventory`/`recrawl`/`retryFailed`, this path
|
|
2236
2241
|
// resumes ANY archive including list-mode ones (`fromList: true`,
|
|
2237
2242
|
// `recursive: false`) — exactly the #369 scenario. `config.roots`
|
|
@@ -2308,7 +2313,7 @@ export class CrawlerOrchestrator extends EventEmitter {
|
|
|
2308
2313
|
dnsBurnedHostCache.set(host, 'dns');
|
|
2309
2314
|
}
|
|
2310
2315
|
if (hosts.length > 0) {
|
|
2311
|
-
//
|
|
2316
|
+
// oxlint-disable-next-line no-console
|
|
2312
2317
|
console.error(`[preload] DNS-burned hosts: ${hosts.length} (will short-circuit subsequent URLs)`);
|
|
2313
2318
|
}
|
|
2314
2319
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitpicker/crawler",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "Web crawler engine with headless browser rendering (writes .nitpicker archives via @nitpicker/archive)",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
"clean": "tsc --build --clean"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@d-zero/beholder": "5.0.
|
|
34
|
-
"@d-zero/dealer": "1.14.
|
|
35
|
-
"@d-zero/shared": "0.23.
|
|
36
|
-
"@nitpicker/archive": "0.25.
|
|
33
|
+
"@d-zero/beholder": "5.0.3",
|
|
34
|
+
"@d-zero/dealer": "1.14.2",
|
|
35
|
+
"@d-zero/shared": "0.23.2",
|
|
36
|
+
"@nitpicker/archive": "0.25.1",
|
|
37
37
|
"ansi-colors": "4.1.3",
|
|
38
38
|
"debug": "4.4.3",
|
|
39
|
-
"follow-redirects": "1.16.
|
|
39
|
+
"follow-redirects": "1.16.2",
|
|
40
40
|
"knex": "3.3.0",
|
|
41
|
-
"puppeteer": "25.
|
|
41
|
+
"puppeteer": "25.15.0",
|
|
42
42
|
"robots-parser": "3.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/debug": "4.1.13",
|
|
46
46
|
"@types/follow-redirects": "1.14.4"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "fa839178ea8f40e92fc742e0480c6cfbbb8fb01f"
|
|
49
49
|
}
|