You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-12Lines changed: 40 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,15 @@
1
1
# functions-differ
2
2
3
3
[](https://github.com/haroldadmin/functions-differ/actions/workflows/build-test.yml)
A tool to selectively deploy only the Firebase Functions that changed.
6
8
7
9
[functions-differ](https://www.npmjs.com/package/functions-differ) takes a list of Firebase Functions from your repository and returns a list of functions that changed since its last invocation.
8
10
This helps you selectively deploy only the functions that changed, thus saving time during re-deployments.
9
11
10
-
It detects any changes to a function by bundling it into a single minified file, and calculating a hash for it. This works for changes in the function's code, change in its installed dependencies, or any other local imports.
12
+
It detects any changes to a function by bundling it into a single minified file, and calculating a hash for it. This works for changes in the function's code, changes in its installed dependencies, or any other local imports.
11
13
12
14
## Usage
13
15
@@ -23,6 +25,8 @@ my-firebase-project
23
25
24
26
- Specify your function names and their paths in `.differspec.json`:
25
27
28
+
> This step is optional if you use the experimental `--discover` flag, which lets functions-differ discover the exported Cloud Functions from your project automatically.
29
+
26
30
```json
27
31
{
28
32
"functions": {
@@ -52,17 +56,17 @@ The default output is suitable for passing to `firebase deploy --only` command.
52
56
53
57
`functions-differ` supports the following options:
| dir | d | The directory containing `.differspec.json` file | (current working directory) |
58
-
| write | w | Write output to `.differspec.json` file or not | true |
59
-
| verbose | v | Output verbose logs | false |
60
-
| prefix || Prefix for each function name output |`functions:`|
61
-
| sep || Separator for each output function |`,`|
62
-
| bundlerConfig || Path to the bundler config file which would be passed to esbuild ||
63
-
| concurrency || Number to control the concurrency of the bundling process. Useful in CI/CD flows with limited memory | Number of functions in .differspec.json |
64
-
| discover || Flag indicating whether to use automatic function path discovery | false |
65
-
| indexFilePath || Location of the index.ts file which exports all the functions. Optional. Only used if used with `--discover`|`src/index.ts`|
| dir | d | The directory containing `.differspec.json` file | (current working directory) |
62
+
| write | w | Write output to `.differspec.json` file or not | true |
63
+
| verbose | v | Output verbose logs | false |
64
+
| prefix || Prefix for each function name output |`functions:`|
65
+
| sep || Separator for each output function |`,`|
66
+
| bundlerConfig || Path to the bundler config file which would be passed to esbuild ||
67
+
| concurrency || Number to control the concurrency of the bundling process. Useful in CI/CD flows with limited memory | Number of functions in .differspec.json |
68
+
| discover ||(**Experimental**) Flag indicating whether to use automatic function path discovery | false |
69
+
| indexFilePath ||(**Experimental**) Location of the index.ts file which exports all the functions. Optional. Only used if used with `--discover`|`src/index.ts`|
66
70
67
71
## .differspec.json
68
72
@@ -86,3 +90,27 @@ Please discuss bugs, feature requests, and help in Github Issues. Pull requests
86
90
Install the package with `npm`:
87
91
88
92
`npm install -g functions-differ`
93
+
94
+
## Notes
95
+
96
+
### Automatic Functions Discovery (Experimental)
97
+
98
+
`functions-differ` has experimental support for discovering Cloud Functions exported from your project automatically. This lets you skip defining function paths in your `.differspec.json` file manually.
99
+
100
+
It does this by using the TypeScript AST on exports from your project's root `index.ts` file. It makes the following assumptions about your codebase:
101
+
102
+
1. The `src/index.ts` file must contain all exported Cloud Functions from your project, and no other exports.
103
+
2. Every Cloud Function is defined in a separate file. E.g.: `src/auth/login/index.ts`, `src/auth/register/index.ts`, etc.
104
+
105
+
If you use automatic functions discovery in your project, make sure the above assumptions hold true.
106
+
107
+
### Integration with CI/CD
108
+
109
+
I built `functions-differ` to help reduce the average deployment time of Cloud Functions in a project, but does not offer native support for CI builds.
110
+
111
+
Files generated during CI builds are usually ephemeral. They are lost once the CI build completes. If you plan to run `functions-differ` in your CI workflow, you need to backup the `.differspec.json` generated by the previous build, and restore it for the next built.
112
+
113
+
Here are some ways to do that for GitHub Actions:
114
+
115
+
1. Use [caching](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows) between CI runs for the `.differspec.json` file.
116
+
2. Read/store the contents of the `.differspec.json` file in GitHub secrets in each CI run using the `gh` CLI available to every job.
0 commit comments