Skip to content

Commit

Permalink
Switch port libraries to keep port consistent between reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Nov 15, 2024
1 parent 3005661 commit 4a5255e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"fast-glob": "^3.3.2",
"filesize": "^10.1.6",
"fs-extra": "^11.2.0",
"get-port": "^7.1.0",
"get-port-please": "^3.1.2",
"giget": "^1.2.3",
"hookable": "^5.5.3",
"is-wsl": "^3.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/wxt/src/core/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getContentScriptJs,
mapWxtOptionsToRegisteredContentScript,
} from './utils/content-scripts';
import { sleep } from './utils/time';

/**
* Creates a dev server and pre-builds all the files that need to exist before loading the extension.
Expand Down Expand Up @@ -119,6 +120,7 @@ async function createServerInternal(
},
async restart() {
await server.stop();
await sleep(5000);
await server.start();
},
transformHtml(url, html, originalUrl) {
Expand Down
4 changes: 2 additions & 2 deletions packages/wxt/src/core/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { builtinModules } from '../builtin-modules';
import { getEslintVersion } from './utils/eslint';
import { safeStringToNumber } from './utils/number';
import { loadEnv } from './utils/env';
import { getPort } from 'get-port-please';

/**
* Given an inline config, discover the config file if necessary, merge the results, resolve any
Expand Down Expand Up @@ -139,8 +140,7 @@ export async function resolveConfig(
if (command === 'serve') {
let port = mergedConfig.dev?.server?.port;
if (port == null || !isFinite(port)) {
const { default: getPort, portNumbers } = await import('get-port');
port = await getPort({ port: portNumbers(3000, 3010) });
port = await getPort({ portRange: [3000, 3010] });
}
devServerConfig = {
port,
Expand Down
29 changes: 14 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a5255e

Please sign in to comment.