From 85399480a368e1ca9c4e0967233d49dbef0837f2 Mon Sep 17 00:00:00 2001 From: Kenny Yeo Date: Fri, 24 May 2024 15:14:41 +0000 Subject: [PATCH] fix(packagers): add logs for SLS_DEBUG --- lib/packagers/npm.js | 3 +++ lib/packagers/yarn.js | 3 +++ tests/packagers/npm.test.js | 8 ++++++++ tests/packagers/yarn.test.js | 9 +++++++++ 4 files changed, 23 insertions(+) diff --git a/lib/packagers/npm.js b/lib/packagers/npm.js index 5d657ef20..d8f936ea2 100644 --- a/lib/packagers/npm.js +++ b/lib/packagers/npm.js @@ -90,6 +90,9 @@ class NPM { if (!failed && !_.isEmpty(err.stdout)) { return BbPromise.resolve({ stdout: err.stdout }); } + if (process.env.SLS_DEBUG) { + console.error(`DEBUG: ${err.stdout}\nSTDERR: ${err.stderr}`); + } } return BbPromise.reject(err); diff --git a/lib/packagers/yarn.js b/lib/packagers/yarn.js index 96884e03a..34316c688 100644 --- a/lib/packagers/yarn.js +++ b/lib/packagers/yarn.js @@ -79,6 +79,9 @@ class Yarn { if (!failed && !_.isEmpty(err.stdout)) { return BbPromise.resolve({ stdout: err.stdout }); } + if (process.env.SLS_DEBUG) { + console.error(`DEBUG: ${err.stdout}\nSTDERR: ${err.stderr}`); + } } return BbPromise.reject(err); diff --git a/tests/packagers/npm.test.js b/tests/packagers/npm.test.js index 7aa164d28..669814a56 100644 --- a/tests/packagers/npm.test.js +++ b/tests/packagers/npm.test.js @@ -22,9 +22,17 @@ jest.mock('../../lib/utils', () => { }); describe('npm', () => { + const ENV = process.env; + + beforeAll(() => { + process.env = { ...ENV, SLS_DEBUG: '*' }; + }); beforeEach(() => { fsMock.readFileSync.mockReturnValue(false); }); + afterAll(() => { + process.env = ENV; + }); it('should return "package-lock.json" as lockfile name', () => { expect(npmModule.lockfileName).toEqual('package-lock.json'); diff --git a/tests/packagers/yarn.test.js b/tests/packagers/yarn.test.js index ff1a0dff1..f90bcd907 100644 --- a/tests/packagers/yarn.test.js +++ b/tests/packagers/yarn.test.js @@ -16,6 +16,15 @@ jest.mock('../../lib/utils', () => { }); describe('yarn', () => { + const ENV = process.env; + + beforeAll(() => { + process.env = { ...ENV, SLS_DEBUG: '*' }; + }); + afterAll(() => { + process.env = ENV; + }); + it('should return "yarn.lock" as lockfile name', () => { expect(yarnModule.lockfileName).toEqual('yarn.lock'); });