Skip to content
Open
Changes from 1 commit
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
97 changes: 97 additions & 0 deletions skills/extension-to-functions-codebase/SKILL.md
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
Comment thread
inlined marked this conversation as resolved.
Outdated
---

# 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.
Comment thread
inlined marked this conversation as resolved.
Outdated

## Triggerrs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.
Comment thread
inlined marked this conversation as resolved.
Outdated

# API Enablement
For all API dependencies listed in `extension.yaml`, add a comment to index.js
Comment thread
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
valation rules and error messages. All process.env calls must be instead replaced with the
valation rules and error messages. All `process.env` calls must be instead replaced with the

appropriate param.value() call. Be sure all process.env values referenced are defined as parameters;
Comment thread
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".
Comment thread
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.
Comment thread
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.
Comment thread
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
Comment thread
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.