From 0d3d11e26c5f1f14588006841453ac7146ead0ad Mon Sep 17 00:00:00 2001 From: Rick Brown Date: Fri, 2 Oct 2020 03:50:20 +1000 Subject: [PATCH] fix: handle case when not running in a nodejs module dir (#284) --- src/utils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils.js b/src/utils.js index 3891a00a..e2da4903 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,7 @@ const la = require('lazy-ass') const is = require('check-more-types') const { join } = require('path') +const { existsSync } = require('fs') /** * Returns parsed command line arguments. @@ -82,6 +83,9 @@ const isPackageScriptName = command => { la(is.unemptyString(command), 'expected command name string', command) const packageFilename = join(process.cwd(), 'package.json') + if (!existsSync(packageFilename)) { + return false + } const packageJson = require(packageFilename) if (!packageJson.scripts) { return false