diff --git a/src/Fable.Cli/Util.fs b/src/Fable.Cli/Util.fs index 9ddb562ea1..117e9d4d55 100644 --- a/src/Fable.Cli/Util.fs +++ b/src/Fable.Cli/Util.fs @@ -230,7 +230,7 @@ module Imports = let importPath = if importPath.StartsWith("${outDir}") // NOTE: Path.Combine in Fable Prelude trims / at the start - // of the 2nd argument, unline .NET IO.Path.Combine + // of the 2nd argument, unlike .NET IO.Path.Combine then Path.Combine(outDir, importPath.Replace("${outDir}", "")) else importPath let sourceDir = Path.GetDirectoryName(sourcePath) diff --git a/src/fable-compiler-js/src/Platform.fs b/src/fable-compiler-js/src/Platform.fs index d4af341d31..a3b0190f41 100644 --- a/src/fable-compiler-js/src/Platform.fs +++ b/src/fable-compiler-js/src/Platform.fs @@ -4,7 +4,7 @@ open Fable.Core.JsInterop type CmdLineOptions = { outDir: string option - // fableDir: string option + libDir: string option benchmark: bool optimize: bool // sourceMaps: bool diff --git a/src/fable-compiler-js/src/app.fs b/src/fable-compiler-js/src/app.fs index 278da224cb..d64145c396 100644 --- a/src/fable-compiler-js/src/app.fs +++ b/src/fable-compiler-js/src/app.fs @@ -59,8 +59,8 @@ module Imports = let importPath = if importPath.StartsWith("${outDir}") // NOTE: Path.Combine in Fable Prelude trims / at the start - // of the 2nd argument, unline .NET IO.Path.Combine - then Path.Combine(outDir, importPath.Replace("${outDir}", "")) + // of the 2nd argument, unlike .NET IO.Path.Combine + then Path.Combine(outDir, importPath.Replace("${outDir}", "")) |> normalizeFullPath else importPath let sourceDir = Path.GetDirectoryName(sourcePath) let targetDir = Path.GetDirectoryName(targetPath) @@ -151,7 +151,7 @@ let parseFiles projectFileName options = // Fable (F# to JS) let projDir = projectFileName |> normalizeFullPath |> Path.GetDirectoryName - let libDir = getFableLibDir() |> normalizeFullPath + let libDir = options.libDir |> Option.defaultValue (getFableLibDir()) |> normalizeFullPath let parseFable (res, fileName) = fable.CompileToBabelAst(libDir, res, fileName, typedArrays = options.typedArrays, @@ -201,15 +201,15 @@ let parseFiles projectFileName options = writeAllText outPath writer.Result } |> runAsync -let argValue key (args: string[]) = +let argValue keys (args: string[]) = args |> Array.pairwise |> Array.tryPick (fun (k, v) -> - if k = key && not (v.StartsWith("-")) + if (List.contains k keys) && not (v.StartsWith("-")) then Some v else None) let tryFlag flag (args: string[]) = - match argValue flag args with + match argValue [flag] args with | Some flag -> match System.Boolean.TryParse(flag) with | true, flag -> Some flag @@ -231,8 +231,8 @@ let run opts projectFileName outDir = let runArgs = opts.[i+1..] |> String.concat " " sprintf "node %s %s" scriptFile runArgs) let options = { - outDir = opts |> argValue "--outDir" |> Option.orElse outDir - // fableDir = opts |> argValue "--fableDir" + outDir = opts |> argValue ["--outDir"; "-o"] |> Option.orElse outDir + libDir = opts |> argValue ["--fableLib"] benchmark = opts |> hasFlag "--benchmark" optimize = opts |> hasFlag "--optimize" // sourceMaps = opts |> hasFlag "--sourceMaps" diff --git a/src/fable-standalone/test/bench-compiler/Platform.fs b/src/fable-standalone/test/bench-compiler/Platform.fs index d97f76e238..6187270c18 100644 --- a/src/fable-standalone/test/bench-compiler/Platform.fs +++ b/src/fable-standalone/test/bench-compiler/Platform.fs @@ -2,7 +2,7 @@ module Fable.Compiler.Platform type CmdLineOptions = { outDir: string option - // fableDir: string option + libDir: string option benchmark: bool optimize: bool // sourceMaps: bool diff --git a/src/fable-standalone/test/bench-compiler/app.fs b/src/fable-standalone/test/bench-compiler/app.fs index a799f04dc9..b5419ca665 100644 --- a/src/fable-standalone/test/bench-compiler/app.fs +++ b/src/fable-standalone/test/bench-compiler/app.fs @@ -49,8 +49,8 @@ module Imports = let importPath = if importPath.StartsWith("${outDir}") // NOTE: Path.Combine in Fable Prelude trims / at the start - // of the 2nd argument, unline .NET IO.Path.Combine - then Path.Combine(outDir, importPath.Replace("${outDir}", "")) + // of the 2nd argument, unlike .NET IO.Path.Combine + then Path.Combine(outDir, importPath.Replace("${outDir}", "")) |> normalizeFullPath else importPath let sourceDir = Path.GetDirectoryName(sourcePath) let targetDir = Path.GetDirectoryName(targetPath) @@ -141,11 +141,7 @@ let parseFiles projectFileName options = // Fable (F# to JS) let projDir = projectFileName |> normalizeFullPath |> Path.GetDirectoryName - let libDir = - // special case for fable-library, the libDir is the outDir - if options.typescript && projectFileName.EndsWith("Fable.Library.fsproj") && Option.isSome options.outDir - then options.outDir.Value |> normalizeFullPath - else getFableLibDir() |> normalizeFullPath + let libDir = options.libDir |> Option.defaultValue (getFableLibDir()) |> normalizeFullPath let parseFable (res, fileName) = fable.CompileToBabelAst(libDir, res, fileName, @@ -196,15 +192,15 @@ let parseFiles projectFileName options = writeAllText outPath writer.Result } |> runAsync -let argValue key (args: string[]) = +let argValue keys (args: string[]) = args |> Array.pairwise |> Array.tryPick (fun (k, v) -> - if k = key && not (v.StartsWith("-")) + if (List.contains k keys) && not (v.StartsWith("-")) then Some v else None) let tryFlag flag (args: string[]) = - match argValue flag args with + match argValue [flag] args with | Some flag -> match System.Boolean.TryParse(flag) with | true, flag -> Some flag @@ -226,8 +222,8 @@ let run opts projectFileName outDir = let runArgs = opts.[i+1..] |> String.concat " " sprintf "node %s %s" scriptFile runArgs) let options = { - outDir = opts |> argValue "--outDir" |> Option.orElse outDir - // fableDir = opts |> argValue "--fableDir" + outDir = opts |> argValue ["--outDir"; "-o"] |> Option.orElse outDir + libDir = opts |> argValue ["--fableLib"] benchmark = opts |> hasFlag "--benchmark" optimize = opts |> hasFlag "--optimize" // sourceMaps = opts |> hasFlag "--sourceMaps" diff --git a/src/fable-standalone/test/bench-compiler/package.json b/src/fable-standalone/test/bench-compiler/package.json index e635e8b024..fc53585d31 100644 --- a/src/fable-standalone/test/bench-compiler/package.json +++ b/src/fable-standalone/test/bench-compiler/package.json @@ -3,6 +3,7 @@ "type": "module", "scripts": { "build-cli": "dotnet run -c Release -p ../../../Fable.Cli -- bench-compiler.fsproj --outDir out-node", + "postbuild-cli": "npm run rollup-bundle", "prebuild-dotnet": "git clean -fdx", "build-dotnet": "dotnet run -c Release bench-compiler.fsproj out-node", @@ -24,10 +25,10 @@ "terser-bundle": "npm run terser -- dist/bundle.js -o dist/bundle.min.js --mangle --compress", "webpack-bundle": "npm run webpack -- -p --entry ./out-node/app.js --output ./dist/bundle.min.js --target node", - "prebuild-lib-dotnet": "git clean -fdx", - "build-lib-dotnet": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib", + "prebuild-lib-dotnet": "git clean -fdx && npm run tsc -- -p ../../../fable-library --outDir ./out-lib", + "build-lib-dotnet": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --fableLib out-lib", "prebuild-lib-dotnet-ts": "git clean -fdx && mkdir out-lib && cp -R ../../../fable-library/*.ts out-lib", - "build-lib-dotnet-ts": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --typescript", + "build-lib-dotnet-ts": "dotnet run -c Release ../../../fable-library/Fable.Library.fsproj out-lib --typescript --fableLib out-lib", "tsc-lib-init": "npm run tsc -- --init --target es2020 --module es2020 --allowJs", "tsc-lib": "npm run tsc -- -p ./out-lib --outDir ./out-lib-js", @@ -39,7 +40,6 @@ "build-test-node-ts": "node out-node/app.js ../../../../../fable-test/fable-test.fsproj out-test --typescript", "test-node": "node ./out-test/src/test.js", - "prebuild-tests-dotnet": "git clean -fdx", "build-tests-dotnet": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests", "build-tests-dotnet-ts": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --typescript", "build-tests-dotnet-opt": "dotnet run -c Release ../../../../tests/Main/Fable.Tests.fsproj out-tests --optimize",