@site-index/observability 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 +21 -0
- package/README.md +96 -0
- package/dist/domains/logger/format.d.ts +3 -0
- package/dist/domains/logger/format.js +25 -0
- package/dist/domains/logger/logger.d.ts +10 -0
- package/dist/domains/logger/logger.js +51 -0
- package/dist/domains/logger/types.d.ts +11 -0
- package/dist/domains/logger/types.js +1 -0
- package/dist/domains/logger/writer.d.ts +2 -0
- package/dist/domains/logger/writer.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Deasilsoft
|
|
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,96 @@
|
|
|
1
|
+
# @site-index/observability
|
|
2
|
+
|
|
3
|
+
Observability and logging utilities for site-index packages.
|
|
4
|
+
|
|
5
|
+
[Repository README](../../../README.md)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @site-index/observability
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requirements:
|
|
14
|
+
|
|
15
|
+
- Node.js `>=22`
|
|
16
|
+
|
|
17
|
+
## When to use
|
|
18
|
+
|
|
19
|
+
Use this package when you want consistent warning/error formatting and logging behavior across site-index tooling.
|
|
20
|
+
|
|
21
|
+
## Public exports
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export { Logger } from "./domains/logger/logger.js";
|
|
25
|
+
export type {
|
|
26
|
+
LoggerOptions,
|
|
27
|
+
LogSink,
|
|
28
|
+
LogWriter,
|
|
29
|
+
} from "./domains/logger/types.js";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Public API
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
class Logger {
|
|
36
|
+
constructor(options?: LoggerOptions);
|
|
37
|
+
configure(options: LoggerOptions): void;
|
|
38
|
+
info(message: string): void;
|
|
39
|
+
warn(input: string | Warning | Warning[]): void;
|
|
40
|
+
error(error: unknown): void;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Types:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
type LogSink = (message: string) => void;
|
|
48
|
+
|
|
49
|
+
type LogWriter = {
|
|
50
|
+
info: LogSink;
|
|
51
|
+
warn: LogSink;
|
|
52
|
+
error: LogSink;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type LoggerOptions = {
|
|
56
|
+
writer?: LogWriter;
|
|
57
|
+
quiet?: boolean;
|
|
58
|
+
verbose?: boolean;
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Behavior
|
|
63
|
+
|
|
64
|
+
- default writers:
|
|
65
|
+
- info -> stdout
|
|
66
|
+
- warn -> stderr
|
|
67
|
+
- error -> stderr
|
|
68
|
+
- `quiet` suppresses info logs
|
|
69
|
+
- `verbose` includes error stack traces when available
|
|
70
|
+
- warning input can be:
|
|
71
|
+
- string
|
|
72
|
+
- single `Warning`
|
|
73
|
+
- `Warning[]`
|
|
74
|
+
- warning formatting:
|
|
75
|
+
- `Warning: <message>`
|
|
76
|
+
- `Warning: <filePath>: <message>`
|
|
77
|
+
- Zod errors are formatted as validation failures with issue lines
|
|
78
|
+
|
|
79
|
+
## Example
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { Logger } from "@site-index/observability";
|
|
83
|
+
|
|
84
|
+
const logger = new Logger({ verbose: true });
|
|
85
|
+
|
|
86
|
+
logger.info("Building artifacts");
|
|
87
|
+
logger.warn("No site-index modules discovered");
|
|
88
|
+
logger.error(new Error("Build failed"));
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Related packages
|
|
92
|
+
|
|
93
|
+
- [`site-index`](../../site-index/README.md)
|
|
94
|
+
- [`@site-index/core`](../core/README.md)
|
|
95
|
+
- [`@site-index/vite-runtime`](../vite-runtime/README.md)
|
|
96
|
+
- [`@site-index/vite-plugin`](../vite-plugin/README.md)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ZodError } from "zod";
|
|
2
|
+
export function formatWarning(warning) {
|
|
3
|
+
if (warning.filePath === undefined) {
|
|
4
|
+
return `Warning: ${warning.message}`;
|
|
5
|
+
}
|
|
6
|
+
return `Warning: ${warning.filePath}: ${warning.message}`;
|
|
7
|
+
}
|
|
8
|
+
export function formatError(error, verbose) {
|
|
9
|
+
if (error instanceof ZodError) {
|
|
10
|
+
const issues = error.issues.map((issue) => {
|
|
11
|
+
if (issue.path.length === 0) {
|
|
12
|
+
return `- ${issue.message}`;
|
|
13
|
+
}
|
|
14
|
+
return `- ${issue.path.join(".")}: ${issue.message}`;
|
|
15
|
+
});
|
|
16
|
+
return ["Error: Validation failed", ...issues].join("\n");
|
|
17
|
+
}
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
if (verbose && error.stack !== undefined) {
|
|
20
|
+
return error.stack;
|
|
21
|
+
}
|
|
22
|
+
return `Error: ${error.message}`;
|
|
23
|
+
}
|
|
24
|
+
return `Error: ${String(error)}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Warning } from "@site-index/core";
|
|
2
|
+
import type { LoggerOptions } from "./types.js";
|
|
3
|
+
export declare class Logger {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(options?: LoggerOptions);
|
|
6
|
+
configure(options: LoggerOptions): void;
|
|
7
|
+
info(message: string): void;
|
|
8
|
+
warn(input: string | Warning | Warning[]): void;
|
|
9
|
+
error(error: unknown): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { formatError, formatWarning } from "./format.js";
|
|
2
|
+
import { defaultLogWriter } from "./writer.js";
|
|
3
|
+
export class Logger {
|
|
4
|
+
#writer = defaultLogWriter;
|
|
5
|
+
#quiet = false;
|
|
6
|
+
#verbose = false;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (options !== undefined) {
|
|
9
|
+
this.configure(options);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
configure(options) {
|
|
13
|
+
if (options.writer !== undefined) {
|
|
14
|
+
this.#writer = options.writer;
|
|
15
|
+
}
|
|
16
|
+
if (options.quiet !== undefined) {
|
|
17
|
+
this.#quiet = options.quiet;
|
|
18
|
+
}
|
|
19
|
+
if (options.verbose !== undefined) {
|
|
20
|
+
this.#verbose = options.verbose;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
info(message) {
|
|
24
|
+
if (this.#quiet) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.#write(this.#writer.info, message);
|
|
28
|
+
}
|
|
29
|
+
warn(input) {
|
|
30
|
+
if (typeof input === "string") {
|
|
31
|
+
this.#write(this.#writer.warn, `Warning: ${input}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(input)) {
|
|
35
|
+
for (const warning of input) {
|
|
36
|
+
this.#write(this.#writer.warn, formatWarning(warning));
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.#write(this.#writer.warn, formatWarning(input));
|
|
41
|
+
}
|
|
42
|
+
error(error) {
|
|
43
|
+
this.#write(this.#writer.error, formatError(error, this.#verbose));
|
|
44
|
+
}
|
|
45
|
+
#write(write, message) {
|
|
46
|
+
if (message.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
write(message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Logger } from "./domains/logger/logger.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@site-index/observability",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Observability utilities for site-index.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"site-index",
|
|
7
|
+
"sitemap",
|
|
8
|
+
"robots",
|
|
9
|
+
"seo",
|
|
10
|
+
"observability",
|
|
11
|
+
"logging"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/Deasilsoft/site-index/tree/main/packages/@site-index/observability",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Deasilsoft/site-index/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/Deasilsoft/site-index.git",
|
|
20
|
+
"directory": "packages/@site-index/observability"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Deasilsoft <contact@deasilsoft.com>",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"main": "dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"!dist/**/*.tsbuildinfo"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -b",
|
|
39
|
+
"clean": "rm -rf dist coverage",
|
|
40
|
+
"prepack": "npm run clean && npm run build",
|
|
41
|
+
"pretest": "npm pack --dry-run",
|
|
42
|
+
"test": "vitest run --coverage",
|
|
43
|
+
"pretypecheck": "npm run build",
|
|
44
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@site-index/core": "0.1.0",
|
|
48
|
+
"zod": "^4.4.3"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
52
|
+
"vitest": "^4.1.6"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=22"
|
|
56
|
+
}
|
|
57
|
+
}
|