From df045effa85655b88fc888931d36093b9ac1dfdc Mon Sep 17 00:00:00 2001 From: nojaf Date: Sun, 25 Feb 2024 11:27:49 +0100 Subject: [PATCH 1/5] Log dependent files of script. --- src/Fable.Compiler/Library.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Fable.Compiler/Library.fs b/src/Fable.Compiler/Library.fs index 0084b951c7..0afead37d9 100644 --- a/src/Fable.Compiler/Library.fs +++ b/src/Fable.Compiler/Library.fs @@ -263,6 +263,9 @@ module CodeServices = let! dependentFiles = checker.GetDependentFiles(currentFile, crackerResponse.ProjectOptions.SourceFiles, sourceReader) + let combinedDependentFiles = String.concat "\n" dependentFiles + Log.info $"Dependent files for %s{currentFile} are:\n%s{combinedDependentFiles}" + let lastFile = if Array.isEmpty dependentFiles then currentFile From b05ee071959ebdd40175b6efc5d2593dba575900 Mon Sep 17 00:00:00 2001 From: nojaf Date: Sun, 25 Feb 2024 12:01:03 +0100 Subject: [PATCH 2/5] Ensure a type is not exported when it is hidden by a signature file. --- src/Fable.Transforms/FSharp2Fable.Util.fs | 30 ++++++++++++++----- .../Integration/CompilationTests.fs | 4 +-- .../data/signatureHidesFunction/HideType.fs | 11 +++++++ .../data/signatureHidesFunction/HideType.fsi | 3 ++ .../HideType.js.expected | 23 ++++++++++++++ .../signatureHidesFunction.fsproj | 2 ++ 6 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 tests/Integration/Integration/data/signatureHidesFunction/HideType.fs create mode 100644 tests/Integration/Integration/data/signatureHidesFunction/HideType.fsi create mode 100644 tests/Integration/Integration/data/signatureHidesFunction/HideType.js.expected diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index 915fc05383..d30591d90c 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -466,8 +466,12 @@ type FsEnt(maybeAbbrevEnt: FSharpEntity) = member _.UnionCases = ent.UnionCases |> Seq.mapToList (fun x -> FsUnionCase(x) :> Fable.UnionCase) - member _.IsPublic = not ent.Accessibility.IsPrivate - member _.IsPrivate = ent.Accessibility.IsPrivate + member _.IsPublic = + not (ent.Accessibility.IsPrivate || Helpers.typeIsHiddenBySignatureFile ent) + + member _.IsPrivate = + ent.Accessibility.IsPrivate || Helpers.typeIsHiddenBySignatureFile ent + member _.IsInternal = ent.Accessibility.IsInternal member _.IsAbstractClass = ent.IsAbstractClass member _.IsNamespace = ent.IsNamespace @@ -822,14 +826,24 @@ module Helpers = | FSharpInlineAnnotation.AlwaysInline | FSharpInlineAnnotation.AggressiveInline -> true + let parentHasSignatureFile (declaringEntity: FSharpEntity option) = + declaringEntity + |> Option.bind (fun p -> p.SignatureLocation) + |> Option.map (fun m -> m.FileName.EndsWith(".fsi", StringComparison.Ordinal)) + |> Option.defaultValue false + let topLevelBindingHiddenBySignatureFile (v: FSharpMemberOrFunctionOrValue) = - let parentHasSignatureFile () = - v.DeclaringEntity - |> Option.bind (fun p -> p.SignatureLocation) - |> Option.map (fun m -> m.FileName.EndsWith(".fsi", StringComparison.Ordinal)) - |> Option.defaultValue false + v.IsModuleValueOrMember + && not v.HasSignatureFile + && parentHasSignatureFile v.DeclaringEntity + + let typeIsHiddenBySignatureFile (ent: FSharpEntity) : bool = + let hasOwnSignatureFile = + match ent.SignatureLocation with + | None -> false + | Some m -> m.FileName.EndsWith(".fsi", StringComparison.Ordinal) - v.IsModuleValueOrMember && not v.HasSignatureFile && parentHasSignatureFile () + not hasOwnSignatureFile && parentHasSignatureFile ent.DeclaringEntity let isNotPrivate (memb: FSharpMemberOrFunctionOrValue) = if memb.IsCompilerGenerated then diff --git a/tests/Integration/Integration/CompilationTests.fs b/tests/Integration/Integration/CompilationTests.fs index 724d852d85..9598835056 100644 --- a/tests/Integration/Integration/CompilationTests.fs +++ b/tests/Integration/Integration/CompilationTests.fs @@ -26,8 +26,8 @@ let tests = for expected in Directory.GetFileSystemEntries(testCaseDir, "*.expected") do let actual = Path.ChangeExtension(expected, ".actual") Expect.isTrue (File.Exists actual) $"No actual file was produced for {expected}" - let expectedContent = File.ReadAllText expected - let actualContent = File.ReadAllText actual + let expectedContent = File.ReadAllText expected |> _.ReplaceLineEndings() + let actualContent = File.ReadAllText actual |> _.ReplaceLineEndings() Expect.equal actualContent expectedContent "The expected content differs from the actual content" return () diff --git a/tests/Integration/Integration/data/signatureHidesFunction/HideType.fs b/tests/Integration/Integration/data/signatureHidesFunction/HideType.fs new file mode 100644 index 0000000000..b6ec34e528 --- /dev/null +++ b/tests/Integration/Integration/data/signatureHidesFunction/HideType.fs @@ -0,0 +1,11 @@ +module HideType + +open Fable.Core + +/// This type should be hidden by the signature file +type public Foobar = + | Foo of int + | Bar of string + +let someFunction () = + JS.console.log "meh" diff --git a/tests/Integration/Integration/data/signatureHidesFunction/HideType.fsi b/tests/Integration/Integration/data/signatureHidesFunction/HideType.fsi new file mode 100644 index 0000000000..b265365d4a --- /dev/null +++ b/tests/Integration/Integration/data/signatureHidesFunction/HideType.fsi @@ -0,0 +1,3 @@ +module HideType + +val someFunction: unit -> unit diff --git a/tests/Integration/Integration/data/signatureHidesFunction/HideType.js.expected b/tests/Integration/Integration/data/signatureHidesFunction/HideType.js.expected new file mode 100644 index 0000000000..c934d03b03 --- /dev/null +++ b/tests/Integration/Integration/data/signatureHidesFunction/HideType.js.expected @@ -0,0 +1,23 @@ +import { Union } from "./fable_modules/fable-library-js.4.13.0/Types.js"; +import { union_type, string_type, int32_type } from "./fable_modules/fable-library-js.4.13.0/Reflection.js"; +import { some } from "./fable_modules/fable-library-js.4.13.0/Option.js"; + +class Foobar extends Union { + constructor(tag, fields) { + super(); + this.tag = tag; + this.fields = fields; + } + cases() { + return ["Foo", "Bar"]; + } +} + +function Foobar_$reflection() { + return union_type("HideType.Foobar", [], Foobar, () => [[["Item", int32_type]], [["Item", string_type]]]); +} + +export function someFunction() { + console.log(some("meh")); +} + diff --git a/tests/Integration/Integration/data/signatureHidesFunction/signatureHidesFunction.fsproj b/tests/Integration/Integration/data/signatureHidesFunction/signatureHidesFunction.fsproj index 212747cd24..82e3792bd5 100644 --- a/tests/Integration/Integration/data/signatureHidesFunction/signatureHidesFunction.fsproj +++ b/tests/Integration/Integration/data/signatureHidesFunction/signatureHidesFunction.fsproj @@ -9,6 +9,8 @@ + + From 83f5539aeb98b8619aed5158e4fcc52f13d743ca Mon Sep 17 00:00:00 2001 From: nojaf Date: Sun, 25 Feb 2024 12:10:28 +0100 Subject: [PATCH 3/5] Use signature file to determine dependent files in compileFileToJavaScript. --- src/Fable.Compiler/Library.fs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Fable.Compiler/Library.fs b/src/Fable.Compiler/Library.fs index 0afead37d9..d8960c04cc 100644 --- a/src/Fable.Compiler/Library.fs +++ b/src/Fable.Compiler/Library.fs @@ -260,11 +260,23 @@ module CodeServices = : Async = async { - let! dependentFiles = - checker.GetDependentFiles(currentFile, crackerResponse.ProjectOptions.SourceFiles, sourceReader) + let signatureFile = + crackerResponse.ProjectOptions.SourceFiles + |> Array.tryFind (fun f -> f = String.Concat(currentFile, "i")) - let combinedDependentFiles = String.concat "\n" dependentFiles - Log.info $"Dependent files for %s{currentFile} are:\n%s{combinedDependentFiles}" + let! dependentFiles = + match signatureFile with + | None -> + checker.GetDependentFiles(currentFile, crackerResponse.ProjectOptions.SourceFiles, sourceReader) + | Some signatureFile -> + checker.GetDependentFiles(signatureFile, crackerResponse.ProjectOptions.SourceFiles, sourceReader) + + Log.info ( + sprintf + "Dependent files for %s are:\n%s" + (Option.defaultValue currentFile signatureFile) + (String.concat "\n" dependentFiles) + ) let lastFile = if Array.isEmpty dependentFiles then From 5215184bfcb4fcc3db59efc57407d4ecb1393483 Mon Sep 17 00:00:00 2001 From: nojaf Date: Sun, 25 Feb 2024 14:28:23 +0100 Subject: [PATCH 4/5] Don't wait indefinitely to build plugin. --- src/Fable.Compiler/Util.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Fable.Compiler/Util.fs b/src/Fable.Compiler/Util.fs index 113fa27f1d..3c393d6bc9 100644 --- a/src/Fable.Compiler/Util.fs +++ b/src/Fable.Compiler/Util.fs @@ -460,7 +460,9 @@ module Process = let runSyncWithOutput workingDir exePath args = let p = startProcess true [] workingDir exePath args - p.WaitForExit() + // Don't wait indefinitely to run process + // This call is used to build local plugins, if the binary is used by another process this process will never end. + p.WaitForExit 7000 |> ignore p.StandardOutput.ReadToEnd() [] From 0ddeb981058ffc4e14d29abb29408f3ac4fd2849 Mon Sep 17 00:00:00 2001 From: nojaf Date: Sun, 25 Feb 2024 15:28:14 +0100 Subject: [PATCH 5/5] Add changelog entries. --- src/Fable.Cli/CHANGELOG.md | 10 ++++++++++ src/Fable.Compiler/CHANGELOG.md | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index 643ac3bb8b..0acbf9a082 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +#### All + +* [GH-3769](https://github.com/fable-compiler/Fable/pull/3769) Local plugin build does not run indefinably. (by @nojaf) + +#### JavaScript + +* [GH-3769](https://github.com/fable-compiler/Fable/pull/3769) Types hidden by signature files should not be exported. (by @nojaf) + ## 4.13.0 - 2024-02-13 ### Added diff --git a/src/Fable.Compiler/CHANGELOG.md b/src/Fable.Compiler/CHANGELOG.md index d6e61214af..47ea531b21 100644 --- a/src/Fable.Compiler/CHANGELOG.md +++ b/src/Fable.Compiler/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +* [GH-3769](https://github.com/fable-compiler/Fable/pull/3769) The dependent files of the current file should be detected for the signature file if there is one present. (by @nojaf) +* [GH-3769](https://github.com/fable-compiler/Fable/pull/3769) Local plugin build does not run indefinably. (by @nojaf) + ## 4.0.0-alpha-007 - 2024-02-20 ### Added