@xsynaptic/astro-build-logger 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexander Synaptic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @xsynaptic/astro-build-logger
2
+
3
+ An [Astro][] integration that records how long each build takes and appends a structured entry to a [JSONL][] file. Each entry captures the build duration, page count, total output size, and the Astro and Node versions used, making it easy to track build performance over time.
4
+
5
+ _Note_: this package is ESM-only.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @xsynaptic/astro-build-logger
11
+ ```
12
+
13
+ ## Use
14
+
15
+ Add the integration to your Astro config:
16
+
17
+ ```ts
18
+ import buildLogger from '@xsynaptic/astro-build-logger';
19
+ import { defineConfig } from 'astro/config';
20
+
21
+ export default defineConfig({
22
+ integrations: [buildLogger()],
23
+ });
24
+ ```
25
+
26
+ After each build, an entry is appended to `astro-build.jsonl` in the project root:
27
+
28
+ ```text
29
+ {"timestamp":"2026-06-07T12:00:00.000Z","durationSeconds":42.5,"pageCount":1280,"outputBytes":83214946,"astroVersion":"6.4.4","nodeVersion":"22.22.2","summary":"42s (1280 pages, 79.4 MB)"}
30
+ ```
31
+
32
+ One JSON object per line means the file is append-only and trivially parseable: read it line by line, or pipe it through tools like `jq`.
33
+
34
+ ## Options
35
+
36
+ ```ts
37
+ buildLogger({ logFileName: 'logs/build-times.jsonl' });
38
+ ```
39
+
40
+ - `logFileName` (default `'astro-build.jsonl'`): path to the JSONL log file, resolved relative to the current working directory. Parent directories are not created automatically.
41
+
42
+ ## License
43
+
44
+ [MIT][mit-license]
45
+
46
+ [astro]: https://astro.build
47
+ [jsonl]: https://jsonlines.org
48
+ [mit-license]: https://opensource.org/licenses/MIT
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ import { AstroIntegration } from "astro";
3
+
4
+ //#region src/index.d.ts
5
+ declare const optionsSchema: z.ZodOptional<z.ZodObject<{
6
+ logFileName: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strip>>;
8
+ type Options = z.input<typeof optionsSchema>;
9
+ declare function buildLogger(options?: Options): AstroIntegration;
10
+ //#endregion
11
+ export { buildLogger as default };
12
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,89 @@
1
+ import astroPackage from "astro/package.json" with { type: "json" };
2
+ import { appendFile, readdir, stat } from "node:fs/promises";
3
+ import { z } from "zod";
4
+ //#region src/index.ts
5
+ const optionsSchema = z.object({
6
+ /**
7
+ * Path to the JSONL log file
8
+ *
9
+ * @default `"astro-build.jsonl"`
10
+ */
11
+ logFileName: z.string().optional() }).optional();
12
+ function formatDuration(totalSeconds) {
13
+ const hours = Math.floor(totalSeconds / 3600);
14
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
15
+ const seconds = Math.round(totalSeconds % 60);
16
+ if (hours > 0) return `${String(hours)}h ${String(minutes)}m ${String(seconds)}s`;
17
+ if (minutes > 0) return `${String(minutes)}m ${String(seconds)}s`;
18
+ return `${String(seconds)}s`;
19
+ }
20
+ function formatBytes(bytes) {
21
+ const units = [
22
+ "B",
23
+ "KB",
24
+ "MB",
25
+ "GB"
26
+ ];
27
+ let value = bytes;
28
+ let unitIndex = 0;
29
+ while (value >= 1024 && unitIndex < units.length - 1) {
30
+ value /= 1024;
31
+ unitIndex += 1;
32
+ }
33
+ const precision = value >= 10 || unitIndex === 0 ? 0 : 1;
34
+ return `${value.toFixed(precision)} ${units[unitIndex] ?? "B"}`;
35
+ }
36
+ function formatSummary(durationSeconds, pageCount, outputBytes) {
37
+ return `${formatDuration(durationSeconds)} (${String(pageCount)} pages, ${formatBytes(outputBytes)})`;
38
+ }
39
+ async function getDirectorySize(dir) {
40
+ const entries = await readdir(dir, { withFileTypes: true });
41
+ let total = 0;
42
+ for (const entry of entries) {
43
+ const child = new URL(entry.isDirectory() ? `${entry.name}/` : entry.name, dir);
44
+ if (entry.isDirectory()) total += await getDirectorySize(child);
45
+ else if (entry.isFile()) {
46
+ const stats = await stat(child);
47
+ total += stats.size;
48
+ }
49
+ }
50
+ return total;
51
+ }
52
+ function buildLogger(options) {
53
+ const logFileName = optionsSchema.parse(options)?.logFileName ?? "astro-build.jsonl";
54
+ let buildStartTime;
55
+ return {
56
+ name: "@xsynaptic/astro-build-logger",
57
+ hooks: {
58
+ "astro:build:start": ({ logger }) => {
59
+ buildStartTime = Date.now();
60
+ logger.info(`Build timing started at ${new Date(buildStartTime).toISOString()}`);
61
+ },
62
+ "astro:build:done": async ({ logger, pages, dir }) => {
63
+ const buildEndTime = Date.now();
64
+ const durationSeconds = Number(((buildEndTime - buildStartTime) / 1e3).toFixed(2));
65
+ const outputBytes = await getDirectorySize(dir);
66
+ const summary = formatSummary(durationSeconds, pages.length, outputBytes);
67
+ const entry = {
68
+ timestamp: new Date(buildEndTime).toISOString(),
69
+ durationSeconds,
70
+ pageCount: pages.length,
71
+ outputBytes,
72
+ astroVersion: astroPackage.version,
73
+ nodeVersion: process.versions.node,
74
+ summary
75
+ };
76
+ try {
77
+ await appendFile(logFileName, JSON.stringify(entry) + "\n");
78
+ logger.info(`Build time logged: ${summary}`);
79
+ } catch (error) {
80
+ logger.error(`Failed to write build log: ${error instanceof Error ? error.message : "unknown error"}`);
81
+ }
82
+ }
83
+ }
84
+ };
85
+ }
86
+ //#endregion
87
+ export { buildLogger as default };
88
+
89
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AstroIntegration } from 'astro';\n\nimport astroPackage from 'astro/package.json' with { type: 'json' };\nimport { appendFile, readdir, stat } from 'node:fs/promises';\nimport { z } from 'zod';\n\nconst optionsSchema = z\n\t.object({\n\t\t/**\n\t\t * Path to the JSONL log file\n\t\t *\n\t\t * @default `\"astro-build.jsonl\"`\n\t\t */\n\t\tlogFileName: z.string().optional(),\n\t})\n\t.optional();\n\ntype Options = z.input<typeof optionsSchema>;\n\ninterface BuildLogEntry {\n\ttimestamp: string;\n\tdurationSeconds: number;\n\tpageCount: number;\n\toutputBytes: number;\n\tastroVersion: string;\n\tnodeVersion: string;\n\tsummary: string;\n\tnotes?: string;\n}\n\nfunction formatDuration(totalSeconds: number): string {\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = Math.round(totalSeconds % 60);\n\n\tif (hours > 0) return `${String(hours)}h ${String(minutes)}m ${String(seconds)}s`;\n\tif (minutes > 0) return `${String(minutes)}m ${String(seconds)}s`;\n\n\treturn `${String(seconds)}s`;\n}\n\nfunction formatBytes(bytes: number): string {\n\tconst units = ['B', 'KB', 'MB', 'GB'];\n\tlet value = bytes;\n\tlet unitIndex = 0;\n\n\twhile (value >= 1024 && unitIndex < units.length - 1) {\n\t\tvalue /= 1024;\n\t\tunitIndex += 1;\n\t}\n\n\tconst precision = value >= 10 || unitIndex === 0 ? 0 : 1;\n\n\treturn `${value.toFixed(precision)} ${units[unitIndex] ?? 'B'}`;\n}\n\nfunction formatSummary(durationSeconds: number, pageCount: number, outputBytes: number): string {\n\treturn `${formatDuration(durationSeconds)} (${String(pageCount)} pages, ${formatBytes(outputBytes)})`;\n}\n\nasync function getDirectorySize(dir: URL): Promise<number> {\n\tconst entries = await readdir(dir, { withFileTypes: true });\n\tlet total = 0;\n\n\tfor (const entry of entries) {\n\t\tconst child = new URL(entry.isDirectory() ? `${entry.name}/` : entry.name, dir);\n\n\t\tif (entry.isDirectory()) {\n\t\t\ttotal += await getDirectorySize(child);\n\t\t} else if (entry.isFile()) {\n\t\t\tconst stats = await stat(child);\n\t\t\ttotal += stats.size;\n\t\t}\n\t}\n\treturn total;\n}\n\nexport default function buildLogger(options?: Options): AstroIntegration {\n\tconst parsed = optionsSchema.parse(options);\n\tconst logFileName = parsed?.logFileName ?? 'astro-build.jsonl';\n\n\tlet buildStartTime: number;\n\n\treturn {\n\t\tname: '@xsynaptic/astro-build-logger',\n\t\thooks: {\n\t\t\t'astro:build:start': ({ logger }) => {\n\t\t\t\tbuildStartTime = Date.now();\n\t\t\t\tlogger.info(`Build timing started at ${new Date(buildStartTime).toISOString()}`);\n\t\t\t},\n\t\t\t'astro:build:done': async ({ logger, pages, dir }) => {\n\t\t\t\tconst buildEndTime = Date.now();\n\t\t\t\tconst durationSeconds = Number(((buildEndTime - buildStartTime) / 1000).toFixed(2));\n\t\t\t\tconst outputBytes = await getDirectorySize(dir);\n\t\t\t\tconst summary = formatSummary(durationSeconds, pages.length, outputBytes);\n\n\t\t\t\tconst entry: BuildLogEntry = {\n\t\t\t\t\ttimestamp: new Date(buildEndTime).toISOString(),\n\t\t\t\t\tdurationSeconds,\n\t\t\t\t\tpageCount: pages.length,\n\t\t\t\t\toutputBytes,\n\t\t\t\t\tastroVersion: astroPackage.version,\n\t\t\t\t\tnodeVersion: process.versions.node,\n\t\t\t\t\tsummary,\n\t\t\t\t};\n\n\t\t\t\ttry {\n\t\t\t\t\tawait appendFile(logFileName, JSON.stringify(entry) + '\\n');\n\t\t\t\t\tlogger.info(`Build time logged: ${summary}`);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t`Failed to write build log: ${error instanceof Error ? error.message : 'unknown error'}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAMA,MAAM,gBAAgB,EACpB,OAAO;;;;;;AAMP,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS,EAClC,CAAC,CAAC,CACD,SAAS;AAeX,SAAS,eAAe,cAA8B;CACrD,MAAM,QAAQ,KAAK,MAAM,eAAe,IAAI;CAC5C,MAAM,UAAU,KAAK,MAAO,eAAe,OAAQ,EAAE;CACrD,MAAM,UAAU,KAAK,MAAM,eAAe,EAAE;CAE5C,IAAI,QAAQ,GAAG,OAAO,GAAG,OAAO,KAAK,EAAE,IAAI,OAAO,OAAO,EAAE,IAAI,OAAO,OAAO,EAAE;CAC/E,IAAI,UAAU,GAAG,OAAO,GAAG,OAAO,OAAO,EAAE,IAAI,OAAO,OAAO,EAAE;CAE/D,OAAO,GAAG,OAAO,OAAO,EAAE;AAC3B;AAEA,SAAS,YAAY,OAAuB;CAC3C,MAAM,QAAQ;EAAC;EAAK;EAAM;EAAM;CAAI;CACpC,IAAI,QAAQ;CACZ,IAAI,YAAY;CAEhB,OAAO,SAAS,QAAQ,YAAY,MAAM,SAAS,GAAG;EACrD,SAAS;EACT,aAAa;CACd;CAEA,MAAM,YAAY,SAAS,MAAM,cAAc,IAAI,IAAI;CAEvD,OAAO,GAAG,MAAM,QAAQ,SAAS,EAAE,GAAG,MAAM,cAAc;AAC3D;AAEA,SAAS,cAAc,iBAAyB,WAAmB,aAA6B;CAC/F,OAAO,GAAG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C,SAAS,OAAO;KACf,OAAO,MACN,8BAA8B,iBAAiB,QAAQ,MAAM,UAAU,iBACxE;IACD;GACD;EACD;CACD;AACD"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@xsynaptic/astro-build-logger",
3
+ "version": "0.1.0",
4
+ "description": "Astro integration that appends build duration, page count, and output size to a JSONL log file",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Alexander Synaptic <x@synapticism.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/xsynaptic/astro-lab.git",
11
+ "directory": "packages/astro-build-logger"
12
+ },
13
+ "homepage": "https://github.com/xsynaptic/astro-lab/tree/main/packages/astro-build-logger#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/xsynaptic/astro-lab/issues"
16
+ },
17
+ "keywords": [
18
+ "astro",
19
+ "astro-integration",
20
+ "build",
21
+ "logging",
22
+ "metrics"
23
+ ],
24
+ "main": "./dist/index.mjs",
25
+ "types": "./dist/index.d.mts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.mts",
29
+ "import": "./dist/index.mjs"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "sideEffects": false,
36
+ "dependencies": {
37
+ "zod": "^4.4.3"
38
+ },
39
+ "peerDependencies": {
40
+ "astro": "^6.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "astro": "^6.4.4"
44
+ },
45
+ "scripts": {
46
+ "build": "tsdown",
47
+ "dev": "tsdown --watch",
48
+ "check-types": "tsc --noEmit"
49
+ }
50
+ }