-
Notifications
You must be signed in to change notification settings - Fork 82
Skill to convert extensions codebases into functions codebases #21
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
a047e48
28cc388
b139d88
79b9f49
01b6584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,97 @@ | ||||||
| --- | ||||||
| name: extension-to-functions-codebase | ||||||
| description: Skill for converting an extensions repository to a functions codebase | ||||||
| --- | ||||||
|
|
||||||
| # Extension to Functions Codebase | ||||||
|
|
||||||
| ## Overview | ||||||
|
|
||||||
| A user likes a Firebase Extension but it doesn't do exactly what they wanted. They | ||||||
| want to convert the extension into a functions codebase that they can modify and | ||||||
| deploy as their own functions. The only problem is that the extensions namespace | ||||||
| doesn't express any of the IaC expected in extensions. This fixes taht. | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| ## Triggerrs | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this section - no need to put this in the skill body, because at this point the skill has already triggered.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was advice I've seen online. I think the point is that when indexing the skill it tells the agent when to use this like a tool call. If I'm right, this will help. If I'm wrong this will do no harm, so I'd like to keep it. |
||||||
| Activate this skill when a developer expresses that they which an extension was | ||||||
| a functions codebase instead of an extension. | ||||||
|
|
||||||
| ## Follow up | ||||||
| If there are any tests in the extensions codebase, be sure to run them after the migration. | ||||||
|
|
||||||
| ## Rules and Constraints | ||||||
|
|
||||||
| # Verify you are ready for the task | ||||||
| If an extensions codebase has a feature that you do not know how to handle yet, such as | ||||||
| lifecycle hooks, panic and tell the user that you cannot handle this task yet. | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| # API Enablement | ||||||
| For all API dependencies listed in `extension.yaml`, add a comment to index.js | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| ```typescript | ||||||
| // APIs to enable: | ||||||
| // - | ||||||
| ``` | ||||||
|
|
||||||
| # Parameterization | ||||||
| All config must be a parameter in the functions codebase. Read the list of all | ||||||
| parameters in the extension's `extension.yaml` file and create a parameter for each | ||||||
| one in the functions codebase. Be sure to keep all metadata such as label, description, type, and | ||||||
| valation rules and error messages. All process.env calls must be instead replaced with the | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| appropriate param.value() call. Be sure all process.env values referenced are defined as parameters; | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
| be encouraged to use built-in parameters though. | ||||||
|
|
||||||
| Custom events should be listed as a multiSelect parameter. For the label should be "Events to emit". | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
| The description should be "Select the events that this function should emit from the following list:" | ||||||
| and then list events as options with `*[type]*: [description]\n`. The event type should be the value | ||||||
| in the multiSelect input list. | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| params must not be called with .value() at global scope. If a global is being intialized with a | ||||||
| parameter, use the onInit function to initialize the global. For example: | ||||||
|
|
||||||
| ```typescript | ||||||
| const myFoo = new Foo(functions.config().foo); | ||||||
| ``` | ||||||
|
|
||||||
| should be turned into | ||||||
|
|
||||||
| ```typescript | ||||||
| const foo = defineString('FOO', { /* descriptions */ }); | ||||||
| let myFoo: Foo; | ||||||
| onInit(() => { | ||||||
| myFoo = new Foo(foo.value()); | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| Never ever ever export an extension's value directly or even an accessor, even through a function. If the codebase used to use an export default, be sure to update the import to an `import * as config from` instead of `import config from` style. | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
| Instead export the parameter as a named export from any library codebase. This allows you to use | ||||||
| the parameter without .value() as a functions configuration parameter in the later step. On the other hand, within a function, you may call .value() on the parameter if you need to actually use the value of the parameter. | ||||||
|
|
||||||
| # Engine pinning | ||||||
| In `extensions.yaml` there will be a line that looks like this: | ||||||
|
|
||||||
| ```yaml | ||||||
| runtime: nodejs20 | ||||||
| ``` | ||||||
|
|
||||||
| This means that the extension is pinned to a specific runtime. If all functions | ||||||
| do not have the same runtime, panic and tell the user that mixed runtimes are | ||||||
| not yet supported. | ||||||
|
|
||||||
| Learn the runtime and use that to update the customer's package.json to list the | ||||||
| node engine as the runtime version. | ||||||
|
|
||||||
| # Switching SDK versions | ||||||
| For all exported functions, replace the import with "functions.extensions.foo" to just | ||||||
| "functions.foo". Use the other builder functions necessary to reach the same function | ||||||
| callback. Where those builder functions expect or allow a parameter, use the named functions | ||||||
| parameter for the configuration. | ||||||
|
|
||||||
| # Wrapping up | ||||||
| If the destination directory looks like a firebase project (e.g. has a firebase.json) Offer | ||||||
| to the functions codebase to firebase.json for the user so that it will be included | ||||||
|
inlined marked this conversation as resolved.
Outdated
|
||||||
| in subsequent deploys. If the user agrees, add the functions codebase to firebase.json. | ||||||
|
|
||||||
| # Testing | ||||||
| If there are any tests in the extensions codebase, be sure to run them after | ||||||
| the migration. This may require modifying the test as well to point to the functions codebase. | ||||||
Uh oh!
There was an error while loading. Please reload this page.