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

Commit b84d13e

Browse files
jsg2021michael-ciniawsky
authored andcommitted
fix(index): fallback to fs if this.fs is undefined (#45)
1 parent 91d2a18 commit b84d13e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: src/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ function loader(...args) {
3838

3939
// Should the file get cached?
4040
let cache = true;
41-
41+
// this.fs can be undefined
42+
// e.g when using the thread-loader
43+
// fallback to the fs module
44+
const stat = this.fs ? this.fs.stat : fs.stat;
4245
const toDepDetails = (dep, mapCallback) => {
43-
this.fs.stat(dep, (err, stats) => {
46+
stat(dep, (err, stats) => {
4447
if (err) {
4548
mapCallback(err);
4649
return;
@@ -109,8 +112,9 @@ function pitch(remainingRequest, prevRequest, dataInput) {
109112
callback();
110113
return;
111114
}
115+
const stat = this.fs ? this.fs.stat : fs.stat;
112116
async.each(cacheData.dependencies.concat(cacheData.contextDependencies), (dep, eachCallback) => {
113-
this.fs.stat(dep.path, (statErr, stats) => {
117+
stat(dep.path, (statErr, stats) => {
114118
if (statErr) {
115119
eachCallback(statErr);
116120
return;

0 commit comments

Comments
 (0)