Skip to content

feat(dev): add --portless support#1301

Open
onmax wants to merge 1 commit intomainfrom
feat/nuxi-portless
Open

feat(dev): add --portless support#1301
onmax wants to merge 1 commit intomainfrom
feat/nuxi-portless

Conversation

@onmax
Copy link
Copy Markdown
Contributor

@onmax onmax commented Apr 30, 2026

Adds nuxi dev --portless, precomputes the Portless hostname so Nuxt/Vite allowlists include it, and exposes the dev server through the external Portless CLI.

@onmax onmax requested a review from danielroe as a code owner April 30, 2026 06:59
Comment thread packages/nuxt-cli/test/e2e/dev.spec.ts Fixed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

📝 Walkthrough

Walkthrough

The changes add portless proxy support to the nuxt dev command. A new utility module (portless.ts) provides functions to verify portless availability, resolve alias names, manage proxy aliases, and handle exit cleanup. The dev command now accepts a --portless CLI flag that integrates portless proxy functionality while preventing concurrent use with --tunnel. When enabled, the flow disables fork/profiling lifecycle paths, registers an alias around the listener, suppresses standard URL display, performs cleanup on exit, and includes rollback behavior on registration failure. Comprehensive unit tests validate utilities and exit cleanup behavior, while e2e tests verify command integration and argument validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(dev): add --portless support' directly and clearly describes the main change in the PR: adding portless functionality to the dev command.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of adding --portless support, precomputing the Portless hostname, and exposing the dev server through Portless CLI.
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 feat/nuxi-portless

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/nuxi/src/commands/dev.ts`:
- Around line 104-128: If registerPortless or listener.showURL fails we
currently restore PORTLESS_URL and call close() but never remove a previously
created alias; modify the catch block around registerPortless/listener.showURL
to call removePortlessAlias(cwd, portlessName!) (awaiting it and ignoring
errors) before restoring process.env.PORTLESS_URL and rethrowing; ensure the
existing closePortless assignment (which also calls removePortlessAlias) remains
for the success path and reference registerPortless, closePortless,
removePortlessAlias, listener.showURL, close, and previousPortlessURL when
implementing the cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7899ac77-5dc4-4f1f-bd7e-6cf32c2fc6e5

📥 Commits

Reviewing files that changed from the base of the PR and between a35d6d3 and 214ab48.

📒 Files selected for processing (4)
  • packages/nuxi/src/commands/dev.ts
  • packages/nuxi/src/dev/portless.ts
  • packages/nuxi/test/unit/dev/portless.spec.ts
  • packages/nuxt-cli/test/e2e/dev.spec.ts

Comment thread packages/nuxi/src/commands/dev.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

  • nuxt-cli-playground

    npm i https://pkg.pr.new/create-nuxt@1301
    
    npm i https://pkg.pr.new/nuxi@1301
    
    npm i https://pkg.pr.new/@nuxt/cli@1301
    

commit: eb6d9ca

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 30, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing feat/nuxi-portless (eb6d9ca) with main (a35d6d3)

Open in CodSpeed

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/nuxt-cli/test/e2e/dev.spec.ts`:
- Around line 99-107: The extractLoggedURLs function returns raw matches that
may include formatting artifacts or trailing slashes causing flaky CI
assertions; update extractLoggedURLs to normalize each URL before returning by
trimming whitespace, stripping ANSI escape sequences, removing surrounding
punctuation (like trailing ')' or '.'), and trimming a single trailing slash
(and optionally lowercasing) so comparisons are consistent; keep the function
name extractLoggedURLs and apply normalization to every match returned from
value.match(...) so tests comparing those URLs are stable.
- Around line 173-196: The test currently calls await close() inside the try
block so a thrown assertion can leak the spawned dev process; refactor to
capture the close function from runCommand into an outer-scoped variable (e.g.,
let close: (() => Promise<void>) | undefined), assign it when runCommand
resolves, and then in the finally block await close() if defined before
restoring consoleLog.mockRestore() and removing binDir; reference runCommand and
the close function to locate where to move the cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3cb523d0-edc2-49db-b161-68f2d2e7db57

📥 Commits

Reviewing files that changed from the base of the PR and between 214ab48 and 7d5e691.

📒 Files selected for processing (4)
  • packages/nuxi/src/commands/dev.ts
  • packages/nuxi/src/dev/portless.ts
  • packages/nuxi/test/unit/commands/dev.spec.ts
  • packages/nuxt-cli/test/e2e/dev.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/nuxi/src/dev/portless.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nuxi/src/commands/dev.ts

Comment thread packages/nuxt-cli/test/e2e/dev.spec.ts
Comment thread packages/nuxt-cli/test/e2e/dev.spec.ts
@onmax onmax marked this pull request as draft April 30, 2026 09:26
@onmax onmax changed the title feat(nuxi): add --portless for dev server feat(dev): add --portless support Apr 30, 2026
@onmax onmax force-pushed the feat/nuxi-portless branch 2 times, most recently from ac9337f to 54f8395 Compare April 30, 2026 13:06
@onmax onmax force-pushed the feat/nuxi-portless branch from 54f8395 to eb6d9ca Compare April 30, 2026 13:18
@onmax onmax marked this pull request as ready for review April 30, 2026 13:25
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/nuxi/src/commands/dev.ts (1)

188-195: ⚠️ Potential issue | 🟠 Major

Remove the redundant listener.close() call—it's already closed by the close() function.

The close() function returned from initialize() already calls listener.close() (via devServer.listener.close()). Calling it again in the Promise.all creates a double-close race condition on shutdown. Remove line 192.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxi/src/commands/dev.ts` around lines 188 - 195, The async close
method is calling listener.close() directly and also calling the close()
function returned from initialize() which already calls
devServer.listener.close(), causing a double-close race; edit the async close
implementation to remove the explicit listener.close() entry from the
Promise.all so it only awaits cleanupCurrentFork, closePortless and the single
close() function (keep references to cleanupCurrentFork, closePortless and
close() as they are).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/nuxi/src/dev/portless.ts`:
- Around line 118-123: readNameFromFile currently swallows all errors (parse,
permission, etc.) and should only ignore missing files; update the
readNameFromFile function so that its promise rejection handler returns
undefined only when the error indicates a missing file (error.code === 'ENOENT'
or equivalent), and rethrow any other errors (so JSON.parse and permission
errors bubble up); keep the existing JSON.parse and type-check logic but replace
the blanket .catch(() => undefined) with conditional error handling that
references readNameFromFile.

---

Outside diff comments:
In `@packages/nuxi/src/commands/dev.ts`:
- Around line 188-195: The async close method is calling listener.close()
directly and also calling the close() function returned from initialize() which
already calls devServer.listener.close(), causing a double-close race; edit the
async close implementation to remove the explicit listener.close() entry from
the Promise.all so it only awaits cleanupCurrentFork, closePortless and the
single close() function (keep references to cleanupCurrentFork, closePortless
and close() as they are).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a14b92ee-85da-41ef-b815-8130d6122c44

📥 Commits

Reviewing files that changed from the base of the PR and between 7d5e691 and eb6d9ca.

📒 Files selected for processing (5)
  • packages/nuxi/src/commands/dev.ts
  • packages/nuxi/src/dev/portless.ts
  • packages/nuxi/test/unit/dev/portless-exit.spec.ts
  • packages/nuxi/test/unit/dev/portless.spec.ts
  • packages/nuxt-cli/test/e2e/dev.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nuxt-cli/test/e2e/dev.spec.ts
  • packages/nuxi/test/unit/dev/portless.spec.ts

Comment on lines +118 to +123
function readNameFromFile(cwd: string, filename: string) {
return readFile(join(cwd, filename), 'utf8')
.then(contents => JSON.parse(contents))
.then(config => typeof config.name === 'string' ? config.name : undefined)
.catch(() => undefined)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Only ignore missing files when resolving the Portless name.

readNameFromFile() currently swallows parse and permission errors as well as missing-file cases. A malformed portless.json/package.json will silently fall back to basename(cwd), which can expose the dev server under the wrong Portless hostname.

Suggested fix
 function readNameFromFile(cwd: string, filename: string) {
   return readFile(join(cwd, filename), 'utf8')
     .then(contents => JSON.parse(contents))
     .then(config => typeof config.name === 'string' ? config.name : undefined)
-    .catch(() => undefined)
+    .catch((error) => {
+      if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
+        return undefined
+      }
+      throw error
+    })
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxi/src/dev/portless.ts` around lines 118 - 123, readNameFromFile
currently swallows all errors (parse, permission, etc.) and should only ignore
missing files; update the readNameFromFile function so that its promise
rejection handler returns undefined only when the error indicates a missing file
(error.code === 'ENOENT' or equivalent), and rethrow any other errors (so
JSON.parse and permission errors bubble up); keep the existing JSON.parse and
type-check logic but replace the blanket .catch(() => undefined) with
conditional error handling that references readNameFromFile.

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