unjs / get-port-please Goto Github PK
View Code? Open in Web Editor NEW๐ Get an available open port
License: MIT License
๐ Get an available open port
License: MIT License
The only way to get portRange
working is like this:
await getPort({ port: null, ports: [], portRange: [23000, 24000] })
This is not very intuitive - if portRange
is set the other options should be ignored I think.
get-port-please v3.0.1
Node.js v16.20.0
I get
Error: Timeout waiting for port 59728 after 4 retries with 500ms interval.
at async ESMLoader.import (https://stackblitzstartersvdm76f-xrf4.w-credentialless.staticblitz.com/blitz.33975f1d.js:213:4862)
at async i.loadESM (https://stackblitzstartersvdm76f-xrf4.w-credentialless.staticblitz.com/blitz.33975f1d.js:60:915)
at async handleMainPromise (https://stackblitzstartersvdm76f-xrf4.w-credentialless.staticblitz.com/blitz.33975f1d.js:168:264)
when running await waitForPort()
.
It happens on StackBlitz and MacOS 13.5 (Node 16.20.0, 18.16.1 when running Nitro tests).
No response
No response
Context: nuxt/nuxt#20019
When get-port-please
is unable to obtain a port, the issue is usually because of a wrong hostname
option. In order to improve DX, we shall implement a fallback strategy to try with localhost
> 127.0.0.1
and ""
(only if explicit public
option is provided to avoid unwanted exposure)
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/ci.yml
actions/checkout v4
actions/setup-node v4
codecov/codecov-action v3
package.json
@types/node ^20.11.25
@vitest/coverage-v8 ^1.3.1
changelogen ^0.5.5
eslint ^8.57.0
eslint-config-unjs ^0.2.1
jiti ^1.21.0
prettier ^3.2.5
typescript ^5.4.2
unbuild ^2.0.0
vitest ^1.3.1
pnpm 8.15.4
Node v18 (but I think it is universal)
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:
import { getPort } from 'get-port-please';
const port = getPort({ ports: [6006, 6007, 6008] });
if (port === 3000) {
console.log('Port is unexpectedly returned as 3000');
}
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.
No response
This is a log generated by me putting `console.log` messages, outputting `_userOptions`, `options` and `availablePort` in the `index.mjs` file in `node_modules`. (feserver_1 being my docker container)
feserver_1 | _userOptions
feserver_1 | {
feserver_1 | "ports": [
feserver_1 | 443,
feserver_1 | 6007,
feserver_1 | 6008,
feserver_1 | 6009,
feserver_1 | 6010
feserver_1 | ],
feserver_1 | "verbose": true
feserver_1 | }
feserver_1 | options
feserver_1 | {
feserver_1 | "name": "default",
feserver_1 | "random": false,
feserver_1 | "ports": [
feserver_1 | 443,
feserver_1 | 6007,
feserver_1 | 6008,
feserver_1 | 6009,
feserver_1 | 6010
feserver_1 | ],
feserver_1 | "portRange": [],
feserver_1 | "alternativePortRange": [
feserver_1 | 3000,
feserver_1 | 3100
feserver_1 | ],
feserver_1 | "verbose": true,
feserver_1 | "port": 3000
feserver_1 | }
feserver_1 | availablePort: 3000
.
.
As the doc says, the package should use process.env.PORT
as default value.
port
First port to check. Default is process.env.PORT || 3000
But as you can see here, it always uses environment variable if it is present.
Line 42 in 4b7b320
It is important to prioritize option over environment variable to make sure that we can use this package to get different ports if it's required.
originally reported in nuxt/content#1781
No response
No response
Context: nuxt/nuxt#20019
We shall improve message to mention on which host(s) the port could not be obtained.
when I have a server running on port 3000 and call getPort(3000)
it returns 3000
rather than detecting a port collision
it defaults to these server options:
console.log(server.address())
// { address: '::', family: 'IPv6', port: 3000 }
Mac, node 18.
await p.getPort({ random: true, portRange: [5000, 6000] });
output:
63493
I get number that are not part of the specified range. (I tried also alternativePortRange
, same issue).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.