mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
ci(core): Improve circular dependency reporting in typedi (no-changelog) (#8071)
## Summary While backend development, this change explicitly logs the location and index of a circular dependency, which helps getting rid of the circular dependency.
This commit is contained in:
committed by
GitHub
parent
8fc9888541
commit
0590ac7826
@@ -1,20 +1,14 @@
|
||||
diff --git a/cjs/container-instance.class.js b/cjs/container-instance.class.js
|
||||
index e473b1e652aa0b6e7462f7ba93fcef2812483b20..1e406113d68c401ee170c997afb53e5f71edeee2 100644
|
||||
index e473b1e652aa0b6e7462f7ba93fcef2812483b20..9e57857e5584373b88a9fad3fbb37bbcc56b554a 100644
|
||||
--- a/cjs/container-instance.class.js
|
||||
+++ b/cjs/container-instance.class.js
|
||||
@@ -209,6 +209,7 @@ class ContainerInstance {
|
||||
// this allows us to support javascript where we don't have decorators and emitted metadata about dependencies
|
||||
// need to be injected, and user can use provided container to get instances he needs
|
||||
params.push(this);
|
||||
+ if (process.env.NODE_ENV === 'production') Object.freeze(constructableTargetType.prototype);
|
||||
value = new constructableTargetType(...params);
|
||||
// TODO: Calling this here, leads to infinite loop, because @Inject decorator registerds a handler
|
||||
// TODO: which calls Container.get, which will check if the requested type has a value set and if not
|
||||
@@ -234,6 +235,7 @@ class ContainerInstance {
|
||||
@@ -234,6 +234,9 @@ class ContainerInstance {
|
||||
*/
|
||||
initializeParams(target, paramTypes) {
|
||||
return paramTypes.map((paramType, index) => {
|
||||
+ if (paramType === undefined) throw new ReferenceError('Cannot inject an `undefined` dependency. Possibly a circular dependency detected');
|
||||
+ if (paramType === undefined) {
|
||||
+ throw new ReferenceError(`Circular dependency: Target${target.name}. Index: ${index} `);
|
||||
+ }
|
||||
const paramHandler = container_class_1.Container.handlers.find(handler => {
|
||||
/**
|
||||
* @Inject()-ed values are stored as parameter handlers and they reference their target
|
||||
* @Inject()-ed values are stored as parameter handlers and they reference their target
|
||||
|
||||
Reference in New Issue
Block a user