antfu / vscode-vite

One step faster for Vite in VS Code ⚡️
https://marketplace.visualstudio.com/items?itemName=antfu.vite
449 stars 25 forks source link

fix: unable to update the port data when it is already in use #40

Open CofCat456 opened 1 month ago

CofCat456 commented 1 month ago

Description

This PR fixes the issue where data was not correctly updated when port 4000 was in use.

I noticed that listening to http.createServer() does not adequately detect if a port is already in use.

As seen in the screenshot, port 4000 is in use, but both npx vite and the notification still show port 4000.

截圖 2024-07-15 下午3 51 33

I resolved this by installing portfinder to check for port occupancy and obtain a new port if necessary.


When port 4000 is in use.

截圖 2024-07-15 下午3 41 41

When port 4001 is in use.

截圖 2024-07-15 下午3 42 16
antfu commented 1 month ago

Could we use https://www.npmjs.com/package/get-port-please ? It would align more with our ecosystem and has zero-deps. Thank you

CofCat456 commented 1 month ago

I update it 😀

I noticed the portfinder will automatically select the host based on ipv4 or ipv6, but get-port-please seems not ...?

If the host is not ::1, get-port-please can not correct work (always return 4000).