@@ -275,6 +275,14 @@ class Sandbox extends EventEmitter {
275275 this [ _npm ] = this [ _test ] . mock ( '../../lib/npm.js' , this [ _mocks ] )
276276 this [ _npm ] . output = ( ...args ) => this [ _output ] . push ( args )
277277 await this [ _npm ] . load ( )
278+ // in some node versions (later 10.x) our executionAsyncId at this point
279+ // will for some reason appear to have been triggered by a different parent
280+ // so immediately after load, if we can see that we lost our ancestry, we
281+ // fix it here with a hammer
282+ if ( chain . get ( executionAsyncId ( ) ) !== this [ _parent ] ) {
283+ chain . set ( executionAsyncId ( ) , this [ _parent ] )
284+ process = this [ _proxy ]
285+ }
278286
279287 const cmd = this [ _npm ] . argv . shift ( )
280288 const impl = this [ _npm ] . commands [ cmd ]
@@ -325,6 +333,14 @@ class Sandbox extends EventEmitter {
325333 this [ _npm ] = this [ _test ] . mock ( '../../lib/npm.js' , this [ _mocks ] )
326334 this [ _npm ] . output = ( ...args ) => this [ _output ] . push ( args )
327335 await this [ _npm ] . load ( )
336+ // in some node versions (later 10.x) our executionAsyncId at this point
337+ // will for some reason appear to have been triggered by a different parent
338+ // so immediately after load, if we can see that we lost our ancestry, we
339+ // fix it here with a hammer
340+ if ( chain . get ( executionAsyncId ( ) ) !== this [ _parent ] ) {
341+ chain . set ( executionAsyncId ( ) , this [ _parent ] )
342+ process = this [ _proxy ]
343+ }
328344
329345 const impl = this [ _npm ] . commands [ command ]
330346 if ( ! impl ) {
0 commit comments