Rollback the rock!
Undo pesky file system mutations with ease.
npm i -s rollback
Both typescript and javascript support come out of the box.
Take a snapshot of a directory.
import { snapshot } from 'rollback';
import { writeFileSync } from 'fs';
snapshot({
path: '/some/directory'
}).then(snap => {
// make some changes
writeFileSync('/some/directory/myFile', 'some updates');
// then rollback all the changes
return snap.rollback();
});Take a snapshot of a file.
import { snapshotFile } from 'rollback';
import { writeFileSync } from 'fs';
snapshotFile({
path: '/some/file.txt'
}).then(snap => {
// make some changes
writeFileSync('/some/file.txt', 'some updates');
// then rollback all the changes
return snap.rollback();
});Take a snapshot of a directory.
import { snapshotSync } from 'rollback';
import { writeFileSync } from 'fs';
const snap = snapshotSync({
path: '/some/directory'
});
writeFileSync('/some/directory/myFile', 'some updates');
snap.rollbackSync();Take a snapshot of a file.
import { snapshotFileSync } from 'rollback';
import { writeFileSync } from 'fs';
const snap = snapshotFileSync({
path: '/some/file.txt'
});
writeFileSync('/some/file.txt', 'some updates');
snap.rollbackSync();Rollback exposes four base methods: snapshot, snapshotSync, snapshotFile, and snapshotFileSync.
All methods accept all configuration options exposed by tmp.
Additionally the following options from fs-extra's copy are supported:
preserveTimestamps, filter, recursive (recursive is only supported for snapshot and snapshotSync)
snapshot and snapshotFile return a Promise which resolves with a Snapshot object.
snapshotSync and snapshotFileSync return a Snapshot directly.
A Snapshot object has the following properties:
| property | type | description |
|---|---|---|
path |
string |
the path of the temporary directory |
cleanup |
() => void |
manually cleans up the temporary directory |
rollback |
(options?: RollbackOptions) => Promise<void> |
asynchronously rolls back any changes to the snapshot |
rollbackSync |
(options?: RollbackOptions) => void |
synchronously rolls back any changes to the snapshot |
RollbackOptions takes the following form:
interface RollbackOptions {
preserveTimestamps?: boolean;
recursive?: boolean; // only supported if the snapshot is of a directory
}The default for rollback options is whatever was specified in the snapshot, snapshotSync, snapshotFile, or snapshotFileSync invocation that generated the Snapshot object.
Licensed under MIT
