Skip to content

Fix issue #3119#3120

Open
GlaDrancE wants to merge 1 commit into
onlook-dev:mainfrom
GlaDrancE:fix-issue-3119
Open

Fix issue #3119#3120
GlaDrancE wants to merge 1 commit into
onlook-dev:mainfrom
GlaDrancE:fix-issue-3119

Conversation

@GlaDrancE

@GlaDrancE GlaDrancE commented Jun 23, 2026

Copy link
Copy Markdown

Fixes a Windows-only crash in the setup:env script. ensureDirectoryExists() in packages/scripts/src/api-keys.ts derived the target directory using a hardcoded forward-slash search (filePath.substring(0, filePath.lastIndexOf('/'))). On Windows, paths use backslashes (e.g. A:...\client.env), so lastIndexOf('/') returns -1, substring(0, -1) returns '', and the subsequent fs.mkdirSync('') throws ENOENT: mkdir '' — preventing the API keys from being written.

Replaced the manual string slicing with Node's cross-platform path.dirname(), plus a guard to skip an empty directory. This produces identical results on Linux/macOS (no regression) and correctly handles backslash paths on Windows.

Related Issues

closes #3119

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

  • Ran bun run setup:env on Windows 11 and confirmed the API Key Configuration step now writes CSB_API_KEY and OPENROUTER_API_KEY to the web client and db .env files without crashing.
  • Verified path.dirname() returns the same directory as the previous logic on POSIX paths, so Linux/macOS behavior is unchanged.

Before:
✓ Set OPENROUTER_API_KEY key
Failed to write API keys: Error: ENOENT: no such file or directory, mkdir ''

After:
✓ Set OPENROUTER_API_KEY key
✅ API keys updated successfully!

Screenshots (if applicable)
N/A — CLI script change.

Summary by CodeRabbit

  • Chores
    • Improved path handling in utility scripts for enhanced cross-platform reliability

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@GlaDrancE is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9ceafb6-ab00-4a92-8dff-90d867ee992e

📥 Commits

Reviewing files that changed from the base of the PR and between 936b015 and 5d9d9a3.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • packages/scripts/src/api-keys.ts

📝 Walkthrough

Walkthrough

In packages/scripts/src/api-keys.ts, the node:path module is imported and ensureDirectoryExists is updated to derive the target directory using path.dirname(filePath) instead of a forward-slash-based substring approach.

Changes

Cross-platform directory extraction fix

Layer / File(s) Summary
Replace slash substring with path.dirname in ensureDirectoryExists
packages/scripts/src/api-keys.ts
Imports node:path and replaces the manual slash-based substring logic with path.dirname(filePath) to compute the target directory before the existence check and creation flow.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related issues

Poem

🐇 A slash is not always the right kind of split,
On Windows, a backslash is perfectly fit.
So I hopped to path.dirname with glee,
No more broken paths — cross-platform and free!
Carrots for all, the directories are right! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title "Fix issue #3119" is vague and doesn't describe the specific change; it only references an issue number without conveying what was actually fixed. Use a more descriptive title that explains the fix, such as "Fix Windows path handling in ensureDirectoryExists by using path.dirname()" or "Fix Windows-only crash in setup:env script due to hardcoded forward-slash parsing."
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive and well-structured, covering the problem, solution, testing, and before/after results. All key template sections are present and properly filled out.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

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.

setup:env crashes on Windows with ENOENT: mkdir '' when writing API keys

1 participant