* @param {Dependency[]} dependencies dependencies * @param {ModuleId} id module id * @param {ChunkGraph} chunkGraph the chunk graph * @param {RuntimeTemplate=} runtimeTemplate the runtime template * @returns {string} source code
(dependencies, id, chunkGraph, runtimeTemplate)
| 838 | * @returns {string} source code |
| 839 | */ |
| 840 | getSyncSource(dependencies, id, chunkGraph, runtimeTemplate) { |
| 841 | const map = this.getUserRequestMap(dependencies, chunkGraph); |
| 842 | const fakeMap = this.getFakeMap(dependencies, chunkGraph); |
| 843 | const returnModuleObject = this.getReturnModuleObjectSource(fakeMap); |
| 844 | const cst = runtimeTemplate ? runtimeTemplate.renderConst() : "var"; |
| 845 | |
| 846 | return `${cst} map = ${JSON.stringify(map, null, "\t")}; |
| 847 | ${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)} |
| 848 | |
| 849 | function webpackContext(req) { |
| 850 | ${cst} id = webpackContextResolve(req); |
| 851 | return ${returnModuleObject}; |
| 852 | } |
| 853 | function webpackContextResolve(req) { |
| 854 | if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { |
| 855 | ${cst} e = new Error("Cannot find module '" + req + "'"); |
| 856 | e.code = 'MODULE_NOT_FOUND'; |
| 857 | throw e; |
| 858 | } |
| 859 | return map[req]; |
| 860 | } |
| 861 | webpackContext.keys = function webpackContextKeys() { |
| 862 | return Object.keys(map); |
| 863 | }; |
| 864 | webpackContext.resolve = webpackContextResolve; |
| 865 | module.exports = webpackContext; |
| 866 | webpackContext.id = ${JSON.stringify(id)};`; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * @param {Dependency[]} dependencies dependencies |
no test coverage detected