Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Replace typedi with our custom DI system (no-changelog) #12389

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

netroy
Copy link
Member

@netroy netroy commented Dec 27, 2024

Summary

This PR replaces typedi with a DI system that we can maintain and have full control over.

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@netroy netroy requested a review from a team as a code owner December 27, 2024 21:20
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Dec 27, 2024
Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

packages/@n8n/di/src/di.ts Outdated Show resolved Hide resolved
packages/@n8n/di/src/di.ts Outdated Show resolved Hide resolved
packages/@n8n/di/src/di.ts Outdated Show resolved Hide resolved
packages/@n8n/di/src/di.ts Show resolved Hide resolved
packages/@n8n/di/src/di.ts Outdated Show resolved Hide resolved
packages/@n8n/di/src/di.ts Outdated Show resolved Hide resolved
Comment on lines +132 to +133
/** Clears all instantiated instances from the container while preserving type registrations */
reset(): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more accurate to rename as clearInstanceCache? factory remains.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the jsdoc should describe the details. The name reset is fine IMO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while preserving type registrations → I'm not clear on what's a type registration. If it means the factory let's use that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More ideas to test if you like

  • Circular dependencies
  • Ensure get after reset creates a new instance
  • Resolution stack gets cleared after an error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add tests for circular dependencies, but had to remove them because circular dependency between 2 classes in the same file causes one of them to be undefined, leading to compile-time, and runtime unhandled error.

in part 2, I'll add more tests after I add the testing related stuff.

packages/cli/package.json Show resolved Hide resolved
packages/@n8n/di/package.json Outdated Show resolved Hide resolved
packages/@n8n/di/README.md Outdated Show resolved Hide resolved
Copy link

cypress bot commented Jan 3, 2025

n8n    Run #8570

Run Properties:  status check passed Passed #8570  •  git commit 2393a43772: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 netroy 🗃️ e2e/*
Project n8n
Branch Review n8n-di
Run status status check passed Passed #8570
Run duration 04m 49s
Commit git commit 2393a43772: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 netroy 🗃️ e2e/*
Committer Iván Ovejero
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 484
View all changes introduced in this branch ↗︎

Copy link
Contributor

github-actions bot commented Jan 3, 2025

✅ All Cypress E2E specs passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants