Commit 40f0dad
feat: add file-based function discovery mode (#1711)
* feat: add stdio-based function discovery mode
Adds an alternative discovery mechanism that outputs function manifests via stderr
instead of starting an HTTP server. This improves reliability by avoiding issues
where module loading blocks the HTTP endpoint from becoming available.
When FUNCTIONS_DISCOVERY_MODE=stdio is set:
- Outputs base64-encoded manifest to stderr with __FIREBASE_FUNCTIONS_MANIFEST__: prefix
- Outputs errors to stderr with __FIREBASE_FUNCTIONS_MANIFEST_ERROR__: prefix
- Exits immediately without starting HTTP server
- Maintains backward compatibility (HTTP remains default)
Includes comprehensive tests that verify both HTTP and stdio discovery work
correctly for all test cases (commonjs, esm, various configurations).
* test: add comprehensive tests for stdio discovery
- Add test fixture for broken syntax error handling
- Refactor tests to use unified DiscoveryResult interface
- Parameterize tests with nested loops to test all cases with both discovery methods
- Add error handling tests for both HTTP and stdio discovery
- All stdio discovery tests passing (16/16)
* fix: resolve linting errors in firebase-functions.ts
- Mark runStdioDiscovery() promise with void operator
- Move handleQuitquitquit function to program root
- Fix TypeScript warnings for error handling
- Add eslint-disable comment for Express async handler
* fix: address PR review comments for stdio discovery
- Add proper error handling for non-Error objects
- Define MANIFEST_PREFIX and MANIFEST_ERROR_PREFIX constants
- Fix HTTP discovery retry logic regression in tests
- Make regex patterns multiline-safe for manifest and error parsing
- Add timeout handling for stdio discovery in tests
* fix: resolve linting errors
* fix: clean up broken-syntax fixture to match other fixtures
- Remove unnecessary dependencies from package.json
- Remove package-lock.json
- The npm link is handled by run.sh script
* fix: address additional PR review comments
- Use process.exitCode instead of process.exit() to prevent race conditions with stderr buffer flushing
- Refactor test to define discoveryMethods array once to reduce code duplication
* remove extraneous comments
* fix: resolve prettier formatting issue
* refactor: use XML-style tags for stdio discovery output
- Replace magic string prefixes with self-documenting XML tags
- Add explicit start/end markers to handle OS buffering edge cases
- Make regex parsing more robust and less greedy
- Addresses review comment about regex being too greedy
* fix: resolve prettier formatting for long regex lines
* Update src/bin/firebase-functions.ts
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* linter.
* refactor: replace stdio discovery with file-based manifest output
- Remove XML-style stdio discovery mode
- Add FUNCTIONS_MANIFEST_OUTPUT_PATH environment variable support
- Write manifest directly to specified file path when env var is set
- Update tests to use file-based discovery instead of stdio parsing
- Simplify error handling with direct stderr output
* fix: resolve lint and formatting issues
* feat: add robust path validation and error handling for file output
- Validate output directory exists and is writable before attempting manifest generation
- Provide specific error messages for common failure cases (ENOENT, EACCES)
- Check directory permissions early to fail fast with helpful guidance
- Improve error messages to help users resolve issues quickly
* fix: address PR review comments for test reliability
- Wait for process termination after kill(9) to prevent orphaned processes
- Use fs.mkdtemp() instead of Date.now() for unique temp directories
- Clean up temp directories after tests complete
- Add proper error cleanup for temp directories
* fix: Gracefully kill child processes in tests
Ensures that child processes spawned during tests are properly killed and awaited, preventing orphaned processes in the CI environment.
---------
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>1 parent aec3457 commit 40f0dad
File tree
4 files changed
+218
-91
lines changed- scripts/bin-test
- sources/broken-syntax
- src/bin
4 files changed
+218
-91
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
| |||
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 145 | + | |
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
145 | | - | |
| 150 | + | |
146 | 151 | | |
147 | 152 | | |
148 | | - | |
| 153 | + | |
149 | 154 | | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | 158 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
169 | 173 | | |
170 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
171 | 184 | | |
172 | | - | |
173 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
174 | 192 | | |
175 | | - | |
176 | | - | |
177 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
178 | 205 | | |
179 | 206 | | |
180 | | - | |
181 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
182 | 211 | | |
183 | | - | |
184 | 212 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
190 | 225 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
195 | 234 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
200 | 251 | | |
201 | 252 | | |
202 | 253 | | |
203 | 254 | | |
204 | 255 | | |
205 | 256 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
215 | 261 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
221 | 267 | | |
222 | 268 | | |
223 | 269 | | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
233 | 273 | | |
234 | 274 | | |
235 | 275 | | |
| |||
320 | 360 | | |
321 | 361 | | |
322 | 362 | | |
323 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
324 | 368 | | |
325 | 369 | | |
326 | 370 | | |
| |||
350 | 394 | | |
351 | 395 | | |
352 | 396 | | |
353 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
354 | 424 | | |
355 | 425 | | |
356 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 54 | + | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
65 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
66 | 75 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
72 | 99 | | |
73 | | - | |
74 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
75 | 104 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 105 | + | |
| 106 | + | |
80 | 107 | | |
81 | | - | |
82 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
0 commit comments