diff --git a/packages/firestore/rollup.config.js b/packages/firestore/rollup.config.js index a75701466ad..6e0638284cb 100644 --- a/packages/firestore/rollup.config.js +++ b/packages/firestore/rollup.config.js @@ -15,18 +15,20 @@ * limitations under the License. */ -import tmp from 'tmp'; -import json from '@rollup/plugin-json'; +import { version as grpcVersion } from '@grpc/grpc-js/package.json'; import alias from '@rollup/plugin-alias'; -import typescriptPlugin from 'rollup-plugin-typescript2'; -import typescript from 'typescript'; -import replace from 'rollup-plugin-replace'; +import json from '@rollup/plugin-json'; import copy from 'rollup-plugin-copy'; +import replace from 'rollup-plugin-replace'; import { terser } from 'rollup-plugin-terser'; +import typescriptPlugin from 'rollup-plugin-typescript2'; +import tmp from 'tmp'; +import typescript from 'typescript'; -import pkg from './package.json'; import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target'; +import pkg from './package.json'; + const util = require('./rollup.shared'); // Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to be able to use require() in esm. @@ -69,7 +71,8 @@ const nodePlugins = function () { ] }), replace({ - 'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') + 'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos'), + '__GRPC_VERSION__': grpcVersion }) ]; }; diff --git a/packages/firestore/src/platform/node/grpc_connection.ts b/packages/firestore/src/platform/node/grpc_connection.ts index f025e38a4eb..651b436724b 100644 --- a/packages/firestore/src/platform/node/grpc_connection.ts +++ b/packages/firestore/src/platform/node/grpc_connection.ts @@ -15,10 +15,6 @@ * limitations under the License. */ -// This is a hack fix for Node ES modules to use `require`. -// @ts-ignore To avoid using `allowSyntheticDefaultImports` flag. -import module from 'module'; - import { Metadata, GrpcObject, @@ -38,11 +34,9 @@ import { logError, logDebug, logWarn } from '../../util/log'; import { NodeCallback, nodePromise } from '../../util/node_api'; import { Deferred } from '../../util/promise'; -// This is a hack fix for Node ES modules to use `require`. -// @ts-ignore To avoid using `--module es2020` flag. -const requireInESM = module.createRequire(import.meta.url); -// eslint-disable-next-line @typescript-eslint/no-require-imports -const { version: grpcVersion } = requireInESM('@grpc/grpc-js/package.json'); +// TODO: Fetch runtime version from grpc-js/package.json instead +// when there's a cleaner way to dynamic require JSON in both Node ESM and CJS +const grpcVersion = '__GRPC_VERSION__'; const LOG_TAG = 'Connection'; const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;