forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect cycles during this.loadModule from loader
fix webpack#10152
- Loading branch information
Showing
11 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
|
||
"use strict"; | ||
|
||
const WebpackError = require("../WebpackError"); | ||
|
||
/** @typedef {import("../Module")} Module */ | ||
|
||
class BuildCycleError extends WebpackError { | ||
/** | ||
* Creates an instance of ModuleDependencyError. | ||
* @param {Module} module the module starting the cycle | ||
*/ | ||
constructor(module) { | ||
super( | ||
"There is a circular build dependency, which makes it impossible to create this module" | ||
); | ||
|
||
this.name = "BuildCycleError"; | ||
this.module = module; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
|
||
module.exports = BuildCycleError; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"./a.json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"./b.json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"./a.json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"./b.json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"./c.json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"./a.json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
it("should error loadModule when a cycle with 2 modules is requested", () => { | ||
expect(require("./loader!./2/a")).toMatch( | ||
/^source: err: There is a circular build dependency/ | ||
); | ||
}); | ||
it("should error loadModule when a cycle with 3 modules is requested", () => { | ||
expect(require("./loader!./3/a")).toMatch( | ||
/^source: source: err: There is a circular build dependency/ | ||
); | ||
}); | ||
it("should error loadModule when requesting itself", () => { | ||
expect(require("./loader!./1/a")).toMatch( | ||
/^err: There is a circular build dependency/ | ||
); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
exports.default = function(source) { | ||
const ref = JSON.parse(source); | ||
const callback = this.async(); | ||
this.loadModule("../loader!" + ref, (err, source, sourceMap, module) => { | ||
if (err) { | ||
callback(null, JSON.stringify(`err: ${err && err.message}`)); | ||
} else { | ||
callback(null, JSON.stringify(`source: ${JSON.parse(source)}`)); | ||
} | ||
}); | ||
}; |