Skip to content

fix Windows node-pty packaging#1

Closed
qq617564112 wants to merge 1 commit into
freshman515:mainfrom
qq617564112:fix/win32-node-pty-packaging
Closed

fix Windows node-pty packaging#1
qq617564112 wants to merge 1 commit into
freshman515:mainfrom
qq617564112:fix/win32-node-pty-packaging

Conversation

@qq617564112

@qq617564112 qq617564112 commented Apr 27, 2026

Copy link
Copy Markdown

Summary

  • promote @lydell/node-pty-win32-x64 to a top-level optional dependency so electron-builder includes it in Windows packages
  • add a packaging regression test that asserts the built app contains the required PTY runtime
  • run the packaging regression automatically after pnpm run dist:win

Test plan

  • pnpm test
  • pnpm run dist:win
  • verify dist/win-unpacked/resources/app.asar.unpacked/node_modules/@lydell/node-pty-win32-x64/package.json exists

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Added packaging validation test to verify Windows distribution integrity.
  • Chores

    • Updated Windows distribution build process to run validation checks.
    • Added Windows-specific optional dependency for enhanced platform support.

Promote the Windows node-pty binary to a top-level optional dependency and add a packaging regression check so Windows installers ship the PTY runtime FastAgents needs at startup.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

These changes add packaging validation for Windows distributions by introducing a test script that verifies the optional Windows-specific dependency (@lydell/node-pty-win32-x64) is properly packaged, integrated into the dist:win build workflow.

Changes

Cohort / File(s) Summary
Build Configuration
package.json
Added test:packaging NPM script, extended dist:win to run packaging validation after building, and added @lydell/node-pty-win32-x64 as an optional dependency.
Packaging Validation Test
scripts/packaging-node-pty.test.mjs
New Node test file that verifies the presence of packaged optional dependency files in the Windows distribution, failing with "Missing packaged optional dependency" if validation fails.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Windows packages now take a test,
To ensure dependencies pack their best,
Optional libraries bundled with care,
Node-pty's presence, validated fair! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix Windows node-pty packaging' accurately and concisely summarizes the main change: addressing a Windows-specific packaging issue with the node-pty dependency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/packaging-node-pty.test.mjs`:
- Line 6: The test uses import.meta.dirname to build appRoot which fails on Node
20.0–20.10; replace that usage by deriving the directory from import.meta.url
using fileURLToPath and path.dirname (i.e., compute const appRoot =
path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')) or
alternatively raise the engines constraint to >=20.11.0; update the code around
the appRoot declaration and add the required import of fileURLToPath from 'url'
if not present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4bc7a63d-3b9f-4092-9e00-3a86cc1d4238

📥 Commits

Reviewing files that changed from the base of the PR and between b0b5558 and 951a5ae.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json
  • scripts/packaging-node-pty.test.mjs

import fs from 'node:fs'
import path from 'node:path'

const appRoot = path.resolve(import.meta.dirname, '..')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

From official Node.js documentation/changelog: in which Node.js versions is import.meta.dirname supported, and is it available in all Node 20.x releases?

💡 Result:

import.meta.dirname is supported in Node.js starting from v20.11.0 and v21.2.0, and in all subsequent versions including all later 20.x releases (20.11.0+). It is not available in Node 20.x releases prior to 20.11.0. From the official Node.js documentation (Modules: ECMAScript modules), it states: "Added in: v21.2.0, v20.11.0". The feature was added via PR #48740 merged to main and backported to v20.x via PR #50502. Multiple secondary sources (Stack Overflow, Sonar, Reddit, Stackademic) confirm introduction in 20.11.0. Node 20 LTS changelog lists 20.11.0 as a release, and documentation for latest v20.x and v25.x confirms presence. No sources indicate availability before 20.11.0 in 20.x.

Citations:


import.meta.dirname is not supported in older Node 20.x versions

Line 6 uses import.meta.dirname, which is only available in Node.js v20.11.0 and later. Since your project declares node >=20, versions 20.0–20.10 will fail at runtime. Use path.dirname(fileURLToPath(import.meta.url)) instead to support the full declared range, or raise the engine floor to >=20.11.0.

Compatibility-safe change
 import test from 'node:test'
 import assert from 'node:assert/strict'
 import fs from 'node:fs'
 import path from 'node:path'
+import { fileURLToPath } from 'node:url'
 
-const appRoot = path.resolve(import.meta.dirname, '..')
+const currentDir = path.dirname(fileURLToPath(import.meta.url))
+const appRoot = path.resolve(currentDir, '..')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/packaging-node-pty.test.mjs` at line 6, The test uses
import.meta.dirname to build appRoot which fails on Node 20.0–20.10; replace
that usage by deriving the directory from import.meta.url using fileURLToPath
and path.dirname (i.e., compute const appRoot =
path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')) or
alternatively raise the engines constraint to >=20.11.0; update the code around
the appRoot declaration and add the required import of fileURLToPath from 'url'
if not present.

@freshman515

Copy link
Copy Markdown
Owner

感谢你的 PR。

这个 Windows node-pty 打包问题已经在当前 main 里通过 @lydell/node- pty-* 平台可选依赖修复了,而且覆盖范围比这个 PR 更完整。

我先不合并这个 PR,原因是:

  • 当前 main 已经包含 @lydell/node-pty-win32-x64,核心修复已覆盖。
  • 直接合并会产生重复的 optionalDependencies,可能覆盖掉 main 里已有
    的其他平台依赖。
  • 新增测试使用了 import.meta.dirname,和项目当前 node >=20 下限不
    完全兼容。
  • pnpm-lock.yaml 里有一些和本修复无关的 lockfile 变动。

所以这个 PR 我先关闭。后续如果要加 Windows 打包回归测试,我会基于当前
main 单独补一个干净版本。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants