I encountered this type of issue when combining multiple package coverage results in a monorepo. I used @skyboyer and @Alexus answer which worked really well and was nice and clean but the dependabot on GitHub came up with an indirect security vulnerability resulting from istanbul use. Using istanbuljs's nyc replacement for the istanbul CLI I implemented the same functionality. Unfortunately, it's not nearly as clean but here it is...
I had to rename all of the coverage-final.json files to something unique. Noting my output directory is coverage and the reporter used was json…
lerna exec -- 'export WORKING_DIR=$(basename $LERNA_PACKAGE_NAME) && cp ./<output dir>/coverage-final.json ./<output dir>/coverage-final-$(echo $WORKING_DIR).json'
After which I needed to place all of those files into a centralized directory…
mkdir -p ./coverage && lerna exec -- 'export WORKING_DIR=$(basename $LERNA_PACKAGE_NAME) && cp ./<output dir>/coverage-final-$(echo $WORKING_DIR).json ../../coverage/coverage-final-$(echo $WORKING_DIR).json'
This copied the package contents into a root-level directory named coverage. Moving forward, I needed to merge all of the copied results into one json file. For the output directory I used the same coverage directory at the root level…
nyc merge ./coverage ./coverage/coverage-final.json
And, finally, I needed to transform the result to lcov for input into coveralls (my use-case);
nyc report --reporter=lcov --temp-dir=coverage
Hope that helps! :-) Repository containing implementation