@@ -9,7 +9,6 @@ const Module = require("./Module");
99const OriginalSource = require ( "webpack-sources" ) . OriginalSource ;
1010const RawSource = require ( "webpack-sources" ) . RawSource ;
1111const AsyncDependenciesBlock = require ( "./AsyncDependenciesBlock" ) ;
12- const DepBlockHelpers = require ( "./dependencies/DepBlockHelpers" ) ;
1312const Template = require ( "./Template" ) ;
1413
1514class ContextModule extends Module {
@@ -275,8 +274,11 @@ function webpackContext(req) {
275274}
276275function webpackContextResolve(req) {
277276 var id = map[req];
278- if(!(id + 1)) // check for number or string
279- throw new Error("Cannot find module '" + req + "'.");
277+ if(!(id + 1)) { // check for number or string
278+ var e = new Error('Cannot find module "' + req + '".');
279+ e.code = 'MODULE_NOT_FOUND';
280+ throw e;
281+ }
280282 return id;
281283}
282284webpackContext.keys = function webpackContextKeys() {
@@ -297,15 +299,21 @@ ${typeof fakeMap === "object" ? `var fakeMap = ${JSON.stringify(fakeMap, null, "
297299
298300function webpackContext(req) {
299301 var id = webpackContextResolve(req);
300- if(!__webpack_require__.m[id])
301- throw new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
302+ if(!__webpack_require__.m[id]) {
303+ var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
304+ e.code = 'MODULE_NOT_FOUND';
305+ throw e;
306+ }
302307 var module = __webpack_require__(id);
303308 ${ returnModuleObject }
304309}
305310function webpackContextResolve(req) {
306311 var id = map[req];
307- if(!(id + 1)) // check for number or string
308- throw new Error("Cannot find module '" + req + "'.");
312+ if(!(id + 1)) { // check for number or string
313+ var e = new Error('Cannot find module "' + req + '".');
314+ e.code = 'MODULE_NOT_FOUND';
315+ throw e;
316+ }
309317 return id;
310318}
311319webpackContext.keys = function webpackContextKeys() {
@@ -326,8 +334,11 @@ ${typeof fakeMap === "object" ? `var fakeMap = ${JSON.stringify(fakeMap, null, "
326334
327335function webpackAsyncContext(req) {
328336 return webpackAsyncContextResolve(req).then(function(id) {
329- if(!__webpack_require__.m[id])
330- throw new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
337+ if(!__webpack_require__.m[id]) {
338+ var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
339+ e.code = 'MODULE_NOT_FOUND';
340+ throw e;
341+ }
331342 var module = __webpack_require__(id);
332343 ${ returnModuleObject }
333344 });
@@ -337,8 +348,11 @@ function webpackAsyncContextResolve(req) {
337348 // uncatched exception popping up in devtools
338349 return Promise.resolve().then(function() {
339350 var id = map[req];
340- if(!(id + 1)) // check for number or string
341- throw new Error("Cannot find module '" + req + "'.");
351+ if(!(id + 1)) { // check for number or string
352+ var e = new Error('Cannot find module "' + req + '".');
353+ e.code = 'MODULE_NOT_FOUND';
354+ throw e;
355+ }
342356 return id;
343357 });
344358}
@@ -370,8 +384,11 @@ function webpackAsyncContextResolve(req) {
370384 // uncatched exception popping up in devtools
371385 return Promise.resolve().then(function() {
372386 var id = map[req];
373- if(!(id + 1)) // check for number or string
374- throw new Error("Cannot find module '" + req + "'.");
387+ if(!(id + 1)) { // check for number or string
388+ var e = new Error('Cannot find module "' + req + '".');
389+ e.code = 'MODULE_NOT_FOUND';
390+ throw e;
391+ }
375392 return id;
376393 });
377394}
@@ -384,7 +401,10 @@ module.exports = webpackAsyncContext;`;
384401 }
385402
386403 getLazyOnceSource ( block , dependencies , id , runtimeTemplate ) {
387- const promise = DepBlockHelpers . getDepBlockPromise ( block , runtimeTemplate , "lazy-once context" ) ;
404+ const promise = runtimeTemplate . blockPromise ( {
405+ block,
406+ message : "lazy-once context"
407+ } ) ;
388408 const map = this . getUserRequestMap ( dependencies ) ;
389409 const fakeMap = this . getFakeMap ( dependencies ) ;
390410 const thenFunction = fakeMap ?
@@ -403,8 +423,11 @@ function webpackAsyncContext(req) {
403423function webpackAsyncContextResolve(req) {
404424 return ${ promise } .then(function() {
405425 var id = map[req];
406- if(!(id + 1)) // check for number or string
407- throw new Error("Cannot find module '" + req + "'.");
426+ if(!(id + 1)) { // check for number or string
427+ var e = new Error('Cannot find module "' + req + '".');
428+ e.code = 'MODULE_NOT_FOUND';
429+ throw e;
430+ }
408431 return id;
409432 });
410433}
@@ -451,8 +474,13 @@ module.exports = webpackAsyncContext;`;
451474 return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
452475function webpackAsyncContext(req) {
453476 var ids = map[req];
454- if(!ids)
455- return Promise.resolve().then(function() { throw new Error("Cannot find module '" + req + "'."); });
477+ if(!ids) {
478+ return Promise.resolve().then(function() {
479+ var e = new Error('Cannot find module "' + req + '".');
480+ e.code = 'MODULE_NOT_FOUND';
481+ throw e;
482+ });
483+ }
456484 return ${ requestPrefix } .then(function() {
457485 var module = __webpack_require__(ids[0]);
458486 ${ returnModuleObject }
@@ -467,7 +495,9 @@ module.exports = webpackAsyncContext;`;
467495
468496 getSourceForEmptyContext ( id ) {
469497 return `function webpackEmptyContext(req) {
470- throw new Error("Cannot find module '" + req + "'.");
498+ var e = new Error('Cannot find module "' + req + '".');
499+ e.code = 'MODULE_NOT_FOUND';
500+ throw e;
471501}
472502webpackEmptyContext.keys = function() { return []; };
473503webpackEmptyContext.resolve = webpackEmptyContext;
@@ -480,7 +510,9 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`;
480510 // Here Promise.resolve().then() is used instead of new Promise() to prevent
481511 // uncatched exception popping up in devtools
482512 return Promise.resolve().then(function() {
483- throw new Error("Cannot find module '" + req + "'.");
513+ var e = new Error('Cannot find module "' + req + '".');
514+ e.code = 'MODULE_NOT_FOUND';
515+ throw e;
484516 });
485517}
486518webpackEmptyAsyncContext.keys = function() { return []; };
0 commit comments