fix: remove dead ternary in WORKSPACE_ROOT resolution#487
fix: remove dead ternary in WORKSPACE_ROOT resolution#487hobostay wants to merge 1 commit intonexu-io:mainfrom
Conversation
Both tools/dev and tools/pack config files had:
ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."
with identical branches. Since `src/` and `dist/` are siblings under
`tools/{dev,pack}/`, both resolve to the same path. The ternary and
ENTRY_DIR_NAME constant were dead code — simplify to "../..".
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Hi @hobostay! 👋 Thanks for the contribution — removing this dead ternary and unused constant is a nice cleanup. I will run a deep review and get back to you within 24h. Thanks for making open-design better! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e256dd9f12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const ENTRY_DIR_NAME = path.basename(__dirname); | ||
|
|
||
| export const WORKSPACE_ROOT = path.resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."); | ||
| export const WORKSPACE_ROOT = path.resolve(__dirname, "../.."); |
There was a problem hiding this comment.
Resolve tools-dev workspace root at repo level
Update this constant to keep climbing three levels from config.ts; with "../..", WORKSPACE_ROOT becomes <repo>/tools (for both src and bundled dist execution), not the repository root. In resolveToolDevConfig, that immediately builds invalid paths like <repo>/tools/apps/daemon/sidecar/index.ts and <repo>/tools/apps/desktop/package.json, so tools-dev cannot locate app entrypoints in normal runs.
Useful? React with 👍 / 👎.
| const ENTRY_DIR_NAME = path.basename(__dirname); | ||
|
|
||
| export const WORKSPACE_ROOT = resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."); | ||
| export const WORKSPACE_ROOT = resolve(__dirname, "../.."); |
There was a problem hiding this comment.
Resolve tools-pack workspace root at repo level
This should also resolve three levels up; "../.." resolves to <repo>/tools, so resolveToolPackConfig points to <repo>/tools/apps/desktop/package.json instead of <repo>/apps/desktop/package.json. That breaks electron version/dist resolution used by build commands, causing tools-pack to fail when it tries to load desktop package metadata.
Useful? React with 👍 / 👎.
mrcfps
left a comment
There was a problem hiding this comment.
@hobostay thanks for the focused cleanup here. I found one path-depth regression that affects both tool configs: the simplified relative path now stops at <repo>/tools instead of the workspace root, so the tool entrypoint paths are built under the wrong directory.
| const ENTRY_DIR_NAME = path.basename(__dirname); | ||
|
|
||
| export const WORKSPACE_ROOT = path.resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."); | ||
| export const WORKSPACE_ROOT = path.resolve(__dirname, "../.."); |
There was a problem hiding this comment.
This needs to keep resolving to the repository root. From tools/dev/src/config.ts (and similarly from a built tools/dev/dist/config.js), path.resolve(__dirname, "../..") lands at <repo>/tools, not <repo>. That makes the changed config later construct paths such as <repo>/tools/apps/daemon/sidecar/index.ts, <repo>/tools/apps/web/sidecar/index.ts, and <repo>/tools/apps/desktop/package.json, so normal tools-dev startup cannot find the app entrypoints. Please keep the three-level climb here, e.g. path.resolve(__dirname, "../../.."), and ideally add/adjust a config test that asserts workspaceRoot contains apps/daemon, apps/web, and apps/desktop. 🙂
| const ENTRY_DIR_NAME = path.basename(__dirname); | ||
|
|
||
| export const WORKSPACE_ROOT = resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."); | ||
| export const WORKSPACE_ROOT = resolve(__dirname, "../.."); |
There was a problem hiding this comment.
Same path-depth issue here: tools/pack/src plus "../.." resolves to <repo>/tools, while resolveElectronVersion() and resolveElectronDistPath() immediately read join(workspaceRoot, "apps/desktop/package.json"). With this change that becomes <repo>/tools/apps/desktop/package.json, so packaging commands will fail before they can resolve Electron metadata. Please keep this at resolve(__dirname, "../../..") (or otherwise derive the actual repo root) and cover the expected desktop package path in the tools-pack config tests.
lefarcen
left a comment
There was a problem hiding this comment.
Hi @hobostay! 👋
Thanks for catching the dead ternary — you're absolutely right that both branches were identical. However, the proposed simplification has an off-by-one error that would break path resolution.
The Issue
Both files currently use "../../.." (three levels up) in the ternary, but your PR changes it to "../.." (two levels up). This breaks the path resolution:
- Current (correct): From
tools/dev/src/→../../../reaches workspace root - After PR: From
tools/dev/src/→../../reaches only<repo>/tools/
This would cause every caller that joins WORKSPACE_ROOT with app paths (like apps/desktop/package.json) to look in the wrong location (tools/apps/... instead of <repo>/apps/...).
Concrete Fix
The correct simplification keeps three levels:
export const WORKSPACE_ROOT = path.resolve(__dirname, "../../..");This is equivalent to the old ternary and resolves correctly from both src/ and dist/ subdirectories.
See inline comments for the specific lines. Thanks for the cleanup effort — with this path fix, it'll be a great improvement!
| const ENTRY_DIR_NAME = path.basename(__dirname); | ||
|
|
||
| export const WORKSPACE_ROOT = path.resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."); | ||
| export const WORKSPACE_ROOT = path.resolve(__dirname, "../.."); |
There was a problem hiding this comment.
P1 Path resolution off by one level.
From tools/dev/src/, "../.." resolves to <repo>/tools, not the workspace root. The old ternary used "../../.." which correctly reaches workspace root.
Why it matters: Callers join WORKSPACE_ROOT with app paths like apps/desktop/package.json. With "../..", these paths become tools/apps/... (doesn't exist).
Concrete fix:
export const WORKSPACE_ROOT = path.resolve(__dirname, "../../..");| const ENTRY_DIR_NAME = path.basename(__dirname); | ||
|
|
||
| export const WORKSPACE_ROOT = resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."); | ||
| export const WORKSPACE_ROOT = resolve(__dirname, "../.."); |
There was a problem hiding this comment.
P1 Same path resolution issue.
From tools/pack/src/, "../.." resolves to <repo>/tools instead of workspace root. This breaks resolveToolPackConfig() (output paths), resolveElectronVersion(), and resolveElectronDistPath() which all expect workspace root.
Concrete fix:
export const WORKSPACE_ROOT = resolve(__dirname, "../../..");
Summary
WORKSPACE_ROOTintools/dev/src/config.tsandtools/pack/src/config.tsfrom a ternary with identical branches to a single"../.."ENTRY_DIR_NAMEconstant from both filesProblem
Both files contained:
The ternary condition checks whether the entry directory is
dist(built) orsrc(source), but sincesrc/anddist/are siblings at the same depth undertools/{dev,pack}/, both branches resolve to the same path — three levels up reaches the repo root from either. The conditional and theENTRY_DIR_NAMEconstant were dead code that suggested a distinction where none existed.Test plan
pnpm tools-dev startstill resolves workspace root correctlypnpm tools-packstill resolves workspace root correctly🤖 Generated with Claude Code