Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

fix(index): fallback to fs if this.fs is undefined #45

Merged
merged 6 commits into from
Oct 31, 2018
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ function loader(...args) {

// Should the file get cached?
let cache = true;

// this.fs can be undefined
// e.g when using the thread-loader
// fallback to the fs module
const stat = this.fs ? this.fs.stat : fs.stat;
const toDepDetails = (dep, mapCallback) => {
this.fs.stat(dep, (err, stats) => {
stat(dep, (err, stats) => {
if (err) {
mapCallback(err);
return;
Expand Down Expand Up @@ -110,7 +113,7 @@ function pitch(remainingRequest, prevRequest, dataInput) {
return;
}
async.each(cacheData.dependencies.concat(cacheData.contextDependencies), (dep, eachCallback) => {
this.fs.stat(dep.path, (statErr, stats) => {
stat(dep.path, (statErr, stats) => {
if (statErr) {
eachCallback(statErr);
return;
Expand Down