<commit_before>'use strict';

const { dummyFile } = require('../settings');
const { filepathType } = require('../utils/filepath');
const { indir, readdir: { sync: readdir } } = require('recur-fs');
const { strong, warn } = require('../utils/cnsl');
const buildFactory = require('../build');
const buildPlugins = require('./buildPlugins');
const cache = require('../cache');
const fs = require('fs');
const glob = require('glob').sync;
const match = require('minimatch');
const path = require('path');

const DEPRECATED_VERSION = 'this build format is no longer compatible with newer versions of Buddy. See https://github.com/popeindustries/buddy/blob/master/docs/config.md for help';
const MIXED_TYPE = 'mixed';
const RE_COMMON = /^(?:common|shared)$/;
const RE_GLOB = /[\*\[\{]/;
const RE_HIDDEN = /^\./;

let numBuilds;

/**
 * Parse and validate "build" section of 'config'
 * @param {Object} config
 */
module.exports = function buildParser (config) {
  if (!config.builds) throw Error('missing build data');
  config.builds = parseBuild(
    config.builds,
    config.fileExtensions,
    config.fileFactory,
    config.npmModulepaths,
    config.runtimeOptions,
    config.server
  );
};

/**
 * Parse and validate build targets
 * @param {Array} builds
 * @param {Object} fileExtensions
 * @param {Function} fileFactory
 * @param {Array} npmModulepaths
 * @param {Object} runtimeOptions
 * @param {Object} serverConfig
 * @param {Object} [parent]
 * @returns {Array}
 */
function parseBuild (builds, fileExtensions, fileFactory, npmModulepaths, runtimeOptions, serverConfig, parent) {
  if (!parent) {
    numBuilds = 0;
  }

  // Deprecate sources
  if ('sources' in builds) {
    warn(`${strong('sources')} attribute is no longer supported. Use environment variable ${strong('NODE_PATH')} instead`, 1);
  }
  // Deprecate targets
  if ('targets' in builds) {
    warn(DEPRECATED_VERSION);
    builds = builds.targets;
  }

  // Support basic mode with single build target
  if (!Array.isArray(builds)) builds = [builds];

  return builds.reduce((builds, buildConfig) => {
    const childBuilds = buildConfig.build;
    const options = buildConfig.options;
    const version = buildConfig.version;

    delete buildConfig.build;
    delete buildConfig.options;
    delete buildConfig.version;

    // Deprecate old formats
    if ('js' in buildConfig || 'css' in buildConfig || 'html' in buildConfig || 'targets' in buildConfig) {
      warn(DEPRECATED_VERSION);
      return builds;
    }
    // Deprecate aliases
    if (buildConfig.alias) warn(`${strong('alias')} attribute is no longer supported. Use package.json ${strong('browser')} field instead`, 1);
    // Deprecate modular
    if ('modular' in buildConfig) warn(`${strong('modular')} attribute has been renamed to ${strong('bundle')}`, 1);
    // Deprecate sources
    if (buildConfig.sources) warn(`${strong('sources')} attribute is no longer supported. Use environment variable ${strong('NODE_PATH')} instead`, 1);

    if (buildConfig.bootstrap == null) buildConfig.bootstrap = true;
    if (buildConfig.label == null) buildConfig.label = '';
    if (buildConfig.bundle == null || buildConfig.modular) buildConfig.bundle = true;
    buildConfig.batch = false;
    buildConfig.boilerplate = true;
    buildConfig.index = ++numBuilds;
    buildConfig.level = parent ? 1 : 0;
    buildConfig.parent = parent;
    buildConfig.runtimeOptions = runtimeOptions;
    buildConfig.watchOnly = !buildConfig.output;

    parseInputOutput(buildConfig, fileExtensions, runtimeOptions);
    // Ignore build targets with nulled input (no grep match)
    if (!('input' in buildConfig && buildConfig.input != null)) return builds;

    const build = buildFactory(buildConfig);
    const caches = parent
      ? { fileCache: parent.fileCache, resolverCache: parent.resolverCache }
      : cache.createCaches(runtimeOptions.watch);<commit_msg>move deprecation notices<commit_after>'use strict';

const { dummyFile } = require('../settings');
const { filepathType } = require('../utils/filepath');
const { indir, readdir: { sync: readdir } } = require('recur-fs');
const { strong, warn } = require('../utils/cnsl');
const buildFactory = require('../build');
const buildPlugins = require('./buildPlugins');
const cache = require('../cache');
const fs = require('fs');
const glob = require('glob').sync;
const match = require('minimatch');
const path = require('path');

const DEPRECATED_ALIAS = `${strong('alias')} attribute is no longer supported. Use package.json ${strong('browser')} field instead`;
const DEPRECATED_MODULAR = `${strong('modular')} attribute has been renamed to ${strong('bundle')}`;
const DEPRECATED_SOURCES = `${strong('sources')} attribute is no longer supported. Use environment variable ${strong('NODE_PATH')} instead`;
const DEPRECATED_VERSION = 'this build format is no longer compatible with newer versions of Buddy. See https://github.com/popeindustries/buddy/blob/master/docs/config.md for help';
const MIXED_TYPE = 'mixed';
const RE_COMMON = /^(?:common|shared)$/;
const RE_GLOB = /[\*\[\{]/;
const RE_HIDDEN = /^\./;

let numBuilds;

/**
 * Parse and validate "build" section of 'config'
 * @param {Object} config
 */
module.exports = function buildParser (config) {
  if (!config.builds) throw Error('missing build data');
  config.builds = parseBuild(
    config.builds,
    config.fileExtensions,
    config.fileFactory,
    config.npmModulepaths,
    config.runtimeOptions,
    config.server
  );
};

/**
 * Parse and validate build targets
 * @param {Array} builds
 * @param {Object} fileExtensions
 * @param {Function} fileFactory
 * @param {Array} npmModulepaths
 * @param {Object} runtimeOptions
 * @param {Object} serverConfig
 * @param {Object} [parent]
 * @returns {Array}
 */
function parseBuild (builds, fileExtensions, fileFactory, npmModulepaths, runtimeOptions, serverConfig, parent) {
  if (!parent) {
    numBuilds = 0;
  }

  // Deprecate sources
  if ('sources' in builds) {
    warn(DEPRECATED_SOURCES, 1);
  }
  // Deprecate targets
  if ('targets' in builds) {
    warn(DEPRECATED_VERSION, 1);
    builds = builds.targets;
  }

  // Support basic mode with single build target
  if (!Array.isArray(builds)) builds = [builds];

  return builds.reduce((builds, buildConfig) => {
    const childBuilds = buildConfig.build;
    const options = buildConfig.options;
    const version = buildConfig.version;

    delete buildConfig.build;
    delete buildConfig.options;
    delete buildConfig.version;

    // Deprecate old formats
    if ('js' in buildConfig || 'css' in buildConfig || 'html' in buildConfig || 'targets' in buildConfig) {
      warn(DEPRECATED_VERSION);
      return builds;
    }
    // Deprecate aliases
    if (buildConfig.alias) warn(DEPRECATED_ALIAS, 1);
    // Deprecate modular
    if ('modular' in buildConfig) warn(DEPRECATED_MODULAR, 1);
    // Deprecate sources
    if (buildConfig.sources) warn(DEPRECATED_SOURCES, 1);

    if (buildConfig.bootstrap == null) buildConfig.bootstrap = true;
    if (buildConfig.label == null) buildConfig.label = '';
    if (buildConfig.bundle == null || buildConfig.modular) buildConfig.bundle = true;
    buildConfig.batch = false;
    buildConfig.boilerplate = true;
    buildConfig.index = ++numBuilds;
    buildConfig.level = parent ? 1 : 0;
    buildConfig.parent = parent;
    buildConfig.runtimeOptions = runtimeOptions;
    buildConfig.watchOnly = !buildConfig.output;

    parseInputOutput(buildConfig, fileExtensions, runtimeOptions);
    // Ignore build targets with nulled input (no grep match)
    if (!('input' in buildConfig && buildConfig.input != null)) return builds;

    const build = buildFactory(buildConfig);
    const caches = parent
      ? { fileCache: parent.fileCache, resolverCache: parent.resolverCache }
      : cache.createCaches(runtimeOptions.watch);
{'fraction_non_alphanumeric': 0.13588272785213512, 'fraction_numerical': 0.0019120458891013384, 'mean_word_length': 4.104749512036435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '630931', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2294, 'n_words': 643}