vite-plugin-better-console 1.0.2
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/README.md +238 -0
- package/dist/caller.d.ts +93 -0
- package/dist/config.d.ts +116 -0
- package/dist/format.d.ts +137 -0
- package/dist/index.d.ts +39 -0
- package/dist/logger.d.ts +156 -0
- package/dist/plugin.d.ts +6 -0
- package/dist/plugin.js +144 -0
- package/dist/runtime/index.d.ts +34 -0
- package/dist/runtime/index.js +352 -0
- package/dist/types.d.ts +125 -0
- package/package.json +49 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// ─── Log Levels ──────────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
4
|
+
|
|
5
|
+
export const LOG_LEVEL_RANK: Record<LogLevel, number> = {
|
|
6
|
+
debug: 0,
|
|
7
|
+
info: 1,
|
|
8
|
+
warn: 2,
|
|
9
|
+
error: 3,
|
|
10
|
+
silent: 99,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// ─── Timestamp ───────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
export type TimestampFormat =
|
|
16
|
+
| 'locale'
|
|
17
|
+
| 'iso'
|
|
18
|
+
| 'time-only'
|
|
19
|
+
| 'date-only'
|
|
20
|
+
| 'relative'
|
|
21
|
+
| ((date: Date) => string)
|
|
22
|
+
|
|
23
|
+
// ─── CSS Styles ──────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
export interface ThemeStyles {
|
|
26
|
+
badge_debug?: string
|
|
27
|
+
badge_info?: string
|
|
28
|
+
badge_warn?: string
|
|
29
|
+
badge_error?: string
|
|
30
|
+
label?: string
|
|
31
|
+
value?: string
|
|
32
|
+
meta?: string
|
|
33
|
+
divider?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ─── Per-call Options ────────────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
export interface LogCallOptions {
|
|
39
|
+
/** Override the effective log level for this call */
|
|
40
|
+
level?: LogLevel
|
|
41
|
+
/** Short note appended at the end of the group */
|
|
42
|
+
comment?: string
|
|
43
|
+
/** Force collapsed / expanded (overrides global default) */
|
|
44
|
+
collapsed?: boolean
|
|
45
|
+
/** When false, this call is skipped entirely — handy for feature flags */
|
|
46
|
+
enabled?: boolean
|
|
47
|
+
/** Override auto-detected caller path */
|
|
48
|
+
path?: string
|
|
49
|
+
/** Override auto-detected caller line */
|
|
50
|
+
line?: string | number
|
|
51
|
+
/** Override auto-detected caller function name */
|
|
52
|
+
fn?: string
|
|
53
|
+
/** Show timestamp for this call (overrides global default) */
|
|
54
|
+
timestamp?: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ─── Logger Options ──────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
export interface LoggerOptions {
|
|
60
|
+
/** Explicitly set dev mode (auto-detected when omitted) */
|
|
61
|
+
dev?: boolean
|
|
62
|
+
/** Show a one-time warning banner when called in production */
|
|
63
|
+
warnInProduction?: boolean
|
|
64
|
+
/** Minimum log level to print. Calls below this are no-ops. */
|
|
65
|
+
logLevel?: LogLevel
|
|
66
|
+
/** Whether console groups are collapsed by default */
|
|
67
|
+
collapsed?: boolean
|
|
68
|
+
/** Show caller file path */
|
|
69
|
+
showPath?: boolean
|
|
70
|
+
/** Show caller line number */
|
|
71
|
+
showLine?: boolean
|
|
72
|
+
/** Show caller function name */
|
|
73
|
+
showFn?: boolean
|
|
74
|
+
/** Show the JS type of the logged value */
|
|
75
|
+
showType?: boolean
|
|
76
|
+
/** Show a timestamp on every log */
|
|
77
|
+
timestamp?: boolean
|
|
78
|
+
/** Format for timestamps */
|
|
79
|
+
timestampFormat?: TimestampFormat
|
|
80
|
+
/** Customise %c badge/label/value colours */
|
|
81
|
+
theme?: ThemeStyles
|
|
82
|
+
/**
|
|
83
|
+
* Badge prefix shown in the group header.
|
|
84
|
+
* Defaults to the log level name in uppercase.
|
|
85
|
+
* Pass an object to customise per level.
|
|
86
|
+
*/
|
|
87
|
+
badge?: Partial<Record<LogLevel, string>> | false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ─── Logger Function ─────────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
export interface LogFn {
|
|
93
|
+
(label: string, value?: unknown, options?: LogCallOptions): void
|
|
94
|
+
debug: (label: string, value?: unknown, options?: LogCallOptions) => void
|
|
95
|
+
info: (label: string, value?: unknown, options?: LogCallOptions) => void
|
|
96
|
+
warn: (label: string, value?: unknown, options?: LogCallOptions) => void
|
|
97
|
+
error: (label: string, value?: unknown, options?: LogCallOptions) => void
|
|
98
|
+
/** Always prints as a table (non-collapsed) */
|
|
99
|
+
table: (label: string, data: unknown, options?: LogCallOptions) => void
|
|
100
|
+
/** True when in dev mode */
|
|
101
|
+
readonly dev: boolean
|
|
102
|
+
/** Current minimum log level */
|
|
103
|
+
readonly level: LogLevel
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ─── Plugin Options ──────────────────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
export interface BetterConsoleOptions extends LoggerOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Auto-inject the runtime into Rollup/Vite entry files.
|
|
111
|
+
* Set to false to import the runtime manually.
|
|
112
|
+
* @default true
|
|
113
|
+
*/
|
|
114
|
+
inject?: boolean
|
|
115
|
+
/**
|
|
116
|
+
* Additional entry paths/globs to inject into (supports * and **).
|
|
117
|
+
* e.g. `['src/main.ts', 'src/bootstrap.ts']`
|
|
118
|
+
*/
|
|
119
|
+
injectEntries?: string[]
|
|
120
|
+
/**
|
|
121
|
+
* A glob string or RegExp. Any matching module also gets the injection.
|
|
122
|
+
* e.g. `'**\/setup.{ts,js}'`
|
|
123
|
+
*/
|
|
124
|
+
injectPattern?: string | RegExp
|
|
125
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-better-console",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Zero-dependency Vite plugin for beautiful dev-only console logging. Grouped output, caller detection, log levels, TypeScript support — silent in production.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/plugin.d.ts",
|
|
10
|
+
"import": "./dist/plugin.js",
|
|
11
|
+
"default": "./dist/plugin.js"
|
|
12
|
+
},
|
|
13
|
+
"./runtime": {
|
|
14
|
+
"types": "./dist/runtime/index.d.ts",
|
|
15
|
+
"import": "./dist/runtime/index.js",
|
|
16
|
+
"default": "./dist/runtime/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/plugin.js",
|
|
20
|
+
"types": "./dist/plugin.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "node build.mjs",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vite": ">=5"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"esbuild": "^0.28.0",
|
|
35
|
+
"typescript": "^5.4.0",
|
|
36
|
+
"vite": "^6.3.5"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"vite-plugin",
|
|
40
|
+
"vite",
|
|
41
|
+
"console",
|
|
42
|
+
"debug",
|
|
43
|
+
"logger",
|
|
44
|
+
"logging",
|
|
45
|
+
"development",
|
|
46
|
+
"typescript"
|
|
47
|
+
],
|
|
48
|
+
"license": "MIT"
|
|
49
|
+
}
|