Skip to content
Merged
Changes from all commits
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
39 changes: 23 additions & 16 deletions src/app/Fake.JavaScript.Yarn/Yarn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Yarn =

/// Default paths to Yarn
let private yarnFileName =
Process.tryFindFileOnPath "yarn"
ProcessUtils.tryFindFileOnPath "yarn"
|> function
| Some yarn when File.Exists yarn -> yarn
| _ ->
Expand All @@ -35,6 +35,7 @@ module Yarn =
| NoLockFile
| Production
| PureLockFile
| FrozenLockFile

/// The list of supported Yarn commands. The `Custom` alternative
/// can be used for other commands not in the list until they are
Expand Down Expand Up @@ -65,6 +66,7 @@ module Yarn =
| NoLockFile -> " --no-lockfile"
| Production -> " --production"
| PureLockFile -> " --pure-lockfile"
| FrozenLockFile -> " --frozen-lockfile"

let private parse = function
| Install installArgs -> sprintf "install%s" (installArgs |> parseInstallArgs)
Expand All @@ -73,20 +75,16 @@ module Yarn =
let private run yarnParams command =
let yarnPath = Path.GetFullPath(yarnParams.YarnFilePath)
let arguments = command |> parse
let exitCode =
Process.execSimple (fun info ->
{ info with
FileName = yarnPath
WorkingDirectory = yarnParams.WorkingDirectory
Arguments = arguments
}
) yarnParams.Timeout

if exitCode <> 0 then failwith (sprintf "'yarn %s' task failed" arguments)
arguments
|> CreateProcess.fromRawCommandLine yarnPath
|> CreateProcess.withWorkingDirectory yarnParams.WorkingDirectory
|> CreateProcess.withTimeout yarnParams.Timeout
|> CreateProcess.ensureExitCodeWithMessage (sprintf "'yarn %s' task failed" arguments)
|> Proc.run
|> ignore

let private yarn setParams = defaultYarnParams |> setParams |> run


/// Run `yarn install`
/// ## Parameters
/// - 'setParams' - set command parameters
Expand All @@ -107,9 +105,8 @@ module Yarn =
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })

let installProduction setParams = yarn setParams <| Install Production

let installProduction setParams = yarn setParams <| Install Production
/// Run `yarn install --force`
/// ## Parameters
/// - 'setParams' - set command parameters
Expand All @@ -132,7 +129,6 @@ module Yarn =
/// })
let installFlat setParams = yarn setParams <| Install Flat


/// Run `yarn install --har`
/// ## Parameters
/// - 'setParams' - set command parameters
Expand Down Expand Up @@ -166,6 +162,17 @@ module Yarn =
/// })
let installPureLock setParams = yarn setParams <| Install PureLockFile

/// Run `yarn install --frozen-lockfile`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installFrozenLockFile (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let installFrozenLockFile setParams = yarn setParams <| Install FrozenLockFile

/// Run `yarn <command>`
/// ## Parameters
/// - 'setParams' - set command parameters
Expand All @@ -175,4 +182,4 @@ module Yarn =
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let exec command setParams = yarn setParams <| Custom command
let exec command setParams = yarn setParams <| Custom command