mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Always override PATH when syncing from shell (#4132)
This commit is contained in:
parent
3522485c6f
commit
a71a6dcaff
@ -22,10 +22,8 @@
|
|||||||
import { shellEnv } from "./utils/shell-env";
|
import { shellEnv } from "./utils/shell-env";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
import logger from "./logger";
|
||||||
interface Env {
|
import { isSnap } from "../common/vars";
|
||||||
[key: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shellSync loads what would have been the environment if this application was
|
* shellSync loads what would have been the environment if this application was
|
||||||
@ -33,12 +31,7 @@ interface Env {
|
|||||||
* useful on macos where this always needs to be done.
|
* useful on macos where this always needs to be done.
|
||||||
*/
|
*/
|
||||||
export async function shellSync() {
|
export async function shellSync() {
|
||||||
const { shell } = os.userInfo();
|
const env = await shellEnv(os.userInfo().shell);
|
||||||
let envVars = {};
|
|
||||||
|
|
||||||
envVars = await shellEnv(shell);
|
|
||||||
|
|
||||||
const env: Env = JSON.parse(JSON.stringify(envVars));
|
|
||||||
|
|
||||||
if (!env.LANG) {
|
if (!env.LANG) {
|
||||||
// the LANG env var expects an underscore instead of electron's dash
|
// the LANG env var expects an underscore instead of electron's dash
|
||||||
@ -47,9 +40,8 @@ export async function shellSync() {
|
|||||||
env.LANG += ".UTF-8";
|
env.LANG += ".UTF-8";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite PATH on darwin
|
if (!isSnap) {
|
||||||
if (process.env.NODE_ENV === "production" && process.platform === "darwin") {
|
process.env.PATH = env.PATH;
|
||||||
process.env["PATH"] = env.PATH;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The spread operator allows joining of objects. The precedence is last to first.
|
// The spread operator allows joining of objects. The precedence is last to first.
|
||||||
@ -57,4 +49,6 @@ export async function shellSync() {
|
|||||||
...env,
|
...env,
|
||||||
...process.env,
|
...process.env,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
logger.debug(`[SHELL-SYNC]: Synced shell env, and updating`, env, process.env);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,9 +22,7 @@
|
|||||||
import shellEnvironment from "shell-env";
|
import shellEnvironment from "shell-env";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
|
|
||||||
export interface EnvironmentVariables {
|
export type EnvironmentVariables = Record<string, string>;
|
||||||
readonly [key: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let shellSyncFailed = false;
|
let shellSyncFailed = false;
|
||||||
|
|
||||||
@ -40,17 +38,15 @@ let shellSyncFailed = false;
|
|||||||
* returned if the call fails.
|
* returned if the call fails.
|
||||||
*/
|
*/
|
||||||
export async function shellEnv(shell?: string, forceRetry = false) : Promise<EnvironmentVariables> {
|
export async function shellEnv(shell?: string, forceRetry = false) : Promise<EnvironmentVariables> {
|
||||||
let envVars = {};
|
|
||||||
|
|
||||||
if (forceRetry) {
|
if (forceRetry) {
|
||||||
shellSyncFailed = false;
|
shellSyncFailed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shellSyncFailed) {
|
if (!shellSyncFailed) {
|
||||||
try {
|
try {
|
||||||
envVars = await Promise.race([
|
return await Promise.race([
|
||||||
shellEnvironment(shell),
|
shellEnvironment(shell),
|
||||||
new Promise((_resolve, reject) => setTimeout(() => {
|
new Promise<EnvironmentVariables>((_resolve, reject) => setTimeout(() => {
|
||||||
reject(new Error("Resolving shell environment is taking very long. Please review your shell configuration."));
|
reject(new Error("Resolving shell environment is taking very long. Please review your shell configuration."));
|
||||||
}, 30_000)),
|
}, 30_000)),
|
||||||
]);
|
]);
|
||||||
@ -62,5 +58,5 @@ export async function shellEnv(shell?: string, forceRetry = false) : Promise<Env
|
|||||||
logger.error("shellSync(): Resolving shell environment took too long. Please review your shell configuration.");
|
logger.error("shellSync(): Resolving shell environment took too long. Please review your shell configuration.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return envVars;
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user