Updated hot reloader
This commit is contained in:
parent
50bc5d2c51
commit
a02e8025bd
10 changed files with 84 additions and 100 deletions
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/hot.iml" filepath="$PROJECT_DIR$/.idea/hot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="main.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true">
|
||||
<option name="VMOptions" value="--observe" />
|
||||
<option name="filePath" value="$PROJECT_DIR$/example/basic/main.dart" />
|
||||
<option name="workingDirectory" value="$PROJECT_DIR$/example/basic" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,7 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="main.dart (No VM service)" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
|
||||
<option name="filePath" value="$PROJECT_DIR$/example/basic/main.dart" />
|
||||
<option name="workingDirectory" value="$PROJECT_DIR$/example/basic" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,41 +1,60 @@
|
|||
# 4.1.0
|
||||
# Change Log
|
||||
|
||||
## 4.1.1
|
||||
|
||||
* Fixed NNBD issues
|
||||
* Updated README
|
||||
|
||||
## 4.1.0
|
||||
|
||||
* Updated `vm_service` to 7.1.x
|
||||
|
||||
# 4.0.0
|
||||
## 4.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
|
||||
# 3.0.0
|
||||
## 3.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x Non NNBD
|
||||
|
||||
# 2.0.6
|
||||
## 2.0.6
|
||||
|
||||
* Support `--observe=*`, `--enable-vm-service=*` (`startsWith`, instead of `==`).
|
||||
|
||||
# 2.0.5
|
||||
## 2.0.5
|
||||
|
||||
* Use `dart:developer` to find the Observatory URI.
|
||||
* Use the app's logger when necessary.
|
||||
* Apply `package:pedantic`.
|
||||
|
||||
# 2.0.4
|
||||
## 2.0.4
|
||||
|
||||
* Forcibly close app loggers on shutdown.
|
||||
|
||||
# 2.0.3
|
||||
## 2.0.3
|
||||
|
||||
* Fixed up manual restart.
|
||||
* Remove stutter on hotkey press.
|
||||
|
||||
# 2.0.2
|
||||
## 2.0.2
|
||||
|
||||
* Fixed for compatibility with `package:angel_websocket@^2.0.0-alpha.5`.
|
||||
|
||||
# 2.0.1
|
||||
* Add import of `package:angel_framework/http.dart`
|
||||
* https://github.com/angel-dart/hot/pull/7
|
||||
## 2.0.1
|
||||
|
||||
* Add import of `package:angel_framework/http.dart`
|
||||
* <https://github.com/angel-dart/hot/pull/7>
|
||||
|
||||
## 2.0.0
|
||||
|
||||
# 2.0.0
|
||||
* Update for Dart 2 + Angel 2.
|
||||
|
||||
# 1.1.1+1
|
||||
## 1.1.1+1
|
||||
|
||||
* Fix a bug that threw when `--observe` was not present.
|
||||
|
||||
# 1.1.1
|
||||
## 1.1.1
|
||||
|
||||
* Disable the observatory from pausing the isolate
|
||||
on exceptions, because Angel already handles
|
||||
all exceptions by itself.
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
# angel3_hot
|
||||
[![version](https://img.shields.io/badge/pub-v4.1.0-brightgreen)](https://pub.dartlang.org/packages/angel3_hot)
|
||||
# Angel3 Hot Reloader
|
||||
|
||||
[![version](https://img.shields.io/badge/pub-v4.1.1-brightgreen)](https://pub.dartlang.org/packages/angel3_hot)
|
||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/hot/LICENSE)
|
||||
|
||||
![Screenshot of terminal](screenshots/screenshot.png)
|
||||
![Screenshot of terminal](screenshots/angel3-screenshot.png)
|
||||
|
||||
Supports *hot reloading* of Angel servers on file changes. This is faster and
|
||||
more reliable than merely reactively restarting a `Process`.
|
||||
Supports *hot reloading* of Angel3 servers on file changes. This is faster and more reliable than merely reactively restarting a `Process`.
|
||||
This package only works with the [Angel3 framework](https://github.com/dukefirehawk/angel).
|
||||
|
||||
This package only works with the [Angel framework](https://github.com/dukefirehawk/angel/tree/angel3).
|
||||
**Not recommended to use in production, unless you are specifically intending for a "hot code push" in production..**
|
||||
|
||||
## Installation
|
||||
|
||||
# Installation
|
||||
In your `pubspec.yaml`:
|
||||
|
||||
```yaml
|
||||
|
@ -21,32 +23,28 @@ dependencies:
|
|||
angel3_hot: ^4.0.0
|
||||
```
|
||||
|
||||
# Usage
|
||||
This package is dependent on the Dart VM service, so you *must* run
|
||||
Dart with the `--observe` (or `--enable-vm-service`) argument!!!
|
||||
## Usage
|
||||
|
||||
Usage is fairly simple. Pass a function that creates an `Angel` server, along with a collection of paths
|
||||
to watch, to the `HotReloader` constructor. The rest is history!!!
|
||||
This package is dependent on the Dart VM service, so you *must* run Dart with the `--observe` (or `--enable-vm-service`) argument!!!
|
||||
|
||||
The recommended pattern is to only use hot-reloading in your application entry point. Create your `Angel` instance
|
||||
within a separate function, conventionally named `createServer`.
|
||||
Usage is fairly simple. Pass a function that creates an `Angel` server, along with a collection of paths to watch, to the `HotReloader` constructor. The rest is history!!!
|
||||
|
||||
**Using this in production mode is not recommended, unless you are
|
||||
specifically intending for a "hot code push" in production..**
|
||||
The recommended pattern is to only use hot-reloading in your application entry point. Create your `Angel` instance within a separate function, conventionally named `createServer`.
|
||||
|
||||
You can watch:
|
||||
* Files
|
||||
* Directories
|
||||
* Globs
|
||||
* URI's
|
||||
* `package:` URI's
|
||||
|
||||
* Files
|
||||
* Directories
|
||||
* Globs
|
||||
* URI's
|
||||
* `package:` URI's
|
||||
|
||||
```dart
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_hot/angel_hot.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_hot/angel_hot.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'src/foo.dart';
|
||||
|
||||
|
@ -55,26 +53,26 @@ main() async {
|
|||
new Directory('src'),
|
||||
new Directory('src'),
|
||||
'main.dart',
|
||||
Uri.parse('package:angel_hot/angel_hot.dart')
|
||||
Uri.parse('package:angel3_hot/angel3_hot.dart')
|
||||
]);
|
||||
await hot.startServer('127.0.0.1', 3000);
|
||||
}
|
||||
|
||||
Future<Angel> createServer() async {
|
||||
var app = new Angel()..serializer = json.encode;
|
||||
var app = Angel()..serializer = json.encode;
|
||||
|
||||
// Edit this line, and then refresh the page in your browser!
|
||||
app.get('/', (req, res) => {'hello': 'hot world!'});
|
||||
app.get('/foo', (req, res) => new Foo(bar: 'baz'));
|
||||
app.get('/foo', (req, res) => Foo(bar: 'baz'));
|
||||
|
||||
app.fallback((req, res) => throw new AngelHttpException.notFound());
|
||||
app.fallback((req, res) => throw AngelHttpException.notFound());
|
||||
|
||||
app.encoders.addAll({
|
||||
'gzip': gzip.encoder,
|
||||
'deflate': zlib.encoder,
|
||||
});
|
||||
|
||||
app.logger = new Logger('angel')
|
||||
app.logger = Logger('angel')
|
||||
..onRecord.listen((rec) {
|
||||
print(rec);
|
||||
if (rec.error != null) {
|
||||
|
|
|
@ -140,7 +140,7 @@ class HotReloader {
|
|||
|
||||
void _logWarning(String msg) {
|
||||
if (_server?.app.logger != null) {
|
||||
_server!.app.logger!.warning(msg);
|
||||
_server?.app.logger?.warning(msg);
|
||||
} else {
|
||||
print(yellow.wrap('WARNING: $msg'));
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class HotReloader {
|
|||
|
||||
void _logInfo(String msg) {
|
||||
if (_server?.app.logger != null) {
|
||||
_server!.app.logger!.info(msg);
|
||||
_server?.app.logger?.info(msg);
|
||||
} else {
|
||||
print(lightGray.wrap(msg));
|
||||
}
|
||||
|
@ -183,10 +183,14 @@ class HotReloader {
|
|||
}
|
||||
_client = await vm.vmServiceConnectUri(uri.toString());
|
||||
_vmachine ??= await _client.getVM();
|
||||
_mainIsolate ??= _vmachine!.isolates!.first;
|
||||
_mainIsolate ??= _vmachine?.isolates?.first;
|
||||
|
||||
for (var isolate in _vmachine!.isolates!) {
|
||||
await _client.setExceptionPauseMode(isolate.id!, 'None');
|
||||
if (_vmachine != null) {
|
||||
for (var isolate in _vmachine!.isolates ?? <vm.IsolateRef>[]) {
|
||||
if (isolate.id != null) {
|
||||
await _client.setExceptionPauseMode(isolate.id!, 'None');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _listenToFilesystem();
|
||||
|
@ -206,16 +210,25 @@ class HotReloader {
|
|||
if (enableHotkeys) {
|
||||
var serverUri =
|
||||
Uri(scheme: 'http', host: server.address.address, port: server.port);
|
||||
var observatoryUri =
|
||||
await dev.Service.getInfo().then((i) => i.serverUri!);
|
||||
|
||||
var observatoryUri;
|
||||
if (isHot) {
|
||||
observatoryUri = await dev.Service.getInfo().then((i) => i.serverUri!);
|
||||
}
|
||||
|
||||
print(styleBold.wrap(
|
||||
'\n🔥 To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".'));
|
||||
stdout.write('Your Angel server is listening at: ');
|
||||
stdout.write('Your server is listening at: ');
|
||||
print(wrapWith('$serverUri', [cyan, styleUnderlined]));
|
||||
stdout.write(
|
||||
'An Observatory debugger and profiler on ${Platform.operatingSystem} is available at: ');
|
||||
print(wrapWith('$observatoryUri', [cyan, styleUnderlined]));
|
||||
|
||||
if (isHot) {
|
||||
stdout.write(
|
||||
'An Observatory debugger and profiler on ${Platform.operatingSystem} is available at: ');
|
||||
print(wrapWith('$observatoryUri', [cyan, styleUnderlined]));
|
||||
} else {
|
||||
stdout.write(
|
||||
'The observatory debugger and profiler are not available.\n');
|
||||
}
|
||||
print(
|
||||
'For a more detailed help message, press "h". To quit, press "q".\n');
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: angel3_hot
|
||||
description: Supports hot reloading/hot code push of Angel servers on file changes.
|
||||
version: 4.1.0
|
||||
version: 4.1.1
|
||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/hot
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
|
BIN
packages/hot/screenshots/angel3-screenshot.png
Normal file
BIN
packages/hot/screenshots/angel3-screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Loading…
Reference in a new issue