bajo 2.3.2 → 2.4.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/app.js CHANGED
@@ -264,6 +264,8 @@ class App {
264
264
  */
265
265
  boot = async () => {
266
266
  this.bajo = new Bajo(this)
267
+ this.bajo.hooks.push(...(this.options.hooks ?? []))
268
+ delete this.options.hooks
267
269
  // argv/args/env
268
270
  const { parseArgsArgv, parseEnv, secToHms } = this.lib.aneka
269
271
  const { parseObject } = this.lib
@@ -273,6 +275,7 @@ class App {
273
275
  this.argv = parseObject(argv, { parseValue: true })
274
276
  this.envVars = parseObject(parseEnv(), { parseValue: true })
275
277
  this.applet = this.envVars._.applet ?? this.argv._.applet
278
+ await this.bajo.runHook('bajo:beforeBoot')
276
279
  await this.bajo.init()
277
280
  // boot complete
278
281
  const elapsed = new Date() - this.runAt
@@ -285,7 +288,7 @@ class App {
285
288
  * @see {@tutorial hook}
286
289
  * @see App#boot
287
290
  */
288
- await this.bajo.runHook('bajo:afterBootCompleted')
291
+ await this.bajo.runHook('bajo:afterBoot')
289
292
  if (this.applet) await runAsApplet.call(this.bajo)
290
293
  return this
291
294
  }
package/class/bajo.js CHANGED
@@ -60,6 +60,8 @@ class Bajo extends Plugin {
60
60
  { ext: '.js', readHandler: this._defConfigHandler },
61
61
  { ext: '.json', readHandler: this.fromJson, writeHandler: this.toJson }
62
62
  ]
63
+
64
+ this.hooks = []
63
65
  }
64
66
 
65
67
  async _defConfigHandler (file, opts = {}) {
@@ -963,13 +965,13 @@ class Bajo extends Plugin {
963
965
  } catch (err) {
964
966
  return
965
967
  }
966
- let fns = filter(this.app.bajo.hooks, { ns, subNs, path })
968
+ let fns = filter(this.hooks, { ns, subNs, path })
967
969
  if (isEmpty(fns)) return []
968
970
  fns = orderBy(fns, ['level'])
969
971
  const results = []
970
972
  for (const i in fns) {
971
973
  const fn = fns[i]
972
- const scope = this.app[fn.src]
974
+ const scope = this.app[fn.src ?? 'main'] ?? this
973
975
  if (fn.noWait) fn.handler.call(scope, ...args)
974
976
  else {
975
977
  const res = await fn.handler.call(scope, ...args)
@@ -978,7 +980,6 @@ class Bajo extends Plugin {
978
980
  resp: res
979
981
  })
980
982
  }
981
- if (this.config.log.traceHook) scope.log.trace('hookExecuted%s', hookName)
982
983
  }
983
984
  return results
984
985
  }
@@ -101,7 +101,6 @@ export async function checkDependencies () {
101
101
  export async function collectHooks () {
102
102
  const { eachPlugins, runHook, isLogInRange, importModule, breakNsPathFromFile } = this.bajo
103
103
  const me = this
104
- me.bajo.hooks = this.bajo.hooks ?? []
105
104
  me.bajo.log.trace('collecting%s', this.t('hooks'))
106
105
  // collects
107
106
  await eachPlugins(async function ({ dir, file }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "2.3.2",
3
+ "version": "2.4.1",
4
4
  "description": "The ultimate framework for whipping up massive apps in no time",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-01-29
4
+
5
+ - [2.4.0] Hooks can now be added through ```config``` object. This is specially usefull if you provide a custom config object on app boot
6
+ - [2.4.1] Bug fix on ```runHook()``` resolver. Source defaults to ```main``` if not provided. Scope defaults to ```bajo``` if not found/initialized yet
7
+
3
8
  ## 2026-01-24
4
9
 
5
10
  - [2.3.2] Hook now can be executed without waiting if property ```noWait``` is ```true```