Skip to content

Conversation

@iced-wav
Copy link
Contributor

Allows passing plugins or plugin factories directly in luaPlugins. Some unit tests are included to illustrate usage.


export interface InMemoryLuaPlugin {
plugin: Plugin | ((options: Record<string, any>) => Plugin);
[option: string]: any;
Copy link
Member

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.

Copy link
Contributor Author

@iced-wav iced-wav Jan 31, 2025

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 InMemoryLuaPlugin) entirely, without the options parameter it just needlessly adds another plugin factory type to handle. (see next post regarding lifetime management)

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!


export interface InMemoryLuaPlugin {
plugin: Plugin | ((options: Record<string, any>) => Plugin);
[option: string]: any;
Copy link
Member

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

@Perryvw Perryvw merged commit aa6593d into TypeScriptToLua:master Jan 31, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants