From 602f7ee515ebe46a4e1e056992bfab6541c6bfba Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 30 Dec 2021 10:16:00 +0900 Subject: [PATCH] fix: skip installing the package, when there is no `package.json` --- lib/main.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c0f4253..d600fea 100644 --- a/lib/main.js +++ b/lib/main.js @@ -429,6 +429,11 @@ Emulate only the body of the API Gateway event. } _packageInstall (program, codeDirectory) { + if (!fs.existsSync(path.join(codeDirectory, 'package.json'))) { + console.log('Skip the installation of the package. (Because package.json is not found.)') + return + } + // Run on windows: // https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows @@ -729,7 +734,9 @@ they may not work as expected in the Lambda environment. if (!program.keepNodeModules) { console.log('=> Running package install') const usedPackageManager = await this._packageInstall(program, codeDirectory) - console.log(`(Package manager used was '${usedPackageManager}'.)`) + if (usedPackageManager) { + console.log(`(Package manager used was '${usedPackageManager}'.)`) + } } await this._postInstallScript(program, codeDirectory) console.log('=> Zipping deployment package')