Create unique temp directories and clean up afterwards
Use os.tmpdir and fs.mkdtemp to create a uniquely named temporary directory in the correct place.
Also attempt to remove the temporary directory on application exit. This uses fs.rmSync which is only available in Node 14, which might be too new.
Thanks for this! I have a couple of questions, if you don't mind?
- We've had some issues with with temporary directories in the past since it's platform dependent. Can I ask what platform(s) you've tested on?
- When you say that
fs.rmSyncis only available in Node 14 which may be too new. Did it work for you when you tested? Any reason to believe it won't work otherwise? Our version of Electron is super outdated so I wouldn't be surprised if we had issues with APIs being too new!
Unfortunately I'm only able to test on Linux
Instead of using rmSync, I could add another npm dependency for a package that does the same in older versions of node (at least one page recommended del) if that is acceptable?
The behaviour if the function doesn't exist is an error message in the console, and the directory not being deleted, which isn't very different from the current behaviour, although potentially more annoying to manually cleanup now if there are multiple temp directories lying about.
I've added a new commit that adds del as an additional dependency, and uses this to delete the temp directory. This should work with older versions of node.
Also, although this replaces the changes from https://github.com/inkle/inky/pull/223, I did test that this does still respect TMPDIR on Linux (and I assume also OSX)