Skip to content

Commit c10450c

Browse files
committed
Move isFile into util
That allows its use in entry.ts as well.
1 parent c72c53f commit c10450c

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

src/node/entry.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { field, logger } from "@coder/logger"
22
import * as cp from "child_process"
3-
import { promises as fs } from "fs"
43
import http from "http"
54
import * as path from "path"
65
import { CliMessage, OpenCommandPipeArgs } from "../../lib/vscode/src/vs/server/ipc"
@@ -19,7 +18,7 @@ import {
1918
import { coderCloudBind } from "./coder-cloud"
2019
import { commit, version } from "./constants"
2120
import { register } from "./routes"
22-
import { humanPath, open } from "./util"
21+
import { humanPath, isFile, open } from "./util"
2322
import { ipcMain, WrapperProcess } from "./wrapper"
2423

2524
export const runVsCodeCli = (args: DefaultedArgs): void => {
@@ -55,21 +54,12 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
5554
forceNewWindow: args["new-window"],
5655
}
5756

58-
const isDir = async (path: string): Promise<boolean> => {
59-
try {
60-
const st = await fs.stat(path)
61-
return st.isDirectory()
62-
} catch (error) {
63-
return false
64-
}
65-
}
66-
6757
for (let i = 0; i < args._.length; i++) {
6858
const fp = path.resolve(args._[i])
69-
if (await isDir(fp)) {
70-
pipeArgs.folderURIs.push(fp)
71-
} else {
59+
if (await isFile(fp)) {
7260
pipeArgs.fileURIs.push(fp)
61+
} else {
62+
pipeArgs.folderURIs.push(fp)
7363
}
7464
}
7565

src/node/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,12 @@ export function canConnect(path: string): Promise<boolean> {
261261
})
262262
})
263263
}
264+
265+
export const isFile = async (path: string): Promise<boolean> => {
266+
try {
267+
const stat = await fs.stat(path)
268+
return stat.isFile()
269+
} catch (error) {
270+
return false
271+
}
272+
}

src/node/vscode.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { field, logger } from "@coder/logger"
22
import * as cp from "child_process"
3-
import * as fs from "fs-extra"
43
import * as net from "net"
54
import * as path from "path"
65
import * as ipc from "../../lib/vscode/src/vs/server/ipc"
76
import { arrayify, generateUuid } from "../common/util"
87
import { rootPath } from "./constants"
98
import { settings } from "./settings"
9+
import { isFile } from "./util"
1010

1111
export class VscodeProvider {
1212
public readonly serverRootPath: string
@@ -123,15 +123,6 @@ export class VscodeProvider {
123123
private async getFirstPath(
124124
startPaths: Array<{ url?: string | string[] | ipc.Query | ipc.Query[]; workspace?: boolean } | undefined>,
125125
): Promise<ipc.StartPath | undefined> {
126-
const isFile = async (path: string): Promise<boolean> => {
127-
try {
128-
const stat = await fs.stat(path)
129-
return stat.isFile()
130-
} catch (error) {
131-
logger.warn(error.message)
132-
return false
133-
}
134-
}
135126
for (let i = 0; i < startPaths.length; ++i) {
136127
const startPath = startPaths[i]
137128
const url = arrayify(startPath && startPath.url).find((p) => !!p)

0 commit comments

Comments
 (0)