Skip to content

Commit

Permalink
fix: workaround limitations in VS and Rider
Browse files Browse the repository at this point in the history
Fix #9
  • Loading branch information
MangelMaxime committed Oct 20, 2024
1 parent 8b9dd27 commit 3dfe5f1
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="EasyBuild.FileSystemProvider" Version="0.3.0" />
<PackageVersion Include="EasyBuild.PackageReleaseNotes.Tasks" Version="1.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="FSharp.Core" Version="8.0.101" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.11.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0">
Expand All @@ -13,5 +18,6 @@
</PackageVersion>
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="SimpleExec" Version="12.0.0" />
<PackageVersion Include="Thoth.Json.Newtonsoft" Version="0.2.0" />
</ItemGroup>
</Project>
</Project>
11 changes: 9 additions & 2 deletions src/build/Fable.Package.SDK.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
-->
<ItemGroup Condition="'$(FablePackageType)' == 'library'">
<!-- Include all files that are compiled with this project -->
<Content Include="@(Compile)" Pack="true"
<!--
Rider and VS don't like using 'Content' or 'None' node for the rule below
IHMO, this is a bug on their side, because in previous versions of Rider, 'Node' was working
-->
<!-- <None Include="@(Compile)" Pack="true"
PackagePath="fable/%(RelativeDir)%(Filename)%(Extension)" /> -->
<Compile Update="@(Compile)" Pack="true"
PackagePath="fable/%(RelativeDir)%(Filename)%(Extension)" />
<!-- Include the project file itself as well -->
<Content Include="$(MSBuildProjectFullPath)" Pack="true" PackagePath="fable/" />
<None Include="$(MSBuildProjectFullPath)" Pack="true" PackagePath="fable/" Visible="false"/>
</ItemGroup>
<!--
Automatically add Fable tags
Expand Down
1 change: 1 addition & 0 deletions tests/Fable.Package.SDK.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="SimpleExec" />
<PackageReference Include="Thoth.Json.Newtonsoft" />
</ItemGroup>
</Project>
52 changes: 46 additions & 6 deletions tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module Fable.Package.SDK.Tests

// open Microsoft.VisualStudio.TestTools.UnitTesting
open SimpleExec
open System.IO
open System.Threading.Tasks
open NUnit
open NUnit.Framework
open Thoth.Json.Core
open Thoth.Json.Newtonsoft

let private expectToFailWithMessage projectName (message: string) =
task {
Expand Down Expand Up @@ -222,21 +221,62 @@ let ``should support multiple fable targets`` () =
)
}

type MSBuildItem =
{
FullPath: string
Pack: bool
}

static member Decoder =
Decode.object (fun get ->
{
FullPath = get.Required.Field "FullPath" Decode.string
Pack =
get.Required.Field
"Pack"
(Decode.string
|> Decode.andThen (
function
| "true" -> Decode.succeed true
| "false" -> Decode.succeed false
| _ -> Decode.fail "Invalid boolean value"
))
}
)

[<Test>]
let ``should include the source file and the project file under 'fable' folder`` () =
task {
let! stdout, _ =
Command.ReadAsync(
"dotnet",
$"msbuild %s{Workspace.fixtures.valid.``library-with-files``.``MyLibrary.fsproj``} --getItem:Content"
$"msbuild %s{Workspace.fixtures.valid.``library-with-files``.``MyLibrary.fsproj``} --getItem:None --getItem:Compile"
)

let projectFile =
Decode.unsafeFromString
(Decode.at [ "Items"; "None" ] (Decode.list MSBuildItem.Decoder))
stdout
// We are only interested in the project file
|> List.filter (fun item -> item.FullPath.Contains("MyLibrary.fsproj"))
|> List.head

let compileItem =
Decode.unsafeFromString
(Decode.at [ "Items"; "Compile" ] (Decode.index 0 MSBuildItem.Decoder))
stdout

Assert.That(compileItem.Pack, Is.True)

Assert.That(
stdout.Trim(),
compileItem.FullPath,
Contains.Substring("tests/fixtures/valid/library-with-files/Entry.fs")
)

Assert.That(projectFile.Pack, Is.True)

Assert.That(
stdout.Trim(),
projectFile.FullPath,
Contains.Substring("tests/fixtures/valid/library-with-files/MyLibrary.fsproj")
)
}
1 change: 1 addition & 0 deletions tests/fixtures/valid/library-with-files/MyLibrary.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<FablePackageType>library</FablePackageType>
<PackageTags>fable-javascript</PackageTags>
</PropertyGroup>
<ItemGroup>
<Compile Include="Entry.fs" />
Expand Down
27 changes: 27 additions & 0 deletions tests/fixtures/valid/library-with-files/packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": 2,
"dependencies": {
".NETStandard,Version=v2.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[8.0.101, )",
"resolved": "8.0.101",
"contentHash": "sOLz3O4BOxnTKfd5OChdRmDUy4Id0GfoEClRG4nzIod8LY1LJZcNyygKAV0A78XOLh8yvhA5hsDYKZXGCR9blw=="
},
"NETStandard.Library": {
"type": "Direct",
"requested": "[2.0.3, )",
"resolved": "2.0.3",
"contentHash": "st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
}
}
}
}
33 changes: 33 additions & 0 deletions tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@
"resolved": "12.0.0",
"contentHash": "ptxlWtxC8vM6Y6e3h9ZTxBBkOWnWrm/Sa1HT+2i1xcXY3Hx2hmKDZP5RShPf8Xr9D+ivlrXNy57ktzyH8kyt+Q=="
},
"Thoth.Json.Newtonsoft": {
"type": "Direct",
"requested": "[0.2.0, )",
"resolved": "0.2.0",
"contentHash": "dMQOT6TJftO97c8gHWFegfSw/0/E+VdhGaSkf3e1Ba+DjrAESLA9HMlYyE30x7nhn7w5SfH1WO9YyzSRTV4Ysg==",
"dependencies": {
"FSharp.Core": "5.0.0",
"Fable.Core": "4.1.0",
"Fable.Package.SDK": "0.1.0",
"Newtonsoft.Json": "13.0.1",
"Thoth.Json.Core": "0.3.0"
}
},
"Fable.Core": {
"type": "Transitive",
"resolved": "4.1.0",
"contentHash": "NISAbAVGEcvH2s+vHLSOCzh98xMYx4aIadWacQdWPcQLploxpSQXLEe9SeszUBhbHa73KMiKREsH4/W3q4A4iA=="
},
"Fable.Package.SDK": {
"type": "Transitive",
"resolved": "0.1.0",
"contentHash": "wrEcGovUimN0PRGgVHlX/gsqCm5d/p9eOG74iaHoteX2dsFZQ9P7d066LRAl5Gj7GUHy7azLyDE41KFvZx1v9A=="
},
"Microsoft.CodeCoverage": {
"type": "Transitive",
"resolved": "17.10.0",
Expand Down Expand Up @@ -79,6 +102,16 @@
"type": "Transitive",
"resolved": "1.6.0",
"contentHash": "COC1aiAJjCoA5GBF+QKL2uLqEBew4JsCkQmoHKbN3TlOZKa2fKLz5CpiRQKDz0RsAOEGsVKqOD5bomsXq/4STQ=="
},
"Thoth.Json.Core": {
"type": "Transitive",
"resolved": "0.3.0",
"contentHash": "6JNLVfP7ne16TvgKXpmhQru1VwXs5QGdQ6YZNdAL84e11MvxJFXKlcbNSNRw3dOI3yruYz0OKvpCRaHpV6JGcA==",
"dependencies": {
"FSharp.Core": "5.0.0",
"Fable.Core": "4.1.0",
"Fable.Package.SDK": "0.1.0"
}
}
}
}
Expand Down

0 comments on commit 3dfe5f1

Please sign in to comment.