Skip to content

Commit 372c7a5

Browse files
committed
Fixing feedback from Gemini
1 parent bfe23a9 commit 372c7a5

7 files changed

Lines changed: 58 additions & 56 deletions

File tree

src/deploy/functions/runtimes/dart/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,22 @@ export class Delegate implements runtimes.RuntimeDelegate {
113113

114114
buildRunnerProcess.on("exit", (code) => {
115115
if (code !== 0 && code !== null) {
116-
logger.debug(`build_runner exited with code ${code}. Hot reload may not work.`);
116+
logger.debug(`build_runner exited with code ${code}. Initial build failed.`);
117117
if (!initialBuildComplete) {
118-
rejectInitialBuild(new Error(`build_runner exited with code ${code}`));
118+
rejectInitialBuild(
119+
new FirebaseError(
120+
`build_runner exited with code ${code}. Your Dart functions may not be deployed or emulated correctly.`,
121+
),
122+
);
119123
}
120124
}
121125
this.buildRunnerProcess = null;
122126
});
123127

124128
buildRunnerProcess.on("error", (err) => {
125-
logger.debug(`Failed to start build_runner: ${err.message}`);
129+
logger.debug(
130+
`Failed to start build_runner: ${err.message}. Your Dart functions may not be deployed or emulated correctly.`,
131+
);
126132
if (!initialBuildComplete) {
127133
rejectInitialBuild(err);
128134
}

src/emulator/functionsEmulator.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,15 @@ export class FunctionsEmulator implements EmulatorInstance {
400400
async sendRequest(trigger: EmulatedTriggerDefinition, body?: any) {
401401
const record = this.getTriggerRecordByKey(this.getTriggerKey(trigger));
402402
const pool = this.workerPools[record.backend.codebase];
403-
const runtime = record.backend.runtime;
404-
if (!pool.readyForWork(trigger.id, runtime)) {
403+
if (!pool.readyForWork(trigger.id, record.backend.runtime)) {
405404
try {
406405
await this.startRuntime(record.backend, trigger);
407406
} catch (e: any) {
408407
this.logger.logLabeled("ERROR", `Failed to start runtime for ${trigger.id}: ${e}`);
409408
return;
410409
}
411410
}
412-
const worker = pool.getIdleWorker(trigger.id, runtime)!;
411+
const worker = pool.getIdleWorker(trigger.id, record.backend.runtime)!;
413412
if (this.debugMode) {
414413
await worker.sendDebugMsg({
415414
functionTarget: trigger.entryPoint,
@@ -424,7 +423,7 @@ export class FunctionsEmulator implements EmulatorInstance {
424423

425424
// For Dart, include the function name in the path so the server can route
426425
// For other runtimes, use / as they use FUNCTION_TARGET env var
427-
const isDart = isLanguageRuntime(runtime, "dart");
426+
const isDart = isLanguageRuntime(record.backend.runtime, "dart");
428427
const path = isDart ? `/${trigger.name}` : `/`;
429428

430429
return new Promise((resolve, reject) => {
@@ -1887,8 +1886,7 @@ export class FunctionsEmulator implements EmulatorInstance {
18871886
this.logger.log("DEBUG", `[functions] Got req.url=${req.url}, mapping to path=${path}`);
18881887

18891888
const pool = this.workerPools[record.backend.codebase];
1890-
const runtime = record.backend.runtime;
1891-
if (!pool.readyForWork(trigger.id, runtime)) {
1889+
if (!pool.readyForWork(trigger.id, record.backend.runtime)) {
18921890
try {
18931891
await this.startRuntime(record.backend, trigger);
18941892
} catch (e: any) {
@@ -1917,7 +1915,7 @@ export class FunctionsEmulator implements EmulatorInstance {
19171915
res as http.ServerResponse,
19181916
reqBody,
19191917
debugBundle,
1920-
runtime,
1918+
record.backend.runtime,
19211919
);
19221920
}
19231921
}

src/emulator/functionsRuntimeWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ export class RuntimeWorkerPool {
301301
if (this.mode === FunctionsExecutionMode.SEQUENTIAL) {
302302
return "~shared~";
303303
}
304-
// For Dart, use a shared key so all functions in a codebase share the same process
305-
// Dart loads all functions and routes based on request path
304+
// For Dart, use a shared key so all functions in a codebase share the same worker process.
305+
// Dart loads all functions into a single process and routes based on request path.
306306
if (isLanguageRuntime(runtime, "dart")) {
307307
return "~dart-shared~";
308308
}

src/init/features/functions/dart.ts

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,11 @@ import * as spawn from "cross-spawn";
22
import { Config } from "../../../config";
33
import { confirm } from "../../../prompt";
44
import { latest } from "../../../deploy/functions/runtimes/supported";
5+
import { readTemplateSync } from "../../../templates";
56

6-
// TODO(ehesp): Create these template files in templates/init/functions/dart/
7-
// TODO(ehesp): Dont use relative path for firebase_functions
8-
const PUBSPEC_TEMPLATE = `name: functions
9-
description: Firebase Functions for Dart
10-
version: 1.0.0
11-
12-
environment:
13-
sdk: '>=3.0.0 <4.0.0'
14-
15-
dependencies:
16-
firebase_functions:
17-
path: ../
18-
19-
dev_dependencies:
20-
build_runner: ^2.4.0
21-
`;
22-
23-
const MAIN_TEMPLATE = `import 'package:firebase_functions/firebase_functions.dart';
24-
25-
void main(List<String> args) {
26-
fireUp(args, (firebase) {
27-
28-
firebase.https.onRequest(
29-
name: 'helloWorld',
30-
options: const HttpsOptions(cors: Cors(['*'])),
31-
(request) async {
32-
return Response(200, body: 'Hello from Dart Functions!');
33-
});
34-
});
35-
}
36-
`;
37-
38-
const GITIGNORE_TEMPLATE = `.dart_tool/
39-
build/
40-
*.dart.js
41-
*.info.json
42-
*.js
43-
*.js.map
44-
*.js.deps
45-
*.js.symbols
46-
firebase-debug.log
47-
firebase-debug.*.log
48-
*.local
49-
`;
7+
const PUBSPEC_TEMPLATE = readTemplateSync("init/functions/dart/pubspec.yaml");
8+
const MAIN_TEMPLATE = readTemplateSync("init/functions/dart/main.dart");
9+
const GITIGNORE_TEMPLATE = readTemplateSync("init/functions/dart/_gitignore");
5010

5111
/**
5212
* Create a Dart Firebase Functions project.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.dart_tool/
2+
build/
3+
*.dart.js
4+
*.info.json
5+
*.js
6+
*.js.map
7+
*.js.deps
8+
*.js.symbols
9+
firebase-debug.log
10+
firebase-debug.*.log
11+
*.local
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:firebase_functions/firebase_functions.dart';
2+
3+
void main(List<String> args) {
4+
fireUp(args, (firebase) {
5+
6+
firebase.https.onRequest(
7+
name: 'helloWorld',
8+
options: const HttpsOptions(cors: Cors(['*'])),
9+
(request) async {
10+
return Response(200, body: 'Hello from Dart Functions!');
11+
});
12+
});
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: functions
2+
description: Firebase Functions for Dart
3+
version: 1.0.0
4+
5+
environment:
6+
sdk: '>=3.0.0 <4.0.0'
7+
8+
dependencies:
9+
# TODO(ehesp): Replace with published package version once available on pub.dev
10+
firebase_functions:
11+
path: ../
12+
13+
dev_dependencies:
14+
build_runner: ^2.4.0

0 commit comments

Comments
 (0)