Remove dead code: unused shell env injection functions
Remove injectEnvIntoShellCommand, shellEscapePosix, shellEscapeWindowsSetValue, ENV_KEY_PATTERN, and the now-unused isWindowsPlatform import. These were leftover from an earlier approach where env vars were injected into the shell command string, replaced by passing env directly to terminal.open.
This commit is contained in:
1 parent
e31fcbdf26
commit
d169cfd54d
1 file changed
-34
@@ -1,10 +1,7 @@
|
||||
import type { ProjectScript } from "@t3tools/contracts";
|
||||
|
||||
import { isWindowsPlatform } from "./lib/utils";
|
||||
|
||||
const SCRIPT_RUN_COMMAND_PATTERN = /^script\.([a-z0-9][a-z0-9-]*)\.run$/;
|
||||
const MAX_SCRIPT_ID_LENGTH = 64;
|
||||
const ENV_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
||||
|
||||
function normalizeScriptId(value: string): string {
|
||||
const cleaned = value
|
||||
@@ -52,37 +49,6 @@ export function nextProjectScriptId(name: string, existingIds: Iterable<string>)
|
||||
return `${baseId}-${Date.now()}`.slice(0, MAX_SCRIPT_ID_LENGTH);
|
||||
}
|
||||
|
||||
function shellEscapePosix(value: string): string {
|
||||
return `'${value.replace(/'/g, `'\\''`)}'`;
|
||||
}
|
||||
|
||||
function shellEscapeWindowsSetValue(value: string): string {
|
||||
return value.replace(/\^/g, "^^").replace(/%/g, "^%").replace(/"/g, '""');
|
||||
}
|
||||
|
||||
function injectEnvIntoShellCommand(
|
||||
command: string,
|
||||
env: Record<string, string>,
|
||||
platform = typeof navigator === "undefined" ? "" : navigator.platform,
|
||||
): string {
|
||||
const entries = Object.entries(env).filter(
|
||||
([key, value]) => ENV_KEY_PATTERN.test(key) && value.length > 0,
|
||||
);
|
||||
if (entries.length === 0) {
|
||||
return command;
|
||||
}
|
||||
|
||||
if (isWindowsPlatform(platform)) {
|
||||
const prefixes = entries.map(
|
||||
([key, value]) => `set "${key}=${shellEscapeWindowsSetValue(value)}"`,
|
||||
);
|
||||
return `${prefixes.join(" && ")} && ${command}`;
|
||||
}
|
||||
|
||||
const assignments = entries.map(([key, value]) => `${key}=${shellEscapePosix(value)}`).join(" ");
|
||||
return `env ${assignments} ${command}`;
|
||||
}
|
||||
|
||||
interface ProjectScriptRuntimeEnvInput {
|
||||
project: {
|
||||
cwd: string;
|
||||
|
||||
Reference in new issue
Block a user