mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 07:32:54 +00:00
fix(terminal): complete Windows ConPTY clear handling (#2465)
* fix(terminal): enable ConPTY clear for Mosh and ET * test(terminal): exercise Windows ConPTY spawn options * fix(terminal): align ConPTY clear ABI * fix(terminal): restore patched ConPTY runtime files * fix(terminal): preserve patched ConPTY in packages * test(ui): keep lazy-load comments ASCII-only * fix(terminal): limit patched node-pty rebuild * test(terminal): avoid platform-specific executable stubs
This commit is contained in:
11 files changed
+303
-3
No files matched your search
@@ -20,6 +20,10 @@ const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const crypto = require("node:crypto");
|
||||
const { execFileSync } = require("node:child_process");
|
||||
const {
|
||||
copyPatchedNodePtyToPackagedApp,
|
||||
rebuildPatchedNodePty,
|
||||
} = require("./nodePtyConptyPatch.cjs");
|
||||
|
||||
const LC_UUID = 0x1b;
|
||||
const MH_MAGIC_64 = 0xfeedfacf; // thin 64-bit, little-endian on disk
|
||||
@@ -299,6 +303,17 @@ async function afterPack(context) {
|
||||
);
|
||||
}
|
||||
|
||||
if (context.electronPlatformName === "win32") {
|
||||
const projectDir = context.packager.appDir || context.packager.projectDir;
|
||||
rebuildPatchedNodePty({ projectDir, platform: "win32", arch: context.arch });
|
||||
copyPatchedNodePtyToPackagedApp({
|
||||
projectDir,
|
||||
resourcesDir: appResourcesDir(context),
|
||||
});
|
||||
console.log("[afterPack] Installed patched node-pty ConPTY runtime into packaged app");
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.electronPlatformName !== "darwin") return;
|
||||
|
||||
const appId = context.packager.appInfo.id || "com.netcatty.app";
|
||||
|
||||
@@ -8,6 +8,10 @@ const {
|
||||
CURSOR_PLATFORM_PACKAGES,
|
||||
ensureCursorSdkPlatformPackages,
|
||||
} = require("./beforePackCursorSdk.cjs");
|
||||
const {
|
||||
copyPatchedNodePtyToPackagedApp,
|
||||
rebuildPatchedNodePty,
|
||||
} = require("./nodePtyConptyPatch.cjs");
|
||||
|
||||
function writeJson(filePath, value) {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
@@ -60,3 +64,93 @@ test("ensureCursorSdkPlatformPackages is a no-op when target packages exist", (t
|
||||
assert.deepEqual(installed, []);
|
||||
assert.deepEqual(calls, []);
|
||||
});
|
||||
|
||||
test("Windows packaging rebuilds patched node-pty from source for the target architecture", () => {
|
||||
const calls = [];
|
||||
const rebuilt = rebuildPatchedNodePty({
|
||||
projectDir: "/workspace/netcatty",
|
||||
platform: "win32",
|
||||
arch: 3,
|
||||
run: (...args) => calls.push(args),
|
||||
exists: () => true,
|
||||
logger: { log() {} },
|
||||
});
|
||||
|
||||
assert.equal(rebuilt, true);
|
||||
assert.equal(calls.length, 2);
|
||||
assert.equal(calls[0][0], process.execPath);
|
||||
assert.deepEqual(calls[0][1], [
|
||||
path.join("/workspace/netcatty", "node_modules", "@electron", "rebuild", "lib", "cli.js"),
|
||||
"--force",
|
||||
"--build-from-source",
|
||||
"--only",
|
||||
"node-pty",
|
||||
"--arch",
|
||||
"arm64",
|
||||
]);
|
||||
assert.equal(calls[0][2].cwd, "/workspace/netcatty");
|
||||
assert.equal(calls[1][0], process.execPath);
|
||||
assert.equal(
|
||||
calls[1][1][0],
|
||||
path.join("/workspace/netcatty", "node_modules", "node-pty", "scripts", "post-install.js"),
|
||||
);
|
||||
assert.equal(calls[1][2].env.npm_config_arch, "arm64");
|
||||
});
|
||||
|
||||
test("Windows packaging fails when rebuilt node-pty runtime files are incomplete", () => {
|
||||
assert.throws(() => rebuildPatchedNodePty({
|
||||
projectDir: "/workspace/netcatty",
|
||||
platform: "win32",
|
||||
arch: 1,
|
||||
run() {},
|
||||
exists: (filePath) => !filePath.endsWith("conpty.dll"),
|
||||
logger: { log() {} },
|
||||
}), /Patched node-pty artifacts missing: .*conpty\.dll/);
|
||||
});
|
||||
|
||||
test("non-Windows packaging keeps the prebuilt node-pty path", () => {
|
||||
const calls = [];
|
||||
const rebuilt = rebuildPatchedNodePty({
|
||||
projectDir: "/workspace/netcatty",
|
||||
platform: "linux",
|
||||
arch: 1,
|
||||
run: (...args) => calls.push(args),
|
||||
logger: { log() {} },
|
||||
});
|
||||
|
||||
assert.equal(rebuilt, false);
|
||||
assert.deepEqual(calls, []);
|
||||
});
|
||||
|
||||
test("Windows afterPack copies rebuilt ConPTY files over packaged prebuilds", () => {
|
||||
const copied = [];
|
||||
const made = [];
|
||||
const destinations = copyPatchedNodePtyToPackagedApp({
|
||||
projectDir: "/workspace/netcatty",
|
||||
resourcesDir: "/workspace/release/resources",
|
||||
copy: (...args) => copied.push(args),
|
||||
mkdir: (...args) => made.push(args),
|
||||
});
|
||||
|
||||
assert.equal(copied.length, 3);
|
||||
assert.equal(made.length, 3);
|
||||
assert.equal(copied[0][0], path.join(
|
||||
"/workspace/netcatty", "node_modules", "node-pty", "build", "Release", "conpty.node",
|
||||
));
|
||||
assert.equal(copied[0][1], path.join(
|
||||
"/workspace/release/resources", "app.asar.unpacked", "node_modules", "node-pty", "build", "Release", "conpty.node",
|
||||
));
|
||||
assert.deepEqual(destinations, copied.map(([, destination]) => destination));
|
||||
});
|
||||
|
||||
test("node-pty patch matches bundled ConPTY clear ABI and preserves the cursor row", () => {
|
||||
const patch = fs.readFileSync(
|
||||
path.join(__dirname, "..", "patches", "node-pty+1.1.0.patch"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
assert.match(patch, /ConptyClearPseudoConsole\(HPCON hPC, BOOL keepCursorRow\)/);
|
||||
assert.match(patch, /PFNCLEARPSEUDOCONSOLE\)\(HPCON hpc, BOOL keepCursorRow\)/);
|
||||
assert.match(patch, /pfnClearPseudoConsole\(handle->hpc, TRUE\)/);
|
||||
assert.doesNotMatch(patch, /node_modules\/node-pty\/build\//);
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { execFileSync } = require("node:child_process");
|
||||
|
||||
const ELECTRON_BUILDER_ARCH = {
|
||||
0: "ia32",
|
||||
1: "x64",
|
||||
2: "armv7l",
|
||||
3: "arm64",
|
||||
4: "universal",
|
||||
};
|
||||
|
||||
function nodePtyArtifacts(projectDir) {
|
||||
const releaseDir = path.join(projectDir, "node_modules", "node-pty", "build", "Release");
|
||||
return [
|
||||
{ source: path.join(releaseDir, "conpty.node"), relative: "conpty.node" },
|
||||
{ source: path.join(releaseDir, "conpty", "conpty.dll"), relative: path.join("conpty", "conpty.dll") },
|
||||
{ source: path.join(releaseDir, "conpty", "OpenConsole.exe"), relative: path.join("conpty", "OpenConsole.exe") },
|
||||
];
|
||||
}
|
||||
|
||||
function rebuildPatchedNodePty({
|
||||
projectDir,
|
||||
platform,
|
||||
arch,
|
||||
run = execFileSync,
|
||||
exists = fs.existsSync,
|
||||
logger = console,
|
||||
}) {
|
||||
if (platform !== "win32") return false;
|
||||
const targetArch = typeof arch === "number" ? ELECTRON_BUILDER_ARCH[arch] : arch;
|
||||
if (!targetArch || targetArch === "universal") {
|
||||
throw new Error(`[nodePtyConptyPatch] Unsupported Windows architecture: ${String(arch)}`);
|
||||
}
|
||||
|
||||
const rebuildCli = path.join(projectDir, "node_modules", "@electron", "rebuild", "lib", "cli.js");
|
||||
logger.log(`[nodePtyConptyPatch] Rebuilding patched node-pty for Windows ${targetArch}`);
|
||||
run(process.execPath, [
|
||||
rebuildCli,
|
||||
"--force",
|
||||
"--build-from-source",
|
||||
"--only",
|
||||
"node-pty",
|
||||
"--arch",
|
||||
targetArch,
|
||||
], {
|
||||
cwd: projectDir,
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
const nodePtyDir = path.join(projectDir, "node_modules", "node-pty");
|
||||
run(process.execPath, [path.join(nodePtyDir, "scripts", "post-install.js")], {
|
||||
cwd: projectDir,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, npm_config_arch: targetArch },
|
||||
});
|
||||
|
||||
const missingArtifacts = nodePtyArtifacts(projectDir)
|
||||
.map(({ source }) => source)
|
||||
.filter((filePath) => !exists(filePath));
|
||||
if (missingArtifacts.length > 0) {
|
||||
throw new Error(
|
||||
`[nodePtyConptyPatch] Patched node-pty artifacts missing: ${missingArtifacts.join(", ")}`,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function copyPatchedNodePtyToPackagedApp({ projectDir, resourcesDir, copy = fs.copyFileSync, mkdir = fs.mkdirSync }) {
|
||||
const packagedReleaseDir = path.join(
|
||||
resourcesDir,
|
||||
"app.asar.unpacked",
|
||||
"node_modules",
|
||||
"node-pty",
|
||||
"build",
|
||||
"Release",
|
||||
);
|
||||
const copied = [];
|
||||
for (const artifact of nodePtyArtifacts(projectDir)) {
|
||||
const destination = path.join(packagedReleaseDir, artifact.relative);
|
||||
mkdir(path.dirname(destination), { recursive: true });
|
||||
copy(artifact.source, destination);
|
||||
copied.push(destination);
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
copyPatchedNodePtyToPackagedApp,
|
||||
nodePtyArtifacts,
|
||||
rebuildPatchedNodePty,
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
const { rebuildPatchedNodePty } = require("./nodePtyConptyPatch.cjs");
|
||||
|
||||
rebuildPatchedNodePty({
|
||||
projectDir: process.cwd(),
|
||||
platform: process.platform,
|
||||
arch: process.env.npm_config_arch || process.arch,
|
||||
});
|
||||
Reference in new issue
Block a user