[codex] Make Windows mpv shortcut self-contained (#40)

This commit is contained in:
2026-04-03 21:35:18 -07:00
committed by GitHub
parent d6c72806bb
commit 7514985feb
131 changed files with 3367 additions and 716 deletions

View File

@@ -16,8 +16,15 @@ async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
function makeFakeYtDlpScript(dir: string, payload: string): void {
const scriptPath = path.join(dir, 'yt-dlp');
const script = `#!/usr/bin/env node
const script =
process.platform === 'win32'
? `#!/usr/bin/env bun
process.stdout.write(${JSON.stringify(payload)});
`
: `#!/usr/bin/env sh
cat <<'EOF' | base64 -d
${Buffer.from(payload).toString('base64')}
EOF
`;
fs.writeFileSync(scriptPath, script, 'utf8');
if (process.platform !== 'win32') {
@@ -28,8 +35,15 @@ process.stdout.write(${JSON.stringify(payload)});
function makeHangingFakeYtDlpScript(dir: string): void {
const scriptPath = path.join(dir, 'yt-dlp');
const script = `#!/usr/bin/env node
const script =
process.platform === 'win32'
? `#!/usr/bin/env bun
setInterval(() => {}, 1000);
`
: `#!/usr/bin/env sh
while :; do
sleep 1;
done
`;
fs.writeFileSync(scriptPath, script, 'utf8');
if (process.platform !== 'win32') {
@@ -44,11 +58,19 @@ async function withFakeYtDlp<T>(payload: string, fn: () => Promise<T>): Promise<
fs.mkdirSync(binDir, { recursive: true });
makeFakeYtDlpScript(binDir, payload);
const originalPath = process.env.PATH ?? '';
const originalCommand = process.env.SUBMINER_YTDLP_BIN;
process.env.PATH = `${binDir}${path.delimiter}${originalPath}`;
process.env.SUBMINER_YTDLP_BIN =
process.platform === 'win32' ? path.join(binDir, 'yt-dlp.cmd') : path.join(binDir, 'yt-dlp');
try {
return await fn();
} finally {
process.env.PATH = originalPath;
if (originalCommand === undefined) {
delete process.env.SUBMINER_YTDLP_BIN;
} else {
process.env.SUBMINER_YTDLP_BIN = originalCommand;
}
}
});
}
@@ -59,11 +81,19 @@ async function withHangingFakeYtDlp<T>(fn: () => Promise<T>): Promise<T> {
fs.mkdirSync(binDir, { recursive: true });
makeHangingFakeYtDlpScript(binDir);
const originalPath = process.env.PATH ?? '';
const originalCommand = process.env.SUBMINER_YTDLP_BIN;
process.env.PATH = `${binDir}${path.delimiter}${originalPath}`;
process.env.SUBMINER_YTDLP_BIN =
process.platform === 'win32' ? path.join(binDir, 'yt-dlp.cmd') : path.join(binDir, 'yt-dlp');
try {
return await fn();
} finally {
process.env.PATH = originalPath;
if (originalCommand === undefined) {
delete process.env.SUBMINER_YTDLP_BIN;
} else {
process.env.SUBMINER_YTDLP_BIN = originalCommand;
}
}
});
}