Skip to content

Commit 3374234

Browse files
committed
fix: remove undefined values from options
This has to be done because of an issue on chokidars site: paulmillr/chokidar#1394
1 parent b01a2c3 commit 3374234

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

lib/Server.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ function useFn(route, fn) {
316316
* @property {typeof useFn} use
317317
*/
318318

319+
/**
320+
* @template {Record<string, any>} T
321+
* @param {T} obj
322+
* @returns {T}
323+
*/
324+
function removeUndefinedValues(obj) {
325+
return /** @type {T} **/ (
326+
Object.fromEntries(
327+
Object.entries(obj).filter(([, value]) => typeof value !== "undefined"),
328+
)
329+
);
330+
}
331+
319332
/**
320333
* @template {BasicApplication} [A=ExpressApplication]
321334
* @template {BasicServer} [S=HTTPServer]
@@ -3269,7 +3282,11 @@ class Server {
32693282

32703283
watchOptions.ignored = getIgnoreMatchers(watchOptions, ignoreFunction);
32713284

3272-
const watcher = chokidar.watch(watchPaths, watchOptions);
3285+
const watcher = chokidar.watch(
3286+
watchPaths,
3287+
// https://github.com/paulmillr/chokidar/issues/1394
3288+
removeUndefinedValues(watchOptions),
3289+
);
32733290

32743291
// disabling refreshing on changing the content
32753292
if (this.options.liveReload) {

test/e2e/__snapshots__/watch-files.test.js.snap.webpack5

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ exports[`watchFiles option should work with options {"poll":true} should reload
106106
"ignoreInitial": true,
107107
"ignorePermissionErrors": true,
108108
"ignored": [],
109-
"interval": undefined,
110109
"persistent": true,
111110
"usePolling": true,
112111
}
@@ -178,7 +177,6 @@ exports[`watchFiles option should work with options {"usePolling":false,"poll":t
178177
"ignoreInitial": true,
179178
"ignorePermissionErrors": true,
180179
"ignored": [],
181-
"interval": undefined,
182180
"persistent": true,
183181
"usePolling": false,
184182
}
@@ -202,7 +200,6 @@ exports[`watchFiles option should work with options {"usePolling":false} should
202200
"ignoreInitial": true,
203201
"ignorePermissionErrors": true,
204202
"ignored": [],
205-
"interval": undefined,
206203
"persistent": true,
207204
"usePolling": false,
208205
}
@@ -274,7 +271,6 @@ exports[`watchFiles option should work with options {"usePolling":true} should r
274271
"ignoreInitial": true,
275272
"ignorePermissionErrors": true,
276273
"ignored": [],
277-
"interval": undefined,
278274
"persistent": true,
279275
"usePolling": true,
280276
}

types/lib/Server.d.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
export = Server;
2-
/**
3-
* @typedef {Object} BasicApplication
4-
* @property {typeof useFn} use
5-
*/
62
/**
73
* @template {BasicApplication} [A=ExpressApplication]
84
* @template {BasicServer} [S=HTTPServer]
@@ -1402,6 +1398,7 @@ declare class Server<
14021398
declare namespace Server {
14031399
export {
14041400
DEFAULT_STATS,
1401+
BasicApplication,
14051402
Schema,
14061403
Compiler,
14071404
MultiCompiler,
@@ -1469,12 +1466,14 @@ declare namespace Server {
14691466
Middleware,
14701467
BasicServer,
14711468
Configuration,
1472-
BasicApplication,
14731469
};
14741470
}
14751471
declare class DEFAULT_STATS {
14761472
private constructor();
14771473
}
1474+
type BasicApplication = {
1475+
use: typeof useFn;
1476+
};
14781477
type Schema = import("schema-utils/declarations/validate").Schema;
14791478
type Compiler = import("webpack").Compiler;
14801479
type MultiCompiler = import("webpack").MultiCompiler;
@@ -1813,9 +1812,6 @@ type Configuration<
18131812
| ((middlewares: Middleware[], devServer: Server<A, S>) => Middleware[])
18141813
| undefined;
18151814
};
1816-
type BasicApplication = {
1817-
use: typeof useFn;
1818-
};
18191815
/**
18201816
* @overload
18211817
* @param {NextHandleFunction} fn

types/lib/getGlobMatchers.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string[] | string} _watchPaths
3+
* @param {import("./Server").WatchOptions} watchOptions
4+
* @returns {[string[], import("chokidar").MatchFunction | null]}*/
5+
export function getGlobbedWatcherPaths(
6+
_watchPaths: string[] | string,
7+
{ disableGlobbing, cwd }: import("./Server").WatchOptions,
8+
): [string[], import("chokidar").MatchFunction | null];
9+
/**
10+
*
11+
* @param {import("./Server").WatchOptions} watchOptions
12+
* @param {import("chokidar").MatchFunction | null } ignoreFunction
13+
* @returns {import("chokidar").Matcher[]}
14+
*/
15+
export function getIgnoreMatchers(
16+
{ disableGlobbing, ignored, cwd }: import("./Server").WatchOptions,
17+
ignoreFunction: import("chokidar").MatchFunction | null,
18+
): import("chokidar").Matcher[];

0 commit comments

Comments
 (0)