Skip to content

Commit

Permalink
Support v2 functions fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Oct 31, 2023
1 parent ed8eb2b commit 4d3bd14
Show file tree
Hide file tree
Showing 7 changed files with 1,031 additions and 1,298 deletions.
9 changes: 4 additions & 5 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
"files": [
"build"
],
"main": "./index.umd.js",
"module": "./index.js",
"type": "module",
"exports": {
".": {
"import": "./index.js",
"require": "./index.umd.js"
"types": "./index.d.ts"
}
},
"scripts": {
Expand All @@ -23,8 +22,8 @@
"dependencies": {
"@faker-js/faker": "^8.0.1",
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.4.0"
"firebase-admin": "^11.11.0",
"firebase-functions": "^4.4.1"
},
"devDependencies": {
"@types/rollup-plugin-generate-package-json": "^3.2.0",
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express from "express";
import * as functions from "firebase-functions";
import { iLikeTurtles } from "@acme/shared";
import { onRequest } from "firebase-functions/v2/https";
import { faker } from "@faker-js/faker";
import express from "express";

const app = express();

app.get("*", (req, res) => {
app.get("*", (_req, res) => {
res.send({
hello: "world",
randomName: faker.person.firstName(),
Expand All @@ -14,4 +14,4 @@ app.get("*", (req, res) => {
});
});

export const server = functions.https.onRequest(app);
export const server = onRequest(app);
7 changes: 3 additions & 4 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"compilerOptions": {
"lib": ["ES2021"],
"module": "ES2020",
"moduleResolution": "node",
"target": "ES2021",
"module": "ESNext",
"moduleResolution": "NodeNext",
"target": "ESNext",
"outDir": "dist",
"resolveJsonModule": true,
"sourceMap": true,
"rootDir": "../../",
"typeRoots": ["node_modules/@types"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
Expand Down
28 changes: 16 additions & 12 deletions apps/api/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import { resolve } from "path";
import { defineConfig } from "vite";
import generatePackageJson from "rollup-plugin-generate-package-json";
import packageJson from "./package.json";
import packageJson from "./package.json" assert { type: "json" };
import { builtinModules } from "node:module";

// NOTE: the @acme/shared package cannot be included into the deps casue it will attempt to be installed in
// NOTE: the @acme/shared package cannot be included into the deps casue it will attempt to be installed in
// the firebase function build step and fail, so as a work around we are using a bundler to move the code into the final bundle that we ship to firebase

// NOTE: we are using vite for bundling but "native" support for nodejs is not yet available
// for the tracking of that there is the following issue and if that is solved this implementation may change
// https://github.com/vitejs/vite/issues/7821

const external = [...builtinModules, ...builtinModules.map((m) => `node:${m}`)];

export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, "src/index.ts"),
name: "firebase-functions-lib",
fileName: "index",
formats: ["es", "umd"],
},
ssr: "./src/index.ts",
outDir: "dist",
rollupOptions: {
external: Object.keys(packageJson.dependencies),
// NOTE: Firebase requires a package.json to be present in the functions folder
// this is a workaround to generate that file so firebase stays happy
output: {
inlineDynamicImports: true,
},
preserveSymlinks: true,
external,
plugins: [
generatePackageJson({
// @ts-ignore
baseContents: packageJson,
}),
],
},
},
ssr: {
external,
},
});
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@vitejs/plugin-react": "^4.0.0",
"vite": "^4.3.8"
"vite": "^4.5.0"
}
}
Loading

0 comments on commit 4d3bd14

Please sign in to comment.