Skip to content

Commit

Permalink
Add installFrozenLockFile option for Yarn
Browse files Browse the repository at this point in the history
Also fix some obsolete warning on Process.execSimple
and Process.tryFindFileOnPath
  • Loading branch information
rfrerebe-stx committed Aug 30, 2019
1 parent 452895d commit 5619d0a
Showing 1 changed file with 23 additions and 16 deletions.
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

0 comments on commit 5619d0a

Please sign in to comment.