-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Rewrote watchChange to make use of async await #2186
chore: Rewrote watchChange to make use of async await #2186
Conversation
@rpl I am getting a flow type error. Unfortunately, I don't have much clue of whats wrong. Any insight? type fileWatcher = {
fileWatchers: Map<string, Watchpack>,
directoryWatchers: Map<string, Watchpack>,
} but now I am getting other errors saying The unit test the running just fine as I tired setting Question: |
Running it once (on Linux) is sufficient. CI on Windows is generally slower. Lines 234 to 235 in 762a1cf
|
Sure thing, the issue is being triggered by this changes just because in the "chained promises" form flow wasn't able to guess what was the type of that "Flow inferring the type as any" basically means going into the "untyped domain", as if there isn't any explicit type checking (quite some time ago I did wrote a tool, flow-coverage-report, to keep an eye on how much of the code is actually typed) to actually , in this case is fine because this is a test and that code would fail if watchpack will change its internals and those property do not work anymore as they used to be or are being removed. At the moment we are writing the types for a subset of the dependencies, and only for the parts that we are actually using and flow does care about, the one for watchpack is this one: flow-typed/watchpack.decl.js (as you can see I've been lazy and I did declare only the bare minimum, which makes sense because we do have to maintain those types over the watchpack releases). To fix the flow failure we do have two options:
// $FlowIgnore: retrieve internal Watchpack properties for testing purpose.
const {fileWatchers, directoryWatchers} = watcher;
diff --git a/flow-typed/watchpack.decl.js b/flow-typed/watchpack.decl.js
index 5e6cf62..4a8e98d 100644
--- a/flow-typed/watchpack.decl.js
+++ b/flow-typed/watchpack.decl.js
@@ -16,6 +16,9 @@ declare module "watchpack" {
constructor(options?: WatchpackOptions): Watchpack,
close(): void,
watch(options: WatchOptions): void,
+
+ fileWatchers: Map<string, {path: string}>,
+ directoryWatchers: Map<string, {path: string}>,
} I think that in this case we may opt for option 1, in the end if we don't add those internal properties to the flow typed declarations we are not going to be tempted to use them on the implementation side :-P
Mainly because the windows workers are usually annoyingly slow and given that flow does just static analysis running the flow checks on windows isn't really needed. [1]: You can read some more details about what are the flow suppress comments here https://flow.org/en/docs/config/options/#toc-suppress-comment-regex (the config option is now deprecated and the strings to be used are hardcoded, but the feature is still there and supported) |
Yes, I tried using
Makes sense.
Got it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, it is definitely nicer :-)
@ankushduacodes Thanks a lot for offering to pick this up, very much appreciated!!!
Rewrote watchChange to make use of async-await:
web-ext/tests/unit/test.watcher.js
Lines 22 to 103 in 629aa14