<commit_before>import { Config } from '../config';
import { Source, Reference } from '../manifest';
import { Project, loadProject, fetchDependencies } from '../project';
import { createTarget, buildTarget } from '../targets';
import { writeLockfile } from '../lockfile';

export interface BuildOptions {}
const defaultOptions = {};

export default async function build(config: Config, options: BuildOptions) {
  options = { ...defaultOptions, ...options };

  // 1. Load and fetch project
  const project = await loadProject(config);

  // 2. Determine src and references for build
  const buildGraph = await createBuildGraph(config, project, options);

  // 3. Create and build targets (sequentially to avoid contention issues)
  for (const target of project.manifest.targets) {
    await createTarget(config, target);
    await buildTarget(config, target, buildGraph);
  }

  // 3. On success, write lockfile
  await writeLockfile(config, project);
}

export interface BuildGraph {
  src: Source[];
  references: Reference[];
}

export async function createBuildGraph(
  config: Config,
  project: Project,
  options: BuildOptions
): Promise<BuildGraph> {
  const src: Map<string, Source> = new Map();
  const references: Map<string, Reference> = new Map();

  const manifests = [
    project.manifest,
    ...(await fetchDependencies(config, project))
  ];

  for (const manifest of manifests) {
    for (const source of manifest.src) {
      const { name } = source;
      if (src.has(name))
        throw new Error(`Conflicting source named "${source.name}"`);
      src.set(name, source);
    }
    for (const reference of manifest.references) {
      const { name } = reference;
      if (references.has(name))
        throw new Error(`Conficting reference named "${reference.name}"`);
      references.set(name, reference);
    }
  }

  return { src: [...src.values()], references: [...references.values()] };
}
<commit_msg>Better check for reference conflict<commit_after>import { Config } from '../config';
import { Source, Reference } from '../manifest';
import { Project, loadProject, fetchDependencies } from '../project';
import { createTarget, buildTarget } from '../targets';
import { writeLockfile } from '../lockfile';

export interface BuildOptions {}
const defaultOptions = {};

export default async function build(config: Config, options: BuildOptions) {
  options = { ...defaultOptions, ...options };

  // 1. Load and fetch project
  const project = await loadProject(config);

  // 2. Determine src and references for build
  const buildGraph = await createBuildGraph(config, project, options);

  // 3. Create and build targets (sequentially to avoid contention issues)
  for (const target of project.manifest.targets) {
    await createTarget(config, target);
    await buildTarget(config, target, buildGraph);
  }

  // 3. On success, write lockfile
  await writeLockfile(config, project);
}

export interface BuildGraph {
  src: Source[];
  references: Reference[];
}

export async function createBuildGraph(
  config: Config,
  project: Project,
  options: BuildOptions
): Promise<BuildGraph> {
  const src: Map<string, Source> = new Map();
  const references: Map<string, Reference> = new Map();

  const manifests = [
    project.manifest,
    ...(await fetchDependencies(config, project))
  ];

  for (const manifest of manifests) {
    for (const source of manifest.src) {
      const { name } = source;
      if (src.has(name))
        throw new Error(`Conflicting source named "${source.name}"`);
      src.set(name, source);
    }
    for (const reference of manifest.references) {
      const { name } = reference;
      if (references.has(name) && reference.guid !== references.get(name).guid)
        throw new Error(`Conficting reference named "${reference.name}"`);
      references.set(name, reference);
    }
  }

  return { src: [...src.values()], references: [...references.values()] };
}

{'fraction_non_alphanumeric': 0.13116420945602442, 'fraction_numerical': 0.0020335536349771225, 'mean_word_length': 3.640330188679245, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2955957', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1069, 'n_words': 354}