Skip to content

Commit

Permalink
Potential cloudflare support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlemTuzlak committed Nov 23, 2024
1 parent 6357263 commit 7f1966d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/vite/editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { exec } from "node:child_process"
import fs from "node:fs"
import path from "node:path"
import { normalizePath } from "vite"
import { checkPath } from "./utils.js"

Expand All @@ -25,30 +22,32 @@ export type EditorConfig = {

export const DEFAULT_EDITOR_CONFIG: EditorConfig = {
name: "VSCode",
open: (path, lineNumber) => {
open: async (path, lineNumber) => {
const { exec } = await import("node:child_process")
exec(`code -g "${normalizePath(path).replaceAll("$", "\\$")}${lineNumber ? `:${lineNumber}` : ""}"`)
},
}

export const handleOpenSource = ({
export const handleOpenSource = async ({
data,
openInEditor,
appDir,
}: {
data: OpenSourceData
appDir: string
openInEditor: (path: string, lineNum: string | undefined) => void
openInEditor: (path: string, lineNum: string | undefined) => Promise<void>
}) => {
const { source, line, routeID } = data.data
const lineNum = line ? `${line}` : undefined

const fs = await import("node:fs")
const path = await import("node:path")
if (source) {
return openInEditor(source, lineNum)
}

if (routeID) {
const routePath = path.join(appDir, routeID)
const checkedPath = checkPath(routePath)
const checkedPath = await checkPath(routePath)

if (!checkedPath) return
const { type, validPath } = checkedPath
Expand Down
2 changes: 1 addition & 1 deletion src/vite/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
)
})
const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG
const openInEditor = (path: string | undefined, lineNum: string | undefined) => {
const openInEditor = async (path: string | undefined, lineNum: string | undefined) => {
if (!path) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/vite/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from "node:fs"
import type { IncomingMessage, ServerResponse } from "node:http"
import type { Connect } from "vite"

Expand Down Expand Up @@ -49,7 +48,8 @@ export const handleDevToolsViteRequest = (
})
}

export function checkPath(routePath: string, extensions = [".tsx", ".jsx", ".ts", ".js"]) {
export async function checkPath(routePath: string, extensions = [".tsx", ".jsx", ".ts", ".js"]) {
const fs = await import("node:fs")
// Check if the path exists as a directory
if (fs.existsSync(routePath) && fs.lstatSync(routePath).isDirectory()) {
return { validPath: routePath, type: "directory" } as const
Expand Down

0 comments on commit 7f1966d

Please sign in to comment.