(
environment: BuildEnvironment,
hook?: Plugin[HookName]
)
| 217 | } |
| 218 | |
| 219 | function wrapEnvironmentHook<HookName extends keyof Plugin>( |
| 220 | environment: BuildEnvironment, |
| 221 | hook?: Plugin[HookName] |
| 222 | ): Plugin[HookName] { |
| 223 | if (!hook) { |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | const fn = getHookHandler(hook); |
| 228 | if (typeof fn !== 'function') { |
| 229 | return hook; |
| 230 | } |
| 231 | |
| 232 | const handler: Plugin[HookName] = function (this: PluginContext, ...args: any[]) { |
| 233 | return fn.call(injectEnvironmentInContext(this, environment), ...args); |
| 234 | }; |
| 235 | |
| 236 | if ('handler' in hook) { |
| 237 | return { |
| 238 | ...hook, |
| 239 | handler |
| 240 | } as Plugin[HookName]; |
| 241 | } |
| 242 | return handler; |
| 243 | } |
| 244 | |
| 245 | function injectEnvironmentInContext<Context extends MinimalPluginContext>( |
| 246 | context: Context, |
no test coverage detected