Skip to content

Commit

Permalink
Firebase Functions ships with a binary (#1003)
Browse files Browse the repository at this point in the history
We introduce a bin associated with the firebase-functions SDK! The binary exposes a simple server on localhost that describes the Firebase Functions defined in the current directory:

```
$ STACK_CONTROL_API_PORT=8181 npx firebase-functions  # Optionally can pass in a FUNCTIONS_DIR as first arg 
Serving at port 8181

$ curl localhost:8181/__/stack.yaml | jq
{
  "endpoints": {
    "onreqv2": {
      "platform": "gcfv2",
      "labels": {},
      "httpsTrigger": {},
      "entryPoint": "onreqv2"
    },
    "onRequest": {
      "platform": "gcfv1",
      "httpsTrigger": {},
      "entryPoint": "onRequest"
    }
  },
  "specVersion": "v1alpha1",
  "requiredAPIs": []
}
```
  • Loading branch information
taeold authored Feb 2, 2022
1 parent 8e21f77 commit f3ed261
Show file tree
Hide file tree
Showing 29 changed files with 872 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
- run: npm install
- run: npm run lint
- run: npm run format
- run: npm run test
- run: npm run build && npm run test
109 changes: 101 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"lib"
],
"main": "lib/index.js",
"bin": {
"firebase-functions": "./lib/bin/firebase-functions.js"
},
"types": "lib/index.d.ts",
"exports": {
".": "./lib/index.js",
Expand Down Expand Up @@ -178,6 +181,7 @@
"mz": "^2.7.0",
"nock": "^10.0.6",
"prettier": "^1.18.2",
"semver": "^7.3.5",
"sinon": "^7.3.2",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
Expand Down
9 changes: 9 additions & 0 deletions spec/fixtures/sources/commonjs-grouped/g1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const functions = require("../../../../src/index");

exports.groupedhttp = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.groupedcallable = functions.https.onCall(() => {
return "PASS";
});
20 changes: 20 additions & 0 deletions spec/fixtures/sources/commonjs-grouped/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const functions = require("../../../../src/index");
const functionsv2 = require("../../../../src/v2/index");

exports.v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v1callable = functions.https.onCall(() => {
return "PASS";
});

exports.v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v2callable = functionsv2.https.onCall(() => {
return "PASS";
});

exports.g1 = require("./g1");
3 changes: 3 additions & 0 deletions spec/fixtures/sources/commonjs-grouped/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "commonjs-grouped"
}
18 changes: 18 additions & 0 deletions spec/fixtures/sources/commonjs-main/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const functions = require("../../../../src/index");
const functionsv2 = require("../../../../src/v2/index");

exports.v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v1callable = functions.https.onCall(() => {
return "PASS";
});

exports.v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
4 changes: 4 additions & 0 deletions spec/fixtures/sources/commonjs-main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "commonjs-main",
"main": "functions.js"
}
18 changes: 18 additions & 0 deletions spec/fixtures/sources/commonjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const functions = require("../../../../src/index");
const functionsv2 = require("../../../../src/v2/index");

exports.v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v1callable = functions.https.onCall(() => {
return "PASS";
});

exports.v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
3 changes: 3 additions & 0 deletions spec/fixtures/sources/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "commonjs"
}
18 changes: 18 additions & 0 deletions spec/fixtures/sources/esm-ext/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as functions from '../../../../lib/index.js';
import * as functionsv2 from "../../../../lib/v2/index.js";

export const v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

export const v1callable = functions.https.onCall(() => {
return "PASS";
});

export const v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

export const v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
4 changes: 4 additions & 0 deletions spec/fixtures/sources/esm-ext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "esm-ext",
"main": "index.mjs"
}
18 changes: 18 additions & 0 deletions spec/fixtures/sources/esm-main/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as functions from "../../../../lib/index.js";
import * as functionsv2 from "../../../../lib/v2/index.js";

export const v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

export const v1callable = functions.https.onCall(() => {
return "PASS";
});

export const v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

export const v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
5 changes: 5 additions & 0 deletions spec/fixtures/sources/esm-main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "esm-main",
"main": "functions.js",
"type": "module"
}
18 changes: 18 additions & 0 deletions spec/fixtures/sources/esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as functions from "../../../../lib/index.js";
import * as functionsv2 from "../../../../lib/v2/index.js";

export const v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

export const v1callable = functions.https.onCall(() => {
return "PASS";
});

export const v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

export const v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
4 changes: 4 additions & 0 deletions spec/fixtures/sources/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "esm",
"type": "module"
}
Loading

0 comments on commit f3ed261

Please sign in to comment.