<commit_before>/**
 * Logic for importing a Framework into the node process.
 */

exports.import = importFramework
exports.resolve = resolve

// The Framework PATH. Equivalent to the -F switch with gcc.
exports.PATH = ['/System/Library/Frameworks', '/System/Library/PrivateFrameworks']

var fs = require('fs')
  , path = require('path')
  , core = require('./core')
  , _class = require('./class')
  , _global = require('./index')
  , bridgesupport = require('./bridgesupport')
  , join = path.join
  , basename = path.basename
  , exists = path.existsSync
  , SUFFIX = '.framework'

// A cache for the frameworks that have already been imported.
var importCache = {};


/**
 * Accepts a single framework name and imports it into the current node process
 */
function importFramework (framework) {
  framework = exports.resolve(framework);

  var shortName = basename(framework, SUFFIX)

  // Return from the framework cache if possible
  var fw = importCache[shortName];
  if (fw) {
    return fw;
  }

  // Load the main framework binary file
  var frameworkPath = join(framework, shortName)
    , lib = core.dlopen(frameworkPath)
  fw = {
      lib: lib
    , name: shortName
    , basePath: framework
    , binaryPath: frameworkPath
  };

  // cache before loading bridgesupport files
  importCache[shortName] = fw;

  // Iterate through the loaded classes list and define "setup getters" for them.
  core.getClassList().forEach(function (c) {
    if (!!_global[c]) return;
    _global.__defineGetter__(c, function () {
      var clazz = _class.getClass(c);
      delete _global[c];
      return _global[c] = clazz;
    });
  });

  // Parse the BridgeSupport file and inline dylib, for the C functions, enums,
  // and other symbols not introspectable at runtime.
  bridgesupport(fw);

  //console.error('Finished importing framework: %s', shortName);
}


/**
 * Accepts a single framework name and resolves it into an absolute path
 * to the base directory of the framework.
 */
function resolve (framework) {
  // already absolute, return as-is
  if (~framework.indexOf('/')) return framework;
  var i = 0
    , l = exports.PATH.length
    , rtn = null
  for (; i<l; i++) {
    rtn = join(exports.PATH[i], framework + SUFFIX);
    if (exists(rtn)) return rtn;
  }
  throw new Error('Could not resolve framework: ' + framework);
}
<commit_msg>Parse the BridgeSupport files first once again. Also only import the Classes *last* (after all other dependant frameworks).<commit_after>/**
 * Logic for importing a Framework into the node process.
 */

exports.import = importFramework
exports.resolve = resolve

// The Framework PATH. Equivalent to the -F switch with gcc.
exports.PATH = ['/System/Library/Frameworks', '/System/Library/PrivateFrameworks']

var fs = require('fs')
  , path = require('path')
  , core = require('./core')
  , _class = require('./class')
  , _global = require('./index')
  , bridgesupport = require('./bridgesupport')
  , join = path.join
  , basename = path.basename
  , exists = path.existsSync
  , SUFFIX = '.framework'

// A cache for the frameworks that have already been imported.
var importCache = {};


/**
 * Accepts a single framework name and imports it into the current node process
 */
function importFramework (framework, skip) {
  framework = exports.resolve(framework);

  var shortName = basename(framework, SUFFIX)

  // Return from the framework cache if possible
  var fw = importCache[shortName];
  if (fw) {
    return fw;
  }

  // Load the main framework binary file
  var frameworkPath = join(framework, shortName)
    , lib = core.dlopen(frameworkPath)
  fw = {
      lib: lib
    , name: shortName
    , basePath: framework
    , binaryPath: frameworkPath
  };

  // cache before loading bridgesupport files
  importCache[shortName] = fw;

  // Parse the BridgeSupport file and inline dylib, for the C functions, enums,
  // and other symbols not introspectable at runtime.
  bridgesupport(fw);

  // Iterate through the loaded classes list and define "setup getters" for them.
  if (!skip) {
    core.getClassList().forEach(function (c) {
      if (!!_global[c]) return;
      _global.__defineGetter__(c, function () {
        var clazz = _class.getClass(c);
        delete _global[c];
        return _global[c] = clazz;
      });
    });
  }

  //console.error('Finished importing framework: %s', shortName);
}


/**
 * Accepts a single framework name and resolves it into an absolute path
 * to the base directory of the framework.
 */
function resolve (framework) {
  // already absolute, return as-is
  if (~framework.indexOf('/')) return framework;
  var i = 0
    , l = exports.PATH.length
    , rtn = null
  for (; i<l; i++) {
    rtn = join(exports.PATH[i], framework + SUFFIX);
    if (exists(rtn)) return rtn;
  }
  throw new Error('Could not resolve framework: ' + framework);
}

{'fraction_non_alphanumeric': 0.12002474737059188, 'fraction_numerical': 0.00041245617653124357, 'mean_word_length': 3.303460514640639, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2420219', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1422, 'n_words': 482}