Skip to content

fix: Support libraries using TargetFrameworks property #12

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 13 commits into from
Apr 14, 2025
64 changes: 49 additions & 15 deletions tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ let ``Missing FablePackageType property should report an error`` () =

[<Test>]
let ``Missing FableTarget property should report an error`` () =
expectToFailWithMessage
Workspace.fixtures.invalid.``MissingFableTarget.fsproj``
"You need to set at least one of Fable target via the PackageTags property. Possible values are: fable-dart, fable-dotnet, fable-javascript, fable-python, fable-rust, fable-all."
task {
do!
expectToFailWithMessage
Workspace.fixtures.invalid.``MissingFableTarget.fsproj``
"You need to set at least one of Fable target via the PackageTags property. Possible values are: fable-dart, fable-dotnet, fable-javascript, fable-python, fable-rust, fable-all."

do!
expectToFailWithMessage
Workspace.fixtures.invalid.``MissingFableTargetMultiTFM.fsproj``
"You need to set at least one of Fable target via the PackageTags property. Possible values are: fable-dart, fable-dotnet, fable-javascript, fable-python, fable-rust, fable-all."
}

[<Test>]
let ``You cannot set both FablePackageType and FableTarget properties`` () =
Expand Down Expand Up @@ -237,20 +245,46 @@ let ``should include the source file and the project file under 'fable' folder``
$"pack %s{Workspace.fixtures.valid.``library-with-files``.``MyLibrary.fsproj``}"
)

let archive = ZipFile.OpenRead(VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibrary.1.0.0.nupkg``)
let archive =
ZipFile.OpenRead(
VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibrary.1.0.0.nupkg``
)

let entries =
archive.Entries
|> Seq.map (fun entry -> entry.FullName)
|> Seq.toList
let entries = archive.Entries |> Seq.map (fun entry -> entry.FullName) |> Seq.toList

Assert.That(
entries,
Contains.Item("fable/Entry.fs")
)
Assert.That(entries, Contains.Item("fable/Entry.fs"))

Assert.That(
entries,
Contains.Item("fable/MyLibrary.fsproj")
Assert.That(entries, Contains.Item("fable/MyLibrary.fsproj"))
}

[<Test>]
let ``should include the source file and the project file under 'fable' folder multi tfm`` () =
task {
// Make sure we work with a fresh nupkg file
let fileInfo =
VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibraryMultiTFM.1.0.0.nupkg``
|> FileInfo

if fileInfo.Exists then
fileInfo.Delete()

Command.Run(
"dotnet",
$"pack %s{Workspace.fixtures.valid.``library-with-files``.``MyLibraryMultiTFM.fsproj``}"
)

let archive =
ZipFile.OpenRead(
VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibraryMultiTFM.1.0.0.nupkg``
)

let entries = archive.Entries |> Seq.map (fun entry -> entry.FullName) |> Seq.toList

Assert.That(entries, Contains.Item("fable/Entry.fs"))

Assert.That(entries, Contains.Item("fable/MyLibraryMultiTFM.fsproj"))

Assert.That(entries, Contains.Item("lib/netstandard2.0/MyLibraryMultiTFM.dll"))

Assert.That(entries, Contains.Item("lib/net8.0/MyLibraryMultiTFM.dll"))
}
1 change: 1 addition & 0 deletions tests/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ fixtures/
bin/
Release/
MyLibrary.1.0.0.nupkg
MyLibraryMultiTFM.1.0.0.nupkg
""">
8 changes: 8 additions & 0 deletions tests/fixtures/invalid/MissingFableTargetMultiTFM.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<FablePackageType>binding</FablePackageType>
</PropertyGroup>
<Import Project="./../Fable.Package.SDK.Imports.props" />
</Project>
12 changes: 12 additions & 0 deletions tests/fixtures/valid/library-with-files/MyLibraryMultiTFM.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<FablePackageType>library</FablePackageType>
<PackageTags>fable-javascript</PackageTags>
</PropertyGroup>
<ItemGroup>
<Compile Include="Entry.fs" />
</ItemGroup>
<Import Project="./../../Fable.Package.SDK.Imports.props" />
</Project>
8 changes: 8 additions & 0 deletions tests/fixtures/valid/library-with-files/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
}
},
"net8.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[8.0.101, )",
"resolved": "8.0.101",
"contentHash": "sOLz3O4BOxnTKfd5OChdRmDUy4Id0GfoEClRG4nzIod8LY1LJZcNyygKAV0A78XOLh8yvhA5hsDYKZXGCR9blw=="
}
}
}
}