简体   繁体   中英

Is it possible to configure watchman triggers in .watchmanconfig?

Facebook watchman docs describe how to configure triggers by passing json into the command like so:

watchman --json-command < ./tasks/cmds/watchman-build-trigger.json where watchman-build-trigger.json contains the following:

[
    "trigger", 
    "/Users/michaelprescott/Projects/neuro", 
    {
        "name": "build",
        "expression": [
            "anyof",
            [
                "match",
                "src/*.js",
                "wholename"
            ],
            [
                "match",
                "src/*.ts",
                "wholename"
            ],
            [
                "match",
                "src/*.html",
                "wholename"
            ]
        ],
        "command": [
            "./tasks/cmds/build.sh"
        ]
    }
]

However, I'm trying to understand how to use .watchmanconfig to setup a watch and set of triggers with watchman watch-project I have the following, but triggers aren't created. Is this possible? Does anyone have examples for .watchmanconfig's

{
    "ignore_dirs": [
        "node_modules"
    ],
    "watched": [
        {
            "path": "/Users/michaelprescott/Projects/neuro",
            "triggers": [
                {
                    "command": [
                        "./tasks/cmds/build.sh"
                    ],
                    "expression": [
                        "anyof",
                        [
                            "match",
                            "src/*.js",
                            "wholename"
                        ],
                        [
                            "match",
                            "src/*.ts",
                            "wholename"
                        ],
                        [
                            "match",
                            "src/*.html",
                            "wholename"
                        ]
                    ],
                    "name": "build"
                }
            ]
        }
    ]
}

No, it's not possible via .watchmanconfig . The rationale is that, since .watchmanconfig is intended to be checked into a repo that may be cloned by arbitrary folks, we'd rather not allow it to be a vehicle by which arbitrary code could be run without those people explicitly taking an action to run it.

Our recommendation is to wrap up the trigger creation in a script of some kind that you can direct users to run when they would like to enable the triggering behavior.

In addition, I'd urge you to instead take a look at watchman-make for this use case; it has nicer ergonomics than triggers because it is very much easier to see the output from the commands that are being run and to terminate them when you want them to stop.

For example, you could implement your trigger this way instead:

watchman-make -r tasks/cmds/build.sh -p 'src/*.js' -p 'src/*.ts' -p 'src/*.html'

(the single quotes are important!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM