diff --git a/src/Fable.Compiler.Service/Fable.Compiler.Service.fsproj b/src/Fable.Compiler.Service/Fable.Compiler.Service.fsproj
index cf74752383..ae56b11389 100644
--- a/src/Fable.Compiler.Service/Fable.Compiler.Service.fsproj
+++ b/src/Fable.Compiler.Service/Fable.Compiler.Service.fsproj
@@ -22,8 +22,10 @@
-
-
+
+
+
+
diff --git a/src/Fable.Compiler.Service/Library.fs b/src/Fable.Compiler.Service/Library.fs
index 5062c3186a..9df9ea349b 100644
--- a/src/Fable.Compiler.Service/Library.fs
+++ b/src/Fable.Compiler.Service/Library.fs
@@ -30,8 +30,7 @@ type BabelWriter
let sb = StringBuilder()
// let mapGenerator = lazy (SourceMapSharp.SourceMapGenerator(?sourceRoot = cliArgs.SourceMapsRoot))
- override x.ToString() =
- sb.ToString()
+ override x.ToString() = sb.ToString()
interface Printer.Writer with
// Don't dispose the stream here because we need to access the memory stream to check if file has changed
@@ -98,18 +97,23 @@ type BabelWriter
// let sourcePath = defaultArg file sourcePath |> Path.getRelativeFileOrDirPath false targetPath false
// mapGenerator.Force().AddMapping(generated, original, source=sourcePath, ?name=displayName)
+// TODO: real bad code, refactor
+let mutable checker = Unchecked.defaultof
+
let mkCompilerForFile
(cliArgs: CliArgs)
(crackerResponse: CrackerResponse)
(currentFile: string)
: Async =
async {
- let checker = InteractiveChecker.Create(crackerResponse.ProjectOptions)
+ checker <- InteractiveChecker.Create(crackerResponse.ProjectOptions)
let! assemblies = checker.GetImportedAssemblies()
- let sourceReader _ =
+ let sourceReader fileName =
let source =
- Array.last crackerResponse.ProjectOptions.SourceFiles
+ Array.find
+ (fun sourceFile -> sourceFile = fileName)
+ crackerResponse.ProjectOptions.SourceFiles
|> System.IO.File.ReadAllText
1, lazy source
@@ -119,7 +123,7 @@ let mkCompilerForFile
cliArgs.ProjectFile,
crackerResponse.ProjectOptions.SourceFiles,
sourceReader,
- Array.last crackerResponse.ProjectOptions.SourceFiles
+ currentFile
)
ignore checkProjectResult.Diagnostics
@@ -172,5 +176,18 @@ let compileFile (com: Compiler) (pathResolver: PathResolver) (outPath: string) =
)
do! BabelPrinter.run writer babel
- return writer.ToString()
+ let output = writer.ToString()
+
+ let sourceReader fileName =
+ let source =
+ Array.find
+ (fun sourceFile -> sourceFile = fileName)
+ com.SourceFiles
+ |> System.IO.File.ReadAllText
+
+ 1, lazy source
+
+ let! dependentFiles = checker.GetDependentFiles(com.CurrentFile, com.SourceFiles, sourceReader)
+
+ return output, dependentFiles
}
diff --git a/src/Fable.Compiler.Service/Library.fsi b/src/Fable.Compiler.Service/Library.fsi
index e8374fdaf6..b14ffb154a 100644
--- a/src/Fable.Compiler.Service/Library.fsi
+++ b/src/Fable.Compiler.Service/Library.fsi
@@ -5,4 +5,4 @@ open Fable.Compiler.Service.Util
open Fable.Compiler.Service.ProjectCracker
val mkCompilerForFile: cliArgs: CliArgs -> crackerResponse: CrackerResponse -> currentFile: string -> Async
-val compileFile: com: Compiler -> pathResolver: PathResolver -> outPath: string -> Async
+val compileFile: com: Compiler -> pathResolver: PathResolver -> outPath: string -> Async
diff --git a/tests/FCSTest/FCSTest.fsproj b/tests/FCSTest/FCSTest.fsproj
index 4d3f0b2816..0b417f4d3a 100644
--- a/tests/FCSTest/FCSTest.fsproj
+++ b/tests/FCSTest/FCSTest.fsproj
@@ -14,8 +14,10 @@
-
-
+
+
+
+
diff --git a/tests/FCSTest/Program.fs b/tests/FCSTest/Program.fs
index 28a69aff1b..05576eddfe 100644
--- a/tests/FCSTest/Program.fs
+++ b/tests/FCSTest/Program.fs
@@ -26,8 +26,12 @@ module CoolCatProjectCracking =
|> Array.choose (fun (line: string) ->
let filePath = Path.Combine(projectDir, line)
- if isFSharpFile line && File.Exists filePath then
- Some filePath
+ if
+ isFSharpFile line
+ && File.Exists filePath
+ && not (filePath.Contains "obj")
+ then
+ Some (Path.normalizeFullPath filePath)
else
None
)
@@ -170,7 +174,7 @@ let compilerForFile =
mkCompilerForFile
cliArgs
crackerResponse
- @"C:\Users\nojaf\Projects\MyFableApp\App.fs"
+ (Path.normalizeFullPath @"C:\Users\nojaf\Projects\MyFableApp\Lib.fs")
|> Async.RunSynchronously
let dummyPathResolver =
@@ -179,11 +183,12 @@ let dummyPathResolver =
member _.GetOrAddDeduplicateTargetDir(_importDir, _addTargetDir) = ""
}
-let javascript =
+let javascript, dependentFiles =
compileFile
compilerForFile
dummyPathResolver
- @"C:\Users\nojaf\Projects\MyFableApp\App.js"
+ @"C:\Users\nojaf\Projects\MyFableApp\Lib.js"
|> Async.RunSynchronously
printfn "this is javascript:\n%s" javascript
+printfn "these files need to be reprocessed: %s" (String.concat "," dependentFiles)