'fs' plugin
You need to initialize isomorphic-git with a file system before you can do pretty much anything.
Here is how:
// Using require() in Node.js
const fs = require('fs')
const git = require('isomorphic-git')
git.plugins.set('fs', fs)
// using ES6 modules
import fs from 'fs'
import { plugins } from 'isomorphic-git'
plugins.set('fs', fs)
In the browser it's more involved because there's no standard 'fs' module. Hop over to the Browser QuickStart to see how that's done.
Note: only one
fsplugin can be registered at a time.
Implementing your own fs plugin
There are actually TWO ways to implement an fs plugin: the classic "callback" API and the newer "promise" API. If your fs plugin object provides a promises property, isomorphic-git will use the "promise" API exclusively.
Using the "callback" API
A "callback" fs plugin must implement the following subset of node's fs module:
- fs.readFile(path[, options], callback)
- fs.writeFile(file, data[, options], callback)
- fs.unlink(path, callback)
- fs.readdir(path[, options], callback)
- fs.mkdir(path[, mode], callback)
- fs.rmdir(path, callback)
- fs.stat(path[, options], callback)
- fs.lstat(path[, options], callback)
- fs.readlink(path[, options], callback)
- fs.symlink(target, path[, type], callback)
Internally, isomorphic-git wraps the provided "callback" API functions using pify.
As of node v12 the fs.promises API has been stabilized. (lightning-fs also provides a fs.promises API!) Nowadays, wrapping the callback functions
with pify is redundant and potentially less performant than using the native promisified versions. Plus, if you're writing your own fs plugin,
the fs.promises API lets you write straightforward implementations using async / await without the messy optional argument handling the callback API needs.
Therefore a second API is now supported...
Using the "promise" API (preferred)
A "promise" fs plugin must implement the same set functions as a "callback" plugin, but it implements the promisified versions, and they should all be on a property called promises:
- fs.promises.readFile(path[, options])
- fs.promises.writeFile(file, data[, options])
- fs.promises.unlink(path)
- fs.promises.readdir(path[, options])
- fs.promises.mkdir(path[, mode])
- fs.promises.rmdir(path)
- fs.promises.stat(path[, options])
- fs.promises.lstat(path[, options])
- fs.promises.readlink(path[, options])
- fs.promises.symlink(target, path[, type])