Skip to content

Commit

Permalink
Use fs.rm() instead of rimraf
Browse files Browse the repository at this point in the history
A regression occurred in 0.2.2 which can be reproduced using:

```js
const assert = require('assert');
const tmp = require('tmp');
tmp.dir({ unsafeCleanup: true }, (err, path, cleanup) => {
  assert.ifError(err);
  cleanup(assert.ifError);
});
```
This works with 0.2.1.  With 0.2.2 it fails with:

    /path/to/tmp/node-tmp/lib/tmp.js:358
            return removeFunction(fileOrDirName, next || function() {});
                   ^

    TypeError: removeFunction is not a function
        at _cleanupCallback (/path/to/tmp/node-tmp/lib/tmp.js:358:16)
        at /path/to/tmp/node-tmp/repro.js:5:3
        at _dirCreated (/path/to/tmp/node-tmp/lib/tmp.js:207:7)
        at FSReqCallback.oncomplete (node:fs:192:23)

This occurs because 00bb5b2 upgraded
the rimraf dependency from ^3.0.0 to ^5.0.5 without handling the change
to a `Promise`-based API in 4.0.0
(isaacs/rimraf@a71e7f9)
or the removal of the default export in 5.0.0
(isaacs/rimraf@c7a3fd4).

This commit fixes the issue by dropping the `rimraf` dependency in favor
of `fs.rm({recursive: true})`.

It also updates the nodejs engine version to 14.14, when `fs.rm()` was
added.

Fixes: 00bb5b2 ("Update rimraf and drop old Node compatibility")
Fixes: #295
Signed-off-by: Kevin Locke <[email protected]>
  • Loading branch information
kevinoid committed Feb 29, 2024
1 parent 9fcf3ce commit eafb034
Show file tree
Hide file tree
Showing 11 changed files with 830 additions and 5,483 deletions.
1,038 changes: 519 additions & 519 deletions docs/global.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ <h3> </h3>
<section>
<article><h1>Tmp</h1>
<p>A simple temporary file and directory creator for <a href="http://nodejs.org/">node.js.</a></p>
<p><a href="https://travis-ci.org/raszi/node-tmp"><img src="https://travis-ci.org/raszi/node-tmp.svg?branch=master" alt="Build Status"></a>
<a href="https://david-dm.org/raszi/node-tmp"><img src="https://david-dm.org/raszi/node-tmp.svg" alt="Dependencies"></a>
<p><a href="https://github.com/raszi/node-tmp/actions/workflows/node.js.yml"><img src="https://img.shields.io/github/actions/workflow/status/raszi/node-tmp/node.js.yml?branch=master" alt="Build Status"></a>
<a href="https://libraries.io/github/raszi/node-tmp"><img src="https://img.shields.io/librariesio/github/raszi/node-tmp" alt="Dependencies"></a>
<a href="https://badge.fury.io/js/tmp"><img src="https://badge.fury.io/js/tmp.svg" alt="npm version"></a>
<a href="https://raszi.github.io/node-tmp/"><img src="https://img.shields.io/badge/API-documented-brightgreen.svg" alt="API documented"></a>
<a href="https://snyk.io/test/npm/tmp"><img src="https://snyk.io/test/npm/tmp/badge.svg" alt="Known Vulnerabilities"></a></p>
Expand Down Expand Up @@ -84,7 +84,7 @@ <h2>An Important Note on Previously Undocumented Breaking Changes</h2>
<h2>An Important Note on Compatibility</h2>
<p>See the <a href="./CHANGELOG.md">CHANGELOG</a> for more information.</p>
<h3>Version 0.2.2</h3>
<p>Since version 0.2.2, all support for node version &lt; 12 has been dropped.</p>
<p>Since version 0.2.2, all support for node version &lt;= 12 has been dropped.</p>
<h3>Version 0.1.0</h3>
<p>Since version 0.1.0, all support for node versions &lt; 0.10.0 has been dropped.</p>
<p>Most importantly, any support for earlier versions of node-tmp was also dropped.</p>
Expand Down Expand Up @@ -338,7 +338,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Fri Aug 26 2022 22:37:40 GMT+0200 (Mitteleuropäische Sommerzeit)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Feb 28 2024 18:30:02 GMT-0700 (Mountain Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
27 changes: 23 additions & 4 deletions docs/tmp.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ <h1 class="page-title">Source: tmp.js</h1>
const path = require('path');
const crypto = require('crypto');
const _c = { fs: fs.constants, os: os.constants };
const rimraf = require('rimraf');

/*
* The working inner variables.
Expand Down Expand Up @@ -71,12 +70,32 @@ <h1 class="page-title">Source: tmp.js</h1>
_removeObjects = [],

// API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs),
FN_RIMRAF_SYNC = rimraf.sync;
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);

let
_gracefulCleanup = false;

/**
* Recursively remove a directory and its contents.
*
* @param {string} dirPath path of directory to remove
* @param {Function} callback
* @private
*/
function rimraf(dirPath, callback) {
return fs.rm(dirPath, { recursive: true }, callback);
}

/**
* Recursively remove a directory and its contents, synchronously.
*
* @param {string} dirPath path of directory to remove
* @private
*/
function FN_RIMRAF_SYNC(dirPath) {
return fs.rmSync(dirPath, { recursive: true });
}

/**
* Gets a temporary file name.
*
Expand Down Expand Up @@ -807,7 +826,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Fri Aug 26 2022 22:37:40 GMT+0200 (Mitteleuropäische Sommerzeit)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Feb 28 2024 18:30:02 GMT-0700 (Mountain Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
25 changes: 22 additions & 3 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const os = require('os');
const path = require('path');
const crypto = require('crypto');
const _c = { fs: fs.constants, os: os.constants };
const rimraf = require('rimraf');

/*
* The working inner variables.
Expand Down Expand Up @@ -43,12 +42,32 @@ const
_removeObjects = [],

// API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs),
FN_RIMRAF_SYNC = rimraf.sync;
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);

let
_gracefulCleanup = false;

/**
* Recursively remove a directory and its contents.
*
* @param {string} dirPath path of directory to remove
* @param {Function} callback
* @private
*/
function rimraf(dirPath, callback) {
return fs.rm(dirPath, { recursive: true }, callback);
}

/**
* Recursively remove a directory and its contents, synchronously.
*
* @param {string} dirPath path of directory to remove
* @private
*/
function FN_RIMRAF_SYNC(dirPath) {
return fs.rmSync(dirPath, { recursive: true });
}

/**
* Gets a temporary file name.
*
Expand Down
Loading

0 comments on commit eafb034

Please sign in to comment.