find method

Future<ProviderBinaryResolution?> find({
  1. String? executable,
  2. Map<String, String> environment = const <String, String>{},
})

Implementation

Future<ProviderBinaryResolution?> find({
  String? executable,
  Map<String, String> environment = const <String, String>{},
}) async {
  var effectiveEnvironment = mergeProviderEnvironment(
    inherited: Platform.environment,
    overrides: environment,
    isWindows: _isWindows,
  );
  if (!_isWindows && !environment.containsKey('PATH')) {
    effectiveEnvironment = _withProviderSearchPath(effectiveEnvironment);
  }
  if (executable != null) {
    final explicit = _resolveCandidate(
      executable,
      effectiveEnvironment,
      isWindows: _isWindows,
    );
    return explicit == null
        ? null
        : _validate(explicit, effectiveEnvironment);
  }

  final home = _home(effectiveEnvironment, isWindows: _isWindows);
  final candidates = <String>[
    if (_environmentValue(
          effectiveEnvironment,
          descriptor.environmentKey,
          isWindows: _isWindows,
        )
        case final String configured when configured.isNotEmpty)
      configured,
    if (descriptor.homeRelativePath case final relative? when home.isNotEmpty)
      p.join(home, relative),
    descriptor.binaryName,
    ...descriptor.commonPaths,
  ];
  final attempted = <String>{};
  final discovered = await _findFirst(
    candidates,
    effectiveEnvironment,
    attempted,
  );
  if (discovered != null) return discovered;
  return _findFirst(
    await _npmCandidates(effectiveEnvironment),
    effectiveEnvironment,
    attempted,
  );
}