Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ class Server<
const { default: pRetry } = await import('p-retry');
const getPort = require('./getPort');
const basePort =
typeof process.env.WEBPACK_DEV_SERVER_BASE_PORT !== 'undefined'
? Number.parseInt(process.env.WEBPACK_DEV_SERVER_BASE_PORT, 10)
typeof process.env.RSPACK_DEV_SERVER_BASE_PORT !== 'undefined'
? Number.parseInt(process.env.RSPACK_DEV_SERVER_BASE_PORT, 10)
: 8080;
Comment thread
chenjiahan marked this conversation as resolved.

// Try to find unused port and listen on it for 3 times,
// if port is not specified in options.
const defaultPortRetry =
typeof process.env.WEBPACK_DEV_SERVER_PORT_RETRY !== 'undefined'
? Number.parseInt(process.env.WEBPACK_DEV_SERVER_PORT_RETRY, 10)
typeof process.env.RSPACK_DEV_SERVER_PORT_RETRY !== 'undefined'
? Number.parseInt(process.env.RSPACK_DEV_SERVER_PORT_RETRY, 10)
: 3;
Comment thread
chenjiahan marked this conversation as resolved.

return pRetry(() => getPort(basePort, host), {
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ describe('API', () => {
let devServerPort;

afterEach(() => {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = undefined;
process.env.WEBPACK_DEV_SERVER_PORT_RETRY = undefined;
process.env.RSPACK_DEV_SERVER_BASE_PORT = undefined;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = undefined;

return dummyServers
.reduce(
Expand All @@ -372,7 +372,7 @@ describe('API', () => {
});

function createDummyServers(n) {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = 60000;
process.env.RSPACK_DEV_SERVER_BASE_PORT = 60000;

return (Array.isArray(n) ? n : [...new Array(n)]).reduce(
(p, _, i) =>
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('API', () => {
it('should return the port when the port is specified', async () => {
const retryCount = 1;

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = retryCount;

const freePort = await Server.getFreePort(9082);

Expand All @@ -410,7 +410,7 @@ describe('API', () => {
it('should return the port when the port is `null`', async () => {
const retryCount = 2;

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = retryCount;

await createDummyServers(retryCount);

Expand Down Expand Up @@ -449,7 +449,7 @@ describe('API', () => {
it('should return the port when the port is undefined', async () => {
const retryCount = 3;

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = retryCount;

await createDummyServers(retryCount);

Expand Down Expand Up @@ -489,7 +489,7 @@ describe('API', () => {
it('should retry finding the port for up to defaultPortRetry times (number)', async () => {
const retryCount = 4;

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = retryCount;

await createDummyServers(retryCount);

Expand Down Expand Up @@ -528,7 +528,7 @@ describe('API', () => {
it('should retry finding the port for up to defaultPortRetry times (string)', async () => {
const retryCount = 5;

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = retryCount;

await createDummyServers(retryCount);

Expand Down Expand Up @@ -567,7 +567,7 @@ describe('API', () => {
it('should retry finding the port when serial ports are busy', async () => {
const busyPorts = [60000, 60001, 60002, 60003, 60004, 60005];

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = 1000;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = 1000;

await createDummyServers(busyPorts);

Expand Down Expand Up @@ -611,7 +611,7 @@ describe('API', () => {
() => () => Promise.reject(new Error('busy')),
);

process.env.WEBPACK_DEV_SERVER_PORT_RETRY = 1;
process.env.RSPACK_DEV_SERVER_PORT_RETRY = 1;

const { RspackDevServer: Server } = require('@rspack/dev-server');

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/host.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('host', () => {
it(`should work using "${host}" host and "auto" port`, async () => {
const compiler = rspack(config);

process.env.WEBPACK_DEV_SERVER_BASE_PORT = port;
process.env.RSPACK_DEV_SERVER_BASE_PORT = port;

const devServerOptions = { port: 'auto' };

Expand Down Expand Up @@ -260,7 +260,7 @@ describe('host', () => {

expect(pageErrors).toMatchSnapshot('page errors');
} finally {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = undefined;
process.env.RSPACK_DEV_SERVER_BASE_PORT = undefined;

await browser.close();
await server.stop();
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/port.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('port', () => {
testedPort === '<not-specified>' ||
typeof testedPort === 'undefined'
) {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = port;
process.env.RSPACK_DEV_SERVER_BASE_PORT = port;
usedPort = port;
} else if (testedPort === 'auto') {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = port;
process.env.RSPACK_DEV_SERVER_BASE_PORT = port;
devServerOptions.port = testedPort;
Comment thread
chenjiahan marked this conversation as resolved.
usedPort = port;
} else {
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('port', () => {
testedPort === '<not-specified>' ||
typeof testedPort === 'undefined'
) {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = undefined;
process.env.RSPACK_DEV_SERVER_BASE_PORT = undefined;
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/web-socket-server-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('web socket server URL', () => {
});

it(`should work behind proxy, when the "host" option is "local-ip" and the "port" option is "auto" ("${webSocketServer}")`, async () => {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = 40000;
process.env.RSPACK_DEV_SERVER_BASE_PORT = 40000;

const proxyHost = Server.internalIPSync('v4');
const proxyPort = port2;
Expand Down Expand Up @@ -404,7 +404,7 @@ describe('web socket server URL', () => {
await browser.close();
await server.stop();

process.env.WEBPACK_DEV_SERVER_BASE_PORT = undefined;
process.env.RSPACK_DEV_SERVER_BASE_PORT = undefined;
}
});

Expand Down Expand Up @@ -2361,7 +2361,7 @@ describe('web socket server URL', () => {
});

it(`should work when "port" option is "auto" ("${webSocketServer}")`, async () => {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = 50000;
process.env.RSPACK_DEV_SERVER_BASE_PORT = 50000;

const compiler = rspack(config);
const devServerOptions = {
Expand Down Expand Up @@ -2430,7 +2430,7 @@ describe('web socket server URL', () => {
await browser.close();
await server.stop();

process.env.WEBPACK_DEV_SERVER_BASE_PORT = undefined;
process.env.RSPACK_DEV_SERVER_BASE_PORT = undefined;
}
});

Expand Down