rollback

Rollback a directory to a prior snapshot

Usage no npm install needed!

<script type="module">
  import rollback from 'https://cdn.skypack.dev/rollback';
</script>

README

Rollback

Gitlab pipeline status Coverage Status David NPM node npm

npm type definitions

Rollback the rock!

Alt text

Undo pesky file system mutations with ease.

Installation

npm i -s rollback

Both typescript and javascript support come out of the box.

Basic Usage

Asynchronous API

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();
});

Synchronous API

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();

Advanced Usage

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.

Snapshot

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.

API Documentation

API

License

Licensed under MIT