tasks/middleware/makeReleaseBuild.js
function scanForOptimization (context)
{
  var module, verboseOut = context.grunt.log.verbose;

  // Track repeated files to determine which modules can be optimized.

  Object.keys (context.modules).forEach (function (name)
  {
    if (context.modules.hasOwnProperty (name)) {
      module = context.modules[name];
      if (!module.external)
        module.filePaths ().forEach (function (path)
        {
          if (!context.filesRefCount[path])
            context.filesRefCount[path] = 1;
          else {
            verboseOut.writeln (util.csprintf ('white',
              'Not optimizing <cyan>%</cyan> because it shares some/all of its files with other modules.', name));
            ++context.filesRefCount[path];
            module.optimize = false;
          }
        });
    }
  });

  // Determine which modules can act as containers for non-optimized sections of code.

  scan (context.options.mainModule, true);

  /**
   * Search for unoptimizable modules.
   * @param {string} moduleName
   * @param {boolean?} first=false Is this the root module?
   * @returns {boolean} `true` if the module is not optimizable.
   */
  function scan (moduleName, first)
  {
    var module = context.modules[moduleName];
    if (!module)
      throw new Error (sprintf ("Module '%' was not found.", moduleName));
    // Ignore the module if it's external.
    if (module.external)
      return false;
    if (!module.optimize) {
      if (first)
        module.nonOptimizedContainer = true;
      disableOptimizationsForChildrenOf (module);
      return true;
    }
    for (var i = 0, m = module.requires.length, any = false; i < m; ++i)
      if (scan (module.requires[i])) //Note: scan() still must be called for ALL submodules!
        any = true;
    if (any)
      module.nonOptimizedContainer = true;
    return false;
  }

  function disableOptimizationsForChildrenOf (module)
  {
    if (module.external)
      return;
    for (var i = 0, m = module.requires.length; i < m; ++i) {
      var sub = context.modules[module.requires[i]];
      if (sub.external)
        continue;
      if (sub.optimize)
        verboseOut.writeln (util.csprintf ('white', "Also disabling optimizations for <cyan>%</cyan>.", sub.name.cyan));
      sub.optimize = false;
      disableOptimizationsForChildrenOf (sub);
    }
  }
}
function scanForOptimization (context)
{
  var module, verboseOut = context.grunt.log.verbose;

  // Track repeated files to determine which modules can be optimized.

  Object.keys (context.modules).forEach (function (name)
  {
    if (context.modules.hasOwnProperty (name)) {
      module = context.modules[name];
      if (!module.external)
        module.filePaths ().forEach (function (path)
        {
          if (!context.filesRefCount[path])
            context.filesRefCount[path] = 1;
          else {
            verboseOut.writeln (util.csprintf ('white',
              'Not optimizing <cyan>%</cyan> because it shares some/all of its files with other modules.', name));
            ++context.filesRefCount[path];
            module.optimize = false;
          }
        });
    }
  });

  // Determine which modules can act as containers for non-optimized sections of code.

  scan (context.options.mainModule, true);

  /**
   * Search for unoptimizable modules.
   * @param {string} moduleName
   * @param {boolean?} first=false Is this the root module?
   * @returns {boolean} `true` if the module is not optimizable.
   */
  function scan (moduleName, first)
  {
    var module = context.modules[moduleName];
    if (!module)
      throw new Error (sprintf ("Module '%' was not found.", moduleName));
    // Ignore the module if it's external.
    if (module.external)
      return false;
    if (!module.optimize) {
      if (first)
        module.nonOptimizedContainer = true;
      disableOptimizationsForChildrenOf (module);
      return true;
    }
    for (var i = 0, m = module.requires.length, any = false; i < m; ++i)
      if (scan (module.requires[i])) //Note: scan() still must be called for ALL submodules!
        any = true;
    if (any)
      module.nonOptimizedContainer = true;
    return false;
  }

  function disableOptimizationsForChildrenOf (module)
  {
    if (module.external)
      return;
    for (var i = 0, m = module.requires.length; i < m; ++i) {
      var sub = context.modules[module.requires[i]];
      if (sub.external)
        continue;
      if (sub.optimize)
        verboseOut.writeln (util.csprintf ('white', "Also disabling optimizations for <cyan>%</cyan>.", sub.name.cyan));
      sub.optimize = false;
      disableOptimizationsForChildrenOf (sub);
    }
  }
}
function scanForOptimization ( context ) { var module , verboseOut = context . grunt . log . verbose ; // Track repeated files to determine which modules can be optimized. Object . keys ( context . modules ) . forEach ( function ( name ) { if ( context . modules . hasOwnProperty ( name ) ) { module = context . modules [ name ] ; if ( ! module . external ) module . filePaths ( ) . forEach ( function ( path ) { if ( ! context . filesRefCount [ path ] ) context . filesRefCount [ path ] = 1 ; else { verboseOut . writeln ( util . csprintf ( 'white' , 'Not optimizing <cyan>%</cyan> because it shares some/all of its files with other modules.' , name ) ) ; ++ context . filesRefCount [ path ] ; module . optimize = false ; } } ) ; } } ) ; // Determine which modules can act as containers for non-optimized sections of code. scan ( context . options . mainModule , true ) ; /**
   * Search for unoptimizable modules.
   * @param {string} moduleName
   * @param {boolean?} first=false Is this the root module?
   * @returns {boolean} `true` if the module is not optimizable.
   */ function scan ( moduleName , first ) { var module = context . modules [ moduleName ] ; if ( ! module ) throw new Error ( sprintf ( "Module '%' was not found." , moduleName ) ) ; // Ignore the module if it's external. if ( module . external ) return false ; if ( ! module . optimize ) { if ( first ) module . nonOptimizedContainer = true ; disableOptimizationsForChildrenOf ( module ) ; return true ; } for ( var i = 0 , m = module . requires . length , any = false ; i < m ; ++ i ) if ( scan ( module . requires [ i ] ) ) //Note: scan() still must be called for ALL submodules! any = true ; if ( any ) module . nonOptimizedContainer = true ; return false ; } function disableOptimizationsForChildrenOf ( module ) { if ( module . external ) return ; for ( var i = 0 , m = module . requires . length ; i < m ; ++ i ) { var sub = context . modules [ module . requires [ i ] ] ; if ( sub . external ) continue ; if ( sub . optimize ) verboseOut . writeln ( util . csprintf ( 'white' , "Also disabling optimizations for <cyan>%</cyan>." , sub . name . cyan ) ) ; sub . optimize = false ; disableOptimizationsForChildrenOf ( sub ) ; } } }
Determine which modules can be optimized.
@param {Context} context The execution context for the middleware stack.
Determine which modules can be optimized .