* 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,
{
runtimeTemplate,
module,
moduleGraph,
chunkGraph,
runtimeRequirements,
runtime
}
)
| 167 | * @returns {void} |
| 168 | */ |
| 169 | apply( |
| 170 | dependency, |
| 171 | source, |
| 172 | { |
| 173 | runtimeTemplate, |
| 174 | module, |
| 175 | moduleGraph, |
| 176 | chunkGraph, |
| 177 | runtimeRequirements, |
| 178 | runtime |
| 179 | } |
| 180 | ) { |
| 181 | const dep = /** @type {ImportDependency} */ (dependency); |
| 182 | const connection = moduleGraph.getConnection(dep); |
| 183 | // Dead branch: module is excluded and has no id; code is never executed. |
| 184 | if (connection && !connection.isTargetActive(runtime)) { |
| 185 | source.replace( |
| 186 | dep.range[0], |
| 187 | dep.range[1] - 1, |
| 188 | "Promise.resolve(/* dead branch */)" |
| 189 | ); |
| 190 | return; |
| 191 | } |
| 192 | const block = /** @type {AsyncDependenciesBlock} */ ( |
| 193 | moduleGraph.getParentBlock(dep) |
| 194 | ); |
| 195 | let content = runtimeTemplate.moduleNamespacePromise({ |
| 196 | chunkGraph, |
| 197 | block, |
| 198 | module: /** @type {Module} */ (moduleGraph.getModule(dep)), |
| 199 | request: dep.request, |
| 200 | strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule, |
| 201 | dependency: dep, |
| 202 | message: "import()", |
| 203 | runtimeRequirements |
| 204 | }); |
| 205 | |
| 206 | // For source phase imports, unwrap the default export |
| 207 | // import.source() should return the source directly, not a namespace |
| 208 | if (ImportPhaseUtils.isSource(dep.phase)) { |
| 209 | content = `${content}.then(${runtimeTemplate.returningFunction( |
| 210 | 'm["default"]', |
| 211 | "m" |
| 212 | )})`; |
| 213 | } |
| 214 | |
| 215 | source.replace(dep.range[0], dep.range[1] - 1, content); |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | module.exports = ImportDependency; |
nothing calls this directly
no test coverage detected