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

Hardcode grpc-js version #5771

Merged
merged 3 commits into from Dec 8, 2021
Merged

Hardcode grpc-js version #5771

merged 3 commits into from Dec 8, 2021

Conversation

hsubox76
Copy link
Contributor

Hardcode the grpc-js version used for logging. This isn't ideal, as getting the version at runtime provides the most accurate version for metrics and debugging, but working around problems with import.meta.url in ESM Node builds while ensuring CJS Node builds still work is causing a lot of problems. Make a TODO to change back to getting runtime version when there is a better way to support it across CJS and ESM Node builds.

See issues:
#5752
#5687

And PR:
#5532

@changeset-bot
Copy link

changeset-bot bot commented Nov 30, 2021

⚠️ No Changeset found

Latest commit: 303c512

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-cla google-cla bot added the cla: yes label Nov 30, 2021
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 30, 2021

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (a777385) Head (ba63caf) Diff
    main 426 kB 426 kB -351 B (-0.1%)

Test Logs

@Feiyang1
Copy link
Member

import.meta is also used in https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/platform/node/load_protos.ts#L23, so this is not sufficient to solve the problem.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 30, 2021

Size Analysis Report

Affected Products

No changes between base commit (a777385) and head commit (ba63caf).

@hsubox76
Copy link
Contributor Author

hsubox76 commented Dec 3, 2021

import.meta is also used in https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/platform/node/load_protos.ts#L23, so this is not sufficient to solve the problem.

It looks like import.meta itself is not the problem, the createRequire is the problem, in that it creates a non-native require that doesn't work in certain Node-like environments (Electron, NextJS). This gets rid of that part. I can try to do an Electron test to make sure it solves the problem.

It seems like createRequire was introduced in Node 12.2.0 while import.meta was introduced in Node 10.4.0. This isn't the direct cause of the problem (the platforms the users are reporting in the issue should be on Node 12 or greater already) but since the Firebase JS SDK supports Node 10+, we probably shouldn't be including an API that requires Node 12.

const require = module.createRequire(import.meta.url);
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
// TODO: Fetch runtime version from grpc-js/package.json instead
Copy link

Choose a reason for hiding this comment

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

IIRC in order to be able to merge this PR, we are waiting on changes from Firestore to surface the GRPC that is why this is not complete? or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is a stopgap measure so that users can use the SDK without errors for now. In the future if and when the grpc-js team (outside of Firebase) is able to provide us with an export, the plan is we'll revert this and use that instead.

Copy link

Choose a reason for hiding this comment

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

I see so we are not actually intending on passing any sort of version at the moment, but rather a placeholder string and in some future we will pass along the version. Makes sense, just wasn't clear if this TODO was for now or later, thank you for clarifying

Copy link
Contributor Author

@hsubox76 hsubox76 Dec 8, 2021

Choose a reason for hiding this comment

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

Oh no, we will pass a version. The version will be grabbed by Rollup at build time based on the version of grpc-js installed when we build the Firebase SDK. Ideally we want the version installed by the user in their node_modules dir, which may differ, but since we specify the version in @firebase/firestore's package.json dependencies, that should be the version they have for the most part.

Line 75 in rollup.config.js above does the string replacement.

@allspain allspain assigned hsubox76 and unassigned allspain Dec 7, 2021
@hsubox76 hsubox76 assigned allspain and unassigned hsubox76 Dec 7, 2021
@allspain allspain assigned hsubox76 and unassigned allspain Dec 8, 2021
@hsubox76 hsubox76 merged commit 8d9a09e into master Dec 8, 2021
@hsubox76 hsubox76 deleted the ch-require branch December 8, 2021 22:42
@hsubox76 hsubox76 mentioned this pull request Dec 9, 2021
@firebase firebase locked and limited conversation to collaborators Jan 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants