Package Exports
- with-local-tmp-dir
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (with-local-tmp-dir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
with-local-tmp-dir
Creates a temporary folder inside CWD and passes the path to a function. Afterwards, the folder is removed. Especially useful for testing.
Install
- Install:
npm install --save with-local-tmp-dir - Import:
import * as pkg from ('with-local-tmp-dir') - Require:
const pkg = require('with-local-tmp-dir')
Usage
const withLocalTmpDir = require('with-local-tmp-dir')
await withLocalTmpDir(() => {
console.log(process.cwd())
//> /Users/max/project/tmp-18815DudQxmdn03Rz
})
// Now the folder does not exist anymore
// Also works with async functions =)
await withLocalTmpDir(async () => await ...)
// The folder is removed even if an exception is thrown
await withLocalTmpDir(async () => throw new Error('File could not be found'))
// Create the temporary folder in a specific path
await withLocalTmpDir('my-subpath', () => console.log(process.cwd()))
// Keep folder if not empty
await withLocalTmpDir('my-subpath', () => console.log(process.cwd()), { unsafeCleanup: false })License
Unless stated otherwise all works are:
- Copyright © Sebastian Landwehr
and licensed under: