Created
September 17, 2018 07:13
-
-
Save ArtemGovorov/55ce56e5e0bd8ec2f4401784710cb98d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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