shippingszn 0.3.0 → 0.4.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/dist/checks/public-assets.js +56 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,55 @@
|
|
|
1
|
+
import { readFileSafe } from "../scan.js";
|
|
1
2
|
import { findPublicDirs, isAssetEmittedDynamically } from "./helpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse a robots.txt body and return true if the `User-agent: *` block (or
|
|
5
|
+
* any wildcard block) disallows everything (`Disallow: /`). That's a
|
|
6
|
+
* declaration that the site intentionally opts out of all crawling, so we
|
|
7
|
+
* shouldn't nag about a missing sitemap — sitemaps for disallowed sites are
|
|
8
|
+
* contradictory.
|
|
9
|
+
*/
|
|
10
|
+
function robotsDisallowsAll(content) {
|
|
11
|
+
const lines = content.split(/\r?\n/);
|
|
12
|
+
let inWildcardBlock = false;
|
|
13
|
+
let sawWildcardBlock = false;
|
|
14
|
+
for (const raw of lines) {
|
|
15
|
+
// Strip comments and trailing whitespace.
|
|
16
|
+
const line = raw.replace(/#.*$/, "").trim();
|
|
17
|
+
if (line === "") {
|
|
18
|
+
// Blank line ends the current block.
|
|
19
|
+
inWildcardBlock = false;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const match = line.match(/^([A-Za-z-]+)\s*:\s*(.*)$/);
|
|
23
|
+
if (!match)
|
|
24
|
+
continue;
|
|
25
|
+
const directive = match[1].toLowerCase();
|
|
26
|
+
const value = match[2].trim();
|
|
27
|
+
if (directive === "user-agent") {
|
|
28
|
+
inWildcardBlock = value === "*";
|
|
29
|
+
if (inWildcardBlock)
|
|
30
|
+
sawWildcardBlock = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (inWildcardBlock && directive === "disallow" && value === "/") {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// If the file has no wildcard block at all, conservatively assume it
|
|
38
|
+
// doesn't disallow everything (some sites only target specific bots).
|
|
39
|
+
void sawWildcardBlock;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
async function hasDisallowAllRobots(ctx) {
|
|
43
|
+
const robotsFiles = ctx.files.filter((f) => /(^|\/)robots\.txt$/i.test(f.relPath));
|
|
44
|
+
for (const file of robotsFiles) {
|
|
45
|
+
const content = await readFileSafe(file);
|
|
46
|
+
if (!content)
|
|
47
|
+
continue;
|
|
48
|
+
if (robotsDisallowsAll(content))
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
2
53
|
export async function checkRobotsTxt(ctx) {
|
|
3
54
|
const has = ctx.files.some((f) => /(^|\/)robots\.txt$/i.test(f.relPath));
|
|
4
55
|
if (has)
|
|
@@ -26,6 +77,11 @@ export async function checkSitemapXml(ctx) {
|
|
|
26
77
|
const dirs = await findPublicDirs(ctx);
|
|
27
78
|
if (dirs.length === 0)
|
|
28
79
|
return [];
|
|
80
|
+
// If the project has declared itself non-indexable via robots.txt
|
|
81
|
+
// (User-agent: * / Disallow: /), a sitemap would be contradictory.
|
|
82
|
+
// Suppress the nag — the site owner has made a deliberate choice.
|
|
83
|
+
if (await hasDisallowAllRobots(ctx))
|
|
84
|
+
return [];
|
|
29
85
|
return [
|
|
30
86
|
{
|
|
31
87
|
checkId: "missing-sitemap-xml",
|
package/dist/index.js
CHANGED
package/package.json
CHANGED