Skip to content

Commit

Permalink
bin/repl: handle missing should dependency (#1229)
Browse files Browse the repository at this point in the history
Dev dependencies are not available in production environments.
  • Loading branch information
alxndrsn authored Oct 17, 2024
1 parent dcca981 commit d2054f4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/bin/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2054f4

Please sign in to comment.