Skip to content

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

Merged
merged 1 commit into from
Jan 31, 2025
Merged

Conversation

iced-wav
Copy link
Contributor

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

@@ -23,14 +24,19 @@ export interface LuaPluginImport {
[option: string]: any;
}

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!

@@ -23,14 +24,19 @@ export interface LuaPluginImport {
[option: string]: any;
}

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy