Skip to content

Commit a01150b

Browse files
committed
fix: improve schema for watch options
1 parent c2fee3b commit a01150b

File tree

3 files changed

+97
-11
lines changed

3 files changed

+97
-11
lines changed

lib/options.json

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,7 @@
10021002
}
10031003
},
10041004
{
1005-
"type": "object",
1006-
"description": "Options for watch.",
1007-
"link": "https://github.com/paulmillr/chokidar#api"
1005+
"$ref": "#/definitions/WatchOptionsChokidar"
10081006
}
10091007
],
10101008
"description": "Watches for files in static content directory.",
@@ -1064,10 +1062,7 @@
10641062
"description": "Path(s) of globs/directories/files to watch for file changes."
10651063
},
10661064
"options": {
1067-
"type": "object",
1068-
"description": "Configure advanced options for watching. See the chokidar documentation for the possible options.",
1069-
"link": "https://github.com/paulmillr/chokidar#api",
1070-
"additionalProperties": true
1065+
"$ref": "#/definitions/WatchOptionsChokidar"
10711066
}
10721067
},
10731068
"additionalProperties": false
@@ -1076,6 +1071,64 @@
10761071
"type": "string",
10771072
"minLength": 1
10781073
},
1074+
"WatchOptionsChokidar": {
1075+
"type": "object",
1076+
"additionalProperties": false,
1077+
"description": "Configure advanced options for watching. See the chokidar documentation for the possible options.",
1078+
"link": "https://github.com/paulmillr/chokidar#api",
1079+
"properties": {
1080+
"persistent": {
1081+
"type": "boolean"
1082+
},
1083+
"ignored": {
1084+
"type": "string"
1085+
},
1086+
"ignoreInitial": {
1087+
"type": "boolean"
1088+
},
1089+
"followSymlinks": {
1090+
"type": "boolean"
1091+
},
1092+
"cwd": {
1093+
"type": "string"
1094+
},
1095+
"disableGlobbing": {
1096+
"type": "boolean"
1097+
},
1098+
"usePolling": {
1099+
"type": "boolean"
1100+
},
1101+
"interval": {
1102+
"type": "number"
1103+
},
1104+
"binaryInterval": {
1105+
"type": "number"
1106+
},
1107+
"alwaysStat": {
1108+
"type": "boolean"
1109+
},
1110+
"depth": {
1111+
"type": "number"
1112+
},
1113+
"awaitWriteFinish": {
1114+
"type": "object",
1115+
"additionalProperties": true
1116+
},
1117+
"ignorePermissionErrors": {
1118+
"type": "boolean"
1119+
},
1120+
"atomic": {
1121+
"anyOf": [
1122+
{
1123+
"type": "boolean"
1124+
},
1125+
{
1126+
"type": "number"
1127+
}
1128+
]
1129+
}
1130+
}
1131+
},
10791132
"WebSocketServer": {
10801133
"anyOf": [
10811134
{

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,14 @@ exports[`options validate should throw an error on the "static" option with '{"s
781781
object { … }"
782782
`;
783783

784+
exports[`options validate should throw an error on the "static" option with '{"watch":{"invalid":true}}' value 1`] = `
785+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
786+
- options.static.watch has an unknown property 'invalid'. These properties are valid:
787+
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
788+
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
789+
-> Read more at https://github.com/paulmillr/chokidar#api"
790+
`;
791+
784792
exports[`options validate should throw an error on the "static" option with '{"watch":10}' value 1`] = `
785793
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
786794
- options.static should be one of these:
@@ -789,14 +797,14 @@ exports[`options validate should throw an error on the "static" option with '{"w
789797
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverstatic
790798
Details:
791799
* options.static.watch should be one of these:
792-
boolean | object { }
800+
boolean | object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
793801
-> Watches for files in static content directory.
794802
-> Read more at https://webpack.js.org/configuration/dev-server/#watch
795803
Details:
796804
* options.static.watch should be a boolean.
797805
* options.static.watch should be an object:
798-
object { }
799-
-> Options for watch.
806+
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
807+
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
800808
-> Read more at https://github.com/paulmillr/chokidar#api"
801809
`;
802810

@@ -830,10 +838,18 @@ exports[`options validate should throw an error on the "static" option with 'nul
830838
object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }"
831839
`;
832840

841+
exports[`options validate should throw an error on the "watchFiles" option with '{"options":{"invalid":true}}' value 1`] = `
842+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
843+
- options.watchFiles.options has an unknown property 'invalid'. These properties are valid:
844+
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
845+
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
846+
-> Read more at https://github.com/paulmillr/chokidar#api"
847+
`;
848+
833849
exports[`options validate should throw an error on the "watchFiles" option with '{"options":false}' value 1`] = `
834850
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
835851
- options.watchFiles.options should be an object:
836-
object { }
852+
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
837853
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
838854
-> Read more at https://github.com/paulmillr/chokidar#api"
839855
`;

test/validate-options.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ const tests = {
485485
serveIndex: {},
486486
watch: {},
487487
},
488+
{
489+
directory: "path",
490+
staticOptions: {},
491+
publicPath: ["/public1/", "/public2/"],
492+
watch: {
493+
ignored: "*.txt",
494+
usePolling: true,
495+
},
496+
},
488497
[
489498
"path1",
490499
{
@@ -512,6 +521,9 @@ const tests = {
512521
{
513522
watch: 10,
514523
},
524+
{
525+
watch: { invalid: true },
526+
},
515527
],
516528
},
517529
setupMiddlewares: {
@@ -571,6 +583,11 @@ const tests = {
571583
{
572584
options: false,
573585
},
586+
{
587+
options: {
588+
invalid: true,
589+
},
590+
},
574591
],
575592
},
576593
};

0 commit comments

Comments
 (0)