bajo 2.13.1 → 2.14.1
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/class/bajo.js +16 -5
- package/class/helper/bajo.js +1 -1
- package/class/helper/base.js +10 -7
- package/package.json +1 -1
- package/wiki/CHANGES.md +14 -0
package/class/bajo.js
CHANGED
|
@@ -850,7 +850,7 @@ class Bajo extends Plugin {
|
|
|
850
850
|
const { parseObject } = this.app.lib
|
|
851
851
|
const { defaultsDeep } = this.app.lib.aneka
|
|
852
852
|
const { uniq, isString, isArray, findIndex, isPlainObject, merge } = this.app.lib._
|
|
853
|
-
let { ns, baseNs, extend, checkOverride, merge: merged, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
853
|
+
let { ns, baseNs, extend, checkOverride, merge: merged, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {}, handler } = options
|
|
854
854
|
|
|
855
855
|
const getParseOptsArgs = (opts, orig) => {
|
|
856
856
|
opts.parserOpts = opts.parserOpts ?? {}
|
|
@@ -864,7 +864,10 @@ class Bajo extends Plugin {
|
|
|
864
864
|
|
|
865
865
|
const output = async (obj) => {
|
|
866
866
|
let orig = parseObject(obj)
|
|
867
|
-
if (!baseNs || extend === false)
|
|
867
|
+
if (!baseNs || extend === false) {
|
|
868
|
+
await this.runHook('bajo:afterReadConfig', file, orig, options)
|
|
869
|
+
return orig
|
|
870
|
+
}
|
|
868
871
|
const { suffix = '', keys = [] } = options
|
|
869
872
|
let bases = this.app.getAllNs()
|
|
870
873
|
if (isString(extend)) extend = extend.split(',').map(i => i.trim)
|
|
@@ -882,24 +885,32 @@ class Bajo extends Plugin {
|
|
|
882
885
|
if (checkOverride) {
|
|
883
886
|
getParseOptsArgs(opts, orig)
|
|
884
887
|
const fileExt = `${this.app.main.dir.pkg}/extend/${baseNs}/override/${ns}${suffix}/${_path}`
|
|
888
|
+
await this.runHook('bajo.override:beforeReadConfig', fileExt, options)
|
|
885
889
|
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, checkOverride: false, merge: false }))
|
|
890
|
+
await this.runHook('bajo.override:afterReadConfig', fileExt, result, options)
|
|
886
891
|
if (!isEmpty(result)) orig = result
|
|
887
892
|
}
|
|
888
893
|
getParseOptsArgs(opts, orig)
|
|
889
894
|
const binder = merged ? merge : defaultsDeep
|
|
890
895
|
for (const base of bases) {
|
|
891
896
|
if (!this.app[base]) continue
|
|
897
|
+
options.sourceNs = base
|
|
892
898
|
const fileExt = `${this.app[base].dir.pkg}/extend/${baseNs}/extend/${ns}${suffix}/${_path}`
|
|
899
|
+
await this.runHook('bajo.extend:beforeReadConfig', fileExt, options)
|
|
893
900
|
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, merge: false }))
|
|
901
|
+
await this.runHook('bajo.extend:afterReadConfig', fileExt, result, options)
|
|
894
902
|
if (isEmpty(result)) continue
|
|
895
903
|
if (isArray(result)) ext = [...result, ...ext]
|
|
896
904
|
else ext = binder({}, result, ext)
|
|
897
905
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
906
|
+
delete options.sourceNs
|
|
907
|
+
let result = isArray(orig) ? [...orig, ...ext] : binder({}, keys.length > 0 ? pick(ext, keys) : ext, orig)
|
|
908
|
+
if (handler) result = await this.callHandler(this.app[ns], handler, result)
|
|
909
|
+
await this.runHook('bajo:afterReadConfig', file, result, options)
|
|
910
|
+
return result
|
|
901
911
|
}
|
|
902
912
|
|
|
913
|
+
await this.runHook('bajo:beforeReadConfig', file, options)
|
|
903
914
|
parserOpts.readFromFile = true
|
|
904
915
|
if (!ns) ns = this.ns
|
|
905
916
|
file = resolvePath(this.getPluginFile(file))
|
package/class/helper/bajo.js
CHANGED
|
@@ -106,7 +106,7 @@ export default factory
|
|
|
106
106
|
export async function buildBaseConfig () {
|
|
107
107
|
// dirs
|
|
108
108
|
const { defaultsDeep, textToArray, currentLoc, resolvePath } = this.app.lib.aneka
|
|
109
|
-
this.config = defaultsDeep({}, this.app.
|
|
109
|
+
this.config = defaultsDeep({}, this.app.argv._, this.app.envVars._)
|
|
110
110
|
set(this, 'dir.base', this.app.dir)
|
|
111
111
|
const path = currentLoc(import.meta).dir + '/../..'
|
|
112
112
|
set(this, 'dir.pkg', resolvePath(path))
|
package/class/helper/base.js
CHANGED
|
@@ -100,17 +100,20 @@ export async function checkDependencies () {
|
|
|
100
100
|
*/
|
|
101
101
|
export async function collectHooks () {
|
|
102
102
|
const { eachPlugins, runHook, isLogInRange, importModule } = this.bajo
|
|
103
|
-
const me = this
|
|
103
|
+
const me = this // "this" is "app"
|
|
104
104
|
me.bajo.log.trace('collecting%s', this.t('hooks'))
|
|
105
|
-
// collects
|
|
106
105
|
await eachPlugins(async function ({ dir, file }) {
|
|
107
|
-
const _file = file.replace(dir + '/hook/', '').replace('.js', '')
|
|
108
|
-
const [names, path] = _file.split('@')
|
|
109
|
-
const [ns, subNs] = names.split('.').map(n => camelCase(n))
|
|
110
106
|
const mod = await importModule(file, { asHandler: true })
|
|
111
107
|
if (!mod) return undefined
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
const _file = file.replace(dir + '/hook/', '').replace('.js', '')
|
|
109
|
+
let [names, path] = _file.split('@')
|
|
110
|
+
names = names.split('$').map(n => trim(n))
|
|
111
|
+
for (const name of names) {
|
|
112
|
+
let [ns, subNs, subSubNs] = name.split('.').map(n => camelCase(n))
|
|
113
|
+
if (subSubNs) subNs = `${subNs}.${subSubNs}`
|
|
114
|
+
const m = merge({}, mod, { ns, subNs, path: camelCase(path), src: this.ns })
|
|
115
|
+
me.bajo.hooks.push(m)
|
|
116
|
+
}
|
|
114
117
|
}, { glob: 'hook/**/*.js', prefix: me.bajo.ns })
|
|
115
118
|
// for log trace purpose only
|
|
116
119
|
if (isLogInRange('trace')) {
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-05-22
|
|
4
|
+
|
|
5
|
+
- [2.14.1] Bug fix in ```helper.buildBaseConfig()```
|
|
6
|
+
- [2.14.1] Bug fix in ```helper.collectHooks()```
|
|
7
|
+
|
|
8
|
+
## 2026-05-16
|
|
9
|
+
|
|
10
|
+
- [2.14.0] Add ```bajo:beforeReadConfig()``` hook
|
|
11
|
+
- [2.14.0] Add ```bajo.override:beforeReadConfig()``` hook
|
|
12
|
+
- [2.14.0] Add ```bajo.extend:beforeReadConfig()``` hook
|
|
13
|
+
- [2.14.0] Add ```bajo:afterReadConfig()``` hook
|
|
14
|
+
- [2.14.0] Add ```bajo.override:afterReadConfig()``` hook
|
|
15
|
+
- [2.14.0] Add ```bajo.extend:afterReadConfig()``` hook
|
|
16
|
+
|
|
3
17
|
## 2026-05-02
|
|
4
18
|
|
|
5
19
|
- [2.13.1] Bug fix in ```app.t()```
|