@superhero/core 4.0.1 → 4.0.3
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/index.js +48 -30
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import os from 'node:os'
|
|
|
2
2
|
import cluster from 'node:cluster'
|
|
3
3
|
import EventEmitter from 'node:events'
|
|
4
4
|
import path from 'node:path'
|
|
5
|
+
import url from 'node:url'
|
|
5
6
|
import bootstrap from '@superhero/bootstrap'
|
|
6
7
|
import Locate from '@superhero/locator'
|
|
7
8
|
import Log from '@superhero/log'
|
|
@@ -289,7 +290,7 @@ export default class Core
|
|
|
289
290
|
}
|
|
290
291
|
else if(false === this.#isBooted)
|
|
291
292
|
{
|
|
292
|
-
await this.#
|
|
293
|
+
await this.#addDependencies()
|
|
293
294
|
await this.#confirmAbsoluteServcieMapPaths()
|
|
294
295
|
|
|
295
296
|
freeze && this.config.freeze()
|
|
@@ -331,8 +332,11 @@ export default class Core
|
|
|
331
332
|
this.#isForked = true
|
|
332
333
|
|
|
333
334
|
// Set the worker execution script.
|
|
334
|
-
const
|
|
335
|
-
|
|
335
|
+
const
|
|
336
|
+
pwd = path.dirname(url.fileURLToPath(import.meta.url)),
|
|
337
|
+
primaryClusterConfig = this.config.find('core/cluster/primary', { exec: path.join(pwd, 'worker.js') })
|
|
338
|
+
|
|
339
|
+
cluster.setupPrimary(primaryClusterConfig)
|
|
336
340
|
|
|
337
341
|
for(let i = 0; i < forks; i++)
|
|
338
342
|
{
|
|
@@ -604,61 +608,75 @@ export default class Core
|
|
|
604
608
|
}
|
|
605
609
|
}
|
|
606
610
|
|
|
607
|
-
async #
|
|
611
|
+
async #addDependencies()
|
|
608
612
|
{
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
613
|
+
let
|
|
614
|
+
dependencies = {},
|
|
615
|
+
loaded = []
|
|
612
616
|
|
|
613
617
|
do
|
|
614
618
|
{
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
loaded.push(...postLoaded)
|
|
619
|
+
loaded = Object.keys(dependencies)
|
|
620
|
+
dependencies = this.#loadNewDependencies(loaded)
|
|
621
|
+
await this.add(Object.values(dependencies))
|
|
619
622
|
}
|
|
620
|
-
while(
|
|
623
|
+
while(Object.keys(dependencies).length < loaded.length)
|
|
621
624
|
|
|
622
625
|
return this
|
|
623
626
|
}
|
|
624
627
|
|
|
625
|
-
#
|
|
628
|
+
#loadNewDependencies(loaded)
|
|
626
629
|
{
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
630
|
+
const
|
|
631
|
+
dependencies = this.config.find('dependency', {}),
|
|
632
|
+
dependenciesType = Object.prototype.toString.call(dependencies)
|
|
633
|
+
|
|
634
|
+
if('[object Object]' !== dependenciesType)
|
|
631
635
|
{
|
|
632
|
-
const error = new TypeError(`Invalid
|
|
633
|
-
error.code = '
|
|
634
|
-
error.cause = 'Config core/dependencies must be an array'
|
|
636
|
+
const error = new TypeError(`Invalid configured dependency type: ${dependenciesType}`)
|
|
637
|
+
error.code = 'E_CORE_INVALID_DEPENDENCY_TYPE'
|
|
635
638
|
throw error
|
|
636
639
|
}
|
|
637
640
|
|
|
638
|
-
for(
|
|
641
|
+
for(const id in dependencies)
|
|
639
642
|
{
|
|
640
|
-
|
|
643
|
+
if(loaded.includes(id))
|
|
644
|
+
{
|
|
645
|
+
continue
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
let dependencyPath = dependencies[id]
|
|
649
|
+
|
|
650
|
+
if(false === dependencyPath)
|
|
651
|
+
{
|
|
652
|
+
continue
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
if(true === path)
|
|
656
|
+
{
|
|
657
|
+
dependencyPath = id
|
|
658
|
+
}
|
|
641
659
|
|
|
642
|
-
if('string'
|
|
660
|
+
if('string' !== typeof dependencyPath)
|
|
643
661
|
{
|
|
644
|
-
const error = new TypeError(`Invalid dependency type: ${Object.prototype.toString.call(
|
|
645
|
-
error.code = '
|
|
646
|
-
error.cause = 'The
|
|
662
|
+
const error = new TypeError(`Invalid dependency path type: ${Object.prototype.toString.call(dependencyPath)}`)
|
|
663
|
+
error.code = 'E_CORE_INVALID_DEPENDENCY_PATH_TYPE'
|
|
664
|
+
error.cause = 'The values of configured dependency attribute must be of type string'
|
|
647
665
|
throw error
|
|
648
666
|
}
|
|
649
667
|
|
|
650
|
-
if(
|
|
668
|
+
if(dependencyPath.startsWith('.'))
|
|
651
669
|
{
|
|
652
|
-
const absolutePath = this.config.findAbsoluteDirPathByConfigEntry('
|
|
670
|
+
const absolutePath = this.config.findAbsoluteDirPathByConfigEntry('dependency', { [id]: dependencies[id] })
|
|
653
671
|
|
|
654
672
|
if('string' === typeof absolutePath)
|
|
655
673
|
{
|
|
656
|
-
dependencies[i] = path.normalize(path.join(absolutePath,
|
|
674
|
+
dependencies[i] = path.normalize(path.join(absolutePath, dependencyPath))
|
|
657
675
|
}
|
|
658
676
|
}
|
|
659
677
|
}
|
|
660
678
|
|
|
661
|
-
return dependencies
|
|
679
|
+
return dependencies
|
|
662
680
|
}
|
|
663
681
|
|
|
664
682
|
#normalizeConfigPaths(configPaths)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Core functionalities for the superhero framework.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
".": "./index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@superhero/
|
|
13
|
-
"@superhero/
|
|
12
|
+
"@superhero/locator": "^4.2.3",
|
|
13
|
+
"@superhero/bootstrap": "^4.1.2"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"test": "node --trace-warnings --test --experimental-test-coverage"
|