chore: linting

This commit is contained in:
zhom
2026-08-01 02:07:17 +04:00
parent b2a80c53e9
commit dcb0442b1c
2 changed files with 48 additions and 13 deletions
+24 -13
View File
@@ -72,25 +72,36 @@ export function xrayDownloadUrl(assetName) {
return `https://github.com/XTLS/Xray-core/releases/download/${XRAY_VERSION}/${assetName}`;
}
// `powershell -Command "<script>" a b` appends the trailing values to the
// command text rather than binding them to $args, so the script ran with a
// null -LiteralPath. Handing the paths over as environment variables binds
// them for real and sidesteps quoting of Windows paths and spaces.
export function windowsExtractionInvocation(archive, destinationDir) {
return {
args: [
"-NoProfile",
"-NonInteractive",
"-Command",
"Expand-Archive -LiteralPath $env:DONUT_XRAY_ARCHIVE -DestinationPath $env:DONUT_XRAY_DESTINATION -Force",
],
env: {
...process.env,
DONUT_XRAY_ARCHIVE: archive,
DONUT_XRAY_DESTINATION: destinationDir,
},
};
}
function extractArchive(archive, destinationDir, windowsTarget) {
if (windowsTarget) {
const result = spawnSync(
"powershell",
[
"-NoProfile",
"-NonInteractive",
"-Command",
"Expand-Archive -LiteralPath $args[0] -DestinationPath $args[1] -Force",
archive,
destinationDir,
],
{ stdio: "inherit" },
);
const { args, env } = windowsExtractionInvocation(archive, destinationDir);
const result = spawnSync("powershell", args, { stdio: "inherit", env });
if (result.status !== 0) {
throw new Error("Failed to extract the Xray-core archive");
}
// Upstream ships these lowercase inside Xray-windows-64.zip.
return {
binary: join(destinationDir, "Xray.exe"),
binary: join(destinationDir, "xray.exe"),
license: join(destinationDir, "LICENSE"),
};
}
+24
View File
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
import test from "node:test";
import {
downloadXray,
windowsExtractionInvocation,
XRAY_ASSETS,
XRAY_LICENSE_FILE,
XRAY_SOURCE_URL,
@@ -92,6 +93,29 @@ test("bundles the upstream license in Tauri and portable releases", async () =>
}
});
test("binds Windows extraction paths that PowerShell can actually read", () => {
const { args, env } = windowsExtractionInvocation(
"C:\\Users\\runner\\AppData\\Local\\Temp\\donut xray\\Xray-windows-64.zip",
"C:\\Users\\runner\\AppData\\Local\\Temp\\donut xray",
);
// `powershell -Command "<script>" a b` folds the trailing values into the
// command text instead of populating $args, which left -LiteralPath null.
const script = args.at(-1);
assert.equal(args.at(-2), "-Command");
assert.doesNotMatch(script, /\$args/);
assert.match(script, /-LiteralPath \$env:DONUT_XRAY_ARCHIVE\b/);
assert.match(script, /-DestinationPath \$env:DONUT_XRAY_DESTINATION\b/);
assert.equal(
env.DONUT_XRAY_ARCHIVE,
"C:\\Users\\runner\\AppData\\Local\\Temp\\donut xray\\Xray-windows-64.zip",
);
assert.equal(
env.DONUT_XRAY_DESTINATION,
"C:\\Users\\runner\\AppData\\Local\\Temp\\donut xray",
);
});
test("rejects an unsupported target before downloading", async () => {
await assert.rejects(
downloadXray("riscv64gc-unknown-linux-gnu"),