@superhero/core 4.0.0-beta.6 → 4.0.0-beta.7

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.
Files changed (2) hide show
  1. package/index.js +10 -24
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -5,6 +5,7 @@ import path from 'node:path'
5
5
  import bootstrap from '@superhero/bootstrap'
6
6
  import Config from '@superhero/config'
7
7
  import Locate from '@superhero/locator'
8
+ import Log from '@superhero/log'
8
9
 
9
10
  export default class Core
10
11
  {
@@ -31,7 +32,7 @@ export default class Core
31
32
  {
32
33
  get: (target, prop, receiver) =>
33
34
  {
34
- // when pushing events to the eventlog, also send the events to all workers
35
+ // when pushing events to the eventlog, also sync the event to all workers
35
36
  if('push' === prop) return (...events) =>
36
37
  {
37
38
  setImmediate(() =>
@@ -48,6 +49,9 @@ export default class Core
48
49
  }
49
50
  })
50
51
 
52
+ // An exposed log instance taht the core instance uses that is open for modification.
53
+ static log = new Log({ label: process.env.CORE_CLUSTER_WORKER ? `[CORE:${process.env.CORE_CLUSTER_WORKER}]` : '[CORE]' })
54
+
51
55
  // Used for graceful termination, if multiple cores are instanciated.
52
56
  static #cores = new Map
53
57
 
@@ -81,7 +85,7 @@ export default class Core
81
85
  if(Core.#destructorIsTriggered)
82
86
  {
83
87
  Core.log.info`redundant shutdown signal ${signal} waiting for previous shutdown process to finalize…`
84
- reason && Core.log.error(reason)
88
+ reason && Core.log.fail`${reason}`
85
89
  return
86
90
  }
87
91
 
@@ -115,12 +119,12 @@ export default class Core
115
119
  const error = new Error('Failed to shutdown gracefully')
116
120
  error.code = 'E_CORE_DESTRUCT_GRACEFUL'
117
121
  error.cause = destructRejects
118
- Core.log.error(error)
122
+ Core.log.fail`${error}`
119
123
  setImmediate(() => process.exit(1))
120
124
  }
121
125
  else if(reason)
122
126
  {
123
- Core.log.error(reason)
127
+ Core.log.fail`${reason}`
124
128
  setImmediate(() => process.exit(1))
125
129
  }
126
130
  else
@@ -377,7 +381,7 @@ export default class Core
377
381
 
378
382
  if('string' === typeof absolutePath)
379
383
  {
380
- serviceMap[entry] = path.normalize(absolutePath + '/' + servicePath)
384
+ serviceMap[entry] = path.normalize(path.join(absolutePath, servicePath))
381
385
  }
382
386
  }
383
387
  }
@@ -634,7 +638,7 @@ export default class Core
634
638
 
635
639
  if('string' === typeof absolutePath)
636
640
  {
637
- dependencies[i] = path.normalize(absolutePath + '/' + dependency)
641
+ dependencies[i] = path.normalize(path.join(absolutePath, dependency))
638
642
  }
639
643
  }
640
644
  }
@@ -734,22 +738,4 @@ export default class Core
734
738
  throw error
735
739
  }
736
740
  }
737
-
738
- // Will make the log methods availible to overwrite
739
- // if a custom logging is desired.
740
- static log =
741
- {
742
- label : process.env.CORE_CLUSTER_WORKER
743
- ? `[CORE:${process.env.CORE_CLUSTER_WORKER}]`
744
- : '[CORE]',
745
- icon : ' ⇢ ',
746
- basic : (template, ...args) => template.reduce((result, part, i) => result + args[i - 1] + part),
747
- simple : (template, ...args) => this.log.label + this.log.icon + this.log.basic(template, ...args),
748
- colors : (template, ...args) => '\x1b[90m' + this.log.supress`${this.log.label + this.log.icon}` + template.reduce((result, part, i) => result + '\x1b[96m\x1b[2m' + args[i - 1] + '\x1b[90m' + part) + '\x1b[0m',
749
- supress : (template, ...args) => '\x1b[1m\x1b[2m' + this.log.basic(template, ...args) + '\x1b[22m',
750
- format : (...args) => this.log.colors(...args),
751
- info : (...args) => console.info (this.log.format(...args)),
752
- warning : (...args) => console.warn (this.log.format(...args)),
753
- error : (...args) => console.error (this.log.format`failure`, ...args)
754
- }
755
741
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/core",
3
- "version": "4.0.0-beta.6",
3
+ "version": "4.0.0-beta.7",
4
4
  "description": "Core functionalities for the superhero framework.",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -11,7 +11,8 @@
11
11
  "dependencies": {
12
12
  "@superhero/bootstrap": "^4.1.0",
13
13
  "@superhero/config": "^4.1.2",
14
- "@superhero/locator": "^4.1.2"
14
+ "@superhero/locator": "^4.1.2",
15
+ "@superhero/log": "^4.0.0"
15
16
  },
16
17
  "scripts": {
17
18
  "test": "node --trace-warnings --test --experimental-test-coverage"