From a97e712272a1fb6d1076d32cf7e158cc4c4b86a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0=20=D0=A3=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D1=97=D0=BD=D1=96!=20=D0=93=D0=B5=D1=80=D0=BE=D1=8F=D0=BC=20?= =?UTF-8?q?=D1=81=D0=BB=D0=B0=D0=B2=D0=B0!?= <777696+ncave@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:58:10 +0000 Subject: [PATCH] Allow Fable 5 to be used with Fable 4 plugins Co-authored-by: Maxime Mangel --- src/Fable.Transforms/Global/Compiler.fs | 10 ++++---- .../Compiler/CompilerHelpersTests.fs | 24 +++++++++++++++++++ .../Compiler/Fable.Tests.Compiler.fsproj | 3 ++- tests/Integration/Compiler/Main.fs | 1 + .../Integration/CompilationTests.fs | 2 +- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 tests/Integration/Compiler/CompilerHelpersTests.fs diff --git a/src/Fable.Transforms/Global/Compiler.fs b/src/Fable.Transforms/Global/Compiler.fs index 14acff1a3a..0a9fe91190 100644 --- a/src/Fable.Transforms/Global/Compiler.fs +++ b/src/Fable.Transforms/Global/Compiler.fs @@ -99,7 +99,7 @@ type InlineExprLazy(f: Compiler -> InlineExpr) = [] 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+))?") @@ -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 diff --git a/tests/Integration/Compiler/CompilerHelpersTests.fs b/tests/Integration/Compiler/CompilerHelpersTests.fs new file mode 100644 index 0000000000..5b4bd5dfa7 --- /dev/null +++ b/tests/Integration/Compiler/CompilerHelpersTests.fs @@ -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 + ] diff --git a/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj b/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj index 096a4285c5..573d040109 100644 --- a/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj +++ b/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj @@ -22,6 +22,7 @@ + - \ No newline at end of file + diff --git a/tests/Integration/Compiler/Main.fs b/tests/Integration/Compiler/Main.fs index 4011447b32..fbed235b93 100644 --- a/tests/Integration/Compiler/Main.fs +++ b/tests/Integration/Compiler/Main.fs @@ -7,6 +7,7 @@ let allTests = [ CompilerMessages.tests AnonRecordInInterface.tests + CompilerHelpers.tests ] diff --git a/tests/Integration/Integration/CompilationTests.fs b/tests/Integration/Integration/CompilationTests.fs index 7591eb56de..4e967edfc9 100644 --- a/tests/Integration/Integration/CompilationTests.fs +++ b/tests/Integration/Integration/CompilationTests.fs @@ -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()