How to debug dart code in firebase emulator - firebase

First, it is possible to write firebase cloud functions in dart.
For that we need
write cloud functions using https://github.com/pulyaevskiy/firebase-functions-interop
compile dart to js code
move compiled code to firebase functions folder
then run firebase emulators as usual
Is it possible to set breakpoints in dart code in the firebase functions emulator?
My use case
using this library https://github.com/pulyaevskiy/firebase-functions-interop
I want to port my firebase functions from TypeScript to Dart but one of the concerns I have now is debugging
How I can debug dart code in the firebase emulator?
In my typescript project
I run this command tsc -w | firebase emulators:start --only functions --inspect-functions
and can set breakpoints in VSCode
But how it will work with https://github.com/pulyaevskiy/firebase-functions-interop in dart?

Related

Debugging functions in firebase emulator without deploying first

I have an application that uses cloud functions to respond to Firestore triggers (onCreate, onDelete). I am trying to use the emulator to test these functions prior to deployment, however that does not work for me.
The emulator is properly setup, I can test and debug cloud functions, BUT I have to deploy them first. Am I missing something?
Basically, I have to do
> firebase emulator:start --inspect-functions
then
> firebase deploy --only functions
Any help or pointers would be greatly appreciated
If you are using TypeScript, you have to build the functions first. Read more.

How do you deploy to Firebase without Firebase functions?

I experimented with firebase functions for the init part and it has created a folder for me. Now when I deploy each time it also picks up the functions folder. When I remove the functions folder I get an error, when deploying. How do I deploy everything but functions?
firebase deploy has a parameter --except . So to deploy everything except functions you can run:
firebase deploy --except functions
You can use the only option/flag, for example firebase deploy --only hosting,storage, see the CLI doc.
You can also use deploy targets which "are short-name identifiers (that you define yourself) for Firebase resources in your Firebase project".
Check to make sure that you have removed the implicit reference to the function in your index.js and then running firebase deploy should do the trick. If you want to explicitly delete the function completely, you can use the firebase functions:delete <myFunction> and then delete the functions folder. You can find more details in the doc here

How do you deploy firebase cloud functions to all aliases?

I have cloud functions set up for a project that will be used by multiple projects. I understand that you can deploy those functions to different projects using firebase use and adding/using aliases. Is there a way to deploy the functions to all known project aliases?
There is nothing built in to the Firebase CLI to do this as each project is considered to be a fully separate environment. You can use the --project <alias_or_project_id> flag to deploy to different aliases without having to switch using firebase use:
firebase deploy --project alias1
firebase deploy --project alias2
firebase deploy --project alias3
You could write a shell script to do all of those one after another or in parallel.
The Firebase CLI doesn't have a command for that. You can write a shell script or some other program to automate the execution of firebase deploy as many times as needed for each project you want to deploy.

FIREBASE_CONFIG environment variable in GCP Cloud Run

This page explains:
Note: The FIREBASE_CONFIG environment variable is included automatically in Cloud Functions for Firebase functions that were deployed via the Firebase CLI.
Can we get access to the same FIREBASE_CONFIG environment variable in Cloud Run environment? If yes, how?
If no, please give instructions on setting firebase-admin initializeApp and firebase initializeApp for authentication on Cloud Run.
Should we save the serviceAccount and firebase-config in our project and import them? If so, what are the best practices for doing that? When working on an open-source project, we should put these files in .gitignore. Then how should we push them to the Cloud Run environment using gcloud CLI?

How to deploy some functions to Cloud Functions for Firebase without affecting some other functions?

When I run
firebase deploy --only functions
it reads the index.js file and updates all functions exported from that file. If on the previous deploy there was a function named a, and in the current deploy there is no such function, a will be deleted.
In other words, the effect is the same as if all existing functions were deleted and then the all functions from the current index.js file were added.
Is it possible to add/update/delete individual functions?
Firebase CLI tools 3.8.0 has added the ability to deploy specific functions.
firebase deploy --only functions:func1,functions:func2
--only <targets>
only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions,
can specify filters with colons to scope function deploys to only those functions (e.g. "--only functions:func1,functions:func2").
When filtering based on export groups (the exported module object keys), use dots to specify group names
(e.g. "--only functions:group1.subgroup1,functions:group2)"
The following way worked for me to deploy a particular function without affecting my other functions, where specificFunctionName is the function I wanted to deploy
firebase deploy --only functions:specificFunctionName
To copy the command quickly in terminal:
firebase deploy --only functions:
firebaser here
There is currently no way to deploy a single function with the Firebase CLI. Running `firebase deploy` will deploy all functions.
We've recently discussed deploying subsets of the functions, but it's not available at the moment - nor can we give a ballpark of if/when it might be.
Update Since Firebase CLI release the ability to deploy single functions is available. See yuku's answer.
firebase deploy --only "functions:<fileName>.<functionName>"
example folder structure:
functions
node_modules
index.js
smsNotification.js
...
You can redeploy just a function in a file with
firebase deploy --only "functions:smsNotification.sendChatNotif"
You can redploy all functions in a file with
firebase deploy --only "functions:smsNotification"
I never managed to get it working (and have no codebase property in my firebase.json) until I tried what #Sergey Mell mentioned in his comment :
firebase deploy --only "functions:func1,functions:func2"
The surrounding double quotes was what solved the issue.
In case anyone still can't make it work using firebase deploy --only functions:func1,functions:func2, it's probably because you're probably using codebases, "codebase": "my-codebase", in your firebase.json. Took me a while to diagnose but after removing that codebase property, deploying only some functions using the --only flag worked for me
This one gave me the missing package. Although package was included but I had to reinstall the mentioned package.
firebase --debug deploy --only functions:[functionName]

Resources