asd-xiv / pluginus Goto Github PK
View Code? Open in Web Editor NEWDependency injection with promise support for Node.js
License: MIT License
Dependency injection with promise support for Node.js
License: MIT License
Hi!
I am experiencing an issue that seems to be related to the loading order of dependencies.
The situation is:
PluginA {
depend: ["PluginB"],
}
PluginB {
depend: ["PluginA"],
}
That causes the error mentioned in the title. Having a quick look at the code, I see that this piece of code could be the issue:
sort((a, b) => {
const aHasB = has(b.name, a.depend)
const bHasA = has(a.name, b.depend)
if (!aHasB && !bHasA) {
return a.depend.length > b.depend.length ? 1 : -1
}
return bHasA ? -1 : 1
}),
While it can be argued that the code should be decoupled or architectured in a different way, I wanted to raise the issue in case this is a known limitation, there is a workaround, or this is something that need addressing at this level.
Verify only file path from files
param. Verifying folders and non-regexp files is enough to ensure all paths exist.
https://github.com/asd14/pluginus/blob/master/src/pluginus.js#L217
Describe
Plugins initialized each time it gets loaded as a dependency.
Reproduce
// plugin 1
module.exports = {
depend: [],
create: () => {
// will log two times
console.log("Init plugin 1")
},
}
// plugin 2
module.exports = {
depend: ["Plugin1"],
create: Plugin2 => {},
}
// plugin 3
module.exports = {
depend: ["Plugin1"],
create: Plugin1 => {},
}
Expected
Plugins should act like singletons, load once and reuse next time it's required by another plugin.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.