@rspack/dev-server 2.0.0-beta.4 → 2.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/131.js CHANGED
@@ -237,6 +237,7 @@ const getConnect = async ()=>{
237
237
  const { connect } = await import("connect-next");
238
238
  return connect;
239
239
  };
240
+ const getChokidar = memoize(()=>import("chokidar"));
240
241
  const getServeStatic = memoize(()=>server_require('serve-static'));
241
242
  const encodeOverlaySettings = (setting)=>'function' == typeof setting ? encodeURIComponent(setting.toString()) : setting;
242
243
  const DEFAULT_ALLOWED_PROTOCOLS = /^(file|.+-extension):/i;
@@ -352,7 +353,7 @@ class Server {
352
353
  if ('3' === process.versions.pnp) return external_node_path_resolve(dir, '.yarn/.cache/rspack-dev-server');
353
354
  return external_node_path_resolve(dir, 'node_modules/.cache/rspack-dev-server');
354
355
  }
355
- addAdditionalEntries(compiler) {
356
+ #addAdditionalEntries(compiler) {
356
357
  const additionalEntries = [];
357
358
  const isWebTarget = Boolean(compiler.platform.web);
358
359
  if (this.options.client && isWebTarget) {
@@ -403,7 +404,7 @@ class Server {
403
404
  name: void 0
404
405
  }).apply(compiler);
405
406
  }
406
- getCompilerOptions() {
407
+ #getCompilerOptions() {
407
408
  if (void 0 !== this.compiler.compilers) {
408
409
  if (1 === this.compiler.compilers.length) return this.compiler.compilers[0].options;
409
410
  const compilerWithDevServer = this.compiler.compilers.find((config)=>config.options.devServer);
@@ -414,14 +415,14 @@ class Server {
414
415
  }
415
416
  return this.compiler.options;
416
417
  }
417
- shouldLogInfrastructureInfo() {
418
- const compilerOptions = this.getCompilerOptions();
418
+ #shouldLogInfrastructureInfo() {
419
+ const compilerOptions = this.#getCompilerOptions();
419
420
  const { level = 'info' } = compilerOptions.infrastructureLogging || {};
420
421
  return 'info' === level || 'log' === level || 'verbose' === level;
421
422
  }
422
- async normalizeOptions() {
423
+ async #normalizeOptions() {
423
424
  const { options } = this;
424
- const compilerOptions = this.getCompilerOptions();
425
+ const compilerOptions = this.#getCompilerOptions();
425
426
  const compilerWatchOptions = compilerOptions.watchOptions;
426
427
  const getWatchOptions = (watchOptions = {})=>{
427
428
  const getPolling = ()=>{
@@ -437,7 +438,7 @@ class Server {
437
438
  };
438
439
  const usePolling = getPolling();
439
440
  const interval = getInterval();
440
- const { poll, ...rest } = watchOptions;
441
+ const { poll: _poll, ...rest } = watchOptions;
441
442
  return {
442
443
  ignoreInitial: true,
443
444
  persistent: true,
@@ -446,8 +447,9 @@ class Server {
446
447
  alwaysStat: true,
447
448
  ignorePermissionErrors: true,
448
449
  usePolling,
449
- interval,
450
- ignored: watchOptions.ignored,
450
+ ...void 0 !== interval ? {
451
+ interval
452
+ } : {},
451
453
  ...rest
452
454
  };
453
455
  };
@@ -458,9 +460,6 @@ class Server {
458
460
  publicPath: [
459
461
  '/'
460
462
  ],
461
- serveIndex: {
462
- icons: true
463
- },
464
463
  watch: getWatchOptions()
465
464
  });
466
465
  let item;
@@ -480,10 +479,6 @@ class Server {
480
479
  publicPath: void 0 !== optionsForStatic.publicPath ? Array.isArray(optionsForStatic.publicPath) ? optionsForStatic.publicPath : [
481
480
  optionsForStatic.publicPath
482
481
  ] : def.publicPath,
483
- serveIndex: void 0 !== optionsForStatic.serveIndex ? 'boolean' == typeof optionsForStatic.serveIndex && optionsForStatic.serveIndex ? def.serveIndex : 'object' == typeof optionsForStatic.serveIndex ? {
484
- ...def.serveIndex,
485
- ...optionsForStatic.serveIndex
486
- } : optionsForStatic.serveIndex : def.serveIndex,
487
482
  watch: void 0 !== optionsForStatic.watch ? 'boolean' == typeof optionsForStatic.watch ? optionsForStatic.watch ? def.watch : false : getWatchOptions(optionsForStatic.watch) : def.watch
488
483
  };
489
484
  }
@@ -799,7 +794,7 @@ class Server {
799
794
  }
800
795
  else options.webSocketServer = false;
801
796
  }
802
- getClientTransport() {
797
+ #getClientTransport() {
803
798
  let clientImplementation;
804
799
  let clientImplementationFound = true;
805
800
  const isKnownWebSocketServerImplementation = this.options.webSocketServer && 'string' == typeof this.options.webSocketServer.type && 'ws' === this.options.webSocketServer.type;
@@ -821,7 +816,7 @@ class Server {
821
816
  if (!clientImplementationFound) throw new Error(`${!isKnownWebSocketServerImplementation ? 'When you use custom web socket implementation you must explicitly specify client.webSocketTransport. ' : ''}client.webSocketTransport must be a string denoting a default implementation (e.g. 'ws') or a full path to a JS file via require.resolve(...) which exports a class `);
822
817
  return clientImplementation;
823
818
  }
824
- getServerTransport() {
819
+ #getServerTransport() {
825
820
  let implementation;
826
821
  let implementationFound = true;
827
822
  switch(typeof this.options.webSocketServer.type){
@@ -850,7 +845,7 @@ class Server {
850
845
  if ('only' === this.options.hot) return server_require.resolve('@rspack/core/hot/only-dev-server');
851
846
  if (this.options.hot) return server_require.resolve('@rspack/core/hot/dev-server');
852
847
  }
853
- setupProgressPlugin() {
848
+ #setupProgressPlugin() {
854
849
  const { ProgressPlugin } = this.compiler.compilers ? this.compiler.compilers[0].webpack : this.compiler.webpack;
855
850
  new ProgressPlugin((percent, msg)=>{
856
851
  const percentValue = Math.floor(100 * percent);
@@ -864,7 +859,7 @@ class Server {
864
859
  if (this.server) this.server.emit('progress-update', payload);
865
860
  }).apply(this.compiler);
866
861
  }
867
- async initialize() {
862
+ async #initialize() {
868
863
  const compilers = isMultiCompiler(this.compiler) ? this.compiler.compilers : [
869
864
  this.compiler
870
865
  ];
@@ -878,19 +873,19 @@ class Server {
878
873
  };
879
874
  }
880
875
  }
881
- this.setupHooks();
882
- await this.setupApp();
883
- await this.createServer();
876
+ this.#setupHooks();
877
+ await this.#setupApp();
878
+ await this.#createServer();
884
879
  if (this.options.webSocketServer) {
885
880
  const compilers = this.compiler.compilers || [
886
881
  this.compiler
887
882
  ];
888
883
  for (const compiler of compilers){
889
884
  if (false === compiler.options.devServer) continue;
890
- this.addAdditionalEntries(compiler);
885
+ this.#addAdditionalEntries(compiler);
891
886
  const { ProvidePlugin, HotModuleReplacementPlugin } = compiler.rspack;
892
887
  new ProvidePlugin({
893
- __rspack_dev_server_client__: this.getClientTransport()
888
+ __rspack_dev_server_client__: this.#getClientTransport()
894
889
  }).apply(compiler);
895
890
  if (this.options.hot) {
896
891
  const HMRPluginExists = compiler.options.plugins.find((plugin)=>plugin && plugin.constructor === HotModuleReplacementPlugin);
@@ -901,11 +896,11 @@ class Server {
901
896
  }
902
897
  }
903
898
  }
904
- if (this.options.client && this.options.client.progress) this.setupProgressPlugin();
899
+ if (this.options.client && this.options.client.progress) this.#setupProgressPlugin();
905
900
  }
906
- this.setupWatchFiles();
907
- this.setupWatchStaticFiles();
908
- await this.setupMiddlewares();
901
+ await this.#setupWatchFiles();
902
+ await this.#setupWatchStaticFiles();
903
+ await this.#setupMiddlewares();
909
904
  if (this.options.setupExitSignals) {
910
905
  const signals = [
911
906
  'SIGINT',
@@ -934,35 +929,35 @@ class Server {
934
929
  const webSocketProxies = this.webSocketProxies;
935
930
  for (const webSocketProxy of webSocketProxies)this.server.on('upgrade', webSocketProxy.upgrade);
936
931
  }
937
- async setupApp() {
932
+ async #setupApp() {
938
933
  this.app = 'function' == typeof this.options.app ? await this.options.app() : (await getConnect())();
939
934
  }
940
- getStats(statsObj) {
935
+ #getStats(statsObj) {
941
936
  const stats = Server.DEFAULT_STATS;
942
- const compilerOptions = this.getCompilerOptions();
937
+ const compilerOptions = this.#getCompilerOptions();
943
938
  if (compilerOptions.stats && compilerOptions.stats.warningsFilter) stats.warningsFilter = compilerOptions.stats.warningsFilter;
944
939
  return statsObj.toJson(stats);
945
940
  }
946
- setupHooks() {
941
+ #setupHooks() {
947
942
  this.compiler.hooks.invalid.tap('rspack-dev-server', ()=>{
948
943
  if (this.webSocketServer) this.sendMessage(this.webSocketServer.clients, 'invalid');
949
944
  });
950
945
  this.compiler.hooks.done.tap('rspack-dev-server', (stats)=>{
951
- if (this.webSocketServer) this.sendStats(this.webSocketServer.clients, this.getStats(stats));
946
+ if (this.webSocketServer) this.#sendStats(this.webSocketServer.clients, this.#getStats(stats));
952
947
  this.stats = stats;
953
948
  });
954
949
  }
955
- setupWatchStaticFiles() {
950
+ async #setupWatchStaticFiles() {
956
951
  const watchFiles = this.options.static;
957
952
  if (watchFiles.length > 0) {
958
- for (const item of watchFiles)if (item.watch) this.watchFiles(item.directory, item.watch);
953
+ for (const item of watchFiles)if (item.watch) await this.watchFiles(item.directory, item.watch);
959
954
  }
960
955
  }
961
- setupWatchFiles() {
956
+ async #setupWatchFiles() {
962
957
  const watchFiles = this.options.watchFiles;
963
- if (watchFiles.length > 0) for (const item of watchFiles)this.watchFiles(item.paths, item.options);
958
+ if (watchFiles.length > 0) for (const item of watchFiles)await this.watchFiles(item.paths, item.options);
964
959
  }
965
- async setupMiddlewares() {
960
+ async #setupMiddlewares() {
966
961
  let middlewares = [];
967
962
  middlewares.push({
968
963
  name: 'host-header-check',
@@ -1007,7 +1002,7 @@ class Server {
1007
1002
  });
1008
1003
  if (void 0 !== this.options.headers) middlewares.push({
1009
1004
  name: 'set-headers',
1010
- middleware: this.setHeaders.bind(this)
1005
+ middleware: this.#setHeaders.bind(this)
1011
1006
  });
1012
1007
  middlewares.push({
1013
1008
  name: 'webpack-dev-middleware',
@@ -1144,17 +1139,6 @@ class Server {
1144
1139
  middleware: getServeStatic()(staticOption.directory, staticOption.staticOptions)
1145
1140
  });
1146
1141
  }
1147
- if (staticOptions.length > 0) {
1148
- const serveIndex = server_require('serve-index');
1149
- for (const staticOption of staticOptions)for (const publicPath of staticOption.publicPath)if (staticOption.serveIndex) middlewares.push({
1150
- name: 'serve-index',
1151
- path: publicPath,
1152
- middleware: (req, res, next)=>{
1153
- if ('GET' !== req.method && 'HEAD' !== req.method) return next();
1154
- serveIndex(staticOption.directory, staticOption.serveIndex)(req, res, next);
1155
- }
1156
- });
1157
- }
1158
1142
  middlewares.push({
1159
1143
  name: 'options-middleware',
1160
1144
  middleware: (req, res, next)=>{
@@ -1183,7 +1167,7 @@ class Server {
1183
1167
  else if (void 0 !== middleware.path) this.app.use(middleware.path, middleware.middleware);
1184
1168
  else this.app.use(middleware.middleware);
1185
1169
  }
1186
- async createServer() {
1170
+ async #createServer() {
1187
1171
  const { type, options } = this.options.server;
1188
1172
  if ('function' == typeof type) this.server = await type(options, this.app);
1189
1173
  else {
@@ -1204,12 +1188,12 @@ class Server {
1204
1188
  throw error;
1205
1189
  });
1206
1190
  }
1207
- createWebSocketServer() {
1208
- this.webSocketServer = new (this.getServerTransport())(this);
1191
+ #createWebSocketServer() {
1192
+ this.webSocketServer = new (this.#getServerTransport())(this);
1209
1193
  (this.webSocketServer?.implementation).on('connection', (client, request)=>{
1210
1194
  const headers = void 0 !== request ? request.headers : void 0;
1211
1195
  if (!headers) this.logger.warn('webSocketServer implementation must pass headers for the "connection" event');
1212
- if (!headers || !this.isValidHost(headers, 'host') || !this.isValidHost(headers, 'origin') || !this.isSameOrigin(headers)) {
1196
+ if (!headers || !this.isValidHost(headers, 'host') || !this.isValidHost(headers, 'origin') || !this.#isSameOrigin(headers)) {
1213
1197
  this.sendMessage([
1214
1198
  client
1215
1199
  ], 'error', 'Invalid Host/Origin header');
@@ -1240,12 +1224,12 @@ class Server {
1240
1224
  } : overlayConfig);
1241
1225
  }
1242
1226
  if (!this.stats) return;
1243
- this.sendStats([
1227
+ this.#sendStats([
1244
1228
  client
1245
- ], this.getStats(this.stats), true);
1229
+ ], this.#getStats(this.stats), true);
1246
1230
  });
1247
1231
  }
1248
- async openBrowser(defaultOpenTarget) {
1232
+ async #openBrowser(defaultOpenTarget) {
1249
1233
  const { default: open } = await import("./0~open.js").then((mod)=>({
1250
1234
  default: mod.node_modules_open
1251
1235
  }));
@@ -1258,7 +1242,7 @@ class Server {
1258
1242
  });
1259
1243
  }));
1260
1244
  }
1261
- async logStatus() {
1245
+ async #logStatus() {
1262
1246
  const server = this.server;
1263
1247
  if (this.options.ipc) this.logger.info(`Project is running at: "${server?.address()}"`);
1264
1248
  else {
@@ -1307,14 +1291,14 @@ class Server {
1307
1291
  'white',
1308
1292
  'dim'
1309
1293
  ], 'Network:')} ${server_styleText('cyan', networkUrlIPv6)}`);
1310
- if (urlLogs.length && this.shouldLogInfrastructureInfo()) console.log(`${urlLogs.join('\n')}\n`);
1294
+ if (urlLogs.length && this.#shouldLogInfrastructureInfo()) console.log(`${urlLogs.join('\n')}\n`);
1311
1295
  if (this.options.open?.length > 0) {
1312
1296
  const openTarget = prettyPrintURL(this.options.host && '0.0.0.0' !== this.options.host && '::' !== this.options.host ? this.options.host : 'localhost');
1313
- await this.openBrowser(openTarget);
1297
+ await this.#openBrowser(openTarget);
1314
1298
  }
1315
1299
  }
1316
1300
  }
1317
- setHeaders(req, res, next) {
1301
+ #setHeaders(req, res, next) {
1318
1302
  let { headers } = this.options;
1319
1303
  if (headers) {
1320
1304
  if ('function' == typeof headers) headers = headers(req, res, this.middleware ? this.middleware.context : void 0);
@@ -1330,7 +1314,7 @@ class Server {
1330
1314
  }
1331
1315
  next();
1332
1316
  }
1333
- isHostAllowed(value) {
1317
+ #isHostAllowed(value) {
1334
1318
  const { allowedHosts } = this.options;
1335
1319
  if ('all' === allowedHosts) return true;
1336
1320
  if (Array.isArray(allowedHosts) && allowedHosts.length > 0) for (const allowedHost of allowedHosts){
@@ -1347,24 +1331,24 @@ class Server {
1347
1331
  if (DEFAULT_ALLOWED_PROTOCOLS.test(header)) return true;
1348
1332
  const hostname = parseHostnameFromHeader(header);
1349
1333
  if (null === hostname) return false;
1350
- if (this.isHostAllowed(hostname)) return true;
1334
+ if (this.#isHostAllowed(hostname)) return true;
1351
1335
  const isValidHostname = validateHost ? ipaddr.IPv4.isValid(hostname) || ipaddr.IPv6.isValid(hostname) || 'localhost' === hostname || hostname.endsWith('.localhost') || hostname === this.options.host : false;
1352
1336
  return isValidHostname;
1353
1337
  }
1354
- isSameOrigin(headers) {
1338
+ #isSameOrigin(headers) {
1355
1339
  if ('all' === this.options.allowedHosts) return true;
1356
1340
  const originHeader = headers.origin;
1357
1341
  if (!originHeader) return 'all' === this.options.allowedHosts;
1358
1342
  if (DEFAULT_ALLOWED_PROTOCOLS.test(originHeader)) return true;
1359
1343
  const origin = parseHostnameFromHeader(originHeader);
1360
1344
  if (null === origin) return false;
1361
- if (this.isHostAllowed(origin)) return true;
1345
+ if (this.#isHostAllowed(origin)) return true;
1362
1346
  const hostHeader = headers.host;
1363
1347
  if (!hostHeader) return 'all' === this.options.allowedHosts;
1364
1348
  if (DEFAULT_ALLOWED_PROTOCOLS.test(hostHeader)) return true;
1365
1349
  const host = parseHostnameFromHeader(hostHeader);
1366
1350
  if (null === host) return false;
1367
- if (this.isHostAllowed(host)) return true;
1351
+ if (this.#isHostAllowed(host)) return true;
1368
1352
  return origin === host;
1369
1353
  }
1370
1354
  sendMessage(clients, type, data, params) {
@@ -1374,7 +1358,7 @@ class Server {
1374
1358
  params
1375
1359
  }));
1376
1360
  }
1377
- sendStats(clients, stats, force) {
1361
+ #sendStats(clients, stats, force) {
1378
1362
  if (!stats) return;
1379
1363
  const shouldEmit = !force && stats && (!stats.errors || 0 === stats.errors.length) && (!stats.warnings || 0 === stats.warnings.length) && this.currentHash === stats.hash;
1380
1364
  if (shouldEmit) return void this.sendMessage(clients, 'still-ok');
@@ -1392,9 +1376,9 @@ class Server {
1392
1376
  if (stats.errors?.length > 0) this.sendMessage(clients, 'errors', stats.errors);
1393
1377
  } else this.sendMessage(clients, 'ok');
1394
1378
  }
1395
- watchFiles(watchPath, watchOptions) {
1396
- const chokidar = server_require('chokidar');
1397
- const watcher = chokidar.watch(watchPath, watchOptions);
1379
+ async watchFiles(watchPath, watchOptions) {
1380
+ const { watch } = await getChokidar();
1381
+ const watcher = watch(watchPath, watchOptions);
1398
1382
  if (this.options.liveReload) watcher.on('change', (item)=>{
1399
1383
  if (this.webSocketServer) this.sendMessage(this.webSocketServer.clients, 'static-changed', item);
1400
1384
  });
@@ -1404,7 +1388,7 @@ class Server {
1404
1388
  if (this.middleware) this.middleware.invalidate(callback);
1405
1389
  }
1406
1390
  async start() {
1407
- await this.normalizeOptions();
1391
+ await this.#normalizeOptions();
1408
1392
  if (this.options.ipc) await new Promise((resolve, reject)=>{
1409
1393
  const net = server_require('node:net');
1410
1394
  const socket = new net.Socket();
@@ -1427,7 +1411,7 @@ class Server {
1427
1411
  this.options.host = await Server.getHostname(this.options.host);
1428
1412
  this.options.port = await Server.getFreePort(this.options.port, this.options.host);
1429
1413
  }
1430
- await this.initialize();
1414
+ await this.#initialize();
1431
1415
  const listenOptions = this.options.ipc ? {
1432
1416
  path: this.options.ipc
1433
1417
  } : {
@@ -1443,8 +1427,8 @@ class Server {
1443
1427
  const READ_WRITE = 438;
1444
1428
  await promises.chmod(this.options.ipc, READ_WRITE);
1445
1429
  }
1446
- if (this.options.webSocketServer) this.createWebSocketServer();
1447
- await this.logStatus();
1430
+ if (this.options.webSocketServer) this.#createWebSocketServer();
1431
+ await this.#logStatus();
1448
1432
  if ('function' == typeof this.options.onListening) this.options.onListening(this);
1449
1433
  }
1450
1434
  startCallback(callback = ()=>{}) {
package/dist/server.d.ts CHANGED
@@ -7,9 +7,9 @@
7
7
  * Copyright (c) JS Foundation and other contributors
8
8
  * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
9
  */
10
- import type { BasicApplication, ClientConfiguration, ClientConnection, Compiler, ConnectHistoryApiFallbackOptions, DevMiddlewareContext, DevMiddlewareOptions, DevServer, EXPECTED_ANY, FSWatcher, HTTPServer, Headers, Host, LiteralUnion, Middleware, MultiCompiler, MultiStats, NextFunction, Open, Port, ProxyConfigArray, Request, RequestHandler, Response, ServerConfiguration, ServerType, Socket, Static, Stats, StatsCompilation, StatsOptions, WatchFiles, WatchOptions, WebSocketServerConfiguration, WebSocketServerImplementation } from './types';
10
+ import type { BasicApplication, BasicServer, ClientConfiguration, ClientConnection, Compiler, ConnectHistoryApiFallbackOptions, DevMiddlewareContext, DevMiddlewareOptions, DevServer, EXPECTED_ANY, FSWatcher, HTTPServer, Headers, Host, LiteralUnion, Middleware, MultiCompiler, MultiStats, Open, Port, ProxyConfigArray, Request, RequestHandler, Response, ServerConfiguration, ServerType, Socket, Static, Stats, StatsOptions, WatchFiles, WatchOptions, WebSocketServerConfiguration, WebSocketServerImplementation } from './types';
11
11
  import type { ConnectApplication } from './types';
12
- export interface Configuration<A extends BasicApplication = ConnectApplication, S extends HTTPServer = HTTPServer> {
12
+ export interface Configuration<A extends BasicApplication = ConnectApplication, S extends BasicServer = HTTPServer> {
13
13
  ipc?: boolean | string;
14
14
  host?: Host;
15
15
  port?: Port;
@@ -32,7 +32,8 @@ export interface Configuration<A extends BasicApplication = ConnectApplication,
32
32
  onListening?: (devServer: Server<A, S>) => void;
33
33
  setupMiddlewares?: (middlewares: Middleware[], devServer: Server<A, S>) => Middleware[];
34
34
  }
35
- declare class Server<A extends BasicApplication = ConnectApplication, S extends import('http').Server = HTTPServer> {
35
+ declare class Server<A extends BasicApplication = ConnectApplication, S extends BasicServer = HTTPServer> {
36
+ #private;
36
37
  compiler: Compiler | MultiCompiler;
37
38
  logger: ReturnType<Compiler['getInfrastructureLogger']>;
38
39
  options: Configuration<A, S>;
@@ -57,49 +58,11 @@ declare class Server<A extends BasicApplication = ConnectApplication, S extends
57
58
  static getHostname(hostname: Host): Promise<string>;
58
59
  static getFreePort(port: string, host: string): Promise<string | number>;
59
60
  static findCacheDir(): string;
60
- addAdditionalEntries(compiler: Compiler): void;
61
- /**
62
- * @private
63
- * @returns {Compiler["options"]} compiler options
64
- */
65
- getCompilerOptions(): import("@rspack/core").RspackOptionsNormalized;
66
- shouldLogInfrastructureInfo(): boolean;
67
- normalizeOptions(): Promise<void>;
68
- /**
69
- * @private
70
- * @returns {string} client transport
71
- */
72
- getClientTransport(): string;
73
- getServerTransport(): unknown;
74
61
  getClientEntry(): string;
75
62
  getClientHotEntry(): string | undefined;
76
- setupProgressPlugin(): void;
77
- /**
78
- * @private
79
- * @returns {Promise<void>}
80
- */
81
- initialize(): Promise<void>;
82
- setupApp(): Promise<void>;
83
- getStats(statsObj: Stats | MultiStats): StatsCompilation;
84
- setupHooks(): void;
85
- setupWatchStaticFiles(): void;
86
- setupWatchFiles(): void;
87
- setupMiddlewares(): Promise<void>;
88
- /**
89
- * @private
90
- * @returns {Promise<void>}
91
- */
92
- createServer(): Promise<void>;
93
- createWebSocketServer(): void;
94
- openBrowser(defaultOpenTarget: string): Promise<void>;
95
- logStatus(): Promise<void>;
96
- setHeaders(req: Request, res: Response, next: NextFunction): void;
97
- isHostAllowed(value: string): boolean;
98
63
  isValidHost(headers: Record<string, string | undefined>, headerToCheck: string, validateHost?: boolean): boolean;
99
- isSameOrigin(headers: Record<string, string | undefined>): boolean;
100
64
  sendMessage(clients: ClientConnection[], type: string, data?: EXPECTED_ANY, params?: EXPECTED_ANY): void;
101
- sendStats(clients: ClientConnection[], stats: StatsCompilation, force?: boolean): void;
102
- watchFiles(watchPath: string | string[], watchOptions?: WatchOptions): void;
65
+ watchFiles(watchPath: string | string[], watchOptions?: WatchOptions): Promise<void>;
103
66
  invalidate(callback?: import('webpack-dev-middleware').Callback): void;
104
67
  start(): Promise<void>;
105
68
  startCallback(callback?: (err?: Error) => void): void;
package/dist/types.d.ts CHANGED
@@ -1,22 +1,18 @@
1
1
  import type { Server as HTTPServer, IncomingMessage, ServerResponse } from 'node:http';
2
- export type { HTTPServer, IncomingMessage };
2
+ import type { ServerOptions } from 'node:https';
3
+ import type { FSWatcher, ChokidarOptions as WatchOptions } from 'chokidar';
4
+ import type { Options as ConnectHistoryApiFallbackOptions } from 'connect-history-api-fallback';
5
+ import type { Server as ConnectApplication, IncomingMessage as ConnectIncomingMessage } from 'connect-next';
6
+ import type { Options as HttpProxyMiddlewareOptions, Filter as HttpProxyMiddlewareOptionsFilter, RequestHandler } from 'http-proxy-middleware';
7
+ import type { ServeStaticOptions } from 'serve-static';
8
+ export type { FSWatcher, WatchOptions, RequestHandler, BasicServer, HTTPServer, ServerOptions, IncomingMessage, ConnectApplication, ConnectHistoryApiFallbackOptions, };
9
+ export type { IPv6 } from 'ipaddr.js';
3
10
  export type { Socket } from 'node:net';
4
11
  export type { AddressInfo } from 'node:net';
5
12
  export type { NetworkInterfaceInfo } from 'node:os';
6
13
  export type { Compiler, DevServer, MultiCompiler, MultiStats, Stats, StatsCompilation, StatsOptions, } from '@rspack/core';
7
- import type { FSWatcher, WatchOptions } from 'chokidar';
8
- export type { FSWatcher, WatchOptions };
9
- import type { Server as ConnectApplication, IncomingMessage as ConnectIncomingMessage } from 'connect-next';
10
- export type { ConnectApplication };
11
- import type { Options as ConnectHistoryApiFallbackOptions } from 'connect-history-api-fallback';
12
- export type { ConnectHistoryApiFallbackOptions };
13
- import type { Options as HttpProxyMiddlewareOptions, Filter as HttpProxyMiddlewareOptionsFilter, RequestHandler } from 'http-proxy-middleware';
14
- export type { RequestHandler };
15
- export type { IPv6 } from 'ipaddr.js';
16
- import type { Options as ServeIndexOptions } from 'serve-index';
17
- export type { ServeIndexOptions };
18
- import type { ServeStaticOptions } from 'serve-static';
19
14
  export type EXPECTED_ANY = any;
15
+ type BasicServer = import('node:net').Server | import('node:tls').Server;
20
16
  /** https://github.com/microsoft/TypeScript/issues/29729 */
21
17
  export type LiteralUnion<T extends U, U> = T | (U & Record<never, never>);
22
18
  export type NextFunction = (err?: EXPECTED_ANY) => void;
@@ -24,7 +20,6 @@ export type SimpleHandleFunction = (req: IncomingMessage, res: ServerResponse) =
24
20
  export type NextHandleFunction = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
25
21
  export type ErrorHandleFunction = (err: EXPECTED_ANY, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
26
22
  export type HandleFunction = SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction;
27
- export type ServerOptions = import('https').ServerOptions;
28
23
  export type Request<T extends BasicApplication = ConnectApplication> = T extends ConnectApplication ? ConnectIncomingMessage : IncomingMessage;
29
24
  export type Response = ServerResponse;
30
25
  export type DevMiddlewareOptions<T extends Request, U extends Response> = import('webpack-dev-middleware').Options<T, U>;
@@ -35,30 +30,23 @@ export interface WatchFiles {
35
30
  paths: string | string[];
36
31
  options?: WatchOptions & {
37
32
  aggregateTimeout?: number;
38
- ignored?: WatchOptions['ignored'];
39
33
  poll?: number | boolean;
40
34
  };
41
35
  }
42
36
  export interface Static {
43
37
  directory?: string;
44
38
  publicPath?: string | string[];
45
- serveIndex?: boolean | ServeIndexOptions;
46
39
  staticOptions?: ServeStaticOptions;
47
- watch?: boolean | (WatchOptions & {
48
- aggregateTimeout?: number;
49
- ignored?: WatchOptions['ignored'];
50
- poll?: number | boolean;
51
- });
40
+ watch?: boolean | NonNullable<WatchFiles['options']>;
52
41
  }
53
42
  export interface NormalizedStatic {
54
43
  directory: string;
55
44
  publicPath: string[];
56
- serveIndex: false | ServeIndexOptions;
57
45
  staticOptions: ServeStaticOptions;
58
46
  watch: false | WatchOptions;
59
47
  }
60
- export type ServerType<A extends BasicApplication = ConnectApplication, S extends import('http').Server = import('http').Server> = LiteralUnion<'http' | 'https' | 'http2', string> | ((serverOptions: ServerOptions, application: A) => S);
61
- export interface ServerConfiguration<A extends BasicApplication = ConnectApplication, S extends import('http').Server = import('http').Server> {
48
+ export type ServerType<A extends BasicApplication, S extends BasicServer> = LiteralUnion<'http' | 'https' | 'http2', string> | ((serverOptions: ServerOptions, application: A) => S);
49
+ export interface ServerConfiguration<A extends BasicApplication = ConnectApplication, S extends BasicServer = HTTPServer> {
62
50
  type?: ServerType<A, S>;
63
51
  options?: ServerOptions;
64
52
  }
@@ -125,7 +113,6 @@ export interface MiddlewareObject {
125
113
  middleware: MiddlewareHandler;
126
114
  }
127
115
  export type Middleware = MiddlewareObject | MiddlewareHandler;
128
- export type BasicServer = import('net').Server | import('tls').Server;
129
116
  export type OverlayMessageOptions = boolean | ((error: Error) => void);
130
117
  declare function useFn(fn: NextHandleFunction): BasicApplication;
131
118
  declare function useFn(fn: HandleFunction): BasicApplication;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/dev-server",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "Development server for rspack",
5
5
  "homepage": "https://rspack.rs",
6
6
  "bugs": "https://github.com/rstackjs/rspack-dev-server/issues",
@@ -46,15 +46,13 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@types/connect-history-api-fallback": "^1.5.4",
49
- "@types/serve-index": "^1.9.4",
50
49
  "@types/serve-static": "^2.2.0",
51
50
  "@types/ws": "^8.18.1",
52
- "chokidar": "^3.6.0",
51
+ "chokidar": "^5.0.0",
53
52
  "connect-history-api-fallback": "^2.0.0",
54
53
  "connect-next": "^4.0.0",
55
54
  "http-proxy-middleware": "^3.0.5",
56
55
  "ipaddr.js": "^2.3.0",
57
- "serve-index": "^1.9.2",
58
56
  "serve-static": "^2.2.1",
59
57
  "webpack-dev-middleware": "^7.4.5",
60
58
  "ws": "^8.19.0"