Skip to content

Commit

Permalink
Allow Fable 5 to be used with Fable 4 plugins
Browse files Browse the repository at this point in the history
Co-authored-by: Maxime Mangel <[email protected]>
  • Loading branch information
ncave and MangelMaxime authored Nov 26, 2024
1 parent 04f23a0 commit a97e712
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Fable.Transforms/Global/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type InlineExprLazy(f: Compiler -> InlineExpr) =

[<AutoOpen>]
module CompilerExt =
let private expectedVersionMatchesActual (expected: string) (actual: string) =
let expectedVersionMatchesActual (expected: string) (actual: string) =
try
let r = System.Text.RegularExpressions.Regex(@"^(\d+)\.(\d+)(?:\.(\d+))?")

Expand All @@ -116,10 +116,10 @@ module CompilerExt =
let actualMajor, actualMinor, actualPatch = parse actual
let expectedMajor, expectedMinor, expectedPatch = parse expected

// Fail also if actual major is bigger than expected major version
actualMajor = expectedMajor
&& (actualMinor > expectedMinor
|| (actualMinor = expectedMinor && actualPatch >= expectedPatch))
actualMajor > expectedMajor
|| (actualMajor = expectedMajor
&& (actualMinor > expectedMinor
|| (actualMinor = expectedMinor && actualPatch >= expectedPatch)))
with _ ->
false

Expand Down
24 changes: 24 additions & 0 deletions tests/Integration/Compiler/CompilerHelpersTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Fable.Tests.Compiler.CompilerHelpers

open Fable.Core
open Util.Testing
open Fable.Tests.Compiler.Util
open Fable.Tests.Compiler.Util.Compiler

let tests =
testList "Compiler Helpers" [
testCase "expectedVersionMatchesActual works for same major version" <| fun _ ->
Fable.CompilerExt.expectedVersionMatchesActual "5.0.0" "5.0.0" |> equal true
Fable.CompilerExt.expectedVersionMatchesActual "5.0.0" "5.0.1" |> equal true
Fable.CompilerExt.expectedVersionMatchesActual "5.1.0" "5.1.0" |> equal true

testCase "expectedVersionMatchesActual works if actual version is higher than expected version" <| fun _ ->
Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.0.0" |> equal true
Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.0.1" |> equal true
Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.1.0" |> equal true

testCase "expectedVersionMatchesActual reject if actual version is lower than expected version" <| fun _ ->
Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "3.0.0" |> equal false
Fable.CompilerExt.expectedVersionMatchesActual "4.0.1" "3.0.0" |> equal false
Fable.CompilerExt.expectedVersionMatchesActual "4.1.0" "3.0.0" |> equal false
]
3 changes: 2 additions & 1 deletion tests/Integration/Compiler/Fable.Tests.Compiler.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="Util/Compiler.fs" />
<Compile Include="CompilerMessagesTests.fs" />
<Compile Include="AnonRecordInInterfaceTests.fs" />
<Compile Include="CompilerHelpersTests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions tests/Integration/Compiler/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let allTests =
[
CompilerMessages.tests
AnonRecordInInterface.tests
CompilerHelpers.tests
]


Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Integration/CompilationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let tests =
Expect.equal exitCode 0 "Expected exit code to be 0"

let normalize content =
Regex.Replace(content, @"(/fable-library-js)[.0-9]+", "$1")
Regex.Replace(content, @"(/fable-library-js)[^/]+", "$1")
|> _.ReplaceLineEndings()
|> _.Trim()

Expand Down

0 comments on commit a97e712

Please sign in to comment.