JSPM

  • Created
  • Published
  • Downloads 956
  • Score
    100M100P100Q109687F
  • License MIT

Creates a temporary folder inside CWD and passes the path to a function. Afterwards, the folder is removed. Especially useful for testing.

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

npm version Build Status Coverage Status dependency status

Creates a temporary folder inside CWD and passes the path to a function. Afterwards, the folder is removed. Especially useful for testing.

Installation

# via NPM
npm install --save with-local-tmp-dir

# via Yarn
yarn add 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'))

Migrating from Version 1.x to 2.x

Version 2 automatically changes the current working directory into the temporary folder. That's why the path parameter is not needed anymore and the path can be directly queried from process.cwd.

License

MIT © Sebastian Landwehr