Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/runtime/src/internal/debugManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ describe("debugManager", () => {
DebugManagerClass.instance = undefined;
const _manager = new DebugManagerClass();

expect(console.log).toHaveBeenCalledWith(
"💡 提示:使用 window.debugConsole.help() 查看使用说明"
);
expect(console.log).not.toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion packages/runtime/src/internal/debugManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DebugManager {
this.debugType === "persistent" ? "持久模式" : "会话模式"
})`
);
} else {
} else if (process.env.NODE_ENV !== "test") {
// eslint-disable-next-line no-console
console.log("💡 提示:使用 window.debugConsole.help() 查看使用说明");
}
Comment on lines +179 to 182
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

避免在浏览器环境访问未定义的 process

这里直接读取 process.env,一旦在纯浏览器环境或未由打包器注入 process 的场景下运行,会立刻抛出 ReferenceError,从而阻断整个初始化流程。这条代码在改动前不存在 process 依赖,因此属于回归风险。建议在判断前先确认 process 是否存在,同时保持原有的“测试环境不输出”语义。

-    } else if (process.env.NODE_ENV !== "test") {
+    } else if (
+      typeof process === "undefined" ||
+      process.env?.NODE_ENV !== "test"
+    ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (process.env.NODE_ENV !== "test") {
// eslint-disable-next-line no-console
console.log("💡 提示:使用 window.debugConsole.help() 查看使用说明");
}
} else if (
typeof process === "undefined" ||
process.env?.NODE_ENV !== "test"
) {
// eslint-disable-next-line no-console
console.log("💡 提示:使用 window.debugConsole.help() 查看使用说明");
}
🤖 Prompt for AI Agents
In packages/runtime/src/internal/debugManager.ts around lines 179-182, the code
directly reads process.env which throws a ReferenceError in browser environments
where process is undefined; update the condition to first check that process
exists (e.g. typeof process !== "undefined" or typeof globalThis.process !==
"undefined") and then check process.env.NODE_ENV !== "test" (safely accessing
process.env), so the message is only suppressed in test env but no
ReferenceError is thrown in pure browsers.

Expand Down
Loading