Skip to content
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

remove a manual build_runner step #3117

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
**/pubspec.lock linguist-generated=true
pkgs/dart_services/lib/src/shared/** linguist-generated=true
pkgs/dartpad_ui/lib/samples.g.dart linguist-generated=true
pkgs/dartpad_ui/web/codemirror/** linguist-generated=true
9 changes: 1 addition & 8 deletions pkgs/dart_services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ To run tests:

`dart test`

### Re-generating source

To rebuild the shelf router, run:

```
dart run build_runner build --delete-conflicting-outputs
```

### Building storage artifacts

Dart services pre-compiles `.dill` files for the Dart SDK and Flutter Web SDK, which
are uploaded to Cloud Storage automatically. These files are located in the
`artifacts/` directory.
Expand Down
59 changes: 32 additions & 27 deletions pkgs/dart_services/lib/src/common_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import 'sdk.dart';
import 'shelf_cors.dart' as shelf_cors;
import 'utils.dart';

part 'common_server.g.dart';

const jsonContentType = 'application/json; charset=utf-8';

const apiPrefix = '/api/<apiVersion>';
Expand Down Expand Up @@ -68,17 +66,38 @@ class CommonServerApi {
final CommonServerImpl impl;
final TaskScheduler scheduler = TaskScheduler();

/// The (lazily-constructed) router.
late final Router router = _$CommonServerApiRouter(this);
/// The shelf router.
late final Router router = () {
final router = Router();

// general requests (GET)
router.get(r'/api/<apiVersion>/version', handleVersion);

// general requests (POST)
router.post(r'/api/<apiVersion>/analyze', handleAnalyze);
router.post(r'/api/<apiVersion>/compile', handleCompile);
router.post(r'/api/<apiVersion>/compileDDC', handleCompileDDC);
router.post(r'/api/<apiVersion>/complete', handleComplete);
router.post(r'/api/<apiVersion>/fixes', handleFixes);
router.post(r'/api/<apiVersion>/format', handleFormat);
router.post(r'/api/<apiVersion>/document', handleDocument);
router.post(r'/api/<apiVersion>/openInIDX', handleOpenInIdx);
return router;
}();

CommonServerApi(this.impl);

Future<void> init() => impl.init();

Future<void> shutdown() => impl.shutdown();

@Route.post('$apiPrefix/analyze')
Future<Response> analyze(Request request, String apiVersion) async {
Future<Response> handleVersion(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

return ok(version().toJson());
}

Future<Response> handleAnalyze(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -91,8 +110,7 @@ class CommonServerApi {
return ok(result.toJson());
}

@Route.post('$apiPrefix/compile')
Future<Response> compile(Request request, String apiVersion) async {
Future<Response> handleCompile(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -109,8 +127,7 @@ class CommonServerApi {
}
}

@Route.post('$apiPrefix/compileDDC')
Future<Response> compileDDC(Request request, String apiVersion) async {
Future<Response> handleCompileDDC(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -134,8 +151,7 @@ class CommonServerApi {
}
}

@Route.post('$apiPrefix/complete')
Future<Response> complete(Request request, String apiVersion) async {
Future<Response> handleComplete(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -147,8 +163,7 @@ class CommonServerApi {
return ok(result.toJson());
}

@Route.post('$apiPrefix/fixes')
Future<Response> fixes(Request request, String apiVersion) async {
Future<Response> handleFixes(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -160,8 +175,7 @@ class CommonServerApi {
return ok(result.toJson());
}

@Route.post('$apiPrefix/format')
Future<Response> format(Request request, String apiVersion) async {
Future<Response> handleFormat(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -177,8 +191,7 @@ class CommonServerApi {
return ok(result.toJson());
}

@Route.post('$apiPrefix/document')
Future<Response> document(Request request, String apiVersion) async {
Future<Response> handleDocument(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

final sourceRequest =
Expand All @@ -194,15 +207,7 @@ class CommonServerApi {
return ok(result.toJson());
}

@Route.get('$apiPrefix/version')
Future<Response> versionGet(Request request, String apiVersion) async {
if (apiVersion != api3) return unhandledVersion(apiVersion);

return ok(version().toJson());
}

@Route.post('$apiPrefix/openInIDX')
Future<Response> openInIdx(Request request, String apiVersion) async {
Future<Response> handleOpenInIdx(Request request, String apiVersion) async {
final code = api.OpenInIdxRequest.fromJson(await request.readAsJson()).code;
final idxUrl = Uri.parse('https://idx.google.com/run.api');

Expand Down
57 changes: 0 additions & 57 deletions pkgs/dart_services/lib/src/common_server.g.dart

This file was deleted.

10 changes: 4 additions & 6 deletions pkgs/dart_services/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: The backend service for DartPad.
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.6.0

dependencies:
analysis_server_lib: ^0.2.5
Expand All @@ -24,16 +24,14 @@ dependencies:
yaml: ^3.1.2

dev_dependencies:
build_runner: ^2.4.11
collection: ^1.18.0
collection: ^1.19.0
# TODO: Unpin once stable is updated to Dart 3.7.
dart_flutter_team_lints: 3.2.1
grinder: ^0.9.5
json_serializable: ^6.9.0
json_serializable: ^6.9.2
package_config: ^2.1.0
shelf_router_generator: ^1.1.1
synchronized: ^3.1.0+1
test: ^1.25.7
test: ^1.25.9
test_descriptor: ^2.0.1

dependency_overrides:
Expand Down
Loading