-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
4 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,19 +17,8 @@ export { isNode } from "https://deno.land/x/[email protected]/mod.ts"; | |
* then cleans up and restores the cwd when complete. | ||
*/ | ||
export async function withTempDir(action: (path: PathRef) => Promise<void> | void) { | ||
const originalDirPath = Deno.cwd(); | ||
const dirPath = await Deno.makeTempDir(); | ||
Deno.chdir(dirPath); | ||
try { | ||
await action(createPathRef(dirPath).resolve()); | ||
} finally { | ||
try { | ||
await Deno.remove(dirPath, { recursive: true }); | ||
} catch { | ||
// ignore | ||
} | ||
Deno.chdir(originalDirPath); | ||
} | ||
await using dirPath = usingTempDir(); | ||
await action(createPathRef(dirPath).resolve()); | ||
} | ||
|
||
export function usingTempDir(): PathRef & AsyncDisposable { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters