From 8f85784997929344f748a8c80292aa34b03ae003 Mon Sep 17 00:00:00 2001 From: Jonathan Grimes Date: Tue, 30 Oct 2018 13:46:42 -0500 Subject: [PATCH 1/6] use the `compiler`'s cached `fs` for stats if there, otherwise, fallback Fix for undefined `this.fs` when behind thread-loader --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 8bf79a6..6db8ff6 100644 --- a/src/index.js +++ b/src/index.js @@ -40,7 +40,7 @@ function loader(...args) { let cache = true; const toDepDetails = (dep, mapCallback) => { - this.fs.stat(dep, (err, stats) => { + (this.fs || fs).stat(dep, (err, stats) => { if (err) { mapCallback(err); return; @@ -110,7 +110,7 @@ function pitch(remainingRequest, prevRequest, dataInput) { return; } async.each(cacheData.dependencies.concat(cacheData.contextDependencies), (dep, eachCallback) => { - this.fs.stat(dep.path, (statErr, stats) => { + (this.fs || fs).stat(dep.path, (statErr, stats) => { if (statErr) { eachCallback(statErr); return; From 1521447fdef2225b3b3e2922d881ac73755bc665 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Tue, 30 Oct 2018 14:32:32 -0500 Subject: [PATCH 2/6] Update src/index.js Co-Authored-By: jsg2021 --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6db8ff6..e1a2527 100644 --- a/src/index.js +++ b/src/index.js @@ -38,7 +38,10 @@ 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 || fs).stat(dep, (err, stats) => { if (err) { From 15a1cf9528fb382b3f754340c2a7c377d8a5f0eb Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Tue, 30 Oct 2018 14:32:36 -0500 Subject: [PATCH 3/6] Update src/index.js Co-Authored-By: jsg2021 --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e1a2527..9bfd423 100644 --- a/src/index.js +++ b/src/index.js @@ -43,7 +43,7 @@ function loader(...args) { // fallback to the fs module const stat = this.fs ? this.fs.stat : fs.stat const toDepDetails = (dep, mapCallback) => { - (this.fs || fs).stat(dep, (err, stats) => { + stat(dep, (err, stats) => { if (err) { mapCallback(err); return; From 5813de3d39b1c5f696c069aa53cf91225912bc19 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Tue, 30 Oct 2018 14:32:40 -0500 Subject: [PATCH 4/6] Update src/index.js Co-Authored-By: jsg2021 --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9bfd423..5a3756b 100644 --- a/src/index.js +++ b/src/index.js @@ -113,7 +113,7 @@ function pitch(remainingRequest, prevRequest, dataInput) { return; } async.each(cacheData.dependencies.concat(cacheData.contextDependencies), (dep, eachCallback) => { - (this.fs || fs).stat(dep.path, (statErr, stats) => { + stat(dep.path, (statErr, stats) => { if (statErr) { eachCallback(statErr); return; From 48ee02f9b5f0a5ba959b799270edbc8fe85c702a Mon Sep 17 00:00:00 2001 From: Jonathan Grimes Date: Tue, 30 Oct 2018 14:34:07 -0500 Subject: [PATCH 5/6] Update index.js --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 5a3756b..641ce77 100644 --- a/src/index.js +++ b/src/index.js @@ -38,10 +38,10 @@ 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 + // 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) => { stat(dep, (err, stats) => { if (err) { From 804e364677724038833c82c3ebd8a626100b2902 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Tue, 30 Oct 2018 15:38:46 -0500 Subject: [PATCH 6/6] Update src/index.js Co-Authored-By: jsg2021 --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 641ce77..a943a49 100644 --- a/src/index.js +++ b/src/index.js @@ -112,6 +112,7 @@ function pitch(remainingRequest, prevRequest, dataInput) { callback(); return; } + const stat = this.fs ? this.fs.stat : fs.stat; async.each(cacheData.dependencies.concat(cacheData.contextDependencies), (dep, eachCallback) => { stat(dep.path, (statErr, stats) => { if (statErr) {