#!/usr/bin/env node

let didSend = false;

// Node 0.10 does not have 'beforeExit'
// process.send is synchronous on 0.10 and 0.12
process.on('exit', function sendCovereageOnExit() {
  if (!didSend) {
    didSend = true;
    process.send({coverage: global.__coverage__});
  }
});

// process.send takes a callback on Node 4+ and should be called in beforeExit
// process.send will schedule more work, so we check to only send once
process.on('beforeExit', function sendCovereageOnBeforeExit() {
  if (!didSend) {
    didSend = true;
    process.send({coverage: global.__coverage__});
  }
});

@@ -40,246 +40,8 @@
 e;%0A%0A
-// Node 0.10 does not have 'beforeExit'%0A// process.send is synchronous on 0.10 and 0.12%0Aprocess.on('exit', function sendCovereageOnExit() %7B%0A  if (!didSend) %7B%0A    didSend = true;%0A    process.send(%7Bcoverage: global.__coverage__%7D);%0A  %7D%0A%7D);%0A%0A
 // p

Drop exit handler used by node versions <4