mirror of
https://github.com/coder/code-server.git
synced 2025-09-18 18:57:50 +08:00
fix: invalid ESM module path on Windows (#7162)
This commit is contained in:
@ -9,6 +9,7 @@ import { commit, version, vsRootPath } from "./constants"
|
|||||||
import { register } from "./routes"
|
import { register } from "./routes"
|
||||||
import { VSCodeModule } from "./routes/vscode"
|
import { VSCodeModule } from "./routes/vscode"
|
||||||
import { isDirectory, open } from "./util"
|
import { isDirectory, open } from "./util"
|
||||||
|
import * as os from "os"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the user passed an extension-related VS Code flag.
|
* Return true if the user passed an extension-related VS Code flag.
|
||||||
@ -51,7 +52,11 @@ export const runCodeCli = async (args: DefaultedArgs): Promise<void> => {
|
|||||||
try {
|
try {
|
||||||
// See vscode.loadVSCode for more on this jank.
|
// See vscode.loadVSCode for more on this jank.
|
||||||
process.env.CODE_SERVER_PARENT_PID = process.pid.toString()
|
process.env.CODE_SERVER_PARENT_PID = process.pid.toString()
|
||||||
const modPath = path.join(vsRootPath, "out/server-main.js")
|
let modPath = path.join(vsRootPath, "out/server-main.js")
|
||||||
|
if (os.platform() === "win32") {
|
||||||
|
// On Windows, absolute paths of ESM modules must be a valid file URI.
|
||||||
|
modPath = "file:///" + modPath.replace(/\\/g, "/")
|
||||||
|
}
|
||||||
const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
|
const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
|
||||||
const serverModule = await mod.loadCodeWithNls()
|
const serverModule = await mod.loadCodeWithNls()
|
||||||
await serverModule.spawnCli(await toCodeArgs(args))
|
await serverModule.spawnCli(await toCodeArgs(args))
|
||||||
|
@ -5,6 +5,7 @@ import { promises as fs } from "fs"
|
|||||||
import * as http from "http"
|
import * as http from "http"
|
||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
|
import * as os from "os"
|
||||||
import { WebsocketRequest } from "../../../typings/pluginapi"
|
import { WebsocketRequest } from "../../../typings/pluginapi"
|
||||||
import { logError } from "../../common/util"
|
import { logError } from "../../common/util"
|
||||||
import { CodeArgs, toCodeArgs } from "../cli"
|
import { CodeArgs, toCodeArgs } from "../cli"
|
||||||
@ -58,7 +59,11 @@ async function loadVSCode(req: express.Request): Promise<IVSCodeServerAPI> {
|
|||||||
// which will also require that we switch to ESM, since a hybrid approach
|
// which will also require that we switch to ESM, since a hybrid approach
|
||||||
// breaks importing `rotating-file-stream` for some reason. To work around
|
// breaks importing `rotating-file-stream` for some reason. To work around
|
||||||
// this, use `eval` for now, but we should consider switching to ESM.
|
// this, use `eval` for now, but we should consider switching to ESM.
|
||||||
const modPath = path.join(vsRootPath, "out/server-main.js")
|
let modPath = path.join(vsRootPath, "out/server-main.js")
|
||||||
|
if (os.platform() === "win32") {
|
||||||
|
// On Windows, absolute paths of ESM modules must be a valid file URI.
|
||||||
|
modPath = "file:///" + modPath.replace(/\\/g, "/")
|
||||||
|
}
|
||||||
const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
|
const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
|
||||||
const serverModule = await mod.loadCodeWithNls()
|
const serverModule = await mod.loadCodeWithNls()
|
||||||
return serverModule.createServer(null, {
|
return serverModule.createServer(null, {
|
||||||
|
Reference in New Issue
Block a user