PackageFilters.fromYaml constructor

PackageFilters.fromYaml(
  1. Map<Object?, Object?> yaml, {
  2. required String path,
  3. required String workspacePath,
})

Implementation

factory PackageFilters.fromYaml(
  Map<Object?, Object?> yaml, {
  required String path,
  required String workspacePath,
}) {
  final scope = assertListOrString(
    key: filterOptionScope.camelCased,
    map: yaml,
    path: path,
  );

  final ignore = assertListOrString(
    key: filterOptionIgnore.camelCased,
    map: yaml,
    path: path,
  );

  final dirExists = assertListOrString(
    key: filterOptionDirExists.camelCased,
    map: yaml,
    path: path,
  );

  final fileExists = assertListOrString(
    key: filterOptionFileExists.camelCased,
    map: yaml,
    path: path,
  );

  final dependsOn = assertListOrString(
    key: filterOptionDependsOn.camelCased,
    map: yaml,
    path: path,
  );

  final noDependsOn = assertListOrString(
    key: filterOptionNoDependsOn.camelCased,
    map: yaml,
    path: path,
  );

  final diff = assertKeyIsA<String?>(
    key: filterOptionDiff.camelCased,
    map: yaml,
    path: path,
  );

  final includeDependents = assertKeyIsA<bool?>(
        key: filterOptionIncludeDependents.camelCased,
        map: yaml,
        path: path,
      ) ??
      false;

  final includeDependencies = assertKeyIsA<bool?>(
        key: filterOptionIncludeDependencies.camelCased,
        map: yaml,
        path: path,
      ) ??
      false;

  final noPrivateOptionKey = filterOptionNoPrivate.camelCased;
  final excludePrivatePackagesTmp = assertKeyIsA<bool?>(
    key: noPrivateOptionKey,
    map: yaml,
    path: path,
  );

  final privateOptionKey = filterOptionPrivate.camelCased;
  final includePrivatePackagesTmp = assertKeyIsA<bool?>(
    key: privateOptionKey,
    map: yaml,
    path: path,
  );

  if (includePrivatePackagesTmp != null &&
      excludePrivatePackagesTmp != null) {
    throw MelosConfigException(
      'Cannot specify both "$noPrivateOptionKey" and '
      '"$excludePrivatePackagesTmp" at the same time in "$path".',
    );
  }
  bool? includePrivatePackages;
  if (includePrivatePackagesTmp != null) {
    includePrivatePackages = includePrivatePackagesTmp;
  }
  if (excludePrivatePackagesTmp != null) {
    includePrivatePackages = !excludePrivatePackagesTmp;
  }

  final published = assertKeyIsA<bool?>(
    key: filterOptionPublished.camelCased,
    map: yaml,
    path: path,
  );

  final nullSafe = assertKeyIsA<bool?>(
    key: filterOptionNullsafety.camelCased,
    map: yaml,
    path: path,
  );

  final flutter = assertKeyIsA<bool?>(
    key: filterOptionFlutter.camelCased,
    map: yaml,
    path: path,
  );

  Glob createPackageGlob(String pattern) =>
      createGlob(pattern, currentDirectoryPath: workspacePath);

  return PackageFilters(
    scope: scope.map(createPackageGlob).toList(),
    ignore: ignore.map(createPackageGlob).toList(),
    dirExists: dirExists,
    fileExists: fileExists,
    dependsOn: dependsOn,
    noDependsOn: noDependsOn,
    diff: diff,
    includeDependents: includeDependents,
    includeDependencies: includeDependencies,
    includePrivatePackages: includePrivatePackages,
    published: published,
    nullSafe: nullSafe,
    flutter: flutter,
  );
}