Skip to content
Kyle Ross edited this page May 21, 2018 · 1 revision

There were many breaking changes with the release of 3.x, this document to will help you migrate to the new version of ModClean successfully.

ModClean 3.x requires Node v8.9+

Modclean 3 utilizes new language features which will not work correctly without flags in older versions of Node. We are trtying to stay in line with Node's LTS as much as possible.

Please be aware of the following breaking changes and update accordingly:

ModClean API

Promises instead of callbacks

All functions now return a Promise instead of accepting a callback. If you still use callbacks, they will not work. This change was made to support async/await, provide better performance across the board, and reduce code and dependencies.

Example:

const modclean = require('modclean');
const mc = modclean(/* options */);

// Async/await
async function myProcess() {
    try {
        let results = await mc.clean();
        // ...
    } catch(error) {
        console.error(error);
    }
}

// Promises
mc.clean()
    .then(results => {
        // ...
    })
    .catch(error => console.error(error));

Constructor no longer calls clean()

The constructor used to automatically call the clean() function by default, but this has been removed. You will now be required to call modclean.clean() in your code.

If you were not calling clean() manually prior, you will now need to.

Stored error objects are now pure Errors

All errors recorded during the process in modclean.errors is now a pure Error instead of an object containing the error. Data passed into those errors will be stored on the Error itself as properties: payload and method.

All events have been renamed and moved around

In order to better understand the events and what they provide, they have been renamed and namespaced for clarity. Emitted values have changed for some of the events, so we suggest looking at the documentation to see what's different.

  • start is now clean:start
  • complete is now clean:complete
  • deleted is now file:deleted
  • process is now file:list
  • finish is now process:done
  • beforeFind is now file:find
  • beforeEmptyDirs is now emptydir:start
  • afterEmptyDirs is now emptydir:done
  • emptyDirs is now emptydir:list
  • deletedEmptyDir is now emptydir:deleted

Removed the finish event

The finish event has been removed as it was redundant.

All errors emitted via event are now under the event error

Prior, there were multiple event names that fired based on the type of error, but these have been change to all fire under the standard error event.

Updated return value of cleanEmptyDirs() function

The return value is now an object containing the keys empty (array of all matched empty directories) and deleted (array of empty directories successfully deleted).

Matched files are now an array of objects instead of an array of paths

All matched files/folders are now an object that contains a bunch of new properties instead of just the string path. This does not apply to empty directories. See documentation for more information.

Option process has been removed, new option filter added

The process option has been removed and a new option filter has been added instead. This is for clarity and to better understand the functionality of this option. See documentation for additional information.

CLI Option -i, --interactive has been removed

This option provided no real gain and added overhead which slows down the entire process. You should run in test mode if you want to see the files/folders being deleted prior.