diff --git a/src/node/entry.ts b/src/node/entry.ts index df218a52..82e04f5d 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -1,6 +1,5 @@ import { field, logger } from "@coder/logger" import * as cp from "child_process" -import { promises as fs } from "fs" import http from "http" import * as path from "path" import { CliMessage, OpenCommandPipeArgs } from "../../lib/vscode/src/vs/server/ipc" @@ -19,7 +18,7 @@ import { import { coderCloudBind } from "./coder-cloud" import { commit, version } from "./constants" import { register } from "./routes" -import { humanPath, open } from "./util" +import { humanPath, isFile, open } from "./util" import { ipcMain, WrapperProcess } from "./wrapper" export const runVsCodeCli = (args: DefaultedArgs): void => { @@ -55,21 +54,12 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st forceNewWindow: args["new-window"], } - const isDir = async (path: string): Promise => { - try { - const st = await fs.stat(path) - return st.isDirectory() - } catch (error) { - return false - } - } - for (let i = 0; i < args._.length; i++) { const fp = path.resolve(args._[i]) - if (await isDir(fp)) { - pipeArgs.folderURIs.push(fp) - } else { + if (await isFile(fp)) { pipeArgs.fileURIs.push(fp) + } else { + pipeArgs.folderURIs.push(fp) } } diff --git a/src/node/util.ts b/src/node/util.ts index 75122fe7..349c8edf 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -261,3 +261,12 @@ export function canConnect(path: string): Promise { }) }) } + +export const isFile = async (path: string): Promise => { + try { + const stat = await fs.stat(path) + return stat.isFile() + } catch (error) { + return false + } +} diff --git a/src/node/vscode.ts b/src/node/vscode.ts index 9d935e66..6e050de2 100644 --- a/src/node/vscode.ts +++ b/src/node/vscode.ts @@ -1,12 +1,12 @@ import { field, logger } from "@coder/logger" import * as cp from "child_process" -import * as fs from "fs-extra" import * as net from "net" import * as path from "path" import * as ipc from "../../lib/vscode/src/vs/server/ipc" import { arrayify, generateUuid } from "../common/util" import { rootPath } from "./constants" import { settings } from "./settings" +import { isFile } from "./util" export class VscodeProvider { public readonly serverRootPath: string @@ -123,15 +123,6 @@ export class VscodeProvider { private async getFirstPath( startPaths: Array<{ url?: string | string[] | ipc.Query | ipc.Query[]; workspace?: boolean } | undefined>, ): Promise { - const isFile = async (path: string): Promise => { - try { - const stat = await fs.stat(path) - return stat.isFile() - } catch (error) { - logger.warn(error.message) - return false - } - } for (let i = 0; i < startPaths.length; ++i) { const startPath = startPaths[i] const url = arrayify(startPath && startPath.url).find((p) => !!p)