// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'dart:async'; final _defaultDependenciesZoneKey = const Symbol( 'buildConfigDefaultDependencies', ); final _packageZoneKey = const Symbol('buildConfigPackage'); T runInBuildConfigZone( T Function() fn, String package, List defaultDependencies, ) => runZoned( fn, zoneValues: { _packageZoneKey: package, _defaultDependenciesZoneKey: defaultDependencies, }, ); String get currentPackage { final package = Zone.current[_packageZoneKey] as String?; if (package == null) { throw StateError( 'Must be running inside a build config zone, which can be done using ' 'the `runInBuildConfigZone` function.', ); } return package; } List get currentPackageDefaultDependencies { final defaultDependencies = Zone.current[_defaultDependenciesZoneKey] as List?; if (defaultDependencies == null) { throw StateError( 'Must be running inside a build config zone, which can be done using ' 'the `runInBuildConfigZone` function.', ); } return defaultDependencies; }