@atomservice/core 0.1.12 → 0.1.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/package.json +1 -1
- package/src/core.config.ts +7 -0
- package/src/core.hooks.ts +10 -12
- package/src/core.types.ts +7 -0
package/package.json
CHANGED
package/src/core.config.ts
CHANGED
|
@@ -6,6 +6,12 @@ import type { ResolvedAtomserviceConfig } from "./core.types.ts"
|
|
|
6
6
|
|
|
7
7
|
const UserConfigSchema = z.object({
|
|
8
8
|
services: z.array(z.any()),
|
|
9
|
+
mirrors: z
|
|
10
|
+
.object({
|
|
11
|
+
apt: z.string().optional(),
|
|
12
|
+
npm: z.string().optional(),
|
|
13
|
+
})
|
|
14
|
+
.optional(),
|
|
9
15
|
})
|
|
10
16
|
|
|
11
17
|
export async function loadConfig(): Promise<ResolvedAtomserviceConfig> {
|
|
@@ -21,5 +27,6 @@ export async function loadConfig(): Promise<ResolvedAtomserviceConfig> {
|
|
|
21
27
|
return {
|
|
22
28
|
root: ATOMSERVICE_DATA_DIR,
|
|
23
29
|
services: parsed.services,
|
|
30
|
+
mirrors: parsed.mirrors,
|
|
24
31
|
}
|
|
25
32
|
}
|
package/src/core.hooks.ts
CHANGED
|
@@ -59,8 +59,8 @@ export function useShell(): typeof Bun.$ {
|
|
|
59
59
|
// 默认抛错(沿用 Bun.$ 行为),服务通过 .nothrow() 显式忽略;.quiet() 抑制实时输出
|
|
60
60
|
if (!process.env.ATOMSERVICE_VERBOSE) return Reflect.apply(shell, undefined, args).quiet()
|
|
61
61
|
|
|
62
|
-
// verbose
|
|
63
|
-
const cmd = Reflect.apply(shell, undefined, args).
|
|
62
|
+
// verbose 模式:不加 .quiet(),让输出实时流式打印到终端
|
|
63
|
+
const cmd = Reflect.apply(shell, undefined, args).nothrow()
|
|
64
64
|
const strings = args[0] as TemplateStringsArray
|
|
65
65
|
const values = args.slice(1)
|
|
66
66
|
const cmdStr = strings.reduce(
|
|
@@ -71,7 +71,6 @@ export function useShell(): typeof Bun.$ {
|
|
|
71
71
|
"",
|
|
72
72
|
)
|
|
73
73
|
|
|
74
|
-
// 惰性执行:仅在首次 await 时运行一次,throwOnError 由是否调用过 .nothrow() 决定
|
|
75
74
|
let throwOnError = true
|
|
76
75
|
let started: Promise<Bun.$.ShellOutput> | undefined
|
|
77
76
|
const exec = () => {
|
|
@@ -79,17 +78,16 @@ export function useShell(): typeof Bun.$ {
|
|
|
79
78
|
started = (async () => {
|
|
80
79
|
process.stdout.write(`${BAR}│${RESET} ${CMD}$ ${short(cmdStr)}${RESET}\n`)
|
|
81
80
|
const result = await cmd
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
if (result.exitCode !== 0) {
|
|
82
|
+
const stderr = result.stderr?.toString().trim()
|
|
83
|
+
if (stderr) {
|
|
84
|
+
for (const line of stderr.split("\n")) {
|
|
85
|
+
const trimmed = line.trim()
|
|
86
|
+
if (!trimmed) continue
|
|
87
|
+
process.stdout.write(`${BAR}│${RESET} ${OUT}${short(line.trimEnd())}${RESET}\n`)
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
printLines(result.stdout)
|
|
92
|
-
printLines(result.stderr)
|
|
93
91
|
if (throwOnError && result.exitCode !== 0) {
|
|
94
92
|
throw new Error(result.stderr?.toString().trim() || `Exit code ${result.exitCode}`)
|
|
95
93
|
}
|
package/src/core.types.ts
CHANGED
|
@@ -11,13 +11,20 @@ export type HealthStatus =
|
|
|
11
11
|
| { status: "unhealthy"; message: string }
|
|
12
12
|
| { status: "unknown"; message?: string }
|
|
13
13
|
|
|
14
|
+
export interface MirrorsConfig {
|
|
15
|
+
apt?: string
|
|
16
|
+
npm?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
export interface ResolvedAtomserviceConfig {
|
|
15
20
|
root: string
|
|
16
21
|
services: AnyService[]
|
|
22
|
+
mirrors?: MirrorsConfig
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export interface AtomserviceConfig {
|
|
20
26
|
services: AnyService[]
|
|
27
|
+
mirrors?: MirrorsConfig
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
export interface ServiceDefinition<ServiceInstance = void> {
|