Skip to content

Commit b6465b0

Browse files
authored
Merge pull request #234 from raszi/gh-233
feat: stabilize tmp for v0.2.0 release
2 parents 61f9a7d + c8823e5 commit b6465b0

30 files changed

+2020
-1106
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- "node"
4+
- "13"
45
- "12"
56
- "11"
67
- "10"

CHANGELOG.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# CHANGELOG
2+
3+
## tmp v0.2.0
4+
5+
- drop support for node version < v8.17.0
6+
7+
***BREAKING CHANGE***
8+
9+
node versions < v8.17.0 are no longer supported.
10+
11+
- [#216](https://github.com/raszi/node-tmp/issues/216)
12+
13+
***BREAKING CHANGE***
14+
15+
SIGINT handler has been removed.
16+
17+
Users must install their own SIGINT handler and call process.exit() so that tmp's process
18+
exit handler can do the cleanup.
19+
20+
A simple handler would be
21+
22+
```
23+
process.on('SIGINT', process.exit);
24+
```
25+
26+
- [#156](https://github.com/raszi/node-tmp/issues/156)
27+
28+
***BREAKING CHANGE***
29+
30+
template option no longer accepts arbitrary paths. all paths must be relative to os.tmpdir().
31+
the template option can point to an absolute path that is located under os.tmpdir().
32+
this can now be used in conjunction with the dir option.
33+
34+
- [#207](https://github.com/raszi/node-tmp/issues/TBD)
35+
36+
***BREAKING CHANGE***
37+
38+
dir option no longer accepts arbitrary paths. all paths must be relative to os.tmpdir().
39+
the dir option can point to an absolute path that is located under os.tmpdir().
40+
41+
- [#218](https://github.com/raszi/node-tmp/issues/TBD)
42+
43+
***BREAKING CHANGE***
44+
45+
name option no longer accepts arbitrary paths. name must no longer contain a path and will always be made relative
46+
to the current os.tmpdir() and the optional dir option.
47+
48+
- [#197](https://github.com/raszi/node-tmp/issues/197)
49+
50+
***BUG FIX***
51+
52+
sync cleanup callback must be returned when using the sync API functions.
53+
54+
fs.rmdirSync() must not be called with a second parameter that is a function.
55+
56+
- [#176](https://github.com/raszi/node-tmp/issues/176)
57+
58+
***BUG FIX***
59+
60+
fail early if no os.tmpdir() was specified.
61+
previous versions of Electron did return undefined when calling os.tmpdir().
62+
_getTmpDir() now tries to resolve the path returned by os.tmpdir().
63+
64+
now using rimraf for removing directory trees.
65+
66+
- [#246](https://github.com/raszi/node-tmp/issues/246)
67+
68+
***BUG FIX***
69+
70+
os.tmpdir() might return a value that includes single or double quotes,
71+
similarly so the dir option, the template option and the name option
72+
73+
- [#240](https://github.com/raszi/node-tmp/issues/240)
74+
75+
***DOCUMENTATION***
76+
77+
better documentation for `tmp.setGracefulCleanup()`.
78+
79+
- [#206](https://github.com/raszi/node-tmp/issues/206)
80+
81+
***DOCUMENTATION***
82+
83+
document name option.
84+
85+
- [#236](https://github.com/raszi/node-tmp/issues/236)
86+
87+
***DOCUMENTATION***
88+
89+
document discardDescriptor option.
90+
91+
- [#237](https://github.com/raszi/node-tmp/issues/237)
92+
93+
***DOCUMENTATION***
94+
95+
document detachDescriptor option.
96+
97+
- [#238](https://github.com/raszi/node-tmp/issues/238)
98+
99+
***DOCUMENTATION***
100+
101+
document mode option.
102+
103+
- [#175](https://github.com/raszi/node-tmp/issues/175)
104+
105+
***DOCUMENTATION***
106+
107+
document unsafeCleanup option.
108+
109+
110+
### Miscellaneous
111+
112+
- stabilized tests
113+
- general clean up
114+
- update jsdoc
115+
116+
117+
## Previous Releases
118+
119+
- no information available

README.md

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ standard OS temporary directory, then you are free to override that as well.
2929

3030
## An Important Note on Compatibility
3131

32+
See the [CHANGELOG](./CHANGELOG.md) for more information.
33+
3234
### Version 0.1.0
3335

3436
Since version 0.1.0, all support for node versions < 0.10.0 has been dropped.
@@ -48,15 +50,6 @@ dependency to version 0.0.33.
4850
For node versions < 0.8 you must limit your node-tmp dependency to
4951
versions < 0.0.33.
5052

51-
### Node Versions < 8.12.0
52-
53-
The SIGINT handler will not work correctly with versions of NodeJS < 8.12.0.
54-
55-
### Windows
56-
57-
Signal handlers for SIGINT will not work. Pressing CTRL-C will leave behind
58-
temporary files and directories.
59-
6053
## How to install
6154

6255
```bash
@@ -72,7 +65,7 @@ Please also check [API docs][4].
7265
Simple temporary file creation, the file will be closed and unlinked on process exit.
7366

7467
```javascript
75-
var tmp = require('tmp');
68+
const tmp = require('tmp');
7669

7770
tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
7871
if (err) throw err;
@@ -92,9 +85,9 @@ tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
9285
A synchronous version of the above.
9386

9487
```javascript
95-
var tmp = require('tmp');
88+
const tmp = require('tmp');
9689

97-
var tmpobj = tmp.fileSync();
90+
const tmpobj = tmp.fileSync();
9891
console.log('File: ', tmpobj.name);
9992
console.log('Filedescriptor: ', tmpobj.fd);
10093

@@ -115,7 +108,7 @@ Simple temporary directory creation, it will be removed on process exit.
115108
If the directory still contains items on process exit, then it won't be removed.
116109

117110
```javascript
118-
var tmp = require('tmp');
111+
const tmp = require('tmp');
119112

120113
tmp.dir(function _tempDirCreated(err, path, cleanupCallback) {
121114
if (err) throw err;
@@ -135,9 +128,9 @@ you can pass the `unsafeCleanup` option when creating it.
135128
A synchronous version of the above.
136129

137130
```javascript
138-
var tmp = require('tmp');
131+
const tmp = require('tmp');
139132

140-
var tmpobj = tmp.dirSync();
133+
const tmpobj = tmp.dirSync();
141134
console.log('Dir: ', tmpobj.name);
142135
// Manual cleanup
143136
tmpobj.removeCallback();
@@ -153,7 +146,7 @@ It is possible with this library to generate a unique filename in the specified
153146
directory.
154147

155148
```javascript
156-
var tmp = require('tmp');
149+
const tmp = require('tmp');
157150

158151
tmp.tmpName(function _tempNameGenerated(err, path) {
159152
if (err) throw err;
@@ -167,9 +160,9 @@ tmp.tmpName(function _tempNameGenerated(err, path) {
167160
A synchronous version of the above.
168161

169162
```javascript
170-
var tmp = require('tmp');
163+
const tmp = require('tmp');
171164

172-
var name = tmp.tmpNameSync();
165+
const name = tmp.tmpNameSync();
173166
console.log('Created temporary filename: ', name);
174167
```
175168

@@ -180,9 +173,9 @@ console.log('Created temporary filename: ', name);
180173
Creates a file with mode `0644`, prefix will be `prefix-` and postfix will be `.txt`.
181174

182175
```javascript
183-
var tmp = require('tmp');
176+
const tmp = require('tmp');
184177

185-
tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileCreated(err, path, fd) {
178+
tmp.file({ mode: 0o644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileCreated(err, path, fd) {
186179
if (err) throw err;
187180

188181
console.log('File: ', path);
@@ -195,9 +188,9 @@ tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileC
195188
A synchronous version of the above.
196189

197190
```javascript
198-
var tmp = require('tmp');
191+
const tmp = require('tmp');
199192

200-
var tmpobj = tmp.fileSync({ mode: 0644, prefix: 'prefix-', postfix: '.txt' });
193+
const tmpobj = tmp.fileSync({ mode: 0o644, prefix: 'prefix-', postfix: '.txt' });
201194
console.log('File: ', tmpobj.name);
202195
console.log('Filedescriptor: ', tmpobj.fd);
203196
```
@@ -219,7 +212,7 @@ descriptor. Two options control how the descriptor is managed:
219212
longer needed.
220213

221214
```javascript
222-
var tmp = require('tmp');
215+
const tmp = require('tmp');
223216

224217
tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
225218
if (err) throw err;
@@ -229,7 +222,7 @@ tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, c
229222
```
230223

231224
```javascript
232-
var tmp = require('tmp');
225+
const tmp = require('tmp');
233226

234227
tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
235228
if (err) throw err;
@@ -246,9 +239,9 @@ tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cl
246239
Creates a directory with mode `0755`, prefix will be `myTmpDir_`.
247240

248241
```javascript
249-
var tmp = require('tmp');
242+
const tmp = require('tmp');
250243

251-
tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path) {
244+
tmp.dir({ mode: 0o750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path) {
252245
if (err) throw err;
253246

254247
console.log('Dir: ', path);
@@ -260,9 +253,9 @@ tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path)
260253
Again, a synchronous version of the above.
261254

262255
```javascript
263-
var tmp = require('tmp');
256+
const tmp = require('tmp');
264257

265-
var tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
258+
const tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
266259
console.log('Dir: ', tmpobj.name);
267260
```
268261

@@ -275,7 +268,7 @@ require tmp to create your temporary filesystem object in a different place than
275268
default `tmp.tmpdir`.
276269

277270
```javascript
278-
var tmp = require('tmp');
271+
const tmp = require('tmp');
279272

280273
tmp.dir({ template: 'tmp-XXXXXX' }, function _tempDirCreated(err, path) {
281274
if (err) throw err;
@@ -289,9 +282,9 @@ tmp.dir({ template: 'tmp-XXXXXX' }, function _tempDirCreated(err, path) {
289282
This will behave similarly to the asynchronous version.
290283

291284
```javascript
292-
var tmp = require('tmp');
285+
const tmp = require('tmp');
293286

294-
var tmpobj = tmp.dirSync({ template: 'tmp-XXXXXX' });
287+
const tmpobj = tmp.dirSync({ template: 'tmp-XXXXXX' });
295288
console.log('Dir: ', tmpobj.name);
296289
```
297290

@@ -303,9 +296,9 @@ The function accepts all standard options, e.g. `prefix`, `postfix`, `dir`, and
303296
You can also leave out the options altogether and just call the function with a callback as first parameter.
304297

305298
```javascript
306-
var tmp = require('tmp');
299+
const tmp = require('tmp');
307300

308-
var options = {};
301+
const options = {};
309302

310303
tmp.tmpName(options, function _tempNameGenerated(err, path) {
311304
if (err) throw err;
@@ -320,19 +313,22 @@ The `tmpNameSync()` function works similarly to `tmpName()`.
320313
Again, you can leave out the options altogether and just invoke the function without any parameters.
321314

322315
```javascript
323-
var tmp = require('tmp');
324-
var options = {};
325-
var tmpname = tmp.tmpNameSync(options);
316+
const tmp = require('tmp');
317+
const options = {};
318+
const tmpname = tmp.tmpNameSync(options);
326319
console.log('Created temporary filename: ', tmpname);
327320
```
328321

329322
## Graceful cleanup
330323

331-
One may want to cleanup the temporary files even when an uncaught exception
332-
occurs. To enforce this, you can call the `setGracefulCleanup()` method:
324+
If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the
325+
temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary
326+
object removal.
327+
328+
To enforce this, you can call the `setGracefulCleanup()` method:
333329

334330
```javascript
335-
var tmp = require('tmp');
331+
const tmp = require('tmp');
336332

337333
tmp.setGracefulCleanup();
338334
```
@@ -341,16 +337,25 @@ tmp.setGracefulCleanup();
341337

342338
All options are optional :)
343339

344-
* `name`: a fixed name that overrides random name generation
345-
* `mode`: the file mode to create with, it fallbacks to `0600` on file creation and `0700` on directory creation
346-
* `prefix`: the optional prefix, fallbacks to `tmp-` if not provided
347-
* `postfix`: the optional postfix, fallbacks to `.tmp` on file creation
348-
* `template`: [`mkstemp`][3] like filename template, no default
349-
* `dir`: the optional temporary directory, fallbacks to system default (guesses from environment)
340+
* `name`: a fixed name that overrides random name generation, the name must be relative and must not contain path segments
341+
* `mode`: the file mode to create with, falls back to `0o600` on file creation and `0o700` on directory creation
342+
* `prefix`: the optional prefix, defaults to `tmp`
343+
* `postfix`: the optional postfix
344+
* `template`: [`mkstemp`][3] like filename template, no default, can be either an absolute or a relative path that resolves
345+
to a relative path of the system's default temporary directory, must include `XXXXXX` once for random name generation, e.g.
346+
'foo/bar/XXXXXX'. Absolute paths are also fine as long as they are relative to os.tmpdir().
347+
Any directories along the so specified path must exist, otherwise a ENOENT error will be thrown upon access,
348+
as tmp will not check the availability of the path, nor will it establish the requested path for you.
349+
* `dir`: the optional temporary directory that must be relative to the system's default temporary directory.
350+
absolute paths are fine as long as they point to a location under the system's default temporary directory.
351+
Any directories along the so specified path must exist, otherwise a ENOENT error will be thrown upon access,
352+
as tmp will not check the availability of the path, nor will it establish the requested path for you.
350353
* `tries`: how many times should the function try to get a unique filename before giving up, default `3`
351354
* `keep`: signals that the temporary file or directory should not be deleted on exit, default is `false`
352355
* In order to clean up, you will have to call the provided `cleanupCallback` function manually.
353356
* `unsafeCleanup`: recursively removes the created temporary directory, even when it's not empty. default is `false`
357+
* `detachDescriptor`: detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection
358+
* `discardDescriptor`: discards the file descriptor (closes file, fd is -1), tmp will no longer try closing the file during garbage collection
354359

355360
[1]: http://nodejs.org/
356361
[2]: https://www.npmjs.com/browse/depended/tmp

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ environment:
77
- nodejs_version: "10"
88
- nodejs_version: "11"
99
- nodejs_version: "12"
10+
- nodejs_version: "13"
1011

1112
install:
1213
- ps: Install-Product node $env:nodejs_version

0 commit comments

Comments
 (0)