Skip to content

Having lots of trouble getting watchman to work #32

Closed

Description

@boxxxie

i'm trying to use watchman in a make file so i can issue make watch and have it lint my code.

JSHINT=./node_modules/jshint/bin/jshint
JSHINTFLAGS=

js_files=$(shell find src -name '*.js')
jshint: $(js_files)
    $(JSHINT) $(JSHINTFLAGS) $?
# .PHONY just tells make that these rules don't produce files. So if there is a
# file called "jshint", it won't interpret that file as the output of the
# jshint recipe.
.PHONY: jshint

watch:
    watchman watch $(shell pwd)/src
    watchman -- trigger $(shell pwd)/src remake '*.js' -- make jshint

when i do this i get triggers for the right dir, however i don't see any output on the console.

we also looked at the watchman log output to see if the files were changing, and they are.
watchman --persistent --server-encoding=json log-level debug
log at https://gist.github.com/nurey/9916489

also, when i run watchman find $(pwd)/src '*.js' i get the file back that i want to be watched.

watchman find $(pwd)/src '*.js'
{
    "version": "2.9.5",
    "clock": "c:1396363466:31774:1:46",
    "files": [
        {
            "dev": 2050,
            "gid": 1000,
            "name": "imageupload.js",
            "exists": true,
            "size": 14890,
            "mode": 33188,
            "uid": 1000,
            "mtime": 1396364671,
            "ctime": 1396364671,
            "ino": 2498402,
            "nlink": 1,
            "oclock": "c:1396363466:31774:1:33",
            "new": true,
            "cclock": "c:1396363466:31774:1:1"
        }
    ]
}

really sorry to be posting an issue like this, but i could really use some working examples. the example on your readme that uses ls -l doesn't work for my either.

Activity

  1. wez commented on Apr 1, 2014

    @wez
    Contributor

    The output from commands run by the trigger does to the watchman log file; it doesn't stay attached to your terminal.

    I've made other comments about this before:
    #20 (comment)

    For your use case, I'd recommend that you use a wrapper script that calls make jshint, because watchman is actually going to make jshint imageupload.js -- it will pass a list of the files that changed to the make invocation and that probably isn't what you want.

    Watchman is a bit different from the other watchers that are out there in that we run primarily as a background service. This makes it a bit more awkward to interact with in cases like this.

    One of the things I'd like to see get added to watchman is a non-persistent client that subscribes to the service and runs ad-hoc triggers for itself. This would make it easier to use watchman for this use-case. We haven't had the bandwidth to add this feature yet.

  2. wez commented on Apr 1, 2014

    @wez
    Contributor

    For linting, you really need to see this in the foreground. If you're not afraid of doing some scripting, you could whip up the client for this pretty easily, here are some tips:

  3. wez commented on Apr 1, 2014

    @wez
    Contributor

    or just run jshint and pass it the files from the files property

  4. wez commented on Apr 20, 2014

    @wez
    Contributor

    I'm closing this out due to lack of feedback. Happy to re-open and continue dialog if you still need some help.

  5. mems commented on Nov 26, 2014

    @mems

    I use make too to auto exec it when a file change. To redirect the output from watchman executed commands, I use a FIFO (also because I use nailgun, not shown it this example):

    #!/usr/bin/make -f
    
    # Get the directory where paths in this makefile are relative (this makefile directory)
    PROJECT_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
    
    # Watchman
    WATCHMAN = watchman
    
    SCRIPTS_SRC_DIR = scripts
    SCRIPTS_SRC_PATTERN = $(SCRIPTS_SRC_DIR)/*.js
    SCRIPTS_SRC_FILES = $(shell find $(SCRIPTS_SRC_DIR) -type f -name '*.js')
    SCRIPTS_FILE = scripts.js
    
    debug: clean $(SCRIPTS_FILE)
    
    incremental-debug: $(SCRIPTS_FILE)
    
    clean:
        rm -f $(SCRIPTS_FILE)
    
    watch: WATCHMANCMD = $(SHELL) -ilc "cd \"$(PROJECT_DIR)\"; $(MAKE) incremental-debug >> \"$(FIFONAME)\" 2>&1 &"
    # We use fifo to pipe all logs in one place
    watch: FIFONAME = ./.make$$PPID-fifo
    watch: clean
    ENDCMD='rm -f "$(FIFONAME)"; watchman watch-del "$(PROJECT_DIR)"';\
        trap "echo '\n\033[1m[Interrupted]\033[0m'; echo \"$$ENDCMD\"; $$ENDCMD; exit 0" SIGINT SIGTERM SIGHUP SIGQUIT;\
        mkfifo "$(FIFONAME)";\
        $(WATCHMAN) watch "$(PROJECT_DIR)";\
        $(WATCHMAN) -- trigger "$(PROJECT_DIR)" "make$$PPID" "$(SCRIPTS_SRC_PATTERN)" -- $(WATCHMANCMD);\
        grep --line-buffered -v "Nothing to be done for" < "$(FIFONAME)"
    
    # concatenate all JavaScript files
    $(SCRIPTS_FILE): $(SCRIPTS_SRC_FILES)
        cat $^ > $@
    
    .PHONY: watch clean debug incremental-debug
    

    make watch will watch file change and execute make incremental-debug and output result in the initial terminal.
    To stop it just hit Ctrl+C or close the terminal.

  6. sertaconay commented on Jan 22, 2016

    @sertaconay

    Hello.
    Even this doesn't work in make file. Why? But watchman-make works well.

    watchman -- trigger ~/www jsfiles '*.js' -- ls -l
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions