<commit_before>/**
 * Copyright (c) 2014, Facebook, Inc. All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
'use strict';

/**
 * TODO: This file has grown into a monster. It really needs to be refactored
 *       into smaller pieces. One of the best places to start would be to move a
 *       bunch of the logic that exists here into node-haste.
 *
 *       Relatedly: It's time we vastly simplify node-haste.
 */

var fs = require('graceful-fs');
var hasteLoaders = require('node-haste/lib/loaders');
var moduleMocker = require('../lib/moduleMocker');
var NodeHaste = require('node-haste/lib/Haste');
var os = require('os');
var path = require('path');
var resolve = require('resolve');
var utils = require('../lib/utils');

var COVERAGE_STORAGE_VAR_NAME = '____JEST_COVERAGE_DATA____';

var NODE_PATH = process.env.NODE_PATH;

var IS_PATH_BASED_MODULE_NAME = /^(?:\.\.?\/|\/)/;

var NODE_CORE_MODULES = {
  assert: true,
  buffer: true,
  child_process: true, // jshint ignore:line
  cluster: true,
  console: true,
  constants: true,
  crypto: true,
  dgram: true,
  dns: true,
  domain: true,
  events: true,
  freelist: true,
  fs: true,
  http: true,
  https: true,
  module: true,
  net: true,
  os: true,
  path: true,
  punycode: true,
  querystring: true,
  readline: true,
  repl: true,
  smalloc: true,
  stream: true,
  string_decoder: true, // jshint ignore:line
  sys: true,
  timers: true,
  tls: true,
  tty: true,
  url: true,
  util: true,
  vm: true,
  zlib: true
};

var VENDOR_PATH = path.resolve(__dirname, '../../vendor');

var _configUnmockListRegExpCache = null;

function _buildLoadersList(config) {
  return [
    new hasteLoaders.ProjectConfigurationLoader(),
    new hasteLoaders.JSTestLoader(config.setupJSTestLoaderOptions),
    new hasteLoaders.JSMockLoader(config.setupJSMockLoaderOptions),
    new hasteLoaders.JSLoader(config.setupJSLoaderOptions),
    new hasteLoaders.ResourceLoader()
  ];
}

function _constructHasteInst(config, options) {
  var HASTE_IGNORE_REGEX = new RegExp(
    config.modulePathIgnorePatterns.length > 0
    ? config.modulePathIgnorePatterns.join('|')
    : '$.'  // never matches
  );

  if (!fs.existsSync(config.cacheDirectory)) {
    fs.mkdirSync(config.cacheDirectory);
  }

  return new NodeHaste(
    _buildLoadersList(config),
    (config.testPathDirs || []),
    {
      ignorePaths: function(path) {
        return path.match(HASTE_IGNORE_REGEX);
      },
      version: JSON.stringify(config),
      useNativeFind: true,
      maxProcesses: os.cpus().length,
      maxOpenFiles: options.maxOpenFiles || 100
    }
  );
}

function _getCacheFilePath(config) {
  return path.join(config.cacheDirectory, 'cache-' + config.name);
}

function Loader(config, environment, resourceMap) {
  this._config = config;
  this._coverageCollectors = {};
  this._currentlyExecutingModulePath = '';
  this._environment = environment;
  this._explicitShouldMock = {};
  this._explicitlySetMocks = {};<commit_msg>Set 777 chmod for .haste-cache.<commit_after>/**
 * Copyright (c) 2014, Facebook, Inc. All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
'use strict';

/**
 * TODO: This file has grown into a monster. It really needs to be refactored
 *       into smaller pieces. One of the best places to start would be to move a
 *       bunch of the logic that exists here into node-haste.
 *
 *       Relatedly: It's time we vastly simplify node-haste.
 */

var fs = require('graceful-fs');
var hasteLoaders = require('node-haste/lib/loaders');
var moduleMocker = require('../lib/moduleMocker');
var NodeHaste = require('node-haste/lib/Haste');
var os = require('os');
var path = require('path');
var resolve = require('resolve');
var utils = require('../lib/utils');

var COVERAGE_STORAGE_VAR_NAME = '____JEST_COVERAGE_DATA____';

var NODE_PATH = process.env.NODE_PATH;

var IS_PATH_BASED_MODULE_NAME = /^(?:\.\.?\/|\/)/;

var NODE_CORE_MODULES = {
  assert: true,
  buffer: true,
  child_process: true, // jshint ignore:line
  cluster: true,
  console: true,
  constants: true,
  crypto: true,
  dgram: true,
  dns: true,
  domain: true,
  events: true,
  freelist: true,
  fs: true,
  http: true,
  https: true,
  module: true,
  net: true,
  os: true,
  path: true,
  punycode: true,
  querystring: true,
  readline: true,
  repl: true,
  smalloc: true,
  stream: true,
  string_decoder: true, // jshint ignore:line
  sys: true,
  timers: true,
  tls: true,
  tty: true,
  url: true,
  util: true,
  vm: true,
  zlib: true
};

var VENDOR_PATH = path.resolve(__dirname, '../../vendor');

var _configUnmockListRegExpCache = null;

function _buildLoadersList(config) {
  return [
    new hasteLoaders.ProjectConfigurationLoader(),
    new hasteLoaders.JSTestLoader(config.setupJSTestLoaderOptions),
    new hasteLoaders.JSMockLoader(config.setupJSMockLoaderOptions),
    new hasteLoaders.JSLoader(config.setupJSLoaderOptions),
    new hasteLoaders.ResourceLoader()
  ];
}

function _constructHasteInst(config, options) {
  var HASTE_IGNORE_REGEX = new RegExp(
    config.modulePathIgnorePatterns.length > 0
    ? config.modulePathIgnorePatterns.join('|')
    : '$.'  // never matches
  );

  if (!fs.existsSync(config.cacheDirectory)) {
    fs.mkdirSync(config.cacheDirectory);
    fs.chmodSync(config.cacheDirectory, '777');
  }

  return new NodeHaste(
    _buildLoadersList(config),
    (config.testPathDirs || []),
    {
      ignorePaths: function(path) {
        return path.match(HASTE_IGNORE_REGEX);
      },
      version: JSON.stringify(config),
      useNativeFind: true,
      maxProcesses: os.cpus().length,
      maxOpenFiles: options.maxOpenFiles || 100
    }
  );
}

function _getCacheFilePath(config) {
  return path.join(config.cacheDirectory, 'cache-' + config.name);
}

function Loader(config, environment, resourceMap) {
  this._config = config;
  this._coverageCollectors = {};
  this._currentlyExecutingModulePath = '';
  this._environment = environment;
  this._explicitShouldMock = {};
  this._explicitlySetMocks = {};
{'fraction_non_alphanumeric': 0.12215288611544461, 'fraction_numerical': 0.0034321372854914196, 'mean_word_length': 3.7488888888888887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1357821', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2103, 'n_words': 550}