From d2054f4d901a548296514f2807a85520ec69f34c Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:39:29 +0300 Subject: [PATCH] bin/repl: handle missing should dependency (#1229) Dev dependencies are not available in production environments. --- lib/bin/repl.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/bin/repl.js b/lib/bin/repl.js index 02018d963..92a66009d 100644 --- a/lib/bin/repl.js +++ b/lib/bin/repl.js @@ -7,18 +7,23 @@ // including this file, may be copied, modified, propagated, or distributed // except according to the terms contained in the LICENSE file. -const should = require('should'); // eslint-disable-line import/no-extraneous-dependencies -require('../../test/assertions'); - const _ = require('lodash'); // eslint-disable-line import/no-extraneous-dependencies const { sql } = require('slonik'); const container = require('../util/default-container'); (async () => { - const context = { ..._.omit(container, 'with'), container, should, sql }; - const contextKeys = Object.keys(context).sort(); - console.log('Available vars:', contextKeys.join(', ')); + const context = { ..._.omit(container, 'with'), container, sql }; + const replGlobals = Object.keys(context); + + try { + // should adds itself directly to global scope, so does not need to be added to the context + require('should'); // eslint-disable-line import/no-extraneous-dependencies + require('../../test/assertions'); + replGlobals.push('should'); + } catch (err) { /* skip devDependencies if unavailable */ } + + console.log('Available vars:', replGlobals.sort().join(', ')); const repl = require('repl').start({ useGlobal: true, // enable should.js prototype pollution