fix(detect): resolve the dev port from every place it's actually pinned#5
Merged
Conversation
A dev script like `PORT=5100 next dev` set the port via an env-var prefix, which portFromScript ignored (it only matched -p/--port flags) and portFromEnv missed (it reads a bare .env, not the prefix). perchd fell back to the framework default (Next.js 3000) while `npm run dev` served on 5100 — the port mismatch a user hit on a real Next project. portFromScript now also matches a `PORT=NNNN` assignment (including after a cross-env wrapper); an explicit -p/--port flag still takes precedence, as next/vite resolve it.
Extends the port fix beyond the script prefix to every place a JS/TS project actually pins its dev port, per-framework so we never report a port the framework ignores: - config-file port — `server.port` (vite/astro/sveltekit) and `devServer.port` (nuxt), which were never read before; - `NUXT_PORT=` script prefix alongside `PORT=`; - the dotenv cascade (.env.local/.env.development/.env) for plain-Node apps, not just a bare .env. Precedence, first hit wins: script flag → script env prefix → config file → dotenv. Verified empirically that Next ignores PORT in .env files, so that source can't mask the real port for Next.
irwansetiawan
marked this pull request as ready for review
July 12, 2026 23:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In a real Next.js project whose dev script is
"dev": "PORT=5100 next dev --turbopack",perchdstarted the server on 3000 whilenpm run devserves on 5100. More broadly, perchd only looked at a-p/--portflag and a bare.env— it missed most of the places a project pins its dev port.What determines the port (per framework)
Verified empirically (incl. that Next ignores
PORTin.envfiles — it loads them but binds 3000 anyway):-p/--portflag, orPORTenv (shell / script prefix, not.env)--portflag, orserver.portin config — they ignorePORT--portflag,PORT/NUXT_PORTenv, ordevServer.portin configPORTfrom the.envcascadeFix
The JS detector now resolves the port from, first hit wins:
-p/--portflag in the dev scriptPORT=/NUXT_PORT=env prefix in the dev script (incl. aftercross-env)server.port(vite/astro/sveltekit) ordevServer.port(nuxt), previously never readPORT=in the dotenv cascade (.env.local,.env.development,.env, …)Sources a framework ignores aren't used to override its port. Detectors stay pure (static file reads, no spawn).
Tests
TDD throughout — 10 new cases. Full suite green (145 passed), typecheck clean. Verified against the real project: detector now returns
port: 5100.