Skip to content

Commit

Permalink
[feat] allow using Vite's 'strict.port: false' option (#2507)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Sep 27, 2021
1 parent 2b9eb71 commit 5d47791
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-trees-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[feat] allow using Vite's `strict.port: false` option
12 changes: 9 additions & 3 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ prog
.option('-H, --https', 'Use self-signed HTTPS certificate', false)
.option('-o, --open', 'Open a browser tab', false)
.action(async ({ port, host, https, open }) => {
await check_port(port);

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const config = await get_config();

Expand All @@ -102,7 +100,15 @@ prog
process.stderr.write(data);
});

welcome({ port, host, https, open });
if (!watcher.vite || !watcher.vite.httpServer) {
throw Error('Could not find server');
}
// we never start the server on a socket path, so address will be of type AddressInfo
const chosen_port = /** @type {import('net').AddressInfo} */ (
watcher.vite.httpServer.address()
).port;

welcome({ port: chosen_port, host, https, open });
} catch (error) {
handle_error(error);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class Watcher extends EventEmitter {
server: {
fs: {
strict: true
}
},
strictPort: true
}
};

Expand Down

0 comments on commit 5d47791

Please sign in to comment.