From 57565fccaf318890ceae64fc8905c4a2ae675ab7 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Tue, 4 Feb 2025 09:24:08 -0500 Subject: [PATCH] fix: nyc path subtly different with new yarn, require relative to cwd this should be backwards-compatible with the previous lookup style, but also works correctly with new yarn if not, and there is a problem (either with existing users or in the future) it now attempts to print out a helpful message indicating why it failed and where it looked --- jet.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jet.js b/jet.js index 7be0440..23ef856 100755 --- a/jet.js +++ b/jet.js @@ -1,7 +1,16 @@ #!/usr/bin/env node +const fs = require('fs'); + if (process.argv.includes('--coverage') && !process.env.NYC_CONFIG) { - process.argv.unshift(require.resolve('./node_modules/.bin/nyc')); - require('./node_modules/.bin/nyc'); + const nycPath = `${process.cwd()}/node_modules/.bin/nyc`; + if (!fs.existsSync(nycPath)) { + throw Error( + `Jet: '--coverage' requested but cannot find 'nyc'. Did not run from app root? Looked in: '${nycPath}'` + ); + } + + process.argv.unshift(require.resolve(nycPath)); + require(nycPath); } else { require('./lib/commonjs/cli.js'); }