Coder Social home page Coder Social logo

chokidar-cli's Introduction

Chokidar CLI

Build Status

Fast cross-platform command line utility to watch file system changes.

The underlying watch library is Chokidar, which is one of the best watch utilities for Node. Chokidar is battle-tested:

It is used in brunch, gulp, karma, PM2, browserify, webpack, BrowserSync, socketstream, derby, and many others. It has proven itself in production environments.

Prerequisites

  • Node.js v8.10.0 or newer

Install

If you need it only with npm scripts:

npm install chokidar-cli

Or globally

npm install -g chokidar-cli

Usage

Chokidar can be invoked using the chokidar command, without the -cli suffix.

Arguments use the form of runtime flags with string parameters, delimited by quotes. While in principal both single and double quotes are supported by chokidar-cli, the actual command line argument parsing is dependent on the operating system and shell used; for cross-platform compatibility, use double quotes (with escaping, if necessary), as single quotes are not universally supported by all operating systems.

This is particularly important when using chokidar-cli for run scripts specified in package.json. For maximum platform compatibility, make sure to use escaped double quotes around chokidar's parameters:

"run": {
  "chokidar": "chokidar \"**/*.js\" -c \"...\""
},

Default behavior

By default chokidar streams changes for all patterns to stdout:

$ chokidar "**/*.js" "**/*.less"
change:test/dir/a.js
change:test/dir/a.less
add:test/b.js
unlink:test/b.js

Each change is represented with format event:relativepath. Possible events: add, unlink, addDir, unlinkDir, change.

Output only relative paths on each change

$ chokidar "**/*.js" "**/*.less" | cut -d ":" -f 2-
test/dir/a.js
test/dir/a.less
test/b.js
test/b.js

Run npm run build-js whenever any .js file changes in the current work directory tree

chokidar "**/*.js" -c "npm run build-js"

Watching in network directories must use polling

chokidar "**/*.less" -c "npm run build-less" --polling

Pass the path and event details in to your custom command

chokidar "**/*.less" -c "if [ '{event}' = 'change' ]; then npm run build-less -- {path}; fi;"

Detailed help

Usage: chokidar <pattern> [<pattern>...] [options]

<pattern>:
Glob pattern to specify files to be watched.
Multiple patterns can be watched by separating patterns with spaces.
To prevent shell globbing, write pattern inside quotes.
Guide to globs: https://github.com/isaacs/node-glob#glob-primer


Options:
  -c, --command           Command to run after each change. Needs to be
                          surrounded with quotes when command contains spaces.
                          Instances of `{path}` or `{event}` within the command
                          will be replaced by the corresponding values from the
                          chokidar event.
  -d, --debounce          Debounce timeout in ms for executing command
                                                                  [default: 400]
  -t, --throttle          Throttle timeout in ms for executing command
                                                                  [default: 0]
  -s, --follow-symlinks   When not set, only the symlinks themselves will be
                          watched for changes instead of following the link
                          references and bubbling events through the links path
                                                      [boolean] [default: false]
  -i, --ignore            Pattern for files which should be ignored. Needs to be
                          surrounded with quotes to prevent shell globbing. The
                          whole relative or absolute path is tested, not just
                          filename. Supports glob patterns or regexes using
                          format: /yourmatch/i
  --initial               When set, command is initially run once
                                                      [boolean] [default: false]
  -p, --polling           Whether to use fs.watchFile(backed by polling) instead
                          of fs.watch. This might lead to high CPU utilization.
                          It is typically necessary to set this to true to
                          successfully watch files over a network, and it may be
                          necessary to successfully watch files in other non-
                          standard situations         [boolean] [default: false]
  --poll-interval         Interval of file system polling. Effective when --
                          polling is set                          [default: 100]
  --poll-interval-binary  Interval of file system polling for binary files.
                          Effective when --polling is set         [default: 300]
  --verbose               When set, output is more verbose and human readable.
                                                      [boolean] [default: false]
  --silent                When set, internal messages of chokidar-cli won't be
                          written.                    [boolean] [default: false]
  -h, --help              Show help                                    [boolean]
  -v, --version           Show version number                          [boolean]

Examples:
  chokidar "**/*.js" -c "npm run build-js"  build when any .js file changes
  chokidar "**/*.js" "**/*.less"            output changes of .js and .less
                                            files

License

MIT

chokidar-cli's People

Contributors

aivenkimmob avatar bryzaguy avatar cbonaco1 avatar chyld avatar elliotchong avatar es128 avatar heikkipora avatar htanjo avatar kimmobrunfeldt avatar paulmillr avatar pomax avatar sbleon avatar swashcap avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chokidar-cli's Issues

Using shell function as a command

Hey, thanks for chokidar. It's a very nice lightweight alternative to gulp and such.

I was hoping to use a bash function as a value to --command option, like that:

#! /usr/bin/env bash

# Start development loop - watch and rebuild, etc.

# Shell strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

function tasks {
  clear
  scripts/build
  scripts/test
}

export -f tasks

scripts/clean
chokidar \
  "src/**/*" \
  --initial \
  --command tasks

I know some workarounds (like in-lining the tasks and separating them with && or just putting them in another script), but the code above makes a really nice, self contained unit. Any chance we can make this work?

Throttle and debounce options are unclear

> chokidar --help

  -d, --debounce          Debounce timeout in ms for executing command
                                                                  [default: 400]
  -t, --throttle          Throttle timeout in ms for executing command
                                                                    [default: 0]

From these descriptions, it's really not clear what these do. For instance, I personally expected debounce to still immediately execute on the first file-change, but then ignore further changes for n milliseconds; instead, it waits n milliseconds after every change. (I then hoped that throttle was perhaps a badly-named tool that had the former behaviour, but that doesn't seem to be the case either!)

A little more explication in the --help might be worthwhile. (=

Error on directory delete

When deleting a folder that I watched, I get the following stack:

Error: { Error: Error watching file for changes: EPERM at exports._errnoException (util.js:1020:11) at FSEvent.FSWatcher._handle.onchange (fs.js:1421:9) code: 'EPERM', errno: 'EPERM', syscall: 'Error watching file for changes:', filename: null } Error: Error watching file for changes: EPERM at exports._errnoException (util.js:1020:11) at FSEvent.FSWatcher._handle.onchange (fs.js:1421:9) Error: { Error: Error watching file for changes: EPERM at exports._errnoException (util.js:1020:11) at FSEvent.FSWatcher._handle.onchange (fs.js:1421:9) code: 'EPERM', errno: 'EPERM', syscall: 'Error watching file for changes:', filename: null } Error: Error watching file for changes: EPERM at exports._errnoException (util.js:1020:11) at FSEvent.FSWatcher._handle.onchange (fs.js:1421:9)

Any idea ?

quiet/silent mode

Hi,
would it be possible to integrate a silent mode so there is no "change:path/to/file" output ?

chokidar does not work

  • platform

windows 10

  • node version

6.7

  • chokidar-cli version

1.2.0

  • code:

npm scripts:

    "scripts": {
        "build": "babel src -d dist",
        "watch": "chokidar 'src/**' -c 'npm run build'"
    },

run:

npm run watch
  • Bug

chokidar does not work(but if globally npm install -g chokidar-cli and run chokidar 'src/**' -c 'npm run build' can run), I am very confused.

combining commands with && fails

node ../node_modules/chokidar-cli --initial '**/*' -c 'echo hello && echo goodbye'

results in:

hello [object Object] echo goodbye

but should result in:

hello
goodbye

Error with -c command

First, some background: I'm using npm as a task runner, and I'd been using watch but I heard chokidar is more efficient. I tried chokidar-cli installed both locally to my project and globally. Unfortunately I'm getting the following error:

> chokidar "dev" -c "npm run dev"

Watching "dev" ..
change:dev\Controller.js
Error when executing npm run dev
Error: spawn ENOENT
    at errnoException (child_process.js:1001:11)
    at Process.ChildProcess._handle.onexit (child_process.js:792:34)

I have no idea what this means. I tried other commands, such as cd .., but still get an error. Could anyone help me out?

`ignore` option

Hi,

I can't seem to get the --ignore option to work with simple patterns whereas regexes do.
chokidar './src/**/*.js' -i '*-test.js' nope
chokidar './src/**/*.js' -i '/-test.js$/' yep

Probably missing something obvious.

Glob expansion in --command

Thanks for your work on the project, it's been really useful!

One hitch I ran into lately was that run doesn't spawn a shell, so when you compare:

$ cat *.js

with

$ chokidar . --command "cat *.js"

the results may not be what you expect.

I'm working around that with a simple --command "cat $(ls *.js)", but it looks a bit... silly.

Export FILENAME as environment variable

I suggest making the updated FILENAME available as an environment variable from within the command. It makes is possible to run commands like this:

  $ chokidar "**/**.js" -c "jshint $FILENAME"

The very much similar filewatcher CLI, written in ruby, exports these environment variables:

FILENAME           Relative filename.
ABSOLUTE_FILENAME  Asolute filename.
RELATIVE_FILENAME  Same as FILENAME but starts with "./"
BASENAME           File basename.
EVENT              Event type. Is either 'changed', 'delete' or 'new'.
DIRNAME            Absolute directory name.

Source: https://github.com/thomasfl/filewatcher

BTW! Chokidar seems to be a very good piece of software.

Pass name of changed file as argument to command

I want to know which file is changed in my command in order to run build proccess for only one changed file, not all files in watched directory.

Can you pass names of changed files as arguments to command being executed?

E.g. I have script

test.sh:
echo *

I run chokidar:

chokidar 'mydir/**' -c './test.sh'

When I change file afile in mydir — test.sh is executed with argument afile

Error: spawn /bin/false ENOENT

I'm getting an error when trying to run Chokidar.

My package.json

"scripts": {
    "build": "rollup -c",
    "watch:js": "chokidar --initial 'src/js/**/*.js' -c 'npm run build'"
},

Command

npm run watch:js

Output

...
add:src/js/util/RNG.js
add:src/js/util/enum.js
add:src/js/util/id.js
add:src/js/util/log.js
Watching "src/js/**/*.js" ..
Error when executing npm run build
Error: spawn /bin/false ENOENT
    at exports._errnoException (util.js:873:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)

Additional details

  • chokidar-cli: 1.2.0
  • node: v4.4.7
  • OS: OS X El Capitan version 10.11.6

Node 4.2 triggers change on file open

Hi,

Recently updated node to 4.2.1 and whenever I run task with chokidar it triggers change on every single touch to file: it is enough to open file to trigger change.

Same package.json works perfect with Node 0.12.7.

Example script:

"watch:sg-styles": "chokidar 'styleguide/styles/**/*.css' -c 'npm run build:sg-styles'",

Add `--once` switch

Please add a --once switch. When --initial and --once switches are set, chokidar-cli will apply the command to all the specified files and exit upon completion.

This command would make debugging chokidar-cli commands much simpler and enable consistency between build and watch scripts.

How to restart a Express/Koa server?

I'm trying to watch all my src files and rerun Koa when a file is changed, but keep hitting Error: listen EADDRINUSE :::3000.

"chokidar": "chokidar '**/*.js' -c 'node dist/server'"

Any ideas how to force Koa to die before running node dist/server?

Subsequent commands are executing before originating task is complete

While working with a project with a 15s grunt build time I noticed that the build process would get initiated on every save causing a number of grunt processes to be spawned at the same time.

As a quick and dirty fix to spawning commands before the previous command has finished I'd like to propose the addition of a --throttle option to allow developers to prevent commands from being executed too frequently. This will be in addition to the debounce option as they're serving two different purposes.

Pull request with --throttle added is incoming.

For a long-term "proper" fix it might be possible to wait for the spawned process to exit before firing the command again; however, I didn't have time to look into it at this moment.

Cheers!

Option to turn off debounce/throttle

Even if you set a wait of 0, if there are multiple change events from fsevents in the same event loop, only one will have a command executed for it.

This is a problem when transpiling or generating sourcemaps, which can affect multiple files at a time.

Vulnerability found in npm audit

I'm using the latest version of npm that has the "audit" functionality that serves to find third-party passwords.

When executing the command the following information is displayed.

captura de tela 2018-06-07 as 02 33 31

When doing fork I get the following message when verifying the audit

found 6 vulnerabilities (3 low, 2 high, 1 critical) in 330 scanned packages
4 vulnerabilities require semver-major dependency updates.
2 vulnerabilities require manual review. See the full report for details.

When updating dependencies, the result of vulnerabilities found by npm audit are as follows.

captura de tela 2018-06-07 as 02 48 46

repo fork: https://github.com/rodrigooler/chokidar-cli/commits/master

Changelog?

I'd like to know what breaking changes are being introduced in 2.0.0.

rename event with concurrently

Hi,

On MacOS 10.13.3, node v9.2.0, as suggested in #34 I use -d 0 to get add and unlink events. However using concurrently I get unlink/add pair for first rename, but not for consequent renames.

concurrently "echo log: {event} {path}"

First rename:

File removed: old/path
File added: new/path
log: unlink old/path
log: add new/path

Second and consequent renames:

File removed: old/path
File added: new/path
log: add new/path

Any suggestion?

memory leak detected

> [email protected] build-less /Users/kbru/code/personal/components-for-todays-web
> lessc src/main.less src/bundle.css && npm run autoprefixer


> [email protected] autoprefixer /Users/kbru/code/personal/components-for-todays-web
> autoprefixer src/bundle.css

change:src/button/button.less
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at ReadStream.EventEmitter.addListener (events.js:179:15)
    at ReadStream.Readable.on (_stream_readable.js:667:33)
    at ReadStream.EventEmitter.once (events.js:204:8)
    at Socket.Readable.pipe (_stream_readable.js:576:8)
    at Object.run (/Users/kbru/code/personal/components-for-todays-web/node_modules/chokidar-cli/utils.js:32:21)
    at run (/Users/kbru/code/personal/components-for-todays-web/node_modules/chokidar-cli/index.js:168:18)
    at delayed [as _onTimeout] (/Users/kbru/code/personal/components-for-todays-web/node_modules/chokidar-cli/node_modules/lodash/index.js:7707:27)
    at Timer.listOnTimeout (timers.js:133:15)

> [email protected] build-less /Users/kbru/code/personal/components-for-todays-web
> lessc src/main.less src/bundle.css && npm run autoprefixer

Changed in symlinked directories aren't being filtered on patterns

On macOS, with version 1.2.1:

ashoat@ashoatmbp2018 [~/Dropbox/src/squadcal/server]$ chokidar -s '**/*.THIS_SHOULD_NEVER_MATCH'
Watching "**/*.THIS_SHOULD_NEVER_MATCH" ..
change:node_modules/web/chat/chat-input-state-container.react.js
change:src/web/chat/chat-input-state-container.react.js
change:node_modules/web/chat/chat-input-state-container.react.js
change:src/web/chat/chat-input-state-container.react.js

No way to customize the shell command to be executed

Different platforms have different shells. The current detection only checks COMSPEC and SHELL environment variables to detect if we're on Windows or *nix.

This obviously doesn't work for everyone and it'd be nice to be able to customize how the underlying platform shell is called.

For example a new flag:

--shell-command "cmd.exe /c {{command}}"

--ignore switches has no effect

Line 162 of index.js
if (opts.ignore) chokidarOpts.ignore = opts.ignore;
->
if (opts.ignore) chokidarOpts.ignored = opts.ignore;

Making the above change seems did the job.
I'm not familiar with Node API so don't know for sure.
Could you take a look?

--initial doesn't respect --ignore

For example:

node_modules/chokidar-cli --ignore 'build' --ignore 'components' '**/*' --initial -c 'duo --use node_modules/duo-jade --copy --verbose index.js index.css'

The duo 'command' creates folders and files in the components folder, and chokidar will run the 'command' over and over again because things changed in the components folder, even though it's ignored.

Key-stroke to immediately re-run

So, does chokidar-cli listen to STDIN at all, or have any purpose for it?

If not, it'd be really nice if, on STDIN receiving, say, , or even just a linereturn, it would re-run the command immediately. (It's annoying to ⌃C, ↑, ↩︎, every time I want to electively re-run the command in question.)

Similarly (doesn't seem to be a big enough problem to submit a second Issue about), I'd like to see a --clear flag or similar, to tput clear between each invocation of the command

Pass all paths from event to command ({path} currently replaced by a single path)

The custom command currently only gets a single path when multiple files were changed:

$ node_modules/.bin/chokidar '**/*' -d 0 -c 'echo {path}' &
Watching "**/*" ..
$ touch foo bar baz
File added: foo
File added: bar
File added: baz
baz

I'm not sure if this is a bug or a feature.

If it's a feature

I'd like to see either of these changes:

  1. {path} gets replaced with all of the event's file paths. This could break things for existing users.
  2. {paths} is a new placeholder that gets replaced with all of the event's file paths. This complicates the API.

Any thoughts on which way might be preferable?

If it's a bug

This might be happening because the code is creating a debounced version of the custom command even if the debounce option is set to zero. And/or there might be a similar problem with the throttling. I think it would be simple enough to avoid using those lodash functions if the relevant options are set to zero.

'{event}' for file rename

when I use the following command:

chokidar 'src/**/*.js' 'src/**/*.jsx' -c 'echo "the change is {event}";''

And then rename a file, I get an output for the 'add' but not for the 'unlink'. I'm trying to use chokidar with babel so if a file is renamed, I want to remove the old file from the output dir and transpile the new one.

Here's an example of what I mean:

> chokidar 'src/**/*.js' 'src/**/*.jsx' -c 'echo "the change is {event}"'                                                              
Watching "src/**/*.js", "src/**/*.jsx" ..
unlink:src/blah.js
add:src/foo.js
the change is add

I'd like to have an output for the change is unlink _AND_ the change is add

please advise.

can't pipe through multiple commands

I can't pipe through multiple commands I'm thinking it's getting caught in buffering and not flushing output.

but this isn't working

chokidar **/*.scala | awk -F: '{print $2}' | awk -F/ '{print $1}'

isn't working at all

childProcess.spawn escaping quotes on windows

when a command such as chokidar *.* --initial -c "echo ""Hello World!""" is executed on windows, the output is

\"Hello World!\"

rather than the expected

"Hello World!"

This appears to be caused by some weird default behavior of childProcess.spawn when windowsVerbatimArguments is not set to true.

The quick fix is to just add the option to utils.js

child = childProcess.spawn(SHELL_PATH, [EXECUTE_OPTION, cmd], {
  cwd: opts.cwd,
  stdio: opts.pipe ? 'inherit' : null,
  windowsVerbatimArguments: true
});

however child_process.spawn now has a shell option that looks like it would simplify things here:

child = childProcess.spawn(cmd, {
  cwd: opts.cwd,
  stdio: opts.pipe ? 'inherit' : null,
  shell: true
})

can't install on linux machine

npm install fails on linux machine with this library. This is pretty awkward since it breaks our build process:

17:03:54 npm ERR! Linux 3.13.0-66-generic
17:03:54 npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install"
17:03:54 npm ERR! node v0.12.9
17:03:54 npm ERR! npm v2.14.9
17:03:54 npm ERR! code EBADPLATFORM
17:03:54
17:03:54 npm ERR! notsup Unsupported
17:03:54 npm ERR! notsup Not compatible with your operating system or architecture: [email protected]
17:03:54 npm ERR! notsup Valid OS: darwin
17:03:54 npm ERR! notsup Valid Arch: any
17:03:54 npm ERR! notsup Actual OS: linux
17:03:54 npm ERR! notsup Actual Arch: x64
17:03:54
17:03:54 npm ERR! Please include the following file with any support request:

Rapid changes do not run the shell command

This happens to me if I stash some changes (say 4 files) the changes are picked up by chokidar-cli as I see the change:[file_path] but some events do not run the shell command. When I put the debounce down to 0, it appears to help, but a random event will not run the shell command. Just wondering if there is some setting that would help this. Or is the idea just to set debounce down to 0? Thanks!

Chokidar CLI spawns no process

On a Turnkey Debian VM, running any chokidar command seems to spawn no process. I am simply prompted for the next command with no feedback. Both chokidar and chokidar-cli are installed globally.

$ chokidar * # also tried chokidar **/src/*, chokidar . and other variants
$ ps aux | grep '[n]pn\|[n]ode\|[c]hokaidar' # Outputs nothing

Interestingly, chokidar -h or chokidar --help also writes no output. It's just a no-op.

I am not sure what other diagnostic steps I can take other than to check if I am missing any dependencies, but I assume that was all taken care of by the nature of npm install anyway.

Where do I go from here?

$PATH not set correctly after 1.0.1

After the 1.0.1 release, $PATH variable is not set correctly, thus causing problems if node binaries are not located somewhere in 'default' $PATH. System: OSX with ZSH

Unfortunately I couldn't figure out what's actually wrong with the release, but here's some debug help:

export PATH=/path/to/somewhere/bin:$PATH

env
=> PATH=/path/to/somewhere/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
😎

npm install [email protected]
touch some-file-to-watch.txt
node_modules/.bin/chokidar 'some-file-to-watch.txt' -c 'env'
=> PATH=/path/to/somewhere/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
😎

npm install [email protected]
node_modules/.bin/chokidar 'some-file-to-watch.txt' -c 'env'
=> PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
😩

Ubuntu bash for windows 10

Error happens in Ubuntu bash for window 10:

Error: watch . EPERM [6/1614]
at exports._errnoException (util.js:1022:11)
at FSWatcher.start (fs.js:1429:19)
at Object.fs.watch (fs.js:1456:11)
at createFsWatchInstance (/usr/lib/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:37:15)
at setFsWatchListener (/usr/lib/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:80:15)
at FSWatcher.NodeFsHandler._watchWithNodeFs (/usr/lib/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:228:14)
at FSWatcher.NodeFsHandler._handleDir (/usr/lib/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:407:19)
at FSWatcher. (/usr/lib/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:455:19)
at FSWatcher. (/usr/lib/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:460:16)

Chokidar's outputs `/c: /c: is a directory`, doesn't run command.

Hi, I'm currently trying to use chokidar via chokidar-cli to watch and build my JS both on Mac OS X and on Windows.

Software versions:

Mac OS X 10.10.4

  • node 4.1.1
  • npm 2.14.4
  • chokidar-cli 1.1.0

Windows 7

  • node 4.2.1
  • npm 2.14.7
  • chokidar-cli 1.1.0
  • mingw32 provided by the latest Git for Windows

On Mac OS X, the paths are correctly watched and, although events are reported twice, they are all reported and the specified command is executed without problems. So, despite the weird double report part — which is supposed to be fixed — I'm pretty satisfied.

On Windows 7, the paths are correctly watched, the events are correctly reported but the specified command is never executed and I always get the same puzzling output: /c: /c: is a directory.

This is the npm script I use:

"chok": "chokidar \"source/js/\" -c \"npm run js:dev\""

and this is how I would call it on its own:

$ npm run chok

It is supposed to be used as part of a larger "system" but, whether it is used as part of that "system" or on its own, the outcome is always the same.

I've tried many quoting strategies and also tried --command to no avail. I've also tried to make it execute dummy commands like -c \"echo 1\" or -c \"npm run foo\" with no change.

When I leave out the -c ... part, chokidar correctly prints the changed file and doesn't output that mysterious /c: /c: is a directory.

Changes within symlinked directories aren't detected by chokidar

I'm using bower link to link a package foo into a service. This creates a few symlinks:

service (master) $ ls -lha bower_components/ 
...
drwxr-xr-x  5 avohra users 4.0K 2016-03-16 19:51 bar/
lrwxrwxrwx  1 avohra users   45 2016-03-17 10:02 foo -> /nail/home/avohra/.local/share/bower/links/foo
...

and

service (master) $ ls -lha /nail/home/avohra/.local/share/bower/links/
...
lrwxrwxrwx 1 avohra users   45 2016-03-17 10:16 foo -> /abs/path/to/package/foo/
...

Within my service, I have chokidar set up to watch some JS files as follows:

...
chokidar \
    'assets/js/**/*.js' 'bower_components/**/*.js' 'closure_config.js' \
    -c 'invoke-closure closure_config.js' \
    --follow-symlinks \
    --verbose
...

I'm unable to get chokidar to detect changes in JS files within the package foo's directory. I know chokidar follows symlinked files. Does it also follow symlinked directories?

PID-tracking / kill-signal support

So, this might be a little out-of-scope, but I figured I'd point out it's a desirous feature:

It'd be nice if chokidar could automatically kill (or better yet, send an arbitrary single to) the previous invocation when it starts a new one. (For instance, when a test-file is changed before a long-running test suite is complete; or in my particular use-case, allowing me to wrap the desired command in less and wanting the less-instance to be killed when chokidar invokes a new instance of the command.)

crash when `paths` is relative with `./` prefix (and exists...)

paulmillr/chokidar#896

upgrade to 3.2.1 or whatever is the latest. you've pointed out that chokidar-cli doesn't use latest chokidar.

npm install chokidar@latest chokidar-cli@latest

+ [email protected]
+ [email protected]
added 44 packages from 29 contributors and audited 81 packages in 1.513s
found 0 vulnerabilities

chokidar --version

chokidar-cli: 2.0.0
chokidar: 3.0.2

./node_modules/.bin/chokidar ./

(node:19234) UnhandledPromiseRejectionWarning: TypeError: Expected pattern to be a non-empty string
    at picomatch (/tmp/test/node_modules/picomatch/lib/picomatch.js:43:11)
    at createPattern (/tmp/test/node_modules/anymatch/index.js:27:18)
    at mtchers.map.matcher (/tmp/test/node_modules/anymatch/index.js:89:43)
    at Array.map (<anonymous>)
    at anymatch (/tmp/test/node_modules/anymatch/index.js:89:28)
    at new WatchHelper (/tmp/test/node_modules/chokidar-cli/node_modules/chokidar/index.js:155:38)
    at FSWatcher._getWatchHelpers (/tmp/test/node_modules/chokidar-cli/node_modules/chokidar/index.js:746:10)
    at NodeFsHandler._addToNodeFs (/tmp/test/node_modules/chokidar-cli/node_modules/chokidar/lib/nodefs-handler.js:518:21)
    at Promise.all.paths.map (/tmp/test/node_modules/chokidar-cli/node_modules/chokidar/index.js:406:47)
    at Array.map (<anonymous>)
    at FSWatcher.add (/tmp/test/node_modules/chokidar-cli/node_modules/chokidar/index.js:405:13)
    at Object.watch (/tmp/test/node_modules/chokidar-cli/node_modules/chokidar/index.js:900:11)
    at startWatching (/tmp/test/node_modules/chokidar-cli/index.js:138:28)
    at main (/tmp/test/node_modules/chokidar-cli/index.js:127:5)
    at Object.<anonymous> (/tmp/test/node_modules/chokidar-cli/index.js:220:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
(node:19234) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:19234) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

./node_modules/.bin/chokidar .

add:node_modules/.bin/chokidar
Watching "." ..

./node_modules/.bin/chokidar ../test/

add:node_modules/.bin/chokidar
Watching "../test/" ..

My real path is like ./src, but that won't work, but plainly src (no ./ prefix) will.

Thanks!

Sorry, not an issue. Just wanted to say thank you for making an awesome CLI watcher. =)

Error $SHELL environment variable is not set

Error $SHELL environment variable is not set is thrown when chokidar-cli is run from the official node.js Docker image. This image doesn't appear to set the SHELL environment variable. This can be fixed by setting the environment variable before running a script.

SHELL=/bin/bash node my-script.js

I understand this may not be chokidar-cli issue but it may be worth mentioning it in documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.