Skip to content
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

Internalize GetFableModulesFromDir & GetFableModulesFromProject #3724

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 38 additions & 35 deletions src/Fable.Compiler/ProjectCracker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,47 @@ type CacheInfo =
| None -> true
| Some other -> this.GetTimestamp() > other.GetTimestamp()

/// Combine the `baseDir` with `fable_modules`
let getFableModulesFromDir (baseDir: string) : string =
IO.Path.Combine(baseDir, Naming.fableModules) |> Path.normalizePath

let getFableModulesFromProject
MangelMaxime marked this conversation as resolved.
Show resolved Hide resolved
(
projDir: string,
outDir: string option,
noCache: bool,
evaluateOnly: bool
)
: string
=
let fableModulesDir =
outDir
|> Option.defaultWith (fun () -> projDir)
|> getFableModulesFromDir

// If we are only evaluating the project, we don't want to delete the fable_modules folder
// in theory we should not have to create it either, but it seems harmless
// to let the check for empty folder
if not evaluateOnly then
if noCache then
if IO.Directory.Exists(fableModulesDir) then
IO.Directory.Delete(fableModulesDir, recursive = true)

if File.isDirectoryEmpty fableModulesDir then
IO.Directory.CreateDirectory(fableModulesDir) |> ignore

IO.File.WriteAllText(
IO.Path.Combine(fableModulesDir, ".gitignore"),
"**/*"
)

fableModulesDir

type CrackerOptions(cliArgs: CliArgs, evaluateOnly: bool) =
let projDir = IO.Path.GetDirectoryName cliArgs.ProjectFile

let fableModulesDir =
CrackerOptions.GetFableModulesFromProject(
getFableModulesFromProject (
projDir,
cliArgs.OutDir,
cliArgs.NoCache,
Expand Down Expand Up @@ -147,38 +183,6 @@ type CrackerOptions(cliArgs: CliArgs, evaluateOnly: bool) =
static member GetFableModulesFromDir(baseDir: string) : string =
IO.Path.Combine(baseDir, Naming.fableModules) |> Path.normalizePath
MangelMaxime marked this conversation as resolved.
Show resolved Hide resolved

static member GetFableModulesFromProject
(
projDir: string,
outDir: string option,
noCache: bool,
evaluateOnly: bool
)
: string
=
let fableModulesDir =
outDir
|> Option.defaultWith (fun () -> projDir)
|> CrackerOptions.GetFableModulesFromDir

// If we are only evaluating the project, we don't want to delete the fable_modules folder
// in theory we should not have to create it either, but it seems harmless
// to let the check for empty folder
if not evaluateOnly then
if noCache then
if IO.Directory.Exists(fableModulesDir) then
IO.Directory.Delete(fableModulesDir, recursive = true)

if File.isDirectoryEmpty fableModulesDir then
IO.Directory.CreateDirectory(fableModulesDir) |> ignore

IO.File.WriteAllText(
IO.Path.Combine(fableModulesDir, ".gitignore"),
"**/*"
)

fableModulesDir

member _.ResetFableModulesDir() =
if IO.Directory.Exists(fableModulesDir) then
IO.Directory.Delete(fableModulesDir, recursive = true)
Expand Down Expand Up @@ -911,8 +915,7 @@ let loadPrecompiledInfo (opts: CrackerOptions) otherOptions sourceFiles =
| Some precompiledLib ->
// Load PrecompiledInfo
let info =
CrackerOptions.GetFableModulesFromDir(precompiledLib)
|> PrecompiledInfoImpl.Load
getFableModulesFromDir precompiledLib |> PrecompiledInfoImpl.Load

// Check if precompiled compiler version and options match
if info.CompilerVersion <> Literals.VERSION then
Expand Down
8 changes: 0 additions & 8 deletions src/Fable.Compiler/ProjectCracker.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ type CrackerOptions =
member SourceMapsRoot: string option
member EvaluateOnly: bool
member BuildDll: normalizedDllPath: string -> unit
static member GetFableModulesFromDir: baseDir: string -> string

static member GetFableModulesFromProject:
projDir: string *
outDir: string option *
noCache: bool *
evaluateOnly: bool ->
string

type CrackerResponse =
{
Expand Down
Loading