google / wireit

Wireit upgrades your npm/pnpm/yarn scripts to make them smarter and more efficient.
Apache License 2.0
6.06k stars 107 forks source link

Configurable `--watch` Debounce #1061

Open ObliviousHarmony opened 8 months ago

ObliviousHarmony commented 8 months ago

When using something like webpack --watch in a service it can cause conflicts with Wireit's --watch option. The build tool progressively outputs and can trigger multiple rebuilds successively in downstream packages. We're currently implementing this by using nodemon but that feels like an unnecessary extra step when we have watch support already in wireit.

I noticed that there's currently a debounce implemented in the watcher already with a value of 0 and it would be great if we could set this to a configurable value. Since --watch itself is not a configuration option but is rather an option I think it makes sense to also make this an option. --watch --delay <ms> seems appropriate. Having delay in the package.json doesn't feel like it makes sense since it only applies to --watch.

deebloo commented 8 months ago

Isn't this solved by setting cascade to false?

ObliviousHarmony commented 8 months ago

In our case, we're using pnpm for task orchestration and wireit for caching. This is preferable to using wireit for both for us as it provides developers with a consistent syntax for running commands via pnpm --filter=<project-name>.

As an example, let's take a look at this configuration in two projects:

project-a/package.json
{
    "wireit": {
        "copy-assets": {
            "command": "rm -rf assets/client && cp -r node_modules/project-b/build assets/client",
            "allowUsuallyExcludedPaths": true,
            "files": [
                "node_modules/project-b/build"
            ]
        }
    }
}
project-b/package.json
{
    "wireit": {
        "watch": {
            "command": "webpack --watch",
            "service": true
        }
    }
}

You would also see the same problem with the above configs if you opened two separate terminals and ran npm run watch in one and npm run copy-assets --watch in the other. Due to the debouce of 0 and webpack progressively outputting files, the copy-assets command is triggered multiple times. If we bumped the debounce it would let webpack finish and only run copy-assets once.

deebloo commented 8 months ago

Ah ok that makes sense!