-
-
Notifications
You must be signed in to change notification settings - Fork 180
Add in-memory plugins #1614
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
Add in-memory plugins #1614
Conversation
@@ -23,14 +24,19 @@ export interface LuaPluginImport { | |||
[option: string]: any; | |||
} | |||
|
|||
export interface InMemoryLuaPlugin { | |||
plugin: Plugin | ((options: Record<string, any>) => Plugin); | |||
[option: string]: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these options and the ((options: Record<string, any>) => Plugin)
really add anything? Since the plugin is in-memory, it can just capture options from its scope, I don't see what first passing the options into tstl and then back via a factory function actually adds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's mostly useful for plugin compatibility, this way you can load third-party plugins directly in memory even if they were written for tsconfig
the same way and without manually loading it separately first.
It also makes internal representation slightly simpler by separating the responsibility of loading a plugin from importing it, and don't end up with two different kinds of plugin factories.
If removing it, I think the best approach is to remove the callback version (from (see next post regarding lifetime management)InMemoryLuaPlugin
) entirely, without the options parameter it just needlessly adds another plugin factory type to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess a big plus for the first point is also that it would simplify re-using the same config object between runs (such as in unit tests) and having tstl itself manage its lifetime the same way it would with a tsconfig
plugin.
If tstl only accepts a plugin object directly, you'd need to rebuild the config object with a fresh Plugin
object each time you use it in case the factory function keeps internal state intended for compiling a single project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, that makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
@@ -23,14 +24,19 @@ export interface LuaPluginImport { | |||
[option: string]: any; | |||
} | |||
|
|||
export interface InMemoryLuaPlugin { | |||
plugin: Plugin | ((options: Record<string, any>) => Plugin); | |||
[option: string]: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, that makes sense
Allows passing plugins or plugin factories directly in
luaPlugins
. Some unit tests are included to illustrate usage.