Closed filiphazardous closed 8 months ago
Yes. It does seem a little counter-intuitive that there are times when we don't want the port
as a first priority 👀
Not sure what you mean. My case is that I have not defined port
, but I have defined ports
. In this case port
defaults to 3000
, and if that port is available - ports
is disregarded.
If this is expected behavior, it should be documented that you can't use ports
without also defining port
in options.
I think it makes sense to prefer custom port yrange when provided. Feel free to make a PR!
Environment
Node v18 (but I think it is universal)
Reproduction
The following repo gets the port 3000 unexpectedly: https://github.com/nuxt-modules/storybook/blob/main/src/storybook.ts (see line 11)
Here is the shortest snippet that reproduces the bug:
Describe the bug
In the file get-ports.ts (https://github.com/unjs/get-port-please/blob/main/src/get-port.ts) on line 29 - the port option defaults to 3000 (unless otherwise defined in _userOptions). On line 53 in the same file, the same value is assigned a higher priority than the actually provided option
ports
. This makes the ports and portRange options hard to use.If this behavior is intentional, it would be convenient if it was documented.
A suggested fix would be to add the default port to the end of
portToCheck
and unshift _userOptions.port to the front of the same array if it is provided.Additional context
No response
Logs