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

Fix bug where function discovery failed on projects using yarn workspaces. #5215

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

taeold
Copy link
Contributor

@taeold taeold commented Nov 4, 2022

Today, the CLI uses the npm ls firebase-functions command to check the version of the firebase functions of the user's functions module. The current implementation doesn't work when using npm/yarn workspaces.

We rewrite the implementation to use [require.resolve] to look up location of the firebase functions package and read the accompanying package.json to look up the version instead. This implementation works with npm/yarn workspaces as demonstrated in the new test cases.

Hopefully addresses #5191

@taeold
Copy link
Contributor Author

taeold commented Nov 4, 2022

@codecov-commenter
Copy link

codecov-commenter commented Nov 4, 2022

Codecov Report

Base: 56.27% // Head: 56.28% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (19cb747) compared to base (51ddf7e).
Patch has no changes to coverable lines.

❗ Current head 19cb747 differs from pull request most recent head af6ff32. Consider uploading reports for the commit af6ff32 to get more accurate results

Additional details and impacted files
@@                   Coverage Diff                    @@
##           dl-cf3-discover-test    #5215      +/-   ##
========================================================
+ Coverage                 56.27%   56.28%   +0.01%     
========================================================
  Files                       309      309              
  Lines                     20838    20828      -10     
  Branches                   4227     4227              
========================================================
- Hits                      11726    11723       -3     
+ Misses                     8100     8093       -7     
  Partials                   1012     1012              
Impacted Files Coverage Δ
src/emulator/auth/state.ts 84.87% <0.00%> (-0.57%) ⬇️
src/deploy/functions/prepare.ts 32.66% <0.00%> (+1.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@taeold taeold marked this pull request as ready for review December 1, 2022 23:53
Copy link
Contributor

@colerogers colerogers left a comment

Choose a reason for hiding this comment

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

small q on the while loop but LGTM

export function findModuleVersion(name: string, resolvedPath: string): string | undefined {
let searchPath = path.dirname(resolvedPath);
// eslint-disable-next-line no-constant-condition
while (true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think search path will always terminate with /, right? Why not use that as the condition instead of doing while (true)?

@taeold
Copy link
Contributor Author

taeold commented Dec 13, 2022

Graphite Merge Job

Current status: ✅ Merged

This pull request was successfully merged as part of a stack.

This comment was auto-generated by Graphite.

Job Reference: Uhty8UE38l3MKEIRA9gp

@taeold taeold changed the base branch from dl-cf3-discover-test to master December 13, 2022 18:54
@taeold taeold merged commit 355e9b9 into master Dec 13, 2022
taeold added a commit that referenced this pull request Jan 6, 2023
…orepo setups (#5391)

Partially fixes #4952.

#5215 made changes to the CLI to detect Functions SDK even in monorepo setups where Functions SDK is hoisted (i.e. Functions SDK dependency is declared in the parent directory but not in the sub-package directory).

We should've made corresponding change in how the Functions SDK binary is executed - instead of always looking up the sub-package's `node_modules`, we should be looking at the `node_modules` closest to where the Functions SDK dependency is declared.

This setup seems common in scenarios where the developer bundles the functions source using bundlers like vite/webpack/etc. This kind of technique has shown to help [AWS lambda's cold start time](https://aws.amazon.com/blogs/compute/optimizing-node-js-dependencies-in-aws-lambda/), and I think it's something we'd want to explore in Google Cloud Functions too.
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.

None yet

4 participants