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

Update default function template #130

Merged
merged 3 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions e2e/nx-firebase-e2e/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,29 @@ export function getProjectData(type: 'libs' | 'apps', name: string, options?: {
}
}

const IMPORT_MATCH = `import * as functions from 'firebase-functions';`
const IMPORT_MATCH = `import * as logger from "firebase-functions/logger";`

export function getMainTs() {
return `
import * as admin from "firebase-admin";
/**
* Import function triggers from their respective submodules:
*
* import {onCall} from "firebase-functions/v2/https";
* import {onDocumentWritten} from "firebase-functions/v2/firestore";
*
* See a full list of supported triggers at https://firebase.google.com/docs/functions
*/

import {onRequest} from "firebase-functions/v2/https";
${IMPORT_MATCH}
admin.initializeApp();

export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
// Start writing functions
// https://firebase.google.com/docs/functions/typescript

export const helloWorld = onRequest((request, response) => {
logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
});
`
}

Expand Down
8 changes: 5 additions & 3 deletions e2e/nx-firebase-e2e/tests/nx-firebase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../test-utils'


const JEST_TIMEOUT = 120000
const JEST_TIMEOUT = 190000
jest.setTimeout(JEST_TIMEOUT)

// NOTE: If one e2e test fails, cleanup fails, so all subsequent tests will fail.
Expand Down Expand Up @@ -437,7 +437,8 @@ describe('nx-firebase e2e', () => {
const distPackage = readJson(distPackageFile)
const deps = distPackage['dependencies']
expect(deps).toBeDefined()
expect(deps['firebase-admin']).toBeDefined()
// firebase-admin is No longer in the default main.ts template
// expect(deps['firebase-admin']).toBeDefined()
expect(deps['firebase-functions']).toBeDefined()

// cleanup
Expand Down Expand Up @@ -554,7 +555,8 @@ describe('nx-firebase e2e', () => {
const distPackage = readJson(`${functionData.distDir}/package.json`)
const deps = distPackage['dependencies']
expect(deps).toBeDefined()
expect(deps['firebase-admin']).toBeDefined()
// firebase-admin not in the template anymore
// expect(deps['firebase-admin']).toBeDefined()
expect(deps['firebase-functions']).toBeDefined()

// check bundled code contains the libcode we added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
import * as functions from "firebase-functions";
/**
* Import function triggers from their respective submodules:
*
* import {onCall} from "firebase-functions/v2/https";
* import {onDocumentWritten} from "firebase-functions/v2/firestore";
*
* See a full list of supported triggers at https://firebase.google.com/docs/functions
*/

// The Firebase Admin SDK to access Firebase Features from within Cloud Functions.
import * as admin from "firebase-admin";
admin.initializeApp();
import {onRequest} from "firebase-functions/v2/https";
import * as logger from "firebase-functions/logger";

// Set up extra settings. Since May 29, 2020, Firebase Firebase Added support for
// calling FirebaseFirestore.settings with { ignoreUndefinedProperties: true }.
// When this parameter is set, Cloud Firestore ignores undefined properties
// inside objects rather than rejecting the API call.
admin.firestore().settings({
ignoreUndefinedProperties: true,
});

// Start writing Firebase Functions
// Start writing functions
// https://firebase.google.com/docs/functions/typescript

export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
export const helloWorld = onRequest((request, response) => {
logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});

8 changes: 4 additions & 4 deletions packages/nx-firebase/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export const tsLibVersion = '^2.0.0'

// Firebase packages are not managed by the plugin
// but they are added if they do not exist already in the workspace
export const firebaseAdminVersion = '^11.3.0'
export const firebaseFunctionsVersion = '^4.1.0'
export const firebaseToolsVersion = '^11.16.1'
export const firebaseAdminVersion = '^11.10.1'
export const firebaseFunctionsVersion = '^4.4.1'
export const firebaseToolsVersion = '^12.4.5'
export const firebaseVersion = '^9.14.0'
export const firebaseFunctionsTestVersion = '^0.2.0'
export const firebaseFunctionsTestVersion = '^3.1.0'

// Target node 16 for all firebase projects now
export const firebaseNodeEngine = '16'
Expand Down