Skip to content

Commit

Permalink
chore(gatsby): Convert detect-port-in-use-and-prompt to typescript (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mottox2 authored Mar 8, 2020
1 parent a14e675 commit eda7385
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { slash } from "gatsby-core-utils"
import { initTracer } from "../utils/tracer"
import apiRunnerNode from "../utils/api-runner-node"
import db from "../db"
import detectPortInUseAndPrompt from "../utils/detect-port-in-use-and-prompt"
import { detectPortInUseAndPrompt } from "../utils/detect-port-in-use-and-prompt"
import onExit from "signal-exit"
import queryUtil from "../query"
import queryWatcher from "../query/query-watcher"
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const report = require(`gatsby-cli/lib/reporter`)

const telemetry = require(`gatsby-telemetry`)

const detectPortInUseAndPrompt = require(`../utils/detect-port-in-use-and-prompt`)
const {
detectPortInUseAndPrompt,
} = require(`../utils/detect-port-in-use-and-prompt`)
const getConfigFile = require(`../bootstrap/get-config-file`)
const preferDefault = require(`../bootstrap/prefer-default`)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const detectPort = require(`detect-port`)
const report = require(`gatsby-cli/lib/reporter`)
const prompts = require(`prompts`)
import detectPort from "detect-port"
import report from "gatsby-cli/lib/reporter"
import prompts from "prompts"

const detectPortInUseAndPrompt = async port => {
export const detectPortInUseAndPrompt = async (
port: number
): Promise<number> => {
let foundPort = port
const detectedPort = await detectPort(port).catch(err => report.panic(err))
const detectedPort = await detectPort(port).catch((err: Error) =>
report.panic(err)
)
if (port !== detectedPort) {
report.log(`\nSomething is already running at port ${port}`)
const response = await prompts({
Expand All @@ -22,5 +26,3 @@ const detectPortInUseAndPrompt = async port => {

return foundPort
}

module.exports = detectPortInUseAndPrompt

0 comments on commit eda7385

Please sign in to comment.