Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use esbuild to bundle firebase functions rewritten in TypeScipt #539

Merged
merged 2 commits into from
Oct 14, 2021

Conversation

SamChou19815
Copy link
Contributor

@SamChou19815 SamChou19815 commented Oct 7, 2021

Summary

powertothetypes

This PR adds a build step to firebase functions instead of using the old approach of using JS only without any build step.

I decided to use esbuild to bundle it mostly for its speed and ease of configuration. You can also use webpack for bundling, but that requires a lot of config.
In addition, I decided to bundle instead of simply transpile since I have future plan to organize our repo into workspaces (see npm workspaces (v7 only) or yarn workspaces). Unfortunately, firebase tools do not work well with with these workspaces, so we have to bundle the code into a single, self-contained js file without any dependencies, so that firebase tools will not look into node_modules. The bundled code is put inside functions/deployment-template with a package.json without dependencies.

Test Plan

cd functions && npm run deploy

Function should be invoked fine (unfortunately I don't have access to the google cloud project)

@dti-github-bot
Copy link
Member

dti-github-bot commented Oct 7, 2021

[diff-counting] Significant lines: 33.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

Visit the preview URL for this PR (updated for commit ad37f77):

https://cornelldti-courseplan-dev--pr539-esbuild-bundle-funct-ha8f04cr.web.app

(expires Wed, 20 Oct 2021 23:03:27 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@SamChou19815 SamChou19815 marked this pull request as ready for review October 7, 2021 00:59
@SamChou19815 SamChou19815 requested a review from a team as a code owner October 7, 2021 00:59
@SamChou19815 SamChou19815 changed the title Use esbuild to bundle firebase functions Use esbuild to bundle firebase functions rewritten in TypeScipt Oct 7, 2021
@SamChou19815 SamChou19815 force-pushed the esbuild-bundle-functions branch 3 times, most recently from 7f89c1f to 17805d8 Compare October 7, 2021 13:40
@hahnbeelee
Copy link
Contributor

hmm looks like i don't have permissions either. @willespencer can you review this?
image

@SamChou19815
Copy link
Contributor Author

SamChou19815 commented Oct 8, 2021

hmm looks like i don't have permissions either. @willespencer can you review this?

image

@hahnbeelee try to run firebase use default to switch to staging site. Here you are trying to deploy to prod.

Copy link
Member

@willespencer willespencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

When I run the deploy command, I get the following error? Not sure what could be causing this

@SamChou19815
Copy link
Contributor Author

image

When I run the deploy command, I get the following error? Not sure what could be causing this

Looks like a windows issue. Are you running this in WSL or normal terminals?

Copy link
Contributor

@hahnbeelee hahnbeelee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I was able to run npm run deploy but when I tried invoking TrackUsers here I got this error:
image

@hahnbeelee
Copy link
Contributor

@SamChou19815
Copy link
Contributor Author

OK, so I was able to run npm run deploy but when I tried invoking TrackUsers here I got this error: image

I might know what's happening. I think bumping firebase-admin might help. It's issue with esbuild is only fixed recently: googleapis/nodejs-firestore#1493

@SamChou19815
Copy link
Contributor Author

SamChou19815 commented Oct 13, 2021

@hahnbeelee I bumped the dependencies and deployed it, but still could not test. Can you help to run it?

Copy link
Contributor

@hahnbeelee hahnbeelee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed! :)
image

@SamChou19815 SamChou19815 merged commit 460142c into master Oct 14, 2021
@SamChou19815 SamChou19815 deleted the esbuild-bundle-functions branch October 14, 2021 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants