Skip to content

Commit aa07a32

Browse files
committed
Hardcode grpc version
1 parent f318c70 commit aa07a32

File tree

2 files changed

+13
-33
lines changed

2 files changed

+13
-33
lines changed

packages/firestore/rollup.config.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18-
import tmp from 'tmp';
19-
import json from '@rollup/plugin-json';
18+
import { version as grpcVersion } from '@grpc/grpc-js/package.json';
2019
import alias from '@rollup/plugin-alias';
20+
import json from '@rollup/plugin-json';
21+
import copy from 'rollup-plugin-copy';
22+
import { terser } from 'rollup-plugin-terser';
2123
import typescriptPlugin from 'rollup-plugin-typescript2';
24+
import tmp from 'tmp';
2225
import typescript from 'typescript';
2326
import replace from 'rollup-plugin-replace';
24-
import copy from 'rollup-plugin-copy';
25-
import { terser } from 'rollup-plugin-terser';
2627

27-
import pkg from './package.json';
2828
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target';
2929

30-
const util = require('./rollup.shared');
30+
import pkg from './package.json';
3131

32-
// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to be able to use require() in esm.
33-
// It only generates the nodejs version of the polyfill, as opposed to the default polyfill which
34-
// supports both browser and nodejs. The browser support is unnecessary and doesn't work well with Jest. See https://github.com/firebase/firebase-js-sdk/issues/5687
35-
function importMetaUrlPolyfillPlugin() {
36-
return {
37-
name: 'import-meta-url-current-module',
38-
resolveImportMeta(property, { moduleId }) {
39-
if (property === 'url') {
40-
// copied from rollup output
41-
return `new (require('url').URL)('file:' + __filename).href`;
42-
}
43-
return null;
44-
}
45-
};
46-
}
32+
const util = require('./rollup.shared');
4733

4834
const nodePlugins = function () {
4935
return [
@@ -69,7 +55,8 @@ const nodePlugins = function () {
6955
]
7056
}),
7157
replace({
72-
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos')
58+
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos'),
59+
'__GRPC_VERSION__': grpcVersion
7360
})
7461
];
7562
};
@@ -120,8 +107,7 @@ const allBuilds = [
120107
},
121108
plugins: [
122109
...util.es2017ToEs5Plugins(/* mangled= */ false),
123-
replace(generateBuildTargetReplaceConfig('cjs', 2017)),
124-
importMetaUrlPolyfillPlugin()
110+
replace(generateBuildTargetReplaceConfig('cjs', 2017))
125111
],
126112
external: util.resolveNodeExterns,
127113
treeshake: {

packages/firestore/src/platform/node/grpc_connection.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
// This is a hack fix for Node ES modules to use `require`.
19-
// @ts-ignore To avoid using `allowSyntheticDefaultImports` flag.
20-
import module from 'module';
21-
2218
import {
2319
Metadata,
2420
GrpcObject,
@@ -38,11 +34,9 @@ import { logError, logDebug, logWarn } from '../../util/log';
3834
import { NodeCallback, nodePromise } from '../../util/node_api';
3935
import { Deferred } from '../../util/promise';
4036

41-
// This is a hack fix for Node ES modules to use `require`.
42-
// @ts-ignore To avoid using `--module es2020` flag.
43-
const require = module.createRequire(import.meta.url);
44-
// eslint-disable-next-line @typescript-eslint/no-require-imports
45-
const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
37+
// TODO: Fetch runtime version from grpc-js/package.json instead
38+
// when it becomes possible to use require() in Node ESM without hacks.
39+
const grpcVersion = '__GRPC_VERSION__';
4640

4741
const LOG_TAG = 'Connection';
4842
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;

0 commit comments

Comments
 (0)