Switch plausible endpoint and harden coverage lane parsing

- update docs-site tracking to use the Plausible capture endpoint
- tighten coverage lane argument and LCOV parsing checks
- make script entrypoint use CommonJS main guard
This commit is contained in:
2026-03-27 23:41:23 -07:00
parent 9caf25bedb
commit 6139d14cd1
3 changed files with 10 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ let mermaidLoader: Promise<any> | null = null;
let plausibleTrackerInitialized = false; let plausibleTrackerInitialized = false;
const MERMAID_MODAL_ID = 'mermaid-diagram-modal'; const MERMAID_MODAL_ID = 'mermaid-diagram-modal';
const PLAUSIBLE_DOMAIN = 'subminer.moe'; const PLAUSIBLE_DOMAIN = 'subminer.moe';
const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/event'; const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/capture';
async function initPlausibleTracker() { async function initPlausibleTracker() {
if (typeof window === 'undefined' || plausibleTrackerInitialized) { if (typeof window === 'undefined' || plausibleTrackerInitialized) {

View File

@@ -6,11 +6,11 @@ const docsThemePath = new URL('./.vitepress/theme/index.ts', import.meta.url);
const docsConfigContents = readFileSync(docsConfigPath, 'utf8'); const docsConfigContents = readFileSync(docsConfigPath, 'utf8');
const docsThemeContents = readFileSync(docsThemePath, 'utf8'); const docsThemeContents = readFileSync(docsThemePath, 'utf8');
test('docs site keeps docs hostname while sending plausible events to subminer.moe via worker.subminer.moe', () => { test('docs site keeps docs hostname while sending plausible events to subminer.moe via worker.subminer.moe capture endpoint', () => {
expect(docsConfigContents).toContain("hostname: 'https://docs.subminer.moe'"); expect(docsConfigContents).toContain("hostname: 'https://docs.subminer.moe'");
expect(docsThemeContents).toContain("const PLAUSIBLE_DOMAIN = 'subminer.moe'"); expect(docsThemeContents).toContain("const PLAUSIBLE_DOMAIN = 'subminer.moe'");
expect(docsThemeContents).toContain( expect(docsThemeContents).toContain(
"const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/event'", "const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/capture'",
); );
expect(docsThemeContents).toContain('@plausible-analytics/tracker'); expect(docsThemeContents).toContain('@plausible-analytics/tracker');
expect(docsThemeContents).toContain('const { init } = await import'); expect(docsThemeContents).toContain('const { init } = await import');

View File

@@ -1,6 +1,5 @@
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process'; import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { join, relative, resolve } from 'node:path'; import { join, relative, resolve } from 'node:path';
type LaneConfig = { type LaneConfig = {
@@ -17,7 +16,7 @@ type LcovRecord = {
branches: Map<string, { line: number; block: string; branch: string; hits: number | null }>; branches: Map<string, { line: number; block: string; branch: string; hits: number | null }>;
}; };
const repoRoot = resolve(fileURLToPath(new URL('..', import.meta.url))); const repoRoot = resolve(__dirname, '..');
const lanes: Record<string, LaneConfig> = { const lanes: Record<string, LaneConfig> = {
'bun-src-full': { 'bun-src-full': {
@@ -77,7 +76,7 @@ function parseCoverageDirArg(argv: string[]): string {
for (let index = 0; index < argv.length; index += 1) { for (let index = 0; index < argv.length; index += 1) {
if (argv[index] === '--coverage-dir') { if (argv[index] === '--coverage-dir') {
const next = argv[index + 1]; const next = argv[index + 1];
if (!next) { if (typeof next !== 'string') {
throw new Error('Missing value for --coverage-dir'); throw new Error('Missing value for --coverage-dir');
} }
return next; return next;
@@ -137,6 +136,9 @@ function parseLcovReport(report: string): LcovRecord[] {
} }
if (line.startsWith('BRDA:')) { if (line.startsWith('BRDA:')) {
const [lineNumber, block, branch, hits] = line.slice(5).split(','); const [lineNumber, block, branch, hits] = line.slice(5).split(',');
if (lineNumber === undefined || block === undefined || branch === undefined || hits === undefined) {
continue;
}
ensureCurrent().branches.set(`${lineNumber}:${block}:${branch}`, { ensureCurrent().branches.set(`${lineNumber}:${block}:${branch}`, {
line: Number(lineNumber), line: Number(lineNumber),
block, block,
@@ -244,7 +246,7 @@ export function mergeLcovReports(reports: string[]): string {
function runCoverageLane(): number { function runCoverageLane(): number {
const laneName = process.argv[2]; const laneName = process.argv[2];
if (!laneName) { if (laneName === undefined) {
process.stderr.write('Missing coverage lane name\n'); process.stderr.write('Missing coverage lane name\n');
return 1; return 1;
} }
@@ -291,6 +293,6 @@ function runCoverageLane(): number {
return 0; return 0;
} }
if (import.meta.main) { if (require.main === module) {
process.exit(runCoverageLane()); process.exit(runCoverageLane());
} }