Skip to content

fix: remove dead ternary in WORKSPACE_ROOT resolution#487

Open
hobostay wants to merge 1 commit intonexu-io:mainfrom
hobostay:fix/workspace-root-ternary
Open

fix: remove dead ternary in WORKSPACE_ROOT resolution#487
hobostay wants to merge 1 commit intonexu-io:mainfrom
hobostay:fix/workspace-root-ternary

Conversation

@hobostay
Copy link
Copy Markdown
Contributor

@hobostay hobostay commented May 5, 2026

Summary

  • Simplifies WORKSPACE_ROOT in tools/dev/src/config.ts and tools/pack/src/config.ts from a ternary with identical branches to a single "../.."
  • Removes unused ENTRY_DIR_NAME constant from both files

Problem

Both files contained:

ENTRY_DIR_NAME === "dist" ? "../../.." : "../../.."

The ternary condition checks whether the entry directory is dist (built) or src (source), but since src/ and dist/ are siblings at the same depth under tools/{dev,pack}/, both branches resolve to the same path — three levels up reaches the repo root from either. The conditional and the ENTRY_DIR_NAME constant were dead code that suggested a distinction where none existed.

Test plan

  • pnpm tools-dev start still resolves workspace root correctly
  • pnpm tools-pack still resolves workspace root correctly

🤖 Generated with Claude Code

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>
@lefarcen lefarcen self-requested a review May 5, 2026 00:44
@lefarcen
Copy link
Copy Markdown
Contributor

lefarcen commented May 5, 2026

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!
— open-design team

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread tools/dev/src/config.ts
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, "../..");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread tools/pack/src/config.ts
const ENTRY_DIR_NAME = path.basename(__dirname);

export const WORKSPACE_ROOT = resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../..");
export const WORKSPACE_ROOT = resolve(__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.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor

@mrcfps mrcfps left a comment

Choose a reason for hiding this comment

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

@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.

Generated by Looper 0.5.4 · runner=reviewer · agent=opencode

Comment thread tools/dev/src/config.ts
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, "../..");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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. 🙂

Comment thread tools/pack/src/config.ts
const ENTRY_DIR_NAME = path.basename(__dirname);

export const WORKSPACE_ROOT = resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../..");
export const WORKSPACE_ROOT = resolve(__dirname, "../..");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@lefarcen lefarcen left a comment

Choose a reason for hiding this comment

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

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!

Comment thread tools/dev/src/config.ts
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, "../..");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, "../../..");

Comment thread tools/pack/src/config.ts
const ENTRY_DIR_NAME = path.basename(__dirname);

export const WORKSPACE_ROOT = resolve(__dirname, ENTRY_DIR_NAME === "dist" ? "../../.." : "../../..");
export const WORKSPACE_ROOT = resolve(__dirname, "../..");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, "../../..");

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.

3 participants