81a139584e
This CL migrates the `frontend_server_client` package into the Dart SDK repository. Key Changes: - Migration: Moved source code and tests into `pkg/frontend_server_client`. - Monorepo Compliance: Updated the pubspec to align with the SDK pub workspace setup. - Linting: Adopts `package:dart_flutter_team_lints` for analysis options and fixes associated linting errors. - Path Resolution: Resolved package configuration and script path issues encountered in local and CI environments; see the [Workspace Tests Fixes](https://docs.google.com/document/d/1UdiRqP19qYgj-ItxDfqXSdUU6CGimiyK3BmdvjtTEyw/edit?pli=1&tab=t.0#heading=h.xfm1ezicaoik) in the design doc for implementation details. Testing: - All tests passing locally. - CI try bots are green. Design Doc: http://goto.google.com/migrating-webdev Cq-Include-Trybots: luci.dart.try:pkg-win-release-try,pkg-win-release-arm64-try,pkg-mac-release-try,pkg-mac-release-arm64-try,pkg-linux-release-try,pkg-linux-release-arm64-try,pkg-linux-debug-try Change-Id: Id44a701107d626df5fcd21d724980243981c7958 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461200 Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Jessy Yameogo <yjessy@google.com>
62 lines
2.2 KiB
Dart
62 lines
2.2 KiB
Dart
// Copyright 2020 The Dart Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/// The JavaScript bootstrap script to support in-browser hot restart.
|
|
///
|
|
/// The [requireUrl] loads our cached RequireJS script file. The [mapperUrl]
|
|
/// loads the special Dart stack trace mapper.
|
|
///
|
|
/// This file is served when the browser requests `$entrypoint.js` in debug
|
|
/// mode, and is responsible for bootstrapping the RequireJS modules and
|
|
/// attaching the hot reload hooks.
|
|
String generateAmdBootstrapScript({
|
|
required String requireUrl,
|
|
required String mapperUrl,
|
|
required String entrypoint,
|
|
}) {
|
|
return '''
|
|
"use strict";
|
|
|
|
// Attach source mapping.
|
|
var mapperEl = document.createElement("script");
|
|
mapperEl.defer = true;
|
|
mapperEl.async = false;
|
|
mapperEl.src = "$mapperUrl";
|
|
document.head.appendChild(mapperEl);
|
|
|
|
// Attach require JS.
|
|
var requireEl = document.createElement("script");
|
|
requireEl.defer = true;
|
|
requireEl.async = false;
|
|
requireEl.src = "$requireUrl";
|
|
|
|
// This attribute tells require JS what to load as main (defined below).
|
|
requireEl.setAttribute("data-main", "$entrypoint.bootstrap");
|
|
document.head.appendChild(requireEl);
|
|
''';
|
|
}
|
|
|
|
/// Generate a synthetic main module which captures the application's main
|
|
/// method.
|
|
///
|
|
/// RE: Object.keys usage in app.main:
|
|
/// This attaches the main entrypoint and hot reload functionality to the
|
|
/// window. The app module will have a single property which contains the
|
|
/// actual application code. The property name is based off of the entrypoint
|
|
/// that is generated, for example the file `foo/bar/baz.dart` will generate
|
|
/// a property named approximately `foo__bar__baz`. Rather than attempt to
|
|
/// guess, we assume the first property of this object is the module.
|
|
String generateAmdMainModule({required String entrypoint}) {
|
|
return '''/* ENTRYPOINT_EXTENTION_MARKER */
|
|
// Create the main module loaded below.
|
|
require(["$entrypoint.lib.js", "dart_sdk"], function(app, dart_sdk) {
|
|
dart_sdk.dart.setStartAsyncSynchronously(true);
|
|
dart_sdk._debugger.registerDevtoolsFormatter();
|
|
|
|
// See the generateMainModule doc comment.
|
|
app[Object.keys(app)[0]].main();
|
|
});
|
|
''';
|
|
}
|