Skip to content

Commit

Permalink
Fix Firestore exports for Node (#5532)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 authored Oct 19, 2021
1 parent 05773dc commit 4d36404
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-cooks-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': minor
---

Fix exports field to also point to Node ESM builds. This change requires Node.js version 10+.
2 changes: 1 addition & 1 deletion packages/firestore/lite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@firebase/firestore-lite",
"description": "A lite version of the Firestore SDK",
"main": "../dist/lite/index.node.cjs.js",
"main-esm": "../dist/lite/index.node.esm2017.js",
"main-esm": "../dist/lite/index.node.mjs",
"module": "../dist/lite/index.browser.esm2017.js",
"browser": "../dist/lite/index.browser.esm2017.js",
"react-native": "../dist/lite/index.rn.esm2017.js",
Expand Down
14 changes: 10 additions & 4 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@firebase/firestore",
"version": "3.1.1",
"engines": {
"node": "^8.13.0 || >=10.10.0"
"node": ">=10.10.0"
},
"description": "The Cloud Firestore component of the Firebase JS SDK.",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
Expand Down Expand Up @@ -49,16 +49,22 @@
},
"exports": {
".": {
"node": "./dist/index.node.cjs.js",
"node": {
"require": "./dist/index.node.cjs.js",
"import": "./dist/index.node.mjs"
},
"default": "./dist/index.esm2017.js"
},
"./lite": {
"node": "./dist/lite/index.node.cjs.js",
"node": {
"require": "./dist/lite/index.node.cjs.js",
"import": "./dist/lite/index.node.mjs"
},
"default": "./dist/lite/index.browser.esm2017.js"
}
},
"main": "dist/index.node.cjs.js",
"main-esm": "dist/index.node.cjs.esm2017.js",
"main-esm": "dist/index.node.mjs",
"react-native": "dist/index.rn.js",
"browser": "dist/index.esm2017.js",
"module": "dist/index.esm2017.js",
Expand Down
11 changes: 10 additions & 1 deletion packages/firestore/src/platform/node/grpc_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
* 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,
credentials as GrpcCredentials,
ServiceError
} from '@grpc/grpc-js';
import { version as grpcVersion } from '@grpc/grpc-js/package.json';

import { Token } from '../../api/credentials';
import { DatabaseInfo } from '../../core/database_info';
Expand All @@ -35,6 +38,12 @@ 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 require = module.createRequire(import.meta.url);
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version: grpcVersion } = require('@grpc/grpc-js/package.json');

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

Expand Down

0 comments on commit 4d36404

Please sign in to comment.