@casoon/astro-post-audit 0.2.2 → 0.2.4
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/bin/install.cjs +13 -3
- package/dist/integration.d.ts +24 -30
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +35 -42
- package/dist/integration.test.js +2 -8
- package/package.json +1 -1
package/bin/install.cjs
CHANGED
|
@@ -150,10 +150,20 @@ async function main() {
|
|
|
150
150
|
const binDir = path.join(__dirname);
|
|
151
151
|
const binaryPath = path.join(binDir, binaryName);
|
|
152
152
|
|
|
153
|
-
// Skip if binary already exists
|
|
153
|
+
// Skip if binary already exists AND matches the expected version
|
|
154
154
|
if (fs.existsSync(binaryPath)) {
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
try {
|
|
156
|
+
const out = execSync(`"${binaryPath}" --version`, { encoding: "utf-8", timeout: 5000 }).trim();
|
|
157
|
+
// Output format: "astro-post-audit 0.2.2"
|
|
158
|
+
const installedVersion = out.split(/\s+/).pop();
|
|
159
|
+
if (installedVersion === VERSION) {
|
|
160
|
+
console.log(`${PACKAGE} v${VERSION} already installed, skipping download.`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
console.log(`${PACKAGE} version mismatch: installed ${installedVersion}, expected ${VERSION}. Re-downloading...`);
|
|
164
|
+
} catch {
|
|
165
|
+
console.log(`${PACKAGE} binary exists but version check failed. Re-downloading...`);
|
|
166
|
+
}
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
const url = getDownloadUrl(target);
|
package/dist/integration.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export interface RulesConfig {
|
|
|
11
11
|
};
|
|
12
12
|
/** File filters — glob patterns to include or exclude pages from all checks. */
|
|
13
13
|
filters?: {
|
|
14
|
-
/** Only check files matching these glob patterns.
|
|
14
|
+
/** Only check files matching these glob patterns. */
|
|
15
15
|
include?: string[];
|
|
16
|
-
/** Skip files matching these glob patterns (e.g. `["404.html", "drafts/**"]`).
|
|
16
|
+
/** Skip files matching these glob patterns (e.g. `["404.html", "drafts/**"]`). */
|
|
17
17
|
exclude?: string[];
|
|
18
18
|
};
|
|
19
19
|
/** URL normalization rules for internal link and canonical consistency. */
|
|
@@ -33,6 +33,8 @@ export interface RulesConfig {
|
|
|
33
33
|
same_origin?: boolean;
|
|
34
34
|
/** Canonical must be a self-reference (point to the page itself). @default false */
|
|
35
35
|
self_reference?: boolean;
|
|
36
|
+
/** Warn when multiple pages share the same canonical URL (cluster detection). @default true */
|
|
37
|
+
detect_clusters?: boolean;
|
|
36
38
|
};
|
|
37
39
|
/** Robots meta tag checks. */
|
|
38
40
|
robots_meta?: {
|
|
@@ -117,7 +119,7 @@ export interface RulesConfig {
|
|
|
117
119
|
/** Require a skip navigation link (e.g. `<a href="#main-content">`). @default false */
|
|
118
120
|
require_skip_link?: boolean;
|
|
119
121
|
};
|
|
120
|
-
/** Asset reference and size checks.
|
|
122
|
+
/** Asset reference and size checks. */
|
|
121
123
|
assets?: {
|
|
122
124
|
/** Check that `<img>`, `<script>`, `<link>` references resolve to files in `dist/`. @default false */
|
|
123
125
|
check_broken_assets?: boolean;
|
|
@@ -143,7 +145,7 @@ export interface RulesConfig {
|
|
|
143
145
|
/** Require `twitter:card` meta tag. @default false */
|
|
144
146
|
require_twitter_card?: boolean;
|
|
145
147
|
};
|
|
146
|
-
/** Structured data (JSON-LD) validation.
|
|
148
|
+
/** Structured data (JSON-LD) validation. */
|
|
147
149
|
structured_data?: {
|
|
148
150
|
/** Validate JSON-LD syntax and semantics (`@context`, `@type`, required properties). @default false */
|
|
149
151
|
check_json_ld?: boolean;
|
|
@@ -163,7 +165,7 @@ export interface RulesConfig {
|
|
|
163
165
|
/** Hreflang links must be reciprocal (A→B and B→A). @default false */
|
|
164
166
|
require_reciprocal?: boolean;
|
|
165
167
|
};
|
|
166
|
-
/** Security heuristic checks.
|
|
168
|
+
/** Security heuristic checks. */
|
|
167
169
|
security?: {
|
|
168
170
|
/** Warn on `target="_blank"` without `rel="noopener"`. @default true */
|
|
169
171
|
check_target_blank?: boolean;
|
|
@@ -172,7 +174,7 @@ export interface RulesConfig {
|
|
|
172
174
|
/** Warn on inline `<script>` tags. @default false */
|
|
173
175
|
warn_inline_scripts?: boolean;
|
|
174
176
|
};
|
|
175
|
-
/** Duplicate content detection.
|
|
177
|
+
/** Duplicate content detection. */
|
|
176
178
|
content_quality?: {
|
|
177
179
|
/** Warn if multiple pages share the same `<title>`. @default false */
|
|
178
180
|
detect_duplicate_titles?: boolean;
|
|
@@ -188,46 +190,38 @@ export interface RulesConfig {
|
|
|
188
190
|
* @example `{ "html/title-too-long": "off", "a11y/img-alt-missing": "error" }`
|
|
189
191
|
*/
|
|
190
192
|
severity?: Record<string, 'error' | 'warning' | 'info' | 'off'>;
|
|
191
|
-
/**
|
|
193
|
+
/** External link checking (HEAD requests to verify URLs return 2xx). */
|
|
192
194
|
external_links?: {
|
|
195
|
+
/** Enable external link checking. @default false */
|
|
193
196
|
enabled?: boolean;
|
|
197
|
+
/** Timeout per request in milliseconds. @default 3000 */
|
|
194
198
|
timeout_ms?: number;
|
|
199
|
+
/** Maximum concurrent requests. @default 10 */
|
|
195
200
|
max_concurrent?: number;
|
|
201
|
+
/** Broken external links are errors (not just warnings). @default false */
|
|
196
202
|
fail_on_broken?: boolean;
|
|
203
|
+
/** Only check links to these domains (empty = all). */
|
|
197
204
|
allow_domains?: string[];
|
|
205
|
+
/** Skip links to these domains. */
|
|
198
206
|
block_domains?: string[];
|
|
199
207
|
};
|
|
200
208
|
}
|
|
201
209
|
export interface PostAuditOptions {
|
|
202
|
-
/** Inline rules config. */
|
|
210
|
+
/** Inline rules config — all check settings go here. */
|
|
203
211
|
rules?: RulesConfig;
|
|
204
|
-
/** Base URL (auto-detected from Astro's `site` config if not set) */
|
|
212
|
+
/** Base URL (auto-detected from Astro's `site` config if not set). */
|
|
205
213
|
site?: string;
|
|
206
|
-
/** Treat warnings as errors */
|
|
214
|
+
/** Treat warnings as errors. */
|
|
207
215
|
strict?: boolean;
|
|
208
|
-
/**
|
|
209
|
-
format?: 'text' | 'json';
|
|
210
|
-
/** Maximum number of errors before aborting */
|
|
216
|
+
/** Maximum number of errors before aborting. */
|
|
211
217
|
maxErrors?: number;
|
|
212
|
-
/**
|
|
213
|
-
include?: string[];
|
|
214
|
-
/** Glob patterns to exclude */
|
|
215
|
-
exclude?: string[];
|
|
216
|
-
/** Skip sitemap.xml checks */
|
|
217
|
-
noSitemapCheck?: boolean;
|
|
218
|
-
/** Enable asset reference checking */
|
|
219
|
-
checkAssets?: boolean;
|
|
220
|
-
/** Enable structured data (JSON-LD) validation */
|
|
221
|
-
checkStructuredData?: boolean;
|
|
222
|
-
/** Enable security heuristic checks */
|
|
223
|
-
checkSecurity?: boolean;
|
|
224
|
-
/** Enable duplicate content detection */
|
|
225
|
-
checkDuplicates?: boolean;
|
|
226
|
-
/** Show page properties overview instead of running checks */
|
|
218
|
+
/** Show page properties overview instead of running checks. */
|
|
227
219
|
pageOverview?: boolean;
|
|
228
|
-
/**
|
|
220
|
+
/** Write the JSON report to this file path (relative to project root). */
|
|
221
|
+
output?: string;
|
|
222
|
+
/** Disable the integration (useful for dev mode). */
|
|
229
223
|
disable?: boolean;
|
|
230
|
-
/** Throw an
|
|
224
|
+
/** Throw an error when the audit finds issues (fails the build). Default: false */
|
|
231
225
|
throwOnError?: boolean;
|
|
232
226
|
}
|
|
233
227
|
export default function postAudit(options?: PostAuditOptions): AstroIntegration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAM9C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,IAAI,CAAC,EAAE;QACL,uGAAuG;QACvG,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,g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AAM,EAAE,CAAC;QACzB,mCAAmC;QACnC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mFAAmF;IACnF,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAUD,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,gBAAgB,CA4FlF"}
|
package/dist/integration.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
function resolveBinaryPath() {
|
|
@@ -17,8 +17,12 @@ export default function postAudit(options = {}) {
|
|
|
17
17
|
siteUrl = config.site?.toString();
|
|
18
18
|
},
|
|
19
19
|
'astro:build:done': ({ dir, logger }) => {
|
|
20
|
-
if (options.disable)
|
|
20
|
+
if (options.disable || process.env.SKIP_AUDIT === '1' || process.env.SKIP_AUDIT === 'true') {
|
|
21
|
+
if (process.env.SKIP_AUDIT) {
|
|
22
|
+
logger.info('Audit skipped (SKIP_AUDIT is set).');
|
|
23
|
+
}
|
|
21
24
|
return;
|
|
25
|
+
}
|
|
22
26
|
// Validate that rules is a non-empty object if provided
|
|
23
27
|
if (options.rules && typeof options.rules === 'object' && Object.keys(options.rules).length === 0) {
|
|
24
28
|
logger.warn('astro-post-audit: "rules" is an empty object — using default config.');
|
|
@@ -29,60 +33,49 @@ export default function postAudit(options = {}) {
|
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
35
|
const distPath = fileURLToPath(dir);
|
|
32
|
-
const args = [distPath];
|
|
33
|
-
//
|
|
36
|
+
const args = [distPath, '--config-stdin'];
|
|
37
|
+
// Build the full JSON config for the Rust binary
|
|
34
38
|
const site = options.site ?? siteUrl;
|
|
39
|
+
const stdinConfig = {
|
|
40
|
+
...options.rules,
|
|
41
|
+
};
|
|
35
42
|
if (site)
|
|
36
|
-
|
|
37
|
-
// Boolean flags
|
|
43
|
+
stdinConfig.site = { base_url: site };
|
|
38
44
|
if (options.strict)
|
|
39
|
-
|
|
40
|
-
if (options.noSitemapCheck)
|
|
41
|
-
args.push('--no-sitemap-check');
|
|
42
|
-
if (options.checkAssets)
|
|
43
|
-
args.push('--check-assets');
|
|
44
|
-
if (options.checkStructuredData)
|
|
45
|
-
args.push('--check-structured-data');
|
|
46
|
-
if (options.checkSecurity)
|
|
47
|
-
args.push('--check-security');
|
|
48
|
-
if (options.checkDuplicates)
|
|
49
|
-
args.push('--check-duplicates');
|
|
50
|
-
if (options.pageOverview)
|
|
51
|
-
args.push('--page-overview');
|
|
52
|
-
// Value flags
|
|
53
|
-
if (options.format)
|
|
54
|
-
args.push('--format', options.format);
|
|
45
|
+
stdinConfig.strict = true;
|
|
55
46
|
if (options.maxErrors != null)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (options.exclude) {
|
|
64
|
-
for (const pattern of options.exclude) {
|
|
65
|
-
args.push('--exclude', pattern);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Pipe inline rules config via stdin as JSON
|
|
69
|
-
let stdinInput;
|
|
70
|
-
if (options.rules) {
|
|
71
|
-
args.push('--config-stdin');
|
|
72
|
-
stdinInput = JSON.stringify(options.rules);
|
|
73
|
-
}
|
|
47
|
+
stdinConfig.max_errors = options.maxErrors;
|
|
48
|
+
if (options.pageOverview)
|
|
49
|
+
stdinConfig.page_overview = true;
|
|
50
|
+
if (options.output)
|
|
51
|
+
stdinConfig.format = 'json';
|
|
52
|
+
const stdinInput = JSON.stringify(stdinConfig);
|
|
74
53
|
logger.info('Running post-build audit...');
|
|
54
|
+
const captureOutput = !!options.output;
|
|
75
55
|
try {
|
|
76
|
-
execFileSync(binaryPath, args, {
|
|
77
|
-
stdio:
|
|
56
|
+
const result = execFileSync(binaryPath, args, {
|
|
57
|
+
stdio: ['pipe', captureOutput ? 'pipe' : 'inherit', 'inherit'],
|
|
78
58
|
input: stdinInput,
|
|
59
|
+
encoding: captureOutput ? 'utf-8' : undefined,
|
|
79
60
|
});
|
|
61
|
+
if (captureOutput && result) {
|
|
62
|
+
writeFileSync(options.output, result);
|
|
63
|
+
logger.info(`Report written to ${options.output}`);
|
|
64
|
+
}
|
|
80
65
|
logger.info('All checks passed!');
|
|
81
66
|
}
|
|
82
67
|
catch (err) {
|
|
83
68
|
const exitCode = err && typeof err === 'object' && 'status' in err
|
|
84
69
|
? err.status
|
|
85
70
|
: undefined;
|
|
71
|
+
// Write output file even on exit code 1 (findings exist but run succeeded)
|
|
72
|
+
if (captureOutput && exitCode === 1 && err && typeof err === 'object' && 'stdout' in err) {
|
|
73
|
+
const stdout = err.stdout;
|
|
74
|
+
if (stdout) {
|
|
75
|
+
writeFileSync(options.output, stdout);
|
|
76
|
+
logger.info(`Report written to ${options.output}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
86
79
|
if (exitCode === 1) {
|
|
87
80
|
if (options.throwOnError) {
|
|
88
81
|
throw new Error('astro-post-audit found issues. See output above.');
|
package/dist/integration.test.js
CHANGED
|
@@ -17,18 +17,12 @@ describe('postAudit', () => {
|
|
|
17
17
|
it('accepts all option types', () => {
|
|
18
18
|
const options = {
|
|
19
19
|
strict: true,
|
|
20
|
-
format: 'json',
|
|
21
20
|
maxErrors: 5,
|
|
22
|
-
include: ['**/*.html'],
|
|
23
|
-
exclude: ['drafts/**'],
|
|
24
|
-
noSitemapCheck: true,
|
|
25
|
-
checkAssets: true,
|
|
26
|
-
checkStructuredData: true,
|
|
27
|
-
checkSecurity: true,
|
|
28
|
-
checkDuplicates: true,
|
|
29
21
|
pageOverview: false,
|
|
22
|
+
output: 'audit-report.json',
|
|
30
23
|
disable: false,
|
|
31
24
|
throwOnError: true,
|
|
25
|
+
rules: { canonical: { require: true } },
|
|
32
26
|
};
|
|
33
27
|
const integration = postAudit(options);
|
|
34
28
|
assert.equal(integration.name, 'astro-post-audit');
|