From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/webpack/lib/ContextModule.js | 100 ++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 13 deletions(-) (limited to 'node_modules/webpack/lib/ContextModule.js') diff --git a/node_modules/webpack/lib/ContextModule.js b/node_modules/webpack/lib/ContextModule.js index 9771fcd80..a894e6268 100644 --- a/node_modules/webpack/lib/ContextModule.js +++ b/node_modules/webpack/lib/ContextModule.js @@ -140,8 +140,13 @@ class ContextModule extends Module { this.addBlock(block); } - } else { + } else if(this.async === "weak" || this.async === "async-weak") { + + // we mark all dependencies as weak + dependencies.forEach(dep => dep.weak = true); + this.dependencies = dependencies; + } else { // if we are lazy create a new async dependency block per dependency // and add all blocks to this context dependencies.forEach((dep, idx) => { @@ -198,6 +203,58 @@ module.exports = webpackContext; webpackContext.id = ${JSON.stringify(id)};`; } + getWeakSyncSource(dependencies, id) { + const map = this.getUserRequestMap(dependencies); + return `var map = ${JSON.stringify(map, null, "\t")}; +function webpackContext(req) { + var id = webpackContextResolve(req); + if(!__webpack_require__.m[id]) + throw new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)"); + return __webpack_require__(id); +}; +function webpackContextResolve(req) { + var id = map[req]; + if(!(id + 1)) // check for number or string + throw new Error("Cannot find module '" + req + "'."); + return id; +}; +webpackContext.keys = function webpackContextKeys() { + return Object.keys(map); +}; +webpackContext.resolve = webpackContextResolve; +webpackContext.id = ${JSON.stringify(id)}; +module.exports = webpackContext;`; + } + + getAsyncWeakSource(dependencies, id) { + const map = this.getUserRequestMap(dependencies); + + return `var map = ${JSON.stringify(map, null, "\t")}; +function webpackAsyncContext(req) { + return webpackAsyncContextResolve(req).then(function(id) { + if(!__webpack_require__.m[id]) + throw new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)"); + return __webpack_require__(id); + }); +}; +function webpackAsyncContextResolve(req) { + // Here Promise.resolve().then() is used instead of new Promise() to prevent + // uncatched exception popping up in devtools + return Promise.resolve().then(function() { + var id = map[req]; + if(!(id + 1)) // check for number or string + throw new Error("Cannot find module '" + req + "'."); + return id; + }); +}; +webpackAsyncContext.keys = function webpackAsyncContextKeys() { + return Object.keys(map); +}; +webpackAsyncContext.resolve = webpackAsyncContextResolve; +webpackAsyncContext.id = ${JSON.stringify(id)}; +module.exports = webpackAsyncContext;`; + } + getEagerSource(dependencies, id) { const map = this.getUserRequestMap(dependencies); return `var map = ${JSON.stringify(map, null, "\t")}; @@ -205,20 +262,21 @@ function webpackAsyncContext(req) { return webpackAsyncContextResolve(req).then(__webpack_require__); }; function webpackAsyncContextResolve(req) { - return new Promise(function(resolve, reject) { + // Here Promise.resolve().then() is used instead of new Promise() to prevent + // uncatched exception popping up in devtools + return Promise.resolve().then(function() { var id = map[req]; if(!(id + 1)) // check for number or string - reject(new Error("Cannot find module '" + req + "'.")); - else - resolve(id); + throw new Error("Cannot find module '" + req + "'."); + return id; }); }; webpackAsyncContext.keys = function webpackAsyncContextKeys() { return Object.keys(map); }; webpackAsyncContext.resolve = webpackAsyncContextResolve; -module.exports = webpackAsyncContext; -webpackAsyncContext.id = ${JSON.stringify(id)};`; +webpackAsyncContext.id = ${JSON.stringify(id)}; +module.exports = webpackAsyncContext;`; } getLazyOnceSource(block, dependencies, id, outputOptions, requestShortener) { @@ -240,8 +298,8 @@ webpackAsyncContext.keys = function webpackAsyncContextKeys() { return Object.keys(map); }; webpackAsyncContext.resolve = webpackAsyncContextResolve; -module.exports = webpackAsyncContext; -webpackAsyncContext.id = ${JSON.stringify(id)};`; +webpackAsyncContext.id = ${JSON.stringify(id)}; +module.exports = webpackAsyncContext;`; } getLazySource(blocks, id) { @@ -282,8 +340,8 @@ function webpackAsyncContext(req) { webpackAsyncContext.keys = function webpackAsyncContextKeys() { return Object.keys(map); }; -module.exports = webpackAsyncContext; -webpackAsyncContext.id = ${JSON.stringify(id)};`; +webpackAsyncContext.id = ${JSON.stringify(id)}; +module.exports = webpackAsyncContext;`; } getSourceForEmptyContext(id) { @@ -298,7 +356,11 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`; getSourceForEmptyAsyncContext(id) { return `function webpackEmptyAsyncContext(req) { - return new Promise(function(resolve, reject) { reject(new Error("Cannot find module '" + req + "'.")); }); + // Here Promise.resolve().then() is used instead of new Promise() to prevent + // uncatched exception popping up in devtools + return Promise.resolve().then(function() { + throw new Error("Cannot find module '" + req + "'."); + }); } webpackEmptyAsyncContext.keys = function() { return []; }; webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext; @@ -318,13 +380,25 @@ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`; return this.getEagerSource(this.dependencies, this.id); } return this.getSourceForEmptyAsyncContext(this.id); - } else if(asyncMode === "lazy-once") { + } + if(asyncMode === "lazy-once") { const block = this.blocks[0]; if(block) { return this.getLazyOnceSource(block, block.dependencies, this.id, outputOptions, requestShortener); } return this.getSourceForEmptyAsyncContext(this.id); } + if(asyncMode === "async-weak") { + if(this.dependencies && this.dependencies.length > 0) { + return this.getAsyncWeakSource(this.dependencies, this.id); + } + return this.getSourceForEmptyAsyncContext(this.id); + } + if(asyncMode === "weak") { + if(this.dependencies && this.dependencies.length > 0) { + return this.getWeakSyncSource(this.dependencies, this.id); + } + } if(this.dependencies && this.dependencies.length > 0) { return this.getSyncSource(this.dependencies, this.id); } -- cgit v1.2.3