Skip to content

Instantly share code, notes, and snippets.

@ArtemGovorov
Created September 17, 2018 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArtemGovorov/55ce56e5e0bd8ec2f4401784710cb98d to your computer and use it in GitHub Desktop.
Save ArtemGovorov/55ce56e5e0bd8ec2f4401784710cb98d to your computer and use it in GitHub Desktop.
'use strict';
var fs = require("graceful-fs");
class WallabyInputFileSystem {
constructor(webpackPostprocessor) {
this._postprocessor = webpackPostprocessor;
}
isSync() {
return false;
}
stat() {
return fs.stat.apply(fs, arguments);
}
readdir() {
return fs.readdir.apply(fs, arguments);
}
readlink() {
return fs.readlink.apply(fs, arguments);
}
readFile(filePath, callback) {
if (global._logFileNames) console.log(filePath);
// for tracked files, reading file from wallaby cache (it will read it from disk if required)
var allTrackedFiles = this._postprocessor.getAllTrackedFiles();
var trackedFile = allTrackedFiles[filePath];
if (trackedFile) {
return trackedFile.getContent()
.then(function (source) {
callback(null, source);
})
.fail(function (err) {
callback(err);
});
}
// for other files just reading from disk
return fs.readFile.apply(fs, arguments);
}
statSync() {
return fs.statSync.apply(fs, arguments);
}
readdirSync() {
return fs.readdirSync.apply(fs, arguments);
}
readFileSync(filePath) {
// for tracked files, reading file from wallaby cache (it will read it from disk if required)
var allTrackedFiles = this._postprocessor.getAllTrackedFiles();
var trackedFile = allTrackedFiles[filePath];
if (trackedFile) {
return trackedFile.getContentSync();
}
// for other files just reading from disk
return fs.readFile.apply(fs, arguments);
}
}
module.exports = WallabyInputFileSystem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment