From 3bf2a488c2e41ffa86a1fa259b3b741c4bea91ed Mon Sep 17 00:00:00 2001 From: Alfonso Garcia-Caro Date: Fri, 1 Oct 2021 00:44:21 +0900 Subject: [PATCH] Replace .fsproj in fable_modules --- src/Fable.Cli/ProjectCracker.fs | 22 ++++++++++++++++------ src/Fable.Transforms/Global/Prelude.fs | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Fable.Cli/ProjectCracker.fs b/src/Fable.Cli/ProjectCracker.fs index 82c4105342..a588013118 100644 --- a/src/Fable.Cli/ProjectCracker.fs +++ b/src/Fable.Cli/ProjectCracker.fs @@ -463,7 +463,14 @@ let createFableDir (opts: CrackerOptions) = fableDir -let copyDirIfDoesNotExist (source: string) (target: string) = +// Replace the .fsproj extension with .fableproj for files in fable_modules +// We do this to avoid conflicts with other F# tooling that scan for .fsproj files +let changeFsprojToFableproj (path: string) = + if path.EndsWith(".fsproj") then + IO.Path.ChangeExtension(path, Naming.fableProjExt) + else path + +let copyDirIfDoesNotExist replaceFsprojExt (source: string) (target: string) = if isDirectoryEmpty target then IO.Directory.CreateDirectory(target) |> ignore if IO.Directory.Exists source |> not then @@ -472,8 +479,10 @@ let copyDirIfDoesNotExist (source: string) (target: string) = let target = target.TrimEnd('/', '\\') for dirPath in IO.Directory.GetDirectories(source, "*", IO.SearchOption.AllDirectories) do IO.Directory.CreateDirectory(dirPath.Replace(source, target)) |> ignore - for newPath in IO.Directory.GetFiles(source, "*.*", IO.SearchOption.AllDirectories) do - IO.File.Copy(newPath, newPath.Replace(source, target), true) + for fromPath in IO.Directory.GetFiles(source, "*.*", IO.SearchOption.AllDirectories) do + let toPath = fromPath.Replace(source, target) + let toPath = if replaceFsprojExt then changeFsprojToFableproj toPath else toPath + IO.File.Copy(fromPath, toPath, true) let copyFableLibraryAndPackageSources (opts: CrackerOptions) (pkgs: FablePackage list) = let fableLibDir = createFableDir opts @@ -501,15 +510,16 @@ let copyFableLibraryAndPackageSources (opts: CrackerOptions) (pkgs: FablePackage Log.verbose(lazy ("fable-library: " + fableLibrarySource)) let fableLibraryTarget = IO.Path.Combine(fableLibDir, "fable-library" + "." + Literals.VERSION) - copyDirIfDoesNotExist fableLibrarySource fableLibraryTarget + copyDirIfDoesNotExist false fableLibrarySource fableLibraryTarget fableLibraryTarget let pkgRefs = pkgs |> List.map (fun pkg -> let sourceDir = IO.Path.GetDirectoryName(pkg.FsprojPath) let targetDir = IO.Path.Combine(fableLibDir, pkg.Id + "." + pkg.Version) - copyDirIfDoesNotExist sourceDir targetDir - { pkg with FsprojPath = IO.Path.Combine(targetDir, IO.Path.GetFileName(pkg.FsprojPath)) }) + copyDirIfDoesNotExist true sourceDir targetDir + let fsprojFile = IO.Path.GetFileName(pkg.FsprojPath) |> changeFsprojToFableproj + { pkg with FsprojPath = IO.Path.Combine(targetDir, fsprojFile) }) fableLibraryPath, pkgRefs diff --git a/src/Fable.Transforms/Global/Prelude.fs b/src/Fable.Transforms/Global/Prelude.fs index 86bb64a81e..e58de9fb84 100644 --- a/src/Fable.Transforms/Global/Prelude.fs +++ b/src/Fable.Transforms/Global/Prelude.fs @@ -129,6 +129,7 @@ module Naming = let [] placeholder = "__PLACE-HOLDER__" let [] dummyFile = "__DUMMY-FILE__.txt" let [] fableHiddenDir = "fable_modules" + let [] fableProjExt = ".fableproj" let [] unknown = "UNKNOWN" let isInFableHiddenDir (file: string) =