Skip to content

Commit 8b55205

Browse files
committed
fix: merge conflict
2 parents 3c23e3d + dff393c commit 8b55205

35 files changed

Lines changed: 421 additions & 522 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.local
44
*.log*
55
*.tsbuildinfo
6+
*.cpuprofile
67

78
# Dist
89
node_modules

client-src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const getCurrentScriptSource = (): string => {
130130
}
131131

132132
// Fail as there was no script to use.
133-
throw new Error('[webpack-dev-server] Failed to get current script source.');
133+
throw new Error('[rspack-dev-server] Failed to get current script source.');
134134
};
135135

136136
const parsedResourceQuery = parseURL(__resourceQuery);

client-src/type.d.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,3 @@ declare interface CommunicationClient {
1818
declare interface CommunicationClientConstructor {
1919
new (url: string): CommunicationClient; // Defines a constructor that takes a string and returns a GreeterInstance
2020
}
21-
22-
declare module 'ansi-html-community' {
23-
function ansiHtmlCommunity(str: string): string;
24-
25-
namespace ansiHtmlCommunity {
26-
function setColors(colors: Record<string, string | string[]>): void;
27-
}
28-
29-
export = ansiHtmlCommunity;
30-
}

client-src/utils/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { LoggerOptions } from '../modules/types';
1212
import logger from '../modules/logger/index';
1313
import { LogLevel } from '../type';
1414

15-
const name = 'webpack-dev-server';
15+
const name = 'rspack-dev-server';
1616
// default level is set on the client side, so it does not need
1717
// to be set by the CLI or API
1818
const defaultLevel = 'info';

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"client"
5252
],
5353
"engines": {
54-
"node": ">= 18.12.0"
54+
"node": "^20.19.0 || >=22.12.0"
5555
},
5656
"packageManager": "pnpm@10.27.0",
5757
"homepage": "https://rspack.rs",
@@ -104,10 +104,8 @@
104104
"@types/serve-static": "^1.15.5",
105105
"@types/sockjs": "^0.3.36",
106106
"@types/ws": "^8.5.10",
107-
"ansi-html-community": "^0.0.8",
108107
"bonjour-service": "^1.2.1",
109108
"chokidar": "^3.6.0",
110-
"colorette": "^2.0.10",
111109
"compression": "^1.8.1",
112110
"connect-history-api-fallback": "^2.0.0",
113111
"express": "^4.22.1",

pnpm-lock.yaml

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server.ts

Lines changed: 37 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import type {
7474
Headers,
7575
} from './types';
7676

77+
const { styleText } = util;
78+
7779
export interface Configuration<
7880
A extends BasicApplication = ExpressApplication,
7981
S extends HTTPServer = HTTPServer,
@@ -186,7 +188,7 @@ class Server<
186188

187189
constructor(options: DevServer, compiler: Compiler | MultiCompiler) {
188190
this.compiler = compiler;
189-
this.logger = this.compiler.getInfrastructureLogger('webpack-dev-server');
191+
this.logger = this.compiler.getInfrastructureLogger('rspack-dev-server');
190192
this.options = options as unknown as Configuration<A, S>;
191193
this.staticWatchers = [];
192194
this.listeners = [];
@@ -359,16 +361,16 @@ class Server<
359361
}
360362

361363
if (!dir) {
362-
return path.resolve(cwd, '.cache/webpack-dev-server');
364+
return path.resolve(cwd, '.cache/rspack-dev-server');
363365
}
364366
if (process.versions.pnp === '1') {
365-
return path.resolve(dir, '.pnp/.cache/webpack-dev-server');
367+
return path.resolve(dir, '.pnp/.cache/rspack-dev-server');
366368
}
367369
if (process.versions.pnp === '3') {
368-
return path.resolve(dir, '.yarn/.cache/webpack-dev-server');
370+
return path.resolve(dir, '.yarn/.cache/rspack-dev-server');
369371
}
370372

371-
return path.resolve(dir, 'node_modules/.cache/webpack-dev-server');
373+
return path.resolve(dir, 'node_modules/.cache/rspack-dev-server');
372374
}
373375

374376
static isWebTarget(compiler: Compiler): boolean {
@@ -637,6 +639,12 @@ class Server<
637639
return (this.compiler as Compiler).options;
638640
}
639641

642+
shouldLogInfrastructureInfo() {
643+
const compilerOptions = this.getCompilerOptions();
644+
const { level = 'info' } = compilerOptions.infrastructureLogging || {};
645+
return level === 'info' || level === 'log' || level === 'verbose';
646+
}
647+
640648
async normalizeOptions() {
641649
const { options } = this;
642650
const compilerOptions = this.getCompilerOptions();
@@ -1577,7 +1585,7 @@ class Server<
15771585
}
15781586

15791587
this.logger.info(
1580-
'Gracefully shutting down. To force exit, press ^C again. Please wait...',
1588+
'Gracefully shutting down. Press ^C again to force exit...',
15811589
);
15821590

15831591
needForceShutdown = true;
@@ -1643,13 +1651,13 @@ class Server<
16431651
}
16441652

16451653
setupHooks(): void {
1646-
this.compiler.hooks.invalid.tap('webpack-dev-server', () => {
1654+
this.compiler.hooks.invalid.tap('rspack-dev-server', () => {
16471655
if (this.webSocketServer) {
16481656
this.sendMessage(this.webSocketServer.clients, 'invalid');
16491657
}
16501658
});
16511659
this.compiler.hooks.done.tap(
1652-
'webpack-dev-server',
1660+
'rspack-dev-server',
16531661
(stats: Stats | MultiStats): void => {
16541662
if (this.webSocketServer) {
16551663
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
@@ -1853,8 +1861,8 @@ class Server<
18531861
});
18541862

18551863
middlewares.push({
1856-
name: 'webpack-dev-server-assets',
1857-
path: '/webpack-dev-server',
1864+
name: 'rspack-dev-server-assets',
1865+
path: '/rspack-dev-server',
18581866
middleware: (req: Request, res: Response, next: NextFunction) => {
18591867
if (req.method !== 'GET' && req.method !== 'HEAD') {
18601868
next();
@@ -2400,10 +2408,10 @@ class Server<
24002408

24012409
this.bonjour = new Bonjour();
24022410
this.bonjour?.publish({
2403-
name: `Webpack Dev Server ${os.hostname()}:${this.options.port}`,
2411+
name: `Rspack Dev Server ${os.hostname()}:${this.options.port}`,
24042412
port: this.options.port as number,
24052413
type,
2406-
subtypes: ['webpack'],
2414+
subtypes: ['rspack'],
24072415
...(this.options.bonjour as Partial<BonjourOptions>),
24082416
});
24092417
}
@@ -2419,43 +2427,6 @@ class Server<
24192427
}
24202428

24212429
async logStatus() {
2422-
const { cyan, isColorSupported, red } = require('colorette');
2423-
2424-
const getColorsOption = (compilerOptions: Compiler['options']): boolean => {
2425-
let colorsEnabled: boolean;
2426-
2427-
if (
2428-
compilerOptions.stats &&
2429-
typeof (compilerOptions.stats as unknown as StatsOptions).colors !==
2430-
'undefined'
2431-
) {
2432-
colorsEnabled = (compilerOptions.stats as unknown as StatsOptions)
2433-
.colors as boolean;
2434-
} else {
2435-
colorsEnabled = isColorSupported as boolean;
2436-
}
2437-
2438-
return colorsEnabled;
2439-
};
2440-
2441-
const colors = {
2442-
info(useColor: boolean, msg: string): string {
2443-
if (useColor) {
2444-
return cyan(msg);
2445-
}
2446-
2447-
return msg;
2448-
},
2449-
error(useColor: boolean, msg: string): string {
2450-
if (useColor) {
2451-
return red(msg);
2452-
}
2453-
2454-
return msg;
2455-
},
2456-
};
2457-
const useColor = getColorsOption(this.getCompilerOptions());
2458-
24592430
const server = this.server as S;
24602431

24612432
if (this.options.ipc) {
@@ -2470,29 +2441,14 @@ class Server<
24702441
const prettyPrintURL = (newHostname: string): string =>
24712442
url.format({ protocol, hostname: newHostname, port, pathname: '/' });
24722443

2473-
let host: string | undefined;
24742444
let localhost: string | undefined;
24752445
let loopbackIPv4: string | undefined;
24762446
let loopbackIPv6: string | undefined;
24772447
let networkUrlIPv4: string | undefined;
24782448
let networkUrlIPv6: string | undefined;
24792449

2480-
if (this.options.host) {
2481-
if (this.options.host === 'localhost') {
2482-
localhost = prettyPrintURL('localhost');
2483-
} else {
2484-
let isIP: IPv6 | ipaddr.IPv4 | null | undefined;
2485-
2486-
try {
2487-
isIP = ipaddr.parse(this.options.host) as IPv6 | ipaddr.IPv4;
2488-
} catch {
2489-
// Ignore
2490-
}
2491-
2492-
if (!isIP) {
2493-
host = prettyPrintURL(this.options.host);
2494-
}
2495-
}
2450+
if (this.options.host === 'localhost') {
2451+
localhost = prettyPrintURL('localhost');
24962452
}
24972453

24982454
const parsedIP = ipaddr.parse(address);
@@ -2529,40 +2485,27 @@ class Server<
25292485
}
25302486
}
25312487

2532-
this.logger.info('Project is running at:');
2533-
2534-
if (host) {
2535-
this.logger.info(`Server: ${colors.info(useColor, host)}`);
2536-
}
2537-
2538-
if (localhost || loopbackIPv4 || loopbackIPv6) {
2539-
const loopbacks = [];
2540-
2541-
if (localhost) {
2542-
loopbacks.push([colors.info(useColor, localhost)]);
2543-
}
2544-
2545-
if (loopbackIPv4) {
2546-
loopbacks.push([colors.info(useColor, loopbackIPv4)]);
2547-
}
2548-
2549-
if (loopbackIPv6) {
2550-
loopbacks.push([colors.info(useColor, loopbackIPv6)]);
2551-
}
2488+
const urlLogs: string[] = [];
25522489

2553-
this.logger.info(`Loopback: ${loopbacks.join(', ')}`);
2490+
const local = localhost || loopbackIPv4 || loopbackIPv6;
2491+
if (local) {
2492+
urlLogs.push(
2493+
` ${styleText('white', '➜')} ${styleText(['white', 'dim'], 'Local:')} ${styleText('cyan', local)}`,
2494+
);
25542495
}
25552496

25562497
if (networkUrlIPv4) {
2557-
this.logger.info(
2558-
`On Your Network (IPv4): ${colors.info(useColor, networkUrlIPv4)}`,
2498+
urlLogs.push(
2499+
` ${styleText('white', '➜')} ${styleText(['white', 'dim'], 'Network:')} ${styleText('cyan', networkUrlIPv4)}`,
2500+
);
2501+
} else if (networkUrlIPv6) {
2502+
urlLogs.push(
2503+
` ${styleText('white', '➜')} ${styleText(['white', 'dim'], 'Network:')} ${styleText('cyan', networkUrlIPv6)}`,
25592504
);
25602505
}
25612506

2562-
if (networkUrlIPv6) {
2563-
this.logger.info(
2564-
`On Your Network (IPv6): ${colors.info(useColor, networkUrlIPv6)}`,
2565-
);
2507+
if (urlLogs.length && this.shouldLogInfrastructureInfo()) {
2508+
console.log(`${urlLogs.join('\n')}\n`);
25662509
}
25672510

25682511
if ((this.options.open as NormalizedOpen[])?.length > 0) {
@@ -2578,27 +2521,6 @@ class Server<
25782521
}
25792522
}
25802523

2581-
if ((this.options.static as NormalizedStatic[])?.length > 0) {
2582-
this.logger.info(
2583-
`Content not from webpack is served from '${colors.info(
2584-
useColor,
2585-
(this.options.static as NormalizedStatic[])
2586-
.map((staticOption) => staticOption.directory)
2587-
.join(', '),
2588-
)}' directory`,
2589-
);
2590-
}
2591-
2592-
if (this.options.historyApiFallback) {
2593-
this.logger.info(
2594-
`404s will fallback to '${colors.info(
2595-
useColor,
2596-
(this.options.historyApiFallback as ConnectHistoryApiFallbackOptions)
2597-
.index || '/index.html',
2598-
)}'`,
2599-
);
2600-
}
2601-
26022524
if (this.options.bonjour) {
26032525
const bonjourProtocol =
26042526
(this.options.bonjour as BonjourOptions | undefined)?.type ||
@@ -2607,7 +2529,7 @@ class Server<
26072529
: 'http';
26082530

26092531
this.logger.info(
2610-
`Broadcasting "${bonjourProtocol}" with subtype of "webpack" via ZeroConf DNS (Bonjour)`,
2532+
`Broadcasting "${bonjourProtocol}" with subtype of "rspack" via ZeroConf DNS (Bonjour)`,
26112533
);
26122534
}
26132535
}

0 commit comments

Comments
 (0)