-
Notifications
You must be signed in to change notification settings - Fork 13
Migrating to 3.x
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 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:
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));
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.
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
.
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 nowclean:start
-
complete
is nowclean:complete
-
deleted
is nowfile:deleted
-
process
is nowfile:list
-
finish
is nowprocess:done
-
beforeFind
is nowfile:find
-
beforeEmptyDirs
is nowemptydir:start
-
afterEmptyDirs
is nowemptydir:done
-
emptyDirs
is nowemptydir:list
-
deletedEmptyDir
is nowemptydir:deleted
The finish
event has been removed as it was redundant.
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.
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).
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.
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.
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.
Information:
Wiki Home
Migrating to 3.x
Migrating to 2.x
Benchmarks
Custom Pattern Plugins
Documentation (v3):
CLI Documentation
API Documentation
Documentation (v2):
CLI Documentation
API Documentation