@@ -158,9 +158,9 @@ export class ModulePluginWrapper implements PluginWrapper {
158158 const plugin = this . getPluginExportedValue ( ) ;
159159 // Get a list of supported patches. This is the subset of objects in the
160160 // plugin exported value with matching file/version fields.
161- const supportedPatches : Array <
162- Partial < Monkeypatch < T > & Intercept < T > >
163- > = plugin . filter (
161+ const supportedPatches : Array < Partial <
162+ Monkeypatch < T > & Intercept < T >
163+ > > = plugin . filter (
164164 patch =>
165165 semver . satisfies ( version , patch . versions || '*' ) &&
166166 ( file === patch . file || ( ! file && ! patch . file ) )
@@ -172,43 +172,40 @@ export class ModulePluginWrapper implements PluginWrapper {
172172 }
173173
174174 // Apply each patch object.
175- return supportedPatches . reduce < T > (
176- ( exportedValue , patch ) => {
177- // TODO(kjin): The only benefit of creating a new StackdriverTracer object
178- // per patched file is to give us granularity in log messages. See if we
179- // can refactor the StackdriverTracer class to avoid this.
180-
181- this . logger . info (
182- `PluginWrapper#applyPlugin: [${ logString } ] Applying plugin.`
183- ) ;
184- if ( patch . patch ) {
185- patch . patch ( exportedValue , this . createTraceAgentInstance ( logString ) ) ;
186- // Queue a function to run if the plugin gets disabled.
187- if ( patch . unpatch ) {
188- const unpatch = patch . unpatch ;
189- this . unpatchFns . push ( ( ) => {
190- this . logger . info (
191- `PluginWrapper#unapplyAll: [${ logString } ] Unpatching file.`
192- ) ;
193- unpatch ( exportedValue ) ;
194- } ) ;
195- }
196- // The patch object should only have either patch() or intercept().
197- if ( patch . intercept ) {
198- this . logger . warn (
199- `PluginWrapper#applyPlugin: [${ logString } ] Patch object has both patch() and intercept() for this file. Only applying patch().`
175+ return supportedPatches . reduce < T > ( ( exportedValue , patch ) => {
176+ // TODO(kjin): The only benefit of creating a new StackdriverTracer object
177+ // per patched file is to give us granularity in log messages. See if we
178+ // can refactor the StackdriverTracer class to avoid this.
179+
180+ this . logger . info (
181+ `PluginWrapper#applyPlugin: [${ logString } ] Applying plugin.`
182+ ) ;
183+ if ( patch . patch ) {
184+ patch . patch ( exportedValue , this . createTraceAgentInstance ( logString ) ) ;
185+ // Queue a function to run if the plugin gets disabled.
186+ if ( patch . unpatch ) {
187+ const unpatch = patch . unpatch ;
188+ this . unpatchFns . push ( ( ) => {
189+ this . logger . info (
190+ `PluginWrapper#unapplyAll: [${ logString } ] Unpatching file.`
200191 ) ;
201- }
202- } else if ( patch . intercept ) {
203- exportedValue = patch . intercept (
204- exportedValue ,
205- this . createTraceAgentInstance ( file )
192+ unpatch ( exportedValue ) ;
193+ } ) ;
194+ }
195+ // The patch object should only have either patch() or intercept().
196+ if ( patch . intercept ) {
197+ this . logger . warn (
198+ `PluginWrapper#applyPlugin: [${ logString } ] Patch object has both patch() and intercept() for this file. Only applying patch().`
206199 ) ;
207200 }
208- return exportedValue ;
209- } ,
210- moduleExports as T
211- ) ;
201+ } else if ( patch . intercept ) {
202+ exportedValue = patch . intercept (
203+ exportedValue ,
204+ this . createTraceAgentInstance ( file )
205+ ) ;
206+ }
207+ return exportedValue ;
208+ } , moduleExports as T ) ;
212209 }
213210
214211 // Helper function to get the cached plugin value if it wasn't loaded yet.
0 commit comments