forked from zulip/zulip
-
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.
debug-require: Throw errors for unknown and unloaded modules.
Signed-off-by: Anders Kaseorg <[email protected]>
- Loading branch information
Showing
2 changed files
with
17 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
/* global __webpack_require__ */ | ||
|
||
let webpackModules; | ||
|
||
function debugRequire(request) { | ||
return __webpack_require__(debugRequire.ids[request]); | ||
if (!Object.prototype.hasOwnProperty.call(debugRequire.ids, request)) { | ||
throw new Error("Cannot find module '" + request + "'"); | ||
} | ||
const moduleId = debugRequire.ids[request]; | ||
if (!Object.prototype.hasOwnProperty.call(webpackModules, moduleId)) { | ||
throw new Error("Module '" + request + "' has not been loaded yet"); | ||
} | ||
return __webpack_require__(moduleId); | ||
} | ||
|
||
debugRequire.initialize = function (ids) { | ||
debugRequire.initialize = function (ids, modules) { | ||
debugRequire.ids = ids; | ||
webpackModules = modules; | ||
}; | ||
|
||
module.exports = debugRequire; |