Skip to content

Commit

Permalink
fix: remove undefined values from options
Browse files Browse the repository at this point in the history
This has to be done because of an issue on chokidars site: paulmillr/chokidar#1394
  • Loading branch information
Fuzzyma committed Dec 20, 2024
1 parent b01a2c3 commit 3374234
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
19 changes: 18 additions & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ function useFn(route, fn) {
* @property {typeof useFn} use
*/

/**
* @template {Record<string, any>} T
* @param {T} obj
* @returns {T}
*/
function removeUndefinedValues(obj) {
return /** @type {T} **/ (
Object.fromEntries(
Object.entries(obj).filter(([, value]) => typeof value !== "undefined"),
)
);
}

/**
* @template {BasicApplication} [A=ExpressApplication]
* @template {BasicServer} [S=HTTPServer]
Expand Down Expand Up @@ -3269,7 +3282,11 @@ class Server {

watchOptions.ignored = getIgnoreMatchers(watchOptions, ignoreFunction);

const watcher = chokidar.watch(watchPaths, watchOptions);
const watcher = chokidar.watch(
watchPaths,
// https://github.com/paulmillr/chokidar/issues/1394
removeUndefinedValues(watchOptions),
);

// disabling refreshing on changing the content
if (this.options.liveReload) {
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/__snapshots__/watch-files.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ exports[`watchFiles option should work with options {"poll":true} should reload
"ignoreInitial": true,
"ignorePermissionErrors": true,
"ignored": [],
"interval": undefined,
"persistent": true,
"usePolling": true,
}
Expand Down Expand Up @@ -178,7 +177,6 @@ exports[`watchFiles option should work with options {"usePolling":false,"poll":t
"ignoreInitial": true,
"ignorePermissionErrors": true,
"ignored": [],
"interval": undefined,
"persistent": true,
"usePolling": false,
}
Expand All @@ -202,7 +200,6 @@ exports[`watchFiles option should work with options {"usePolling":false} should
"ignoreInitial": true,
"ignorePermissionErrors": true,
"ignored": [],
"interval": undefined,
"persistent": true,
"usePolling": false,
}
Expand Down Expand Up @@ -274,7 +271,6 @@ exports[`watchFiles option should work with options {"usePolling":true} should r
"ignoreInitial": true,
"ignorePermissionErrors": true,
"ignored": [],
"interval": undefined,
"persistent": true,
"usePolling": true,
}
Expand Down
12 changes: 4 additions & 8 deletions types/lib/Server.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export = Server;
/**
* @typedef {Object} BasicApplication
* @property {typeof useFn} use
*/
/**
* @template {BasicApplication} [A=ExpressApplication]
* @template {BasicServer} [S=HTTPServer]
Expand Down Expand Up @@ -1402,6 +1398,7 @@ declare class Server<
declare namespace Server {
export {
DEFAULT_STATS,
BasicApplication,
Schema,
Compiler,
MultiCompiler,
Expand Down Expand Up @@ -1469,12 +1466,14 @@ declare namespace Server {
Middleware,
BasicServer,
Configuration,
BasicApplication,
};
}
declare class DEFAULT_STATS {
private constructor();
}
type BasicApplication = {
use: typeof useFn;
};
type Schema = import("schema-utils/declarations/validate").Schema;
type Compiler = import("webpack").Compiler;
type MultiCompiler = import("webpack").MultiCompiler;
Expand Down Expand Up @@ -1813,9 +1812,6 @@ type Configuration<
| ((middlewares: Middleware[], devServer: Server<A, S>) => Middleware[])
| undefined;
};
type BasicApplication = {
use: typeof useFn;
};
/**
* @overload
* @param {NextHandleFunction} fn
Expand Down
18 changes: 18 additions & 0 deletions types/lib/getGlobMatchers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param {string[] | string} _watchPaths
* @param {import("./Server").WatchOptions} watchOptions
* @returns {[string[], import("chokidar").MatchFunction | null]}*/
export function getGlobbedWatcherPaths(
_watchPaths: string[] | string,
{ disableGlobbing, cwd }: import("./Server").WatchOptions,
): [string[], import("chokidar").MatchFunction | null];
/**
*
* @param {import("./Server").WatchOptions} watchOptions
* @param {import("chokidar").MatchFunction | null } ignoreFunction
* @returns {import("chokidar").Matcher[]}
*/
export function getIgnoreMatchers(
{ disableGlobbing, ignored, cwd }: import("./Server").WatchOptions,
ignoreFunction: import("chokidar").MatchFunction | null,
): import("chokidar").Matcher[];

0 comments on commit 3374234

Please sign in to comment.