Skip to content

Commit a24aba9

Browse files
authored
Check ports in a more cross-platform way. (#2209)
* Check ports in a more cross-platform way. * Add changeset * Clarify log message and clean up code.
1 parent 3e1034b commit a24aba9

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

.changeset/late-mugs-agree.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Check ports usage in a more cross-platform way in dev server error logging

packages/kit/src/cli.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,23 @@ prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
182182

183183
/** @param {number} port */
184184
async function check_port(port) {
185+
if (await ports.check(port)) {
186+
return;
187+
}
188+
console.log(colors.bold().red(`Port ${port} is occupied`));
185189
const n = await ports.blame(port);
186-
187190
if (n) {
188-
console.log(colors.bold().red(`Port ${port} is occupied`));
189-
190191
// prettier-ignore
191192
console.log(
192193
`Terminate process ${colors.bold(n)} or specify a different port with ${colors.bold('--port')}\n`
193194
);
194-
195-
process.exit(1);
195+
} else {
196+
// prettier-ignore
197+
console.log(
198+
`Terminate the process occupying the port or specify a different port with ${colors.bold('--port')}\n`
199+
);
196200
}
201+
process.exit(1);
197202
}
198203

199204
/**

0 commit comments

Comments
 (0)