@huaqiu/dsh-plugin-log 0.3.11 → 0.3.14
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/lib/index.mjs +114 -18
- package/package.json +2 -4
- package/src/index.ts +24 -19
- package/src/paths.ts +102 -0
package/lib/index.mjs
CHANGED
|
@@ -1,8 +1,99 @@
|
|
|
1
1
|
import { mkdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
2
2
|
import { appendFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
3
|
+
import { homedir, platform, tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
|
|
5
|
+
//#region src/paths.ts
|
|
6
|
+
/**
|
|
7
|
+
* Inlined from `@hqedge/paths` (hq-edge/packages/paths/src/index.ts) so this
|
|
8
|
+
* plugin stays fully self-contained — no runtime dependency on the published
|
|
9
|
+
* package. Keep in sync when `@hqedge/paths` changes its path conventions.
|
|
10
|
+
*
|
|
11
|
+
* ────────────────────────────────────────────────────────────────────────────
|
|
12
|
+
* Shared OS-native path resolution for HQ Edge runtimes.
|
|
13
|
+
*
|
|
14
|
+
* The single source of truth for where HQ Edge places per-user directories.
|
|
15
|
+
* `getHqEdgeHome()` is the root: every other path getter (`getLogBaseDir`,
|
|
16
|
+
* `getLogDir`) is derived from it, so all HQ Edge user directories live under
|
|
17
|
+
* one self-contained tree and every consumer resolves the same location.
|
|
18
|
+
*
|
|
19
|
+
* Path conventions by platform (env-paths `data` shape, except macOS — see
|
|
20
|
+
* below):
|
|
21
|
+
*
|
|
22
|
+
* - macOS: ~/.hq-edge/ (this override)
|
|
23
|
+
* - Linux: ~/.local/share/hq-edge/ (honors $XDG_DATA_HOME)
|
|
24
|
+
* - Windows: %LOCALAPPDATA%\hq-edge\
|
|
25
|
+
*
|
|
26
|
+
* macOS deviates from `env-paths`: a dotfile under `$HOME` rather than the
|
|
27
|
+
* `~/Library/Application Support/hq-edge/` sandbox location. Rationale: HQ
|
|
28
|
+
* Edge is a single-developer EDA workstation tool, not a sandboxed macOS app.
|
|
29
|
+
* A dotfile in `$HOME` is more discoverable (one `ls -la` shows every HQ Edge
|
|
30
|
+
* user-data tree), survives sandbox / permission oddities, and aligns with the
|
|
31
|
+
* historical `~/.hq` location users already had from `dshHome.ts` before this
|
|
32
|
+
* unification. It also means DSH plugin code that imports `@hqedge/paths` does
|
|
33
|
+
* not need to branch on platform for the macOS case.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Application identifier used for OS-native directories.
|
|
37
|
+
*/
|
|
38
|
+
const APP_ID = "hq-edge";
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the OS-native per-user home/data directory for HQ Edge — the single
|
|
41
|
+
* root from which every other HQ Edge path getter is derived.
|
|
42
|
+
*
|
|
43
|
+
* - macOS: ~/.hq-edge/ (override)
|
|
44
|
+
* - Linux: ~/.local/share/hq-edge/ (honors $XDG_DATA_HOME)
|
|
45
|
+
* - Windows: %LOCALAPPDATA%\hq-edge\
|
|
46
|
+
*
|
|
47
|
+
* The macOS override is documented above. The path may also be overridden
|
|
48
|
+
* explicitly via `override` or the `HQ_EDGE_HOME` environment variable (useful
|
|
49
|
+
* for tests / bundling / portable installs).
|
|
50
|
+
*/
|
|
51
|
+
function getHqEdgeHome(override) {
|
|
52
|
+
if (override) return override;
|
|
53
|
+
if (process.env.HQ_EDGE_HOME) return process.env.HQ_EDGE_HOME;
|
|
54
|
+
const home = homedir();
|
|
55
|
+
if (platform() === "darwin") return join(home, ".hq-edge");
|
|
56
|
+
if (platform() === "win32") {
|
|
57
|
+
const localAppData = process.env.LOCALAPPDATA;
|
|
58
|
+
if (localAppData) return join(localAppData, APP_ID);
|
|
59
|
+
return join(home, "AppData", "Local", APP_ID);
|
|
60
|
+
}
|
|
61
|
+
const xdgDataHome = process.env.XDG_DATA_HOME;
|
|
62
|
+
return xdgDataHome ? join(xdgDataHome, APP_ID) : join(home, ".local", "share", APP_ID);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the OS-native base log directory for HQ Edge.
|
|
66
|
+
*
|
|
67
|
+
* Built on top of `getHqEdgeHome()` as `<home>/logs` on every platform, so
|
|
68
|
+
* logs live inside the HQ Edge home tree:
|
|
69
|
+
*
|
|
70
|
+
* macOS: ~/.hq-edge/logs/
|
|
71
|
+
* Linux: ~/.local/share/hq-edge/logs/
|
|
72
|
+
* Windows: %LOCALAPPDATA%\hq-edge\logs\
|
|
73
|
+
*
|
|
74
|
+
* The path may be overridden explicitly via `override` or the
|
|
75
|
+
* `HQ_EDGE_LOG_DIR` environment variable.
|
|
76
|
+
*/
|
|
77
|
+
function getLogBaseDir(override) {
|
|
78
|
+
if (override) return override;
|
|
79
|
+
if (process.env.HQ_EDGE_LOG_DIR) return process.env.HQ_EDGE_LOG_DIR;
|
|
80
|
+
return join(getHqEdgeHome(), "logs");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the per-component log directory, e.g. `<base>/dsh-plugins/`.
|
|
84
|
+
*
|
|
85
|
+
* The directory is created on demand by the rotating file stream.
|
|
86
|
+
*
|
|
87
|
+
* Note: the directory name is the component verbatim — there is no implicit
|
|
88
|
+
* version scoping. Callers that need version isolation (e.g. the DSH home,
|
|
89
|
+
* which keeps one tree per HQ Edge release) must layer it on top of
|
|
90
|
+
* `getHqEdgeHome()` themselves. Cross-version logs (server, plugin diagnostics)
|
|
91
|
+
* intentionally share a tree so a single `tail -F` follows them across upgrades.
|
|
92
|
+
*/
|
|
93
|
+
function getLogDir(component, baseDirOverride) {
|
|
94
|
+
return join(getLogBaseDir(baseDirOverride), component);
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
6
97
|
//#region src/levels.ts
|
|
7
98
|
/** Levels ordered from most to least verbose. */
|
|
8
99
|
const LOG_LEVELS = [
|
|
@@ -133,22 +224,27 @@ function redactString(value) {
|
|
|
133
224
|
* temporary prints and re-run.
|
|
134
225
|
*
|
|
135
226
|
* This package gives every plugin one shared, file-backed, cross-platform log
|
|
136
|
-
*
|
|
227
|
+
* inside the current HQ Edge log tree:
|
|
228
|
+
*
|
|
229
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.log (current)
|
|
230
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.1.log (previous, after rotation)
|
|
231
|
+
*
|
|
232
|
+
* ## HQ Edge home resolution
|
|
137
233
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
234
|
+
* The directory comes from the inlined `@hqedge/paths` resolution
|
|
235
|
+
* (`src/paths.ts`): the same root every HQ Edge runtime uses, so plugin logs
|
|
236
|
+
* land inside the current HQ Edge log tree:
|
|
140
237
|
*
|
|
141
|
-
*
|
|
238
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.log (current)
|
|
239
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.1.log (previous, after rotation)
|
|
142
240
|
*
|
|
143
|
-
*
|
|
144
|
-
* helper the rest of DSH uses, so every override HQ Edge (or any other host)
|
|
145
|
-
* performs is honoured for free:
|
|
241
|
+
* Resolution honours the same overrides as the rest of HQ Edge:
|
|
146
242
|
*
|
|
147
|
-
* explicit `configure({ dir })` > $DSH_PLUGIN_LOG_DIR > $
|
|
243
|
+
* explicit `configure({ dir })` > $DSH_PLUGIN_LOG_DIR > $HQ_EDGE_LOG_DIR / $HQ_EDGE_HOME
|
|
148
244
|
*
|
|
149
|
-
* HQ Edge
|
|
150
|
-
*
|
|
151
|
-
*
|
|
245
|
+
* HQ Edge runs DSH with `HQ_EDGE_HOME` set to its own per-user data directory,
|
|
246
|
+
* so plugin logs live next to the rest of that installation's state and never
|
|
247
|
+
* in the user's default home.
|
|
152
248
|
*
|
|
153
249
|
* ## Cross-platform notes
|
|
154
250
|
*
|
|
@@ -242,7 +338,7 @@ function resolveLogDir(explicit) {
|
|
|
242
338
|
if (explicit !== void 0 && explicit.length > 0) candidates.push(explicit);
|
|
243
339
|
const fromEnv = env("DSH_PLUGIN_LOG_DIR");
|
|
244
340
|
if (fromEnv) candidates.push(fromEnv);
|
|
245
|
-
candidates.push(
|
|
341
|
+
candidates.push(getLogDir("dsh-plugins"));
|
|
246
342
|
candidates.push(join(tmpdir(), "hq-dsh-plugins", "logs"));
|
|
247
343
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
248
344
|
const dir = candidates[i];
|
|
@@ -434,16 +530,16 @@ function bootstrap() {
|
|
|
434
530
|
s.bootstrapped = true;
|
|
435
531
|
const cfg = currentConfig();
|
|
436
532
|
const logger = createLogger("dsh-plugin-log", {});
|
|
437
|
-
let
|
|
533
|
+
let hqEdgeHome = null;
|
|
438
534
|
try {
|
|
439
|
-
|
|
535
|
+
hqEdgeHome = getHqEdgeHome();
|
|
440
536
|
} catch {
|
|
441
|
-
|
|
537
|
+
hqEdgeHome = null;
|
|
442
538
|
}
|
|
443
539
|
logger.info("plugin log ready", {
|
|
444
540
|
logFile: join(cfg.dir, cfg.fileName),
|
|
445
541
|
logDir: cfg.dir,
|
|
446
|
-
|
|
542
|
+
hqEdgeHome,
|
|
447
543
|
level: cfg.level,
|
|
448
544
|
consoleLevel: cfg.consoleLevel,
|
|
449
545
|
pid: process.pid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/dsh-plugin-log",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.mjs",
|
|
6
6
|
"types": "./lib/index.d.mts",
|
|
@@ -22,9 +22,7 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@deepseek-ai/dsh-home-paths": "^0.1.0-rc.0"
|
|
27
|
-
},
|
|
25
|
+
"dependencies": {},
|
|
28
26
|
"devDependencies": {
|
|
29
27
|
"@types/node": "^24.0.0"
|
|
30
28
|
},
|
package/src/index.ts
CHANGED
|
@@ -12,22 +12,27 @@
|
|
|
12
12
|
* temporary prints and re-run.
|
|
13
13
|
*
|
|
14
14
|
* This package gives every plugin one shared, file-backed, cross-platform log
|
|
15
|
-
*
|
|
15
|
+
* inside the current HQ Edge log tree:
|
|
16
16
|
*
|
|
17
|
-
* <
|
|
18
|
-
* <
|
|
17
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.log (current)
|
|
18
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.1.log (previous, after rotation)
|
|
19
19
|
*
|
|
20
|
-
* ##
|
|
20
|
+
* ## HQ Edge home resolution
|
|
21
21
|
*
|
|
22
|
-
* The directory comes from `@
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* The directory comes from the inlined `@hqedge/paths` resolution
|
|
23
|
+
* (`src/paths.ts`): the same root every HQ Edge runtime uses, so plugin logs
|
|
24
|
+
* land inside the current HQ Edge log tree:
|
|
25
25
|
*
|
|
26
|
-
*
|
|
26
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.log (current)
|
|
27
|
+
* <HQ_EDGE_HOME>/logs/dsh-plugins/dsh-plugins.1.log (previous, after rotation)
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Resolution honours the same overrides as the rest of HQ Edge:
|
|
30
|
+
*
|
|
31
|
+
* explicit `configure({ dir })` > $DSH_PLUGIN_LOG_DIR > $HQ_EDGE_LOG_DIR / $HQ_EDGE_HOME
|
|
32
|
+
*
|
|
33
|
+
* HQ Edge runs DSH with `HQ_EDGE_HOME` set to its own per-user data directory,
|
|
34
|
+
* so plugin logs live next to the rest of that installation's state and never
|
|
35
|
+
* in the user's default home.
|
|
31
36
|
*
|
|
32
37
|
* ## Cross-platform notes
|
|
33
38
|
*
|
|
@@ -57,7 +62,7 @@ import {
|
|
|
57
62
|
import { appendFile } from 'node:fs/promises'
|
|
58
63
|
import { tmpdir } from 'node:os'
|
|
59
64
|
import { join } from 'node:path'
|
|
60
|
-
import {
|
|
65
|
+
import { getHqEdgeHome, getLogDir } from './paths.js'
|
|
61
66
|
|
|
62
67
|
import { isEnabled, parseLevel, type LogLevel } from './levels.js'
|
|
63
68
|
import { redact } from './redact.js'
|
|
@@ -187,9 +192,9 @@ function resolveLogDir(explicit?: string): { dir: string; fallback: boolean } {
|
|
|
187
192
|
if (explicit !== undefined && explicit.length > 0) candidates.push(explicit)
|
|
188
193
|
const fromEnv = env('DSH_PLUGIN_LOG_DIR')
|
|
189
194
|
if (fromEnv) candidates.push(fromEnv)
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
candidates.push(
|
|
195
|
+
// Inside the current HQ Edge log tree (honours $HQ_EDGE_HOME / $HQ_EDGE_LOG_DIR
|
|
196
|
+
// through the inlined paths resolver), so plugin logs follow the host install.
|
|
197
|
+
candidates.push(getLogDir('dsh-plugins'))
|
|
193
198
|
candidates.push(join(tmpdir(), 'hq-dsh-plugins', 'logs'))
|
|
194
199
|
|
|
195
200
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
@@ -425,16 +430,16 @@ function bootstrap(): void {
|
|
|
425
430
|
s.bootstrapped = true
|
|
426
431
|
const cfg = currentConfig()
|
|
427
432
|
const logger = createLogger('dsh-plugin-log', {})
|
|
428
|
-
let
|
|
433
|
+
let hqEdgeHome: string | null = null
|
|
429
434
|
try {
|
|
430
|
-
|
|
435
|
+
hqEdgeHome = getHqEdgeHome()
|
|
431
436
|
} catch {
|
|
432
|
-
|
|
437
|
+
hqEdgeHome = null
|
|
433
438
|
}
|
|
434
439
|
logger.info('plugin log ready', {
|
|
435
440
|
logFile: join(cfg.dir, cfg.fileName),
|
|
436
441
|
logDir: cfg.dir,
|
|
437
|
-
|
|
442
|
+
hqEdgeHome,
|
|
438
443
|
level: cfg.level,
|
|
439
444
|
consoleLevel: cfg.consoleLevel,
|
|
440
445
|
pid: process.pid,
|
package/src/paths.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inlined from `@hqedge/paths` (hq-edge/packages/paths/src/index.ts) so this
|
|
3
|
+
* plugin stays fully self-contained — no runtime dependency on the published
|
|
4
|
+
* package. Keep in sync when `@hqedge/paths` changes its path conventions.
|
|
5
|
+
*
|
|
6
|
+
* ────────────────────────────────────────────────────────────────────────────
|
|
7
|
+
* Shared OS-native path resolution for HQ Edge runtimes.
|
|
8
|
+
*
|
|
9
|
+
* The single source of truth for where HQ Edge places per-user directories.
|
|
10
|
+
* `getHqEdgeHome()` is the root: every other path getter (`getLogBaseDir`,
|
|
11
|
+
* `getLogDir`) is derived from it, so all HQ Edge user directories live under
|
|
12
|
+
* one self-contained tree and every consumer resolves the same location.
|
|
13
|
+
*
|
|
14
|
+
* Path conventions by platform (env-paths `data` shape, except macOS — see
|
|
15
|
+
* below):
|
|
16
|
+
*
|
|
17
|
+
* - macOS: ~/.hq-edge/ (this override)
|
|
18
|
+
* - Linux: ~/.local/share/hq-edge/ (honors $XDG_DATA_HOME)
|
|
19
|
+
* - Windows: %LOCALAPPDATA%\hq-edge\
|
|
20
|
+
*
|
|
21
|
+
* macOS deviates from `env-paths`: a dotfile under `$HOME` rather than the
|
|
22
|
+
* `~/Library/Application Support/hq-edge/` sandbox location. Rationale: HQ
|
|
23
|
+
* Edge is a single-developer EDA workstation tool, not a sandboxed macOS app.
|
|
24
|
+
* A dotfile in `$HOME` is more discoverable (one `ls -la` shows every HQ Edge
|
|
25
|
+
* user-data tree), survives sandbox / permission oddities, and aligns with the
|
|
26
|
+
* historical `~/.hq` location users already had from `dshHome.ts` before this
|
|
27
|
+
* unification. It also means DSH plugin code that imports `@hqedge/paths` does
|
|
28
|
+
* not need to branch on platform for the macOS case.
|
|
29
|
+
*/
|
|
30
|
+
import { homedir, platform } from 'node:os'
|
|
31
|
+
import { join } from 'node:path'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Application identifier used for OS-native directories.
|
|
35
|
+
*/
|
|
36
|
+
export const APP_ID = 'hq-edge'
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resolves the OS-native per-user home/data directory for HQ Edge — the single
|
|
40
|
+
* root from which every other HQ Edge path getter is derived.
|
|
41
|
+
*
|
|
42
|
+
* - macOS: ~/.hq-edge/ (override)
|
|
43
|
+
* - Linux: ~/.local/share/hq-edge/ (honors $XDG_DATA_HOME)
|
|
44
|
+
* - Windows: %LOCALAPPDATA%\hq-edge\
|
|
45
|
+
*
|
|
46
|
+
* The macOS override is documented above. The path may also be overridden
|
|
47
|
+
* explicitly via `override` or the `HQ_EDGE_HOME` environment variable (useful
|
|
48
|
+
* for tests / bundling / portable installs).
|
|
49
|
+
*/
|
|
50
|
+
export function getHqEdgeHome(override?: string): string {
|
|
51
|
+
if (override) return override
|
|
52
|
+
if (process.env.HQ_EDGE_HOME) return process.env.HQ_EDGE_HOME
|
|
53
|
+
|
|
54
|
+
const home = homedir()
|
|
55
|
+
// macOS override: dotfile under $HOME, not the Library sandbox.
|
|
56
|
+
// See the file header for the rationale.
|
|
57
|
+
if (platform() === 'darwin') {
|
|
58
|
+
return join(home, '.hq-edge')
|
|
59
|
+
}
|
|
60
|
+
if (platform() === 'win32') {
|
|
61
|
+
const localAppData = process.env.LOCALAPPDATA
|
|
62
|
+
if (localAppData) return join(localAppData, APP_ID)
|
|
63
|
+
return join(home, 'AppData', 'Local', APP_ID)
|
|
64
|
+
}
|
|
65
|
+
// Linux / other POSIX — follows the XDG_DATA_HOME convention.
|
|
66
|
+
const xdgDataHome = process.env.XDG_DATA_HOME
|
|
67
|
+
return xdgDataHome ? join(xdgDataHome, APP_ID) : join(home, '.local', 'share', APP_ID)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Resolves the OS-native base log directory for HQ Edge.
|
|
72
|
+
*
|
|
73
|
+
* Built on top of `getHqEdgeHome()` as `<home>/logs` on every platform, so
|
|
74
|
+
* logs live inside the HQ Edge home tree:
|
|
75
|
+
*
|
|
76
|
+
* macOS: ~/.hq-edge/logs/
|
|
77
|
+
* Linux: ~/.local/share/hq-edge/logs/
|
|
78
|
+
* Windows: %LOCALAPPDATA%\hq-edge\logs\
|
|
79
|
+
*
|
|
80
|
+
* The path may be overridden explicitly via `override` or the
|
|
81
|
+
* `HQ_EDGE_LOG_DIR` environment variable.
|
|
82
|
+
*/
|
|
83
|
+
export function getLogBaseDir(override?: string): string {
|
|
84
|
+
if (override) return override
|
|
85
|
+
if (process.env.HQ_EDGE_LOG_DIR) return process.env.HQ_EDGE_LOG_DIR
|
|
86
|
+
return join(getHqEdgeHome(), 'logs')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resolves the per-component log directory, e.g. `<base>/dsh-plugins/`.
|
|
91
|
+
*
|
|
92
|
+
* The directory is created on demand by the rotating file stream.
|
|
93
|
+
*
|
|
94
|
+
* Note: the directory name is the component verbatim — there is no implicit
|
|
95
|
+
* version scoping. Callers that need version isolation (e.g. the DSH home,
|
|
96
|
+
* which keeps one tree per HQ Edge release) must layer it on top of
|
|
97
|
+
* `getHqEdgeHome()` themselves. Cross-version logs (server, plugin diagnostics)
|
|
98
|
+
* intentionally share a tree so a single `tail -F` follows them across upgrades.
|
|
99
|
+
*/
|
|
100
|
+
export function getLogDir(component: string, baseDirOverride?: string): string {
|
|
101
|
+
return join(getLogBaseDir(baseDirOverride), component)
|
|
102
|
+
}
|