diff --git a/cli/deno.lock b/cli/deno.lock index 8ad2b287d3..365b7d0e79 100644 --- a/cli/deno.lock +++ b/cli/deno.lock @@ -64,6 +64,8 @@ "npm:es-main": "npm:es-main@1.3.0", "npm:esbuild": "npm:esbuild@0.23.0", "npm:express": "npm:express@4.19.2", + "npm:get-port": "npm:get-port@7.1.0", + "npm:get-port@7.1.0": "npm:get-port@7.1.0", "npm:gitignore-parser": "npm:gitignore-parser@0.0.2", "npm:jszip@3.7.1": "npm:jszip@3.7.1", "npm:minimatch": "npm:minimatch@10.0.1", @@ -656,6 +658,10 @@ "hasown": "hasown@2.0.2" } }, + "get-port@7.1.0": { + "integrity": "sha512-QB9NKEeDg3xxVwCCwJQ9+xycaz6pBB6iQ76wiWMl1927n0Kir6alPiP+yuiICLLU4jpMe08dXfpebuQppFA2zw==", + "dependencies": {} + }, "gitignore-parser@0.0.2": { "integrity": "sha512-X6mpqUv59uWLGD4n3hZ8Cu8KbF2PMWPSFYmxZjdkpm3yOU7hSUYnzTkZI1mcWqchphvqyuz3/BhgBR4E/JtkCg==", "dependencies": {} diff --git a/cli/deps.ts b/cli/deps.ts index eaa6d46cc4..fc862a65fd 100644 --- a/cli/deps.ts +++ b/cli/deps.ts @@ -19,7 +19,6 @@ export { ensureDir } from "jsr:@std/fs"; export { SEPARATOR as SEP } from "jsr:@std/path"; export * as path from "jsr:@std/path/"; export { encodeHex } from "jsr:@std/encoding"; -export { getAvailablePort } from "jsr:@std/net"; export { writeAllSync } from "jsr:@std/io/write-all"; export { copy } from "jsr:@std/io/copy"; export { readAll } from "jsr:@std/io/read-all"; @@ -36,6 +35,6 @@ export { default as JSZip } from "npm:jszip@3.7.1"; export * as express from "npm:express"; export * as http from "node:http"; export { WebSocketServer, WebSocket } from "npm:ws"; - +export * as getPort from "npm:get-port@7.1.0"; export * as open from "npm:open"; export * as esMain from "npm:es-main"; diff --git a/cli/dev.ts b/cli/dev.ts index 62c7a8e55f..d9dc1ab3f8 100644 --- a/cli/dev.ts +++ b/cli/dev.ts @@ -3,7 +3,7 @@ import { SEP, WebSocketServer, express, - getAvailablePort, + getPort, http, log, open, @@ -81,7 +81,7 @@ async function dev(opts: GlobalOptions & SyncOptions) { } async function startApp() { - const app = express(); + const app = express.default(); const server = http.createServer(app); const wss = new WebSocketServer({ server }); @@ -117,7 +117,7 @@ async function dev(opts: GlobalOptions & SyncOptions) { }); // Start the server - const port = await getAvailablePort({ preferredPort: 3001 }); + const port = await getPort.default({ port: 3001 }); const url = `${workspace.remote}scripts/dev?workspace=${workspace.workspaceId}&local=true` + (port === PORT ? "" : `&port=${port}`); diff --git a/cli/login.ts b/cli/login.ts index ce7613b31c..0d9d65a578 100644 --- a/cli/login.ts +++ b/cli/login.ts @@ -1,5 +1,5 @@ import { GlobalOptions } from "./types.ts"; -import { colors, getAvailablePort, log, open, Secret, Select } from "./deps.ts"; +import { colors, getPort, log, open, Secret, Select } from "./deps.ts"; import * as http from "node:http"; export async function loginInteractive(remote: string) { @@ -45,8 +45,12 @@ export async function tryGetLoginInfo( export async function browserLogin( baseUrl: string ): Promise { - const env = Deno.env.get("TOKEN_PORT"); - const port = env ? Number(env) : await getAvailablePort(); + const env = + Deno.env.get("TOKEN_PORT") != undefined + ? parseInt(Deno.env.get("TOKEN_PORT")!) + : undefined; + const port = await getPort.default({ port: env }); + if (port == undefined) { log.info(colors.red.underline("failed to aquire port")); return undefined;