Unverified 提交 80c0281e authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

fix: exclude unsupported node-pty artifacts from windows signing (#3171)

## Summary - remove unsupported `node-pty` artifacts before Windows signing runs, including Darwin prebuild directories and the extra `bin` directory - keep the supported Windows `node-pty` runtime binaries in place for packaged app execution - expand the Windows signing unit test to verify unsupported artifacts are removed and Windows binaries remain ## Test plan - npm run fmt - npm run lint:fix - npm run ts - npm test #skip-bugbot <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/3171" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
上级 592fdce3
...@@ -7,3 +7,4 @@ Read this when adding Electron native dependencies such as `node-pty`, or any pa ...@@ -7,3 +7,4 @@ Read this when adding Electron native dependencies such as `node-pty`, or any pa
- Add native runtime packages to `forge.config.ts` `rebuildConfig.extraModules` so Electron Forge rebuilds them against the packaged Electron version. - Add native runtime packages to `forge.config.ts` `rebuildConfig.extraModules` so Electron Forge rebuilds them against the packaged Electron version.
- If the package loads helper binaries from disk at runtime (for example `node-pty` loading `spawn-helper` or `winpty-agent` next to its native module), unpack the whole package directory with `packagerConfig.asar.unpackDir`; auto-unpacking `.node` files alone is not enough. - If the package loads helper binaries from disk at runtime (for example `node-pty` loading `spawn-helper` or `winpty-agent` next to its native module), unpack the whole package directory with `packagerConfig.asar.unpackDir`; auto-unpacking `.node` files alone is not enough.
- Windows release builds using `@electron/windows-sign` recursively try to sign `.ps1` scripts in packaged native dependencies. If a bundled dependency includes helper PowerShell files that are not Authenticode-signable (such as `node-pty`'s `deps/winpty/misc/*.ps1`), remove or exclude them before the Forge signing step or `signtool.exe` will fail with `Number of errors: 2`. - Windows release builds using `@electron/windows-sign` recursively try to sign `.ps1` scripts in packaged native dependencies. If a bundled dependency includes helper PowerShell files that are not Authenticode-signable (such as `node-pty`'s `deps/winpty/misc/*.ps1`), remove or exclude them before the Forge signing step or `signtool.exe` will fail with `Number of errors: 2`.
- Windows signing can also fail on non-Windows native prebuilds that were unpacked into the app bundle. For `node-pty`, strip Darwin-only artifacts such as `prebuilds/darwin-*` and `bin/*` before signing or `signtool.exe` may fail with `This file format cannot be signed because it is not recognized`.
...@@ -18,7 +18,7 @@ afterEach(async () => { ...@@ -18,7 +18,7 @@ afterEach(async () => {
}); });
describe("removeUnsupportedWindowsSigningFiles", () => { describe("removeUnsupportedWindowsSigningFiles", () => {
it("removes the node-pty PowerShell scripts that signtool cannot sign", async () => { it("removes node-pty artifacts that Windows signtool should not touch", async () => {
const buildPath = await fs.mkdtemp( const buildPath = await fs.mkdtemp(
path.join(os.tmpdir(), "dyad-windows-signing-"), path.join(os.tmpdir(), "dyad-windows-signing-"),
); );
...@@ -27,9 +27,25 @@ describe("removeUnsupportedWindowsSigningFiles", () => { ...@@ -27,9 +27,25 @@ describe("removeUnsupportedWindowsSigningFiles", () => {
for (const relativePath of UNSUPPORTED_WINDOWS_SIGNING_RELATIVE_PATHS) { for (const relativePath of UNSUPPORTED_WINDOWS_SIGNING_RELATIVE_PATHS) {
const absolutePath = path.join(buildPath, relativePath); const absolutePath = path.join(buildPath, relativePath);
await fs.mkdir(path.dirname(absolutePath), { recursive: true }); await fs.mkdir(path.dirname(absolutePath), { recursive: true });
await fs.writeFile(absolutePath, "Write-Host 'hello'\n");
if (path.extname(relativePath)) {
await fs.writeFile(absolutePath, "Write-Host 'hello'\n");
} else {
await fs.mkdir(absolutePath, { recursive: true });
await fs.writeFile(
path.join(absolutePath, "placeholder.node"),
"not-a-windows-binary",
);
}
} }
const supportedWindowsBinary = path.join(
buildPath,
"node_modules/node-pty/prebuilds/win32-x64/pty.node",
);
await fs.mkdir(path.dirname(supportedWindowsBinary), { recursive: true });
await fs.writeFile(supportedWindowsBinary, "windows-binary");
await removeUnsupportedWindowsSigningFiles(buildPath); await removeUnsupportedWindowsSigningFiles(buildPath);
await Promise.all( await Promise.all(
...@@ -39,5 +55,9 @@ describe("removeUnsupportedWindowsSigningFiles", () => { ...@@ -39,5 +55,9 @@ describe("removeUnsupportedWindowsSigningFiles", () => {
).rejects.toThrow(); ).rejects.toThrow();
}), }),
); );
await expect(fs.readFile(supportedWindowsBinary, "utf8")).resolves.toBe(
"windows-binary",
);
}); });
}); });
...@@ -4,6 +4,9 @@ import path from "node:path"; ...@@ -4,6 +4,9 @@ import path from "node:path";
export const UNSUPPORTED_WINDOWS_SIGNING_RELATIVE_PATHS = [ export const UNSUPPORTED_WINDOWS_SIGNING_RELATIVE_PATHS = [
"node_modules/node-pty/deps/winpty/misc/ConinMode.ps1", "node_modules/node-pty/deps/winpty/misc/ConinMode.ps1",
"node_modules/node-pty/deps/winpty/misc/IdentifyConsoleWindow.ps1", "node_modules/node-pty/deps/winpty/misc/IdentifyConsoleWindow.ps1",
"node_modules/node-pty/prebuilds/darwin-arm64",
"node_modules/node-pty/prebuilds/darwin-x64",
"node_modules/node-pty/bin",
] as const; ] as const;
export async function removeUnsupportedWindowsSigningFiles( export async function removeUnsupportedWindowsSigningFiles(
...@@ -12,7 +15,7 @@ export async function removeUnsupportedWindowsSigningFiles( ...@@ -12,7 +15,7 @@ export async function removeUnsupportedWindowsSigningFiles(
await Promise.all( await Promise.all(
UNSUPPORTED_WINDOWS_SIGNING_RELATIVE_PATHS.map(async (relativePath) => { UNSUPPORTED_WINDOWS_SIGNING_RELATIVE_PATHS.map(async (relativePath) => {
const absolutePath = path.join(buildPath, relativePath); const absolutePath = path.join(buildPath, relativePath);
await fs.rm(absolutePath, { force: true }); await fs.rm(absolutePath, { force: true, recursive: true });
}), }),
); );
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论