<commit_before>#     NoFlo - Flow-Based Programming for JavaScript
#     (c) 2013 The Grid
#     (c) 2013 <NAME>, Nemein
#     NoFlo may be freely distributed under the MIT license
#
# This is the Node.js version of the ComponentLoader.

reader = require 'read-installed'
{_} = require 'underscore'
path = require 'path'
fs = require 'fs'
loader = require '../ComponentLoader'
internalSocket = require '../InternalSocket'

# We allow components to be un-compiled CoffeeScript
require 'coffee-script'

# Disable NPM logging in normal NoFlo operation
log = require 'npmlog'
log.pause()

class ComponentLoader extends loader.ComponentLoader
  getModuleComponents: (moduleDef, callback) ->
    components = {}
    @checked.push moduleDef.name

    depCount = _.keys(moduleDef.dependencies).length
    done = _.after depCount + 1, =>
      callback components

    # Handle sub-modules
    _.each moduleDef.dependencies, (def) =>
      return done() unless def.name?
      return done() unless @checked.indexOf(def.name) is -1
      @getModuleComponents def, (depComponents) ->
        return done() if _.isEmpty depComponents
        components[name] = cPath for name, cPath of depComponents
        done()

    # No need for further processing for non-NoFlo projects
    return done() unless moduleDef.noflo

    checkOwn = (def) =>
      # Handle own components
      prefix = @getModulePrefix def.name

      # See if the library has a default icon
      if def.noflo.icon
        @libraryIcons[prefix] = def.noflo.icon

      if def.noflo.loader
        # Run a custom component loader
        loader = require path.resolve def.realPath def.noflo.loader
        loader @
      if def.noflo.components
        for name, cPath of def.noflo.components
          @registerComponent prefix, name, path.resolve def.realPath, cPath
      if moduleDef.noflo.graphs
        for name, gPath of def.noflo.graphs<commit_msg>Another fix for Node.js custom loaders<commit_after>#     NoFlo - Flow-Based Programming for JavaScript
#     (c) 2013 The Grid
#     (c) 2013 <NAME>, Nemein
#     NoFlo may be freely distributed under the MIT license
#
# This is the Node.js version of the ComponentLoader.

reader = require 'read-installed'
{_} = require 'underscore'
path = require 'path'
fs = require 'fs'
loader = require '../ComponentLoader'
internalSocket = require '../InternalSocket'

# We allow components to be un-compiled CoffeeScript
require 'coffee-script'

# Disable NPM logging in normal NoFlo operation
log = require 'npmlog'
log.pause()

class ComponentLoader extends loader.ComponentLoader
  getModuleComponents: (moduleDef, callback) ->
    components = {}
    @checked.push moduleDef.name

    depCount = _.keys(moduleDef.dependencies).length
    done = _.after depCount + 1, =>
      callback components

    # Handle sub-modules
    _.each moduleDef.dependencies, (def) =>
      return done() unless def.name?
      return done() unless @checked.indexOf(def.name) is -1
      @getModuleComponents def, (depComponents) ->
        return done() if _.isEmpty depComponents
        components[name] = cPath for name, cPath of depComponents
        done()

    # No need for further processing for non-NoFlo projects
    return done() unless moduleDef.noflo

    checkOwn = (def) =>
      # Handle own components
      prefix = @getModulePrefix def.name

      # See if the library has a default icon
      if def.noflo.icon
        @libraryIcons[prefix] = def.noflo.icon

      if def.noflo.loader
        # Run a custom component loader
        loader = require path.resolve def.realPath, def.noflo.loader
        loader @
      if def.noflo.components
        for name, cPath of def.noflo.components
          @registerComponent prefix, name, path.resolve def.realPath, cPath
      if moduleDef.noflo.graphs
        for name, gPath of def.noflo.graphs
{'fraction_non_alphanumeric': 0.0877922077922078, 'fraction_numerical': 0.005194805194805195, 'mean_word_length': 2.9497435897435897, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5200967', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1077, 'n_words': 368}