Skip to content

Commit 908bc9c

Browse files
committed
fix: add sources files only when packaging the package so we don't impact IDE
1 parent 633563e commit 908bc9c

6 files changed

+55
-100
lines changed

Directory.Packages.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
</PackageVersion>
1919
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
2020
<PackageVersion Include="SimpleExec" Version="12.0.0" />
21-
<PackageVersion Include="Thoth.Json.Newtonsoft" Version="0.2.0" />
2221
</ItemGroup>
23-
</Project>
22+
</Project>

src/build/Fable.Package.SDK.targets

+23-16
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<!--
44
If FablePackageType is a library, we need to include the source files in the Nuget package.
5+
6+
We don't want generated files, so before fsharp (AssemblyAttributes) and AssemblyInfo
57
-->
6-
<ItemGroup Condition="'$(FablePackageType)' == 'library'">
7-
<!-- Include all files that are compiled with this project -->
8-
<!--
9-
Rider and VS don't like using 'Content' or 'None' node for the rule below
8+
<Target Name="CreateFablePackageFiles"
9+
BeforeTargets="FSharpSourceCodeCompileOrder;GenerateTargetFrameworkMonikerAttribute">
10+
<ItemGroup>
11+
<_PackageFiles Include="@(Compile)">
12+
<Pack>true</Pack>
13+
<PackagePath>fable/%(RecursiveDir)%(Filename)%(Extension)</PackagePath>
14+
<BuildAction>None</BuildAction>
15+
</_PackageFiles>
16+
17+
<_PackageFiles Include="$(MSBuildProjectFullPath)">
18+
<Pack>true</Pack>
19+
<PackagePath>fable/</PackagePath>
20+
<BuildAction>None</BuildAction>
21+
</_PackageFiles>
22+
</ItemGroup>
23+
</Target>
24+
25+
<!-- Add the new target to GenerateNuspecDependsOn -->
26+
<PropertyGroup>
27+
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);CreateFablePackageFiles</GenerateNuspecDependsOn>
28+
</PropertyGroup>
1029

11-
IHMO, this is a bug on their side, because in previous versions of Rider, 'Node' was working
12-
-->
13-
<!-- <None Include="@(Compile)" Pack="true"
14-
PackagePath="fable/%(RelativeDir)%(Filename)%(Extension)" /> -->
15-
<Compile Update="@(Compile)" Pack="true"
16-
PackagePath="fable/%(RelativeDir)%(Filename)%(Extension)" />
17-
<!-- Include the project file itself as well -->
18-
<None Include="$(MSBuildProjectFullPath)" Pack="true" PackagePath="fable/" Visible="false"/>
19-
</ItemGroup>
2030
<!--
2131
Automatically add Fable tags
2232
-->
@@ -64,7 +74,4 @@
6474
Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(PackageTags), '(^|;)(fable-library)($|;)'))
6575
And $([System.Text.RegularExpressions.Regex]::IsMatch($(PackageTags), '(^|;)(fable-binding)($|;)'))" />
6676
</Target>
67-
<Target Name="GetOutputValue">
68-
<Message Importance="high" Text="$(PackageTags)"></Message>
69-
</Target>
7077
</Project>

tests/Fable.Package.SDK.Tests.fsproj

-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
</PackageReference>
1919
<PackageReference Include="NUnit3TestAdapter" />
2020
<PackageReference Include="SimpleExec" />
21-
<PackageReference Include="Thoth.Json.Newtonsoft" />
2221
</ItemGroup>
2322
</Project>

tests/Main.fs

+21-48
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module Fable.Package.SDK.Tests
33
// open Microsoft.VisualStudio.TestTools.UnitTesting
44
open SimpleExec
55
open NUnit.Framework
6-
open Thoth.Json.Core
7-
open Thoth.Json.Newtonsoft
6+
open System.IO
7+
open System.IO.Compression
88

99
let private expectToFailWithMessage projectName (message: string) =
1010
task {
@@ -221,62 +221,35 @@ let ``should support multiple fable targets`` () =
221221
)
222222
}
223223

224-
type MSBuildItem =
225-
{
226-
FullPath: string
227-
Pack: bool
228-
}
229-
230-
static member Decoder =
231-
Decode.object (fun get ->
232-
{
233-
FullPath = get.Required.Field "FullPath" Decode.string
234-
Pack =
235-
get.Required.Field
236-
"Pack"
237-
(Decode.string
238-
|> Decode.andThen (
239-
function
240-
| "true" -> Decode.succeed true
241-
| "false" -> Decode.succeed false
242-
| _ -> Decode.fail "Invalid boolean value"
243-
))
244-
}
245-
)
246-
247224
[<Test>]
248225
let ``should include the source file and the project file under 'fable' folder`` () =
249226
task {
250-
let! stdout, _ =
251-
Command.ReadAsync(
252-
"dotnet",
253-
$"msbuild %s{Workspace.fixtures.valid.``library-with-files``.``MyLibrary.fsproj``} --getItem:None --getItem:Compile"
254-
)
227+
// Make sure we work with a fresh nupkg file
228+
let fileInfo =
229+
VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibrary.1.0.0.nupkg``
230+
|> FileInfo
255231

256-
let projectFile =
257-
Decode.unsafeFromString
258-
(Decode.at [ "Items"; "None" ] (Decode.list MSBuildItem.Decoder))
259-
stdout
260-
// We are only interested in the project file
261-
|> List.filter (fun item -> item.FullPath.Contains("MyLibrary.fsproj"))
262-
|> List.head
232+
fileInfo.Delete()
263233

264-
let compileItem =
265-
Decode.unsafeFromString
266-
(Decode.at [ "Items"; "Compile" ] (Decode.index 0 MSBuildItem.Decoder))
267-
stdout
234+
Command.Run(
235+
"dotnet",
236+
$"pack %s{Workspace.fixtures.valid.``library-with-files``.``MyLibrary.fsproj``}"
237+
)
268238

269-
Assert.That(compileItem.Pack, Is.True)
239+
let archive = ZipFile.OpenRead(VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibrary.1.0.0.nupkg``)
240+
241+
let entries =
242+
archive.Entries
243+
|> Seq.map (fun entry -> entry.FullName)
244+
|> Seq.toList
270245

271246
Assert.That(
272-
compileItem.FullPath,
273-
Contains.Substring("tests/fixtures/valid/library-with-files/Entry.fs")
247+
entries,
248+
Contains.Item("fable/Entry.fs")
274249
)
275250

276-
Assert.That(projectFile.Pack, Is.True)
277-
278251
Assert.That(
279-
projectFile.FullPath,
280-
Contains.Substring("tests/fixtures/valid/library-with-files/MyLibrary.fsproj")
252+
entries,
253+
Contains.Item("fable/MyLibrary.fsproj")
281254
)
282255
}

tests/Workspace.fs

+10
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ module Workspace
44
open EasyBuild.FileSystemProvider
55

66
type Workspace = RelativeFileSystem<".">
7+
8+
type VirtualWorkspace = VirtualFileSystem<".",
9+
"""
10+
fixtures/
11+
valid/
12+
library-with-files/
13+
bin/
14+
Release/
15+
MyLibrary.1.0.0.nupkg
16+
""">

tests/packages.lock.json

-33
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,6 @@
4848
"resolved": "12.0.0",
4949
"contentHash": "ptxlWtxC8vM6Y6e3h9ZTxBBkOWnWrm/Sa1HT+2i1xcXY3Hx2hmKDZP5RShPf8Xr9D+ivlrXNy57ktzyH8kyt+Q=="
5050
},
51-
"Thoth.Json.Newtonsoft": {
52-
"type": "Direct",
53-
"requested": "[0.2.0, )",
54-
"resolved": "0.2.0",
55-
"contentHash": "dMQOT6TJftO97c8gHWFegfSw/0/E+VdhGaSkf3e1Ba+DjrAESLA9HMlYyE30x7nhn7w5SfH1WO9YyzSRTV4Ysg==",
56-
"dependencies": {
57-
"FSharp.Core": "5.0.0",
58-
"Fable.Core": "4.1.0",
59-
"Fable.Package.SDK": "0.1.0",
60-
"Newtonsoft.Json": "13.0.1",
61-
"Thoth.Json.Core": "0.3.0"
62-
}
63-
},
64-
"Fable.Core": {
65-
"type": "Transitive",
66-
"resolved": "4.1.0",
67-
"contentHash": "NISAbAVGEcvH2s+vHLSOCzh98xMYx4aIadWacQdWPcQLploxpSQXLEe9SeszUBhbHa73KMiKREsH4/W3q4A4iA=="
68-
},
69-
"Fable.Package.SDK": {
70-
"type": "Transitive",
71-
"resolved": "0.1.0",
72-
"contentHash": "wrEcGovUimN0PRGgVHlX/gsqCm5d/p9eOG74iaHoteX2dsFZQ9P7d066LRAl5Gj7GUHy7azLyDE41KFvZx1v9A=="
73-
},
7451
"Microsoft.CodeCoverage": {
7552
"type": "Transitive",
7653
"resolved": "17.10.0",
@@ -102,16 +79,6 @@
10279
"type": "Transitive",
10380
"resolved": "1.6.0",
10481
"contentHash": "COC1aiAJjCoA5GBF+QKL2uLqEBew4JsCkQmoHKbN3TlOZKa2fKLz5CpiRQKDz0RsAOEGsVKqOD5bomsXq/4STQ=="
105-
},
106-
"Thoth.Json.Core": {
107-
"type": "Transitive",
108-
"resolved": "0.3.0",
109-
"contentHash": "6JNLVfP7ne16TvgKXpmhQru1VwXs5QGdQ6YZNdAL84e11MvxJFXKlcbNSNRw3dOI3yruYz0OKvpCRaHpV6JGcA==",
110-
"dependencies": {
111-
"FSharp.Core": "5.0.0",
112-
"Fable.Core": "4.1.0",
113-
"Fable.Package.SDK": "0.1.0"
114-
}
11582
}
11683
}
11784
}

0 commit comments

Comments
 (0)