Skip to content

Add custom watched and ignored files #8

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

cwstra
Copy link

@cwstra cwstra commented Mar 19, 2024

As promised, I took a shot at allowing the user to add watched files. This'll allow embed authors to keep an eye on configuration files, and regenerate should they change.

@@ -28,7 +28,7 @@ module Chokidar = {
type watchOptions = {ignored?: array<string>, ignoreInitial?: bool}

@send
external watch: (t, string, ~options: watchOptions=?) => Watcher.t = "watch"
external watch: (t, array<string>, ~options: watchOptions=?) => Watcher.t = "watch"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we might have multiple globs, swapped out the overload we're hitting.

Comment on lines +49 to +56
module MicroMatch = {
type mm = {
makeRe: string => RegExp.t
}
@module("micromatch")
external mm: mm = "default"
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-glob already depends on micromatch, so we can use this to test glob matches for free.

@@ -166,6 +174,24 @@ type handleOtherCommandConfig<'config> = {

type setupConfig = {args: CliArgs.t}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I had tinkered with adding a parameter here, which would have avoided the breaking change to setup's return type.

type setupConfig  = {
  args: CliArgs.t,
  addWatcher: watcher => unit
}

However, I realized that with this API, an embed developer could then start doing funny things with addWatcher (e.g. add new watchers after we've already started watching), which would be a whole new can of worms to worry about. By using the return type, we force all watchers to be known once setup is done.

Comment on lines +187 to +193
@unboxed
type setupResult<'config> =
| SetupResult({
config: 'config,
additionalFileWatchers?: array<watcher>,
additionalIgnorePatterns?: array<string>
})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially used a plain-ol' record here, but that caused some inference issues due to the config parameter, so I swapped it out for the unboxed single-case variant to sidestep that issue.

generate: generateConfig<'config> => promise<result<generated, string>>,
cliHelpText: string,
handleOtherCommand?: handleOtherCommandConfig<'config> => promise<unit>,
onWatch?: onWatchConfig<'config> => promise<unit>,
}

let defaultSetup = async _ => ()
let defaultSetup = async (_): setupResult<_> => SetupResult({config: ()})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As promised, the return type is a breaking change.

Comment on lines +535 to +536
Console.log(`Watching the following patterns for file changes...`)
Array.forEach(watchedFiles, f => Console.log(`- ${f}`))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweaked the display here so we can show all the globs we're keeping an eye on.

@zth
Copy link
Owner

zth commented Mar 20, 2024

Great! I'm a bit low on time at the moment but will hopefully get around to this soon.

@cwstra
Copy link
Author

cwstra commented Mar 20, 2024

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants