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

Report incompatible Fable version from Feliz.CompilerPlugins #539

Open
MangelMaxime opened this issue Jan 2, 2023 · 4 comments
Open

Report incompatible Fable version from Feliz.CompilerPlugins #539

MangelMaxime opened this issue Jan 2, 2023 · 4 comments

Comments

@MangelMaxime
Copy link
Contributor

If user use Feliz.CompilerPlugins v2, with Fable 3 there is no compilation error.

Only a runtime one from React about invalid hook usage.

Is it possible detect Fable version and make the compilations fails if it is invalid?

@alfonsogarciacaro

@Zaid-Ajaj
Copy link
Owner

If user use Feliz.CompilerPlugins v2, with Fable 3 there is no compilation error.

Something like this?

#if FABLE_COMPILER_3
failwith "Detected Fable v3 compiler using Feliz v2.0.0. Please upgrade Fable to latest v4"
#endif

@MangelMaxime
Copy link
Contributor Author

I would prefer a compilation error than a runtime error but that's already a plus.

And it also assume that the user don't install Feliz.CompilerPlugins alone but always through Felizwhich should be ok to assume I think.

In the plugin, there is actually a Fable minimum version set but not sure if it does something or not:

/// <summary>Applies to custom defined React hooks to ensure the generated code starts with "use" in order for fast-refresh to pick it up</summary>
type HookAttribute() =
inherit MemberDeclarationPluginAttribute()
override _.FableMinimumVersion = "4.0"

@Zaid-Ajaj
Copy link
Owner

@MangelMaxime I think the FableMinimumVersion doesn't do much now because 4.0.0 doesn't account for theta-018 prerelease versions

@MangelMaxime
Copy link
Contributor Author

There is a check against FableMinimumVersion in Fable source code:

https://github.com/fable-compiler/Fable/blob/8c0767d4426c697e04421194ab1d265bfd8e597e/src/Fable.Transforms/Global/Compiler.fs#L163-L176

        member com.ApplyPlugin<'Plugin, 'Input when 'Plugin :> PluginAttribute>(plugins: Map<_,_>, atts: Fable.Attribute seq, input: 'Input, transform) =
            if Map.isEmpty plugins then input
            else
                // Reverse attributes so plugins closer to member/type are applied first
                (input, Seq.rev atts) ||> Seq.fold (fun input att ->
                    match Map.tryFind att.Entity plugins with
                    | None -> input
                    | Some plugin ->
                        let pluginInstance = System.Activator.CreateInstance(plugin, List.toArray att.ConstructorArgs) :?> 'Plugin
                        if not(expectedVersionMatchesActual pluginInstance.FableMinimumVersion Literals.VERSION) then
                            failwithf "Plugin %s expects v%s but currently running Fable v%s"
                                        plugin.FullName pluginInstance.FableMinimumVersion Literals.VERSION
                        let helper = com.ToPluginHelper()
                        transform pluginInstance helper input)

I will try to look if the check is actually doing something or if there is an bug in it.

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

No branches or pull requests

2 participants