* Returns source with library export. * @param {Source} source source * @param {RenderContext} renderContext render context * @param {LibraryContext<T>} libraryContext context * @returns {Source} source with library export
(source, { chunkGraph, moduleGraph, chunk }, { options, compilation })
| 81 | * @returns {Source} source with library export |
| 82 | */ |
| 83 | render(source, { chunkGraph, moduleGraph, chunk }, { options, compilation }) { |
| 84 | const modules = chunkGraph |
| 85 | .getChunkModules(chunk) |
| 86 | .filter( |
| 87 | (m) => m instanceof ExternalModule && m.externalType === "system" |
| 88 | ); |
| 89 | const externals = /** @type {ExternalModule[]} */ (modules); |
| 90 | |
| 91 | // The name this bundle should be registered as with System |
| 92 | const name = options.name |
| 93 | ? `${JSON.stringify(compilation.getPath(options.name, { chunk }))}, ` |
| 94 | : ""; |
| 95 | |
| 96 | // The array of dependencies that are external to webpack and will be provided by System |
| 97 | const systemDependencies = JSON.stringify( |
| 98 | externals.map((m) => |
| 99 | typeof m.request === "object" && !Array.isArray(m.request) |
| 100 | ? m.request.amd |
| 101 | : m.request |
| 102 | ) |
| 103 | ); |
| 104 | |
| 105 | // The name of the variable provided by System for exporting |
| 106 | const dynamicExport = "__WEBPACK_DYNAMIC_EXPORT__"; |
| 107 | |
| 108 | // An array of the internal variable names for the webpack externals |
| 109 | const externalWebpackNames = externals.map( |
| 110 | (m) => |
| 111 | `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier( |
| 112 | `${chunkGraph.getModuleId(m)}` |
| 113 | )}__` |
| 114 | ); |
| 115 | |
| 116 | // Declaring variables for the internal variable names for the webpack externals |
| 117 | const externalVarDeclarations = externalWebpackNames |
| 118 | .map((name) => `var ${name} = {};`) |
| 119 | .join("\n"); |
| 120 | |
| 121 | // Define __esModule flag on all internal variables and helpers |
| 122 | /** @type {string[]} */ |
| 123 | const externalVarInitialization = []; |
| 124 | |
| 125 | // The system.register format requires an array of setter functions for externals. |
| 126 | const setters = |
| 127 | externalWebpackNames.length === 0 |
| 128 | ? "" |
| 129 | : Template.asString([ |
| 130 | "setters: [", |
| 131 | Template.indent( |
| 132 | externals |
| 133 | .map((module, i) => { |
| 134 | const external = externalWebpackNames[i]; |
| 135 | const exportsInfo = moduleGraph.getExportsInfo(module); |
| 136 | const otherUnused = |
| 137 | exportsInfo.otherExportsInfo.getUsed(chunk.runtime) === |
| 138 | UsageState.Unused; |
| 139 | /** @type {string[]} */ |
| 140 | const instructions = []; |
nothing calls this directly
no test coverage detected