fix(electron): use safe npm invocation on windows
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import path, { join } from "path"
|
import path, { join } from "path"
|
||||||
import { execFileSync } from "child_process"
|
import { spawnSync } from "child_process"
|
||||||
import { fileURLToPath } from "url"
|
import { fileURLToPath } from "url"
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL(".", import.meta.url))
|
const __dirname = fileURLToPath(new URL(".", import.meta.url))
|
||||||
@@ -11,7 +11,8 @@ const workspaceRoot = join(appDir, "..", "..")
|
|||||||
const serverRoot = join(appDir, "..", "server")
|
const serverRoot = join(appDir, "..", "server")
|
||||||
const resourcesRoot = join(appDir, "electron", "resources")
|
const resourcesRoot = join(appDir, "electron", "resources")
|
||||||
const serverDest = join(resourcesRoot, "server")
|
const serverDest = join(resourcesRoot, "server")
|
||||||
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
|
const npmExecPath = process.env.npm_execpath
|
||||||
|
const npmNodeExecPath = process.env.npm_node_execpath
|
||||||
|
|
||||||
const serverSources = ["dist", "public", "node_modules", "package.json"]
|
const serverSources = ["dist", "public", "node_modules", "package.json"]
|
||||||
const serverDepsMarker = join(serverRoot, "node_modules", "fastify", "package.json")
|
const serverDepsMarker = join(serverRoot, "node_modules", "fastify", "package.json")
|
||||||
@@ -34,27 +35,34 @@ function ensureServerDependencies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log("installing production server dependencies")
|
log("installing production server dependencies")
|
||||||
execFileSync(
|
const npmArgs = [
|
||||||
npmCmd,
|
"install",
|
||||||
[
|
"--omit=dev",
|
||||||
"install",
|
"--ignore-scripts",
|
||||||
"--omit=dev",
|
"--workspaces=false",
|
||||||
"--ignore-scripts",
|
"--package-lock=false",
|
||||||
"--workspaces=false",
|
"--install-strategy=shallow",
|
||||||
"--package-lock=false",
|
"--fund=false",
|
||||||
"--install-strategy=shallow",
|
"--audit=false",
|
||||||
"--fund=false",
|
]
|
||||||
"--audit=false",
|
|
||||||
],
|
const env = {
|
||||||
{
|
...process.env,
|
||||||
cwd: serverRoot,
|
PATH: `${join(workspaceRoot, "node_modules", ".bin")}${path.delimiter}${process.env.PATH ?? ""}`,
|
||||||
stdio: "inherit",
|
npm_config_workspaces: "false",
|
||||||
env: {
|
}
|
||||||
...process.env,
|
|
||||||
PATH: `${join(workspaceRoot, "node_modules", ".bin")}${path.delimiter}${process.env.PATH ?? ""}`,
|
const npmCli = npmExecPath && npmNodeExecPath ? [npmNodeExecPath, [npmExecPath, ...npmArgs]] : null
|
||||||
},
|
const result = npmCli
|
||||||
},
|
? spawnSync(npmCli[0], npmCli[1], { cwd: serverRoot, stdio: "inherit", env })
|
||||||
)
|
: spawnSync("npm", npmArgs, { cwd: serverRoot, stdio: "inherit", env, shell: process.platform === "win32" })
|
||||||
|
|
||||||
|
if (result.status !== 0) {
|
||||||
|
if (result.error) {
|
||||||
|
throw result.error
|
||||||
|
}
|
||||||
|
throw new Error(`npm install exited with code ${result.status ?? 1}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyServerArtifacts() {
|
function copyServerArtifacts() {
|
||||||
|
|||||||
Reference in New Issue
Block a user