* Applies the plugin by registering its hooks on the compiler. * @param {Dependency} dependency the dependency for which the template should be applied * @param {ReplaceSource} source the current replace source which can be modified * @param {DependencyTemplateContext} templateContext the cont
(
dependency,
source,
{
runtime,
runtimeTemplate,
moduleGraph,
chunkGraph,
initFragments,
runtimeRequirements
}
)
| 113 | * @returns {void} |
| 114 | */ |
| 115 | apply( |
| 116 | dependency, |
| 117 | source, |
| 118 | { |
| 119 | runtime, |
| 120 | runtimeTemplate, |
| 121 | moduleGraph, |
| 122 | chunkGraph, |
| 123 | initFragments, |
| 124 | runtimeRequirements |
| 125 | } |
| 126 | ) { |
| 127 | const dep = /** @type {ProvidedDependency} */ (dependency); |
| 128 | const connection = |
| 129 | /** @type {ModuleGraphConnection} */ |
| 130 | (moduleGraph.getConnection(dep)); |
| 131 | const exportsInfo = moduleGraph.getExportsInfo(connection.module); |
| 132 | const usedName = exportsInfo.getUsedName(dep.ids, runtime); |
| 133 | |
| 134 | const moduleRaw = runtimeTemplate.moduleRaw({ |
| 135 | module: moduleGraph.getModule(dep), |
| 136 | chunkGraph, |
| 137 | request: dep.request, |
| 138 | runtimeRequirements |
| 139 | }); |
| 140 | |
| 141 | const provided = !usedName |
| 142 | ? moduleRaw |
| 143 | : usedName instanceof InlinedUsedName |
| 144 | ? `(${moduleRaw}, ${usedName.render( |
| 145 | Template.toNormalComment( |
| 146 | `inlined export ${propertyAccess(dep.ids)}` |
| 147 | ) |
| 148 | )})` |
| 149 | : `${moduleRaw}${propertyAccess(/** @type {string[]} */ (usedName), 0)}`; |
| 150 | |
| 151 | initFragments.push( |
| 152 | new InitFragment( |
| 153 | `/* provided dependency */ var ${dep.identifier} = ${provided};\n`, |
| 154 | InitFragment.STAGE_PROVIDES, |
| 155 | 1, |
| 156 | `provided ${dep.identifier}` |
| 157 | ) |
| 158 | ); |
| 159 | source.replace(dep.range[0], dep.range[1] - 1, dep.identifier); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | ProvidedDependency.Template = ProvidedDependencyTemplate; |
nothing calls this directly
no test coverage detected