@pumpkin-plugins/build API / replace-output / replaceOutput
Function: replaceOutput()
replaceOutput(
staged,target,aside,restoreFailureMessage,onRestoreFailure?):void
Defined in: tools/build/src/replace-output.ts:17
Replaces an existing file or directory with a staged one: moves the old output aside, renames the staged output into its place, and moves the old output back if that rename fails.
The caller checks that target exists and has the expected kind, and removes aside after a successful replace.
Parameters
staged
string
target
string
aside
string
A free path on the same file system that holds the old output during the swap.
restoreFailureMessage
string
Message of the error thrown when the old output cannot be moved back.
onRestoreFailure?
() => void
Runs before that error is thrown, so the caller can keep aside for recovery.
Returns
void
Throws
When neither the staged nor the old output could be moved to target. It holds the publish error and the restore error, and aside still holds the old output. A failed publish whose restore succeeds rethrows the publish error unchanged.