Skip to content

Fix release standalone frontend path#139

Merged
simantak-dabhade merged 1 commit into
mainfrom
hotfix/release-standalone-server-path
Jun 10, 2026
Merged

Fix release standalone frontend path#139
simantak-dabhade merged 1 commit into
mainfrom
hotfix/release-standalone-server-path

Conversation

@pranavjana

Copy link
Copy Markdown
Collaborator

Summary

  • make release start script detect either Next standalone layout: frontend/frontend/server.js or frontend/server.js
  • copy public and .next/static next to the actual standalone server directory
  • prevents downloaded release zips from failing with Cannot find module .../frontend/frontend/server.js when Next emits a flattened standalone layout

Verification

  • make -f makefiles/Makefile build-release
  • verified generated release contains frontend/frontend/server.js in the current local build
  • verified generated start.mjs includes fallback logic for both server paths

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The scripts/build-release.mjs script is refactored to support flexible frontend directory structures. Previously, the frontend server path and asset destinations were hard-coded. The change introduces conditional detection: the generated start.mjs launcher now checks at runtime whether frontend/frontend/server.js exists and selects the appropriate server path and working directory. A new releaseFrontendAppDir() helper determines the correct directory structure at build time, allowing the release assembly to copy assets (public and .next/static) to the appropriate location instead of always using a fixed nested path.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing the release standalone frontend path detection to handle both nested and flattened Next.js directory layouts.
Description check ✅ Passed The description is directly related to the changeset, providing clear details about the fix for detecting Next standalone layout paths and copying assets to the correct location.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/release-standalone-server-path

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (2)
scripts/build-release.mjs (2)

85-90: ⚡ Quick win

Cache the repeated condition check.

The condition existsSync(fromRoot("./frontend/frontend/server.js")) is evaluated twice. Cache the result to avoid redundant filesystem checks and improve maintainability.

♻️ Proposed refactor
-const frontendServerPath = existsSync(fromRoot("./frontend/frontend/server.js"))
-  ? fromRoot("./frontend/frontend/server.js")
-  : fromRoot("./frontend/server.js");
-const frontendCwd = existsSync(fromRoot("./frontend/frontend/server.js"))
-  ? fromRoot("./frontend/frontend")
-  : fromRoot("./frontend");
+const hasNestedLayout = existsSync(fromRoot("./frontend/frontend/server.js"));
+const frontendServerPath = hasNestedLayout
+  ? fromRoot("./frontend/frontend/server.js")
+  : fromRoot("./frontend/server.js");
+const frontendCwd = hasNestedLayout
+  ? fromRoot("./frontend/frontend")
+  : fromRoot("./frontend");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/build-release.mjs` around lines 85 - 90, The duplicate filesystem
check existsSync(fromRoot("./frontend/frontend/server.js")) used to compute
frontendServerPath and frontendCwd should be evaluated once and stored in a
local boolean; update the code so you compute a const e.g. hasNestedFrontend =
existsSync(fromRoot("./frontend/frontend/server.js")) and then use
hasNestedFrontend to choose values for frontendServerPath and frontendCwd
(referencing the symbols frontendServerPath, frontendCwd, existsSync, and
fromRoot) to eliminate the redundant check.

235-239: ⚡ Quick win

Validate that server.js exists in the fallback path.

The function returns the fallback directory without verifying that server.js exists there. If Next.js produces an unexpected structure, assets will be copied to the wrong location and the release will fail at runtime with unclear errors.

🛡️ Proposed defensive check
 function releaseFrontendAppDir() {
   const nested = join(packageRoot, "frontend", "frontend");
   if (existsSync(join(nested, "server.js"))) return nested;
-  return join(packageRoot, "frontend");
+  const flat = join(packageRoot, "frontend");
+  if (!existsSync(join(flat, "server.js"))) {
+    throw new Error(
+      "Could not find server.js in Next standalone output. " +
+      "Expected either frontend/frontend/server.js or frontend/server.js."
+    );
+  }
+  return flat;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/build-release.mjs` around lines 235 - 239, In releaseFrontendAppDir
make the fallback path safe: after computing nested and checking
existsSync(join(nested, "server.js")), also verify existsSync(join(packageRoot,
"frontend", "server.js")) before returning the fallback; if that file is
missing, throw or log a clear error (or exit) indicating server.js was not found
in either nested or fallback so the release process stops early. Reference
releaseFrontendAppDir, nested and packageRoot to locate where to add the second
existsSync check and the error handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/build-release.mjs`:
- Around line 85-90: The duplicate filesystem check
existsSync(fromRoot("./frontend/frontend/server.js")) used to compute
frontendServerPath and frontendCwd should be evaluated once and stored in a
local boolean; update the code so you compute a const e.g. hasNestedFrontend =
existsSync(fromRoot("./frontend/frontend/server.js")) and then use
hasNestedFrontend to choose values for frontendServerPath and frontendCwd
(referencing the symbols frontendServerPath, frontendCwd, existsSync, and
fromRoot) to eliminate the redundant check.
- Around line 235-239: In releaseFrontendAppDir make the fallback path safe:
after computing nested and checking existsSync(join(nested, "server.js")), also
verify existsSync(join(packageRoot, "frontend", "server.js")) before returning
the fallback; if that file is missing, throw or log a clear error (or exit)
indicating server.js was not found in either nested or fallback so the release
process stops early. Reference releaseFrontendAppDir, nested and packageRoot to
locate where to add the second existsSync check and the error handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b92340b7-3db0-42bb-91ef-b94a2d3ed392

📥 Commits

Reviewing files that changed from the base of the PR and between 5819118 and 705f609.

📒 Files selected for processing (1)
  • scripts/build-release.mjs

@simantak-dabhade simantak-dabhade left a comment

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.

LGTM

@simantak-dabhade simantak-dabhade merged commit c299587 into main Jun 10, 2026
3 checks passed
@simantak-dabhade simantak-dabhade deleted the hotfix/release-standalone-server-path branch June 10, 2026 00:04
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.

2 participants