From afcc8d27acad6c0965ea0878304b1a89db450d09 Mon Sep 17 00:00:00 2001 From: Cedric Deege Date: Mon, 2 Oct 2023 12:07:48 +0200 Subject: [PATCH] feat: Automatically detect nested functions organised in folders. --- src/discoverer/discoverer.spec.ts | 1 + src/discoverer/discoverer.ts | 10 ++++++++-- test-e2e/index.ts | 3 ++- test-e2e/nestedFunctions/deeplyNested.trigger.ts | 1 + test-e2e/nestedFunctions/index.ts | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 test-e2e/nestedFunctions/deeplyNested.trigger.ts create mode 100644 test-e2e/nestedFunctions/index.ts diff --git a/src/discoverer/discoverer.spec.ts b/src/discoverer/discoverer.spec.ts index 3e7c95b..8047dd8 100644 --- a/src/discoverer/discoverer.spec.ts +++ b/src/discoverer/discoverer.spec.ts @@ -8,6 +8,7 @@ describe("Function Discovery", function () { firstFunction: "test-e2e/firstFunctions/function.ts", secondFunctionHttpTrigger: "test-e2e/secondFunction/http.trigger.ts", secondFunctionPubSub: "test-e2e/secondFunction/pubsub.trigger.ts", + "nestedFunctions.deeplyNestedFunction": "test-e2e/nestedFunctions/deeplyNested.trigger.ts", }; const indexFilePath = "test-e2e/index.ts"; const result = getFirebaseFunctionsAndPaths(indexFilePath); diff --git a/src/discoverer/discoverer.ts b/src/discoverer/discoverer.ts index e9a42ce..e898826 100644 --- a/src/discoverer/discoverer.ts +++ b/src/discoverer/discoverer.ts @@ -28,8 +28,14 @@ const getExports = (indexFilePath = "src/index.ts"): Record => { } const filePath = declaration.getSourceFile().getFilePath(); - - exports[exportName] = relative(cwd(), filePath); + if (declaration.getSymbolOrThrow().getExports().length > 0) { + const nestedExports = getExports(filePath); + for (const [nestedExportName, nestedFilePath] of Object.entries(nestedExports)) { + exports[`${exportName}.${nestedExportName}`] = nestedFilePath; + } + } else { + exports[exportName] = relative(cwd(), filePath); + } } return exports; diff --git a/test-e2e/index.ts b/test-e2e/index.ts index bf0caf0..8786630 100644 --- a/test-e2e/index.ts +++ b/test-e2e/index.ts @@ -1,4 +1,5 @@ import { firstFunction } from "./firstFunctions/function"; import { secondFunctionHttpTrigger, secondFunctionPubSub } from "./secondFunction"; +import * as nestedFunctions from "./nestedFunctions"; -export { firstFunction, secondFunctionHttpTrigger, secondFunctionPubSub }; +export { firstFunction, secondFunctionHttpTrigger, secondFunctionPubSub, nestedFunctions }; diff --git a/test-e2e/nestedFunctions/deeplyNested.trigger.ts b/test-e2e/nestedFunctions/deeplyNested.trigger.ts new file mode 100644 index 0000000..9a1730a --- /dev/null +++ b/test-e2e/nestedFunctions/deeplyNested.trigger.ts @@ -0,0 +1 @@ +export function deeplyNestedFunction() {} diff --git a/test-e2e/nestedFunctions/index.ts b/test-e2e/nestedFunctions/index.ts new file mode 100644 index 0000000..97ad447 --- /dev/null +++ b/test-e2e/nestedFunctions/index.ts @@ -0,0 +1 @@ +export { deeplyNestedFunction } from "./deeplyNested.trigger";