googlearchive / cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki
Apache License 2.0
827 stars 115 forks source link

Watch does not work on linux systems #196

Open jason0518 opened 6 years ago

jason0518 commented 6 years ago

Environment details

Steps to reproduce

  1. Run any example/etc project on a linux system.
  2. Change a non node_module file in your function
  3. The function doesn't restart itself picking up your changes

Possible solution

  1. If you change src/supervisor/worker.js#L172 to watch a single file in your project (vs the recursive option) then it works as expected. If you checkout the Node docs there is a caveat for this as the recursive option only works on Mac or Windows.
  2. Perhaps using Chokidar to overcome these watch issues would be a good remedy
ribizli commented 5 years ago

I've solved this issue locally with node-watch. Same API call, minimal change:

require('node-watch').(localdir, {
        recursive: true
      }, (event, filename) => {
dirkjot commented 5 years ago

This worked for me, here are full instructions and a fix for @ribizli's small typo:

Using Firebase with typescript, all I have to do is run tsc -w in a separate terminal (the watch variant of npm run build). I can now change my source code and the emulator will notice the changes.

If you installed firebase globally, you can find these files by navigating to cd $(npm root -g)/firebase-tools/node_modules/@google-cloud.