<commit_before>#! /usr/bin/env node

const fs = require('fs');
const sortKeys = require('sort-keys');
const asArray = require('as/array');
const asObject = require('as/object');
const includes = require('array-includes');

const packages = require('./utilities/packages');

const globalManifest = require('../package.json');
const originalDependencies = globalManifest.dependencies;

const serialize = (value) => JSON.stringify(value, null, 2) + '\n';

// Pull local dependencies into global manifest.
const ourPackageNames = packages.map(project => project.manifest.name);

const dependencies = sortKeys(packages.reduce((target, project) => {
  const externalDependencies = asObject(
    asArray(project.manifest.dependencies)
      .filter(dependency => !includes(ourPackageNames, dependency.key))
  );

  return Object.assign({}, externalDependencies, target);
}, originalDependencies));

const newGlobalManifest = Object.assign({}, globalManifest, { dependencies });

fs.writeFileSync(
  `${__dirname}/../package.json`,
  serialize(newGlobalManifest)
);

// Push global versions to local manifests.
packages.forEach((project) => {
  if (!project.manifest.dependencies) return;

  const newManifest = Object.assign({}, project.manifest);

  Object.keys(newManifest.dependencies).forEach(name => {
    if (!('name' in dependencies)) return;
    newManifest.dependencies[name] = dependencies[name];
  });

  fs.writeFileSync(
    `${project.cwd}/package.json`,
    serialize(newManifest)<commit_msg>Update `npm run sync-dependencies`<commit_after>#! /usr/bin/env node

const fs = require('fs');
const sortKeys = require('sort-keys');
const asArray = require('as/array');
const asObject = require('as/object');
const includes = require('array-includes');

const projects = require('./utilities/packages');

const globalManifest = require('../package.json');
const originalDependencies = globalManifest.dependencies;

const serialize = (value) => JSON.stringify(value, null, 2) + '\n';

const ourPackageNames = projects.map(project => project.manifest.name);

// Pull local dependencies into global manifest.
const dependencies = sortKeys(projects.reduce((target, project) => {
  const externalDependencies = asObject(
    asArray(project.manifest.dependencies)
      .filter(dependency => !includes(ourPackageNames, dependency.key))
  );

  return Object.assign({}, externalDependencies, target);
}, originalDependencies));

const newGlobalManifest = Object.assign({}, globalManifest, { dependencies });

fs.writeFileSync(
  `${__dirname}/../package.json`,
  serialize(newGlobalManifest)
);

// Push global versions to local manifests.
projects.forEach((project) => {
  if (!project.manifest.dependencies) return;

  const newManifest = Object.assign({}, project.manifest);

  Object.keys(newManifest.dependencies).forEach(name => {
    if (!('name' in dependencies)) return;
    newManifest.dependencies[name] = dependencies[name];
  });

  fs.writeFileSync(
    `${project.cwd}/package.json`,
    serialize(newManifest)
{'fraction_non_alphanumeric': 0.1499503475670308, 'fraction_numerical': 0.0006620324395895399, 'mean_word_length': 5.335429769392033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5297362', 'n_tokens_mistral': 852, 'n_tokens_neox': 824, 'n_words': 188}