Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[rush-serve-plugin] The auto-picked port never reaches the port parameter: `_value` is ignored since ts-command-line uses `#value`

未關閉 適合新手
#6,144 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
nodejs, typescript

研究方向

從 rush-plugins/rush-serve-plugin/src/phasedCommandHandler.ts 第 241 行左右開始,那裡會把自動選取的連接埠寫入 portParameter._value;接著查看 libraries/ts-command-line/src/parameters/CommandLineIntegerParameter.ts,確認該值保存在 #value 中,且只能透過 _setValue() 設定。當連接埠為 0 的處理程式執行後,portParameter.value 等於啟用中的連接埠,並且有單元測試涵蓋這一點,即為完成。在提出替代內部 setter 的公開方案之前,先用現有的 serve-plugin 測試確認修復。

由索引模型根據 Issue 內容生成。

描述

Summary

When rush start (or another watch-mode phased command with portParameterLongName) runs without an explicit port, @rushstack/rush-serve-plugin listens on an OS-assigned port and then tries to publish it through the command-line parameter, so that other plugins (and the operations that receive the parameter) see the real port. It does so by writing portParameter._value. Since @rushstack/ts-command-line switched parameters to native private fields (#5943), CommandLineIntegerParameter stores its value in #value, so the assignment only adds an unused property. portParameter.value stays undefined, and nothing downstream sees the port.

Versions

  • @microsoft/rush / @rushstack/rush-serve-plugin 5.181.0
  • @rushstack/ts-command-line 5.3.17 (any version that includes #5943)
  • Node.js 22

Repro

  1. Configure rush-serve-plugin with portParameterLongName: "--port", and define --port as an integer parameter of the start command, associated with a phase.
  2. Add a second plugin that taps createOperationsAsync after the serve plugin (any stage above -1) and logs context.customParameters.get('--port').value.
  3. Run rush start without --port.

Expected

The serve plugin logs Content is being served from: https://localhost:<port>/, and the second plugin logs the same <port>.

Actual

The second plugin logs undefined. An explicit --port 4321 works, because then the value comes from the parser.

Code pointer (main)

  • rush-plugins/rush-serve-plugin/src/phasedCommandHandler.ts, line 241: (portParameter as unknown as { _value?: string })._value = `${activePort}`;
  • libraries/ts-command-line/src/parameters/CommandLineIntegerParameter.ts: the value lives in #value and is written only by _setValue().

Suggested fix

Set the value through the parameter's setter (it also stores a number, as the integer parameter expects, instead of a string):

(portParameter as unknown as { _setValue(data: unknown): void })._setValue(activePort);

Since _setValue is @internal, a public way for a plugin to override a parsed parameter value (or a session-level API that publishes the serve plugin's active port) would avoid the cast. A unit test that runs the handler with port 0 and checks portParameter.value would catch a regression.

Filed with help from GitHub Copilot (AI); reviewed by the reporter.

主要語言
TypeScript
星號
6.5k
分支
710
平均合併
1 天 15 小時
30 天內合併 PR
37

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/rushstack 的其他 Issue

查看 microsoft/rushstack 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。