Skip to content

Commit

Permalink
Update findAvailablePort to use inquirer
Browse files Browse the repository at this point in the history
Prompt's dependency winston is causing a warning in the console:

> (node:15613) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency

This has been raised as an issue on prompt's GitHub repo [1] but given the last release of prompt was 4 years ago, I think it makes sense to move away to an alternative that's actively maintained.

[1]: flatiron/prompt#199
  • Loading branch information
36degrees committed May 26, 2020
1 parent fbea30c commit 3595a27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
23 changes: 7 additions & 16 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getKeypath = require('keypather/get')
const marked = require('marked')
const path = require('path')
const portScanner = require('portscanner')
const prompt = require('prompt')
const inquirer = require('inquirer')
const request = require('sync-request')

// Local dependencies
Expand Down Expand Up @@ -86,23 +86,14 @@ exports.findAvailablePort = function (app, callback) {
} else {
// Port in use - offer to change to available port
console.error('ERROR: Port ' + port + ' in use - you may have another prototype running.\n')
// Set up prompt settings
prompt.colors = false
prompt.start()
prompt.message = ''
prompt.delimiter = ''

// Ask user if they want to change port
prompt.get([{
name: 'answer',
description: 'Change to an available port? (y/n)',
required: true,
type: 'string',
pattern: /y(es)?|no?/i,
message: 'Please enter y or n'
}], function (err, result) {
if (err) { throw err }
if (result.answer.match(/y(es)?/i)) {
inquirer.prompt([{
name: 'changePort',
message: 'Change to an available port?',
type: 'confirm'
}]).then(answers => {
if (answers.changePort) {
// User answers yes
port = availablePort
fs.writeFileSync(path.join(__dirname, '/../.port.tmp'), port)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"gulp-nodemon": "^2.5.0",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.0",
"inquirer": "^7.1.0",
"keypather": "^3.0.0",
"marked": "^0.8.2",
"notifications-node-client": "^4.7.2",
Expand Down

0 comments on commit 3595a27

Please sign in to comment.