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

Change default entrypoint of the firebase-functions package to v2 instead of v1 #1594

Merged
merged 10 commits into from
Sep 5, 2024
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ _Please avoid double posting across multiple channels!_

```js
// functions/index.js
const functions = require("firebase-functions");
const { onValueCreated } = require("firebase-functions/database");
const logger = require("firebase-functions/logger");
const notifyUsers = require("./notify-users");

exports.newPost = functions.database.ref("/posts/{postId}").onCreate((snapshot, context) => {
functions.logger.info("Received new post with ID:", context.params.postId);
return notifyUsers(snapshot.val());
exports.newPost = onValueCreated({ ref: "/posts/{postId}" }, (event) => {
logger.info("Received new post with ID:", event.params.postId);
return notifyUsers(event.data.val());
});
```

Expand Down
80 changes: 76 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
"lib",
"protos"
],
"main": "lib/v1/index.js",
"main": "lib/v2/index.js",
"bin": {
"firebase-functions": "./lib/bin/firebase-functions.js"
},
"types": "lib/v1/index.d.ts",
"types": "lib/v2/index.d.ts",
"exports": {
".": "./lib/v1/index.js",
"./logger/compat": "./lib/logger/compat.js",
"./logger": "./lib/logger/index.js",
"./params": "./lib/params/index.js",
Expand All @@ -43,6 +42,25 @@
"./v1/storage": "./lib/v1/providers/storage.js",
"./v1/tasks": "./lib/v1/providers/tasks.js",
"./v1/testLab": "./lib/v1/providers/testLab.js",
".": "./lib/v2/index.js",
"./core": "./lib/v2/core.js",
taeold marked this conversation as resolved.
Show resolved Hide resolved
"./options": "./lib/v2/options.js",
"./https": "./lib/v2/providers/https.js",
"./pubsub": "./lib/v2/providers/pubsub.js",
"./storage": "./lib/v2/providers/storage.js",
"./tasks": "./lib/v2/providers/tasks.js",
"./alerts": "./lib/v2/providers/alerts/index.js",
"./alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js",
"./alerts/billing": "./lib/v2/providers/alerts/billing.js",
"./alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js",
"./alerts/performance": "./lib/v2/providers/alerts/performance.js",
"./eventarc": "./lib/v2/providers/eventarc.js",
"./identity": "./lib/v2/providers/identity.js",
"./database": "./lib/v2/providers/database.js",
"./scheduler": "./lib/v2/providers/scheduler.js",
"./remoteConfig": "./lib/v2/providers/remoteConfig.js",
"./testLab": "./lib/v2/providers/testLab.js",
"./firestore": "./lib/v2/providers/firestore.js",
"./v2": "./lib/v2/index.js",
"./v2/core": "./lib/v2/core.js",
"./v2/options": "./lib/v2/options.js",
Expand Down Expand Up @@ -107,6 +125,60 @@
"v1/testLab": [
"lib/v1/providers/testLab"
],
"core": [
"./lib/v2/core"
],
"options": [
"./lib/v2/options"
],
"https": [
"./lib/v2/providers/https"
],
"pubsub": [
"./lib/v2/providers/pubsub"
],
"storage": [
"./lib/v2/providers/storage"
],
"tasks": [
"./lib/v2/providers/tasks"
],
"alerts": [
"./lib/v2/providers/alerts/index"
],
"alerts/appDistribution": [
"./lib/v2/providers/alerts/appDistribution"
],
"alerts/billing": [
"./lib/v2/providers/alerts/billing"
],
"alerts/crashlytics": [
"./lib/v2/providers/alerts/crashlytics"
],
"alerts/performance": [
"./lib/v2/providers/alerts/performance"
],
"eventarc": [
"./lib/v2/providers/eventarc"
],
"identity": [
"./lib/v2/providers/identity"
],
"database": [
"./lib/v2/providers/database"
],
"scheduler": [
"./lib/v2/providers/scheduler"
],
"remoteConfig": [
"./lib/v2/providers/remoteConfig"
],
"testLab": [
"./lib/v2/providers/testLab"
],
"firestore": [
"./lib/v2/providers/firestore"
],
"v2": [
"lib/v2"
],
Expand Down Expand Up @@ -252,4 +324,4 @@
"engines": {
"node": ">=14.10.0"
}
}
}
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/commonjs-grouped/g1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const functions = require("firebase-functions");
const functions = require("firebase-functions/v1");

exports.groupedhttp = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/commonjs-grouped/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const functions = require("firebase-functions");
const functions = require("firebase-functions/v1");
const functionsv2 = require("firebase-functions/v2");
const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText;
const backfill = require("@firebase-extensions/local-backfill-sdk").backfill;
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/commonjs-main/functions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const functions = require("firebase-functions");
const functions = require("firebase-functions/v1");
const functionsv2 = require("firebase-functions/v2");
const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText;
const backfill = require("@firebase-extensions/local-backfill-sdk").backfill;
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/commonjs-preserve/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const functions = require("firebase-functions");
const functions = require("firebase-functions/v1");
const functionsv2 = require("firebase-functions/v2");
const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText;
const backfill = require("@firebase-extensions/local-backfill-sdk").backfill;
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/commonjs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const functions = require("firebase-functions");
const functions = require("firebase-functions/v1");
const functionsv2 = require("firebase-functions/v2");
const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText;
const backfill = require("@firebase-extensions/local-backfill-sdk").backfill;
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/esm-ext/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as functions from "firebase-functions";
import * as functions from "firebase-functions/v1";
import * as functionsv2 from "firebase-functions/v2";
import { firestoreTranslateText } from "@firebase-extensions/firebase-firestore-translate-text-sdk";
import { backfill } from "@firebase-extensions/local-backfill-sdk";
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/esm-main/functions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as functions from "firebase-functions";
import * as functions from "firebase-functions/v1";
import * as functionsv2 from "firebase-functions/v2";
import { firestoreTranslateText } from "@firebase-extensions/firebase-firestore-translate-text-sdk";
import { backfill } from "@firebase-extensions/local-backfill-sdk";
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin-test/sources/esm/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as functions from "firebase-functions";
import * as functions from "firebase-functions/v1";
import * as functionsv2 from "firebase-functions/v2";
import { firestoreTranslateText } from "@firebase-extensions/firebase-firestore-translate-text-sdk";
import { backfill } from "@firebase-extensions/local-backfill-sdk";
Expand Down
Loading