-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially replace chokidar with @parcel/watcher (#2379)
Co-authored-by: Natalie Weizenbaum <[email protected]>
- Loading branch information
Showing
6 changed files
with
107 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'package:js/js.dart'; | ||
import 'package:node_interop/js.dart'; | ||
import 'package:node_interop/util.dart'; | ||
|
||
@JS() | ||
class ParcelWatcherSubscription { | ||
external void unsubscribe(); | ||
} | ||
|
||
@JS() | ||
class ParcelWatcherEvent { | ||
external String get type; | ||
external String get path; | ||
} | ||
|
||
/// The @parcel/watcher module. | ||
/// | ||
/// See [the docs on npm](https://www.npmjs.com/package/@parcel/watcher). | ||
@JS('parcel_watcher') | ||
class ParcelWatcher { | ||
external static Promise subscribe(String path, Function callback); | ||
static Future<ParcelWatcherSubscription> subscribeFuture(String path, | ||
void Function(Object? error, List<ParcelWatcherEvent>) callback) => | ||
promiseToFuture( | ||
subscribe(path, allowInterop((Object? error, List<dynamic> events) { | ||
callback(error, events.cast<ParcelWatcherEvent>()); | ||
}))); | ||
|
||
external static Promise getEventsSince(String path, String snapshotPath); | ||
static Future<List<ParcelWatcherEvent>> getEventsSinceFuture( | ||
String path, String snapshotPath) async { | ||
List<dynamic> events = | ||
await promiseToFuture(getEventsSince(path, snapshotPath)); | ||
return events.cast<ParcelWatcherEvent>(); | ||
} | ||
|
||
external static Promise writeSnapshot(String path, String snapshotPath); | ||
static Future<void> writeSnapshotFuture(String path, String snapshotPath) => | ||
promiseToFuture(writeSnapshot(path, snapshotPath)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters