Skip to content

Commit e84aa4d

Browse files
Merge pull request #2103 from fable-compiler/loader-cache
Cache for JS files
2 parents 2a54391 + 564db8a commit e84aa4d

File tree

19 files changed

+667
-344
lines changed

19 files changed

+667
-344
lines changed

build.fsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ let buildTypescript projectDir =
5656
let buildFableSplitter() =
5757
buildTypescript "src/fable-splitter"
5858

59+
let buildFableLoader() =
60+
buildTypescript "src/fable-loader"
61+
5962
let buildSplitterWithArgs projectDir args =
6063
if pathExists "src/fable-splitter/dist" |> not then
6164
buildFableSplitter()
@@ -290,7 +293,7 @@ let packages =
290293
"fable-babel-plugins", doNothing
291294
"fable-compiler", buildCompiler
292295
"fable-compiler-js", buildCompilerJs
293-
"fable-loader", doNothing
296+
"fable-loader", buildFableLoader
294297
"fable-metadata", doNothing
295298
"fable-publish-utils", doNothing
296299
"fable-splitter", buildFableSplitter
@@ -323,6 +326,7 @@ match argsLower with
323326
| ("fable-compiler"|"compiler")::_ -> buildCompiler()
324327
| ("fable-compiler-js"|"compiler-js")::_ -> buildCompilerJs()
325328
| ("fable-splitter"|"splitter")::_ -> buildFableSplitter()
329+
| ("fable-loader"|"loader")::_ -> buildFableLoader()
326330
| ("fable-standalone"|"standalone")::_ -> buildStandalone()
327331
| "download-standalone"::_ -> downloadStandalone()
328332
| "publish"::restArgs -> publishPackages restArgs

src/Fable.Cli/Agent.fs

Lines changed: 198 additions & 142 deletions
Large diffs are not rendered by default.

src/Fable.Cli/Parser.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Message =
1010
rootDir: string
1111
define: string[]
1212
noReferences: bool
13+
noRestore: bool
1314
typedArrays: bool
1415
clampByteArrays: bool
1516
classTypes: bool
@@ -77,6 +78,7 @@ let parse (msg: string) =
7778
|> Array.append [|Naming.fableCompilerConstant|]
7879
|> Array.distinct
7980
noReferences = parseBoolean false "noReferences" json
81+
noRestore = parseBoolean false "noRestore" json
8082
typedArrays = parseBoolean false "typedArrays" json
8183
clampByteArrays = parseBoolean false "clampByteArrays" json
8284
classTypes = parseBoolean false "classTypes" json

src/Fable.Cli/ProjectCracker.fs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ open FSharp.Compiler.SourceCodeServices
1111
open Fable
1212
open Globbing.Operators
1313

14+
type Options = {
15+
define: string[]
16+
noReferences: bool
17+
noRestore: bool
18+
rootDir: string
19+
projFile: string
20+
}
21+
1422
let isSystemPackage (pkgName: string) =
1523
pkgName.StartsWith("System.")
1624
|| pkgName.StartsWith("Microsoft.")
@@ -234,12 +242,15 @@ let private isUsefulOption (opt : string) =
234242
/// and get F# compiler args from an .fsproj file. As we'll merge this
235243
/// later with other projects we'll only take the sources and the references,
236244
/// checking if some .dlls correspond to Fable libraries
237-
let fullCrack noReferences (projFile: string): CrackedFsproj =
245+
let fullCrack (opts: Options): CrackedFsproj =
246+
let projFile = opts.projFile
238247
// Use case insensitive keys, as package names in .paket.resolved
239248
// may have a different case, see #1227
240249
let dllRefs = Dictionary(StringComparer.OrdinalIgnoreCase)
241250
// Try restoring project
242-
if projFile.EndsWith(".fsproj") then
251+
if opts.noRestore then
252+
Log.always "Skipping restore..."
253+
else
243254
Process.runCmd Log.always
244255
(IO.Path.GetDirectoryName projFile)
245256
"dotnet" ["restore"; IO.Path.GetFileName projFile]
@@ -265,7 +276,7 @@ let fullCrack noReferences (projFile: string): CrackedFsproj =
265276
else
266277
(Path.normalizeFullPath line)::src, otherOpts)
267278
let projRefs =
268-
if noReferences then []
279+
if opts.noReferences then []
269280
else
270281
projRefs |> List.choose (fun projRef ->
271282
// Remove dllRefs corresponding to project references
@@ -307,7 +318,7 @@ let easyCrack (projFile: string): CrackedFsproj =
307318
PackageReferences = []
308319
OtherCompilerOptions = [] }
309320

310-
let getCrackedProjectsFromMainFsproj noReferences (projFile: string) =
321+
let getCrackedProjectsFromMainFsproj (opts: Options) =
311322
let rec crackProjects (acc: CrackedFsproj list) (projFile: string) =
312323
let crackedFsproj =
313324
match acc |> List.tryFind (fun x -> x.ProjectFile = projFile) with
@@ -316,29 +327,29 @@ let getCrackedProjectsFromMainFsproj noReferences (projFile: string) =
316327
// Add always a reference to the front to preserve compilation order
317328
// Duplicated items will be removed later
318329
List.fold crackProjects (crackedFsproj::acc) crackedFsproj.ProjectReferences
319-
let mainProj = fullCrack noReferences projFile
330+
let mainProj = fullCrack opts
320331
let refProjs =
321332
List.fold crackProjects [] mainProj.ProjectReferences
322333
|> List.distinctBy (fun x -> x.ProjectFile)
323334
refProjs, mainProj
324335

325-
let getCrackedProjects define noReferences (projFile: string) =
326-
match (Path.GetExtension projFile).ToLower() with
336+
let getCrackedProjects (opts: Options) =
337+
match (Path.GetExtension opts.projFile).ToLower() with
327338
| ".fsx" ->
328-
getProjectOptionsFromScript define projFile
339+
getProjectOptionsFromScript opts.define opts.projFile
329340
| ".fsproj" ->
330-
getCrackedProjectsFromMainFsproj noReferences projFile
341+
getCrackedProjectsFromMainFsproj opts
331342
| s -> failwithf "Unsupported project type: %s" s
332343

333344
// It is common for editors with rich editing or 'intellisense' to also be watching the project
334345
// file for changes. In some cases that editor will lock the file which can cause fable to
335346
// get a read error. If that happens the lock is usually brief so we can reasonably wait
336347
// for it to be released.
337-
let retryGetCrackedProjects define noReferences (projFile: string) =
348+
let retryGetCrackedProjects opts =
338349
let retryUntil = (DateTime.Now + TimeSpan.FromSeconds 2.)
339350
let rec retry () =
340351
try
341-
getCrackedProjects define noReferences projFile
352+
getCrackedProjects opts
342353
with
343354
| :? IOException as ioex ->
344355
if retryUntil > DateTime.Now then
@@ -357,7 +368,7 @@ let createFableDir rootDir =
357368
let fableDir = IO.Path.Combine(rootDir, Naming.fableHiddenDir)
358369
if isDirectoryEmpty fableDir then
359370
Directory.CreateDirectory(fableDir) |> ignore
360-
File.WriteAllText(IO.Path.Combine(fableDir, ".gitignore"), "*.*")
371+
File.WriteAllText(IO.Path.Combine(fableDir, ".gitignore"), "**/*")
361372
fableDir
362373

363374
let copyDirIfDoesNotExist (source: string) (target: string) =
@@ -398,13 +409,12 @@ let removeFilesInObjFolder sourceFiles =
398409
let reg = System.Text.RegularExpressions.Regex(@"[\\\/]obj[\\\/]")
399410
sourceFiles |> Array.filter (reg.IsMatch >> not)
400411

401-
let getFullProjectOpts (define: string[]) (noReferences: bool) (rootDir: string) (projFile: string) =
402-
let projFile = Path.GetFullPath(projFile)
403-
if not(File.Exists(projFile)) then
404-
failwith ("File does not exist: " + projFile)
405-
let projRefs, mainProj = retryGetCrackedProjects define noReferences projFile
412+
let getFullProjectOpts (opts: Options) =
413+
if not(File.Exists(opts.projFile)) then
414+
failwith ("File does not exist: " + opts.projFile)
415+
let projRefs, mainProj = retryGetCrackedProjects opts
406416
let fableLibraryPath, pkgRefs =
407-
copyFableLibraryAndPackageSources rootDir mainProj.PackageReferences
417+
copyFableLibraryAndPackageSources opts.rootDir mainProj.PackageReferences
408418
let projOpts =
409419
let sourceFiles =
410420
let pkgSources = pkgRefs |> List.collect getSourcesFromFsproj
@@ -433,9 +443,9 @@ let getFullProjectOpts (define: string[]) (noReferences: bool) (rootDir: string)
433443
mainProj.DllReferences
434444
|> List.mapToArray (fun r -> "-r:" + r)
435445
let otherOpts = mainProj.OtherCompilerOptions |> Array.ofList
436-
[ getBasicCompilerArgs define
446+
[ getBasicCompilerArgs opts.define
437447
otherOpts
438448
dllRefs ]
439449
|> Array.concat
440-
makeProjectOptions projFile sourceFiles otherOptions
450+
makeProjectOptions opts.projFile sourceFiles otherOptions
441451
projOpts, fableLibraryPath

src/Fable.Cli/Util.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ type IMessageHandler =
5555
abstract Respond: write: (TextWriter->unit) -> unit
5656

5757
type AgentMsg =
58+
| Parsed of projectFile: string
59+
* Fable.Transforms.State.Project
60+
* FSharp.Compiler.SourceCodeServices.InteractiveChecker
5861
| Received of handler: IMessageHandler
5962
| Respond of response: obj * handler: IMessageHandler
6063

@@ -125,7 +128,8 @@ module Log =
125128
let writerLock = obj()
126129

127130
let always (msg: string) =
128-
if GlobalParams.Singleton.Verbosity <> Fable.Verbosity.Silent then
131+
if GlobalParams.Singleton.Verbosity <> Fable.Verbosity.Silent
132+
&& not(String.IsNullOrEmpty(msg)) then
129133
lock writerLock (fun () ->
130134
Console.Out.WriteLine(msg)
131135
Console.Out.Flush())

src/Fable.Transforms/Replacements.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ let isCompatibleWithJsComparison = function
725725
// * `LanguagePrimitive.PhysicalHash` creates an identity hash no matter whether GetHashCode is implemented or not.
726726
let identityHash r (arg: Expr) =
727727
match arg.Type with
728-
| Boolean | Char | String | Number _ | Enum _ | Option | Tuple | List
728+
| Boolean | Char | String | Number _ | Enum _ | Option _ | Tuple _ | List _
729729
| Builtin(BclInt64 | BclUInt64 | BclDecimal | BclBigInt)
730730
| Builtin(BclGuid | BclTimeSpan | BclDateTime | BclDateTimeOffset)
731731
| Builtin(FSharpSet _ | FSharpMap _ | FSharpChoice _ | FSharpResult _) ->

src/Fable.Transforms/State.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open System.Collections.Concurrent
2424
type Project(projectOptions: FSharpProjectOptions,
2525
implFiles: IDictionary<string, FSharpImplementationFileContents>,
2626
errors: FSharpErrorInfo array) =
27-
let projectFile = Path.normalizePath projectOptions.ProjectFileName
27+
let projectFile = projectOptions.ProjectFileName
2828
let inlineExprs = ConcurrentDictionary<string, InlineExpr>()
2929
let rootModules =
3030
implFiles |> Seq.map (fun kv ->

src/fable-compiler/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function processArgs(args?: {[x: string]: any}) {
4545
delete args.path;
4646
}
4747
for (const k of Object.keys(args)) {
48-
if (args[k] !== false) {
48+
if (args[k] != null && args[k] !== false) {
4949
cliArgs.push("--" + k.replace(/[A-Z]/g, (x) => "-" + x.toLowerCase()));
5050
if (args[k] !== true) {
5151
cliArgs.push(args[k]);

src/fable-loader/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

src/fable-loader/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Override .gitignore to include the `dist` folder

0 commit comments

Comments
 (0)