@superhero/core 4.0.2 → 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.
Files changed (2) hide show
  1. package/index.js +42 -28
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -290,7 +290,7 @@ export default class Core
290
290
  }
291
291
  else if(false === this.#isBooted)
292
292
  {
293
- await this.#confirmAndAddDependencies()
293
+ await this.#addDependencies()
294
294
  await this.#confirmAbsoluteServcieMapPaths()
295
295
 
296
296
  freeze && this.config.freeze()
@@ -608,61 +608,75 @@ export default class Core
608
608
  }
609
609
  }
610
610
 
611
- async #confirmAndAddDependencies()
611
+ async #addDependencies()
612
612
  {
613
- const loaded = []
614
-
615
- let postLoaded, dependencies
613
+ let
614
+ dependencies = {},
615
+ loaded = []
616
616
 
617
617
  do
618
618
  {
619
- dependencies = this.#findNotLodadedDependencies(this.config, loaded)
620
- await this.add(dependencies)
621
- postLoaded = this.#findNotLodadedDependencies(this.config, loaded)
622
- loaded.push(...postLoaded)
619
+ loaded = Object.keys(dependencies)
620
+ dependencies = this.#loadNewDependencies(loaded)
621
+ await this.add(Object.values(dependencies))
623
622
  }
624
- while(postLoaded.length)
623
+ while(Object.keys(dependencies).length < loaded.length)
625
624
 
626
625
  return this
627
626
  }
628
627
 
629
- #findNotLodadedDependencies(loaded)
628
+ #loadNewDependencies(loaded)
630
629
  {
631
- const dependencies = this.config.find('core/dependencies',
632
- this.config.find('core/dependency', []))
633
-
634
- if(false === Array.isArray(dependencies))
630
+ const
631
+ dependencies = this.config.find('dependency', {}),
632
+ dependenciesType = Object.prototype.toString.call(dependencies)
633
+
634
+ if('[object Object]' !== dependenciesType)
635
635
  {
636
- const error = new TypeError(`Invalid dependencies type: ${Object.prototype.toString.call(dependencies)}`)
637
- error.code = 'E_CORE_CONFIG_DEPENDENCY_INVALID_TYPE'
638
- 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'
639
638
  throw error
640
639
  }
641
640
 
642
- for(let i = 0; i < dependencies.length; i++)
641
+ for(const id in dependencies)
643
642
  {
644
- const dependency = dependencies[i]
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
+ }
645
659
 
646
- if('string' === typeof dependency)
660
+ if('string' !== typeof dependencyPath)
647
661
  {
648
- const error = new TypeError(`Invalid dependency type: ${Object.prototype.toString.call(dependency)}`)
649
- error.code = 'E_CORE_CONFIG_DEPENDENCY_INVALID_TYPE'
650
- error.cause = 'The dependency values in config core/dependencies must be of type string'
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'
651
665
  throw error
652
666
  }
653
667
 
654
- if(dependency.startsWith('.'))
668
+ if(dependencyPath.startsWith('.'))
655
669
  {
656
- const absolutePath = this.config.findAbsoluteDirPathByConfigEntry('core/dependencies', [ dependency ])
670
+ const absolutePath = this.config.findAbsoluteDirPathByConfigEntry('dependency', { [id]: dependencies[id] })
657
671
 
658
672
  if('string' === typeof absolutePath)
659
673
  {
660
- dependencies[i] = path.normalize(path.join(absolutePath, dependency))
674
+ dependencies[i] = path.normalize(path.join(absolutePath, dependencyPath))
661
675
  }
662
676
  }
663
677
  }
664
678
 
665
- return dependencies.filter((dependency) => false === loaded.includes(dependency))
679
+ return dependencies
666
680
  }
667
681
 
668
682
  #normalizeConfigPaths(configPaths)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/core",
3
- "version": "4.0.2",
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/bootstrap": "^4.1.1",
13
- "@superhero/locator": "^4.2.2"
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"