mikser-io 6.1.0 → 6.2.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/package.json +1 -1
- package/src/engine.js +1 -1
- package/src/render.js +34 -1
package/package.json
CHANGED
package/src/engine.js
CHANGED
package/src/render.js
CHANGED
|
@@ -2,6 +2,25 @@ import { readFileSync } from 'node:fs'
|
|
|
2
2
|
import { createRequire } from 'node:module'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import _ from 'lodash'
|
|
5
|
+
import { useLogger } from './engine.js'
|
|
6
|
+
|
|
7
|
+
// Flatten template-helper args into a single human-readable message.
|
|
8
|
+
// Handlebars helpers receive a trailing options object (it has a `.hash`
|
|
9
|
+
// property) which we drop.
|
|
10
|
+
function formatLogArgs(args) {
|
|
11
|
+
if (args.length && typeof args[args.length - 1] === 'object' && args[args.length - 1] !== null && 'hash' in args[args.length - 1]) {
|
|
12
|
+
args = args.slice(0, -1)
|
|
13
|
+
}
|
|
14
|
+
return args
|
|
15
|
+
.map(arg => {
|
|
16
|
+
if (arg == null) return String(arg)
|
|
17
|
+
if (typeof arg === 'object') {
|
|
18
|
+
try { return JSON.stringify(arg) } catch { return String(arg) }
|
|
19
|
+
}
|
|
20
|
+
return String(arg)
|
|
21
|
+
})
|
|
22
|
+
.join(' ')
|
|
23
|
+
}
|
|
5
24
|
|
|
6
25
|
export default async ({ entity, options, config, context, state, logger, port }) => {
|
|
7
26
|
logger = logger || {
|
|
@@ -65,7 +84,21 @@ export default async ({ entity, options, config, context, state, logger, port })
|
|
|
65
84
|
data: context.data,
|
|
66
85
|
content() {
|
|
67
86
|
return readFileSync(entity.source, { encoding: 'utf8' })
|
|
68
|
-
}
|
|
87
|
+
},
|
|
88
|
+
// Logger functions are exposed directly so each renderer's
|
|
89
|
+
// auto-helper loop picks them up are picked up; falls back to the local `logger` in
|
|
90
|
+
// worker contexts where the engine singleton isn't initialised.
|
|
91
|
+
//
|
|
92
|
+
// Args are flattened into a single space-separated message so
|
|
93
|
+
// every value the template passed shows up — pino otherwise drops
|
|
94
|
+
// trailing positional args unless the first contains %s/%d format
|
|
95
|
+
// specifiers. Handlebars appends an internal options object as
|
|
96
|
+
// the last arg, which we strip before joining.
|
|
97
|
+
log: (...args) => (useLogger() ?? logger).info(formatLogArgs(args)),
|
|
98
|
+
warn: (...args) => (useLogger() ?? logger).warn(formatLogArgs(args)),
|
|
99
|
+
error: (...args) => (useLogger() ?? logger).error(formatLogArgs(args)),
|
|
100
|
+
debug: (...args) => (useLogger() ?? logger).debug(formatLogArgs(args)),
|
|
101
|
+
trace: (...args) => (useLogger() ?? logger).trace(formatLogArgs(args)),
|
|
69
102
|
}
|
|
70
103
|
|
|
71
104
|
for (let pluginName of pluginsToLoad) {
|