• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript dependency-graph.DepGraph类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中dependency-graph.DepGraph的典型用法代码示例。如果您正苦于以下问题:TypeScript DepGraph类的具体用法?TypeScript DepGraph怎么用?TypeScript DepGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DepGraph类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: sortEntryPointsByDependency

  /**
   * Sort the array of entry points so that the dependant entry points always come later than
   * their dependencies in the array.
   * @param entryPoints An array entry points to sort.
   * @returns the result of sorting the entry points.
   */
  sortEntryPointsByDependency(entryPoints: EntryPoint[]): SortedEntryPointsInfo {
    const invalidEntryPoints: InvalidEntryPoint[] = [];
    const ignoredDependencies: IgnoredDependency[] = [];
    const graph = new DepGraph<EntryPoint>();

    // Add the entry ponts to the graph as nodes
    entryPoints.forEach(entryPoint => graph.addNode(entryPoint.path, entryPoint));

    // Now add the dependencies between them
    entryPoints.forEach(entryPoint => {
      const entryPointPath = entryPoint.fesm2015 || entryPoint.esm2015;
      if (!entryPointPath) {
        throw new Error(
            `ESM2015 format (flat and non-flat) missing in '${entryPoint.path}' entry-point.`);
      }

      const dependencies = new Set<string>();
      const missing = new Set<string>();
      this.host.computeDependencies(entryPointPath, dependencies, missing);

      if (missing.size > 0) {
        // This entry point has dependencies that are missing
        // so remove it from the graph.
        removeNodes(entryPoint, Array.from(missing));
      } else {
        dependencies.forEach(dependencyPath => {
          if (graph.hasNode(dependencyPath)) {
            // The dependency path maps to an entry point that exists in the graph
            // so add the dependency.
            graph.addDependency(entryPoint.path, dependencyPath);
          } else if (invalidEntryPoints.some(i => i.entryPoint.path === dependencyPath)) {
            // The dependency path maps to an entry-point that was previously removed
            // from the graph, so remove this entry-point as well.
            removeNodes(entryPoint, [dependencyPath]);
          } else {
            // The dependency path points to a package that ngcc does not care about.
            ignoredDependencies.push({entryPoint, dependencyPath});
          }
        });
      }
    });

    // The map now only holds entry-points that ngcc cares about and whose dependencies
    // (direct and transitive) all exist.
    return {
      entryPoints: graph.overallOrder().map(path => graph.getNodeData(path)),
      invalidEntryPoints,
      ignoredDependencies
    };

    function removeNodes(entryPoint: EntryPoint, missingDependencies: string[]) {
      const nodesToRemove = [entryPoint.path, ...graph.dependantsOf(entryPoint.path)];
      nodesToRemove.forEach(node => {
        invalidEntryPoints.push({entryPoint: graph.getNodeData(node), missingDependencies});
        graph.removeNode(node);
      });
    }
  }
开发者ID:foresthz,项目名称:angular,代码行数:64,代码来源:dependency_resolver.ts


示例2: computeDependencyGraph

  /**
   * Computes a dependency graph of the given entry-points.
   *
   * The graph only holds entry-points that ngcc cares about and whose dependencies
   * (direct and transitive) all exist.
   */
  private computeDependencyGraph(entryPoints: EntryPoint[]): DependencyGraph {
    const invalidEntryPoints: InvalidEntryPoint[] = [];
    const ignoredDependencies: IgnoredDependency[] = [];
    const graph = new DepGraph<EntryPoint>();

    const angularEntryPoints = entryPoints.filter(entryPoint => entryPoint.compiledByAngular);

    // Add the Angular compiled entry points to the graph as nodes
    angularEntryPoints.forEach(entryPoint => graph.addNode(entryPoint.path, entryPoint));

    // Now add the dependencies between them
    angularEntryPoints.forEach(entryPoint => {
      const entryPointPath = getEntryPointPath(entryPoint);
      const {dependencies, missing, deepImports} = this.host.findDependencies(entryPointPath);

      if (missing.size > 0) {
        // This entry point has dependencies that are missing
        // so remove it from the graph.
        removeNodes(entryPoint, Array.from(missing));
      } else {
        dependencies.forEach(dependencyPath => {
          if (graph.hasNode(dependencyPath)) {
            // The dependency path maps to an entry point that exists in the graph
            // so add the dependency.
            graph.addDependency(entryPoint.path, dependencyPath);
          } else if (invalidEntryPoints.some(i => i.entryPoint.path === dependencyPath)) {
            // The dependency path maps to an entry-point that was previously removed
            // from the graph, so remove this entry-point as well.
            removeNodes(entryPoint, [dependencyPath]);
          } else {
            // The dependency path points to a package that ngcc does not care about.
            ignoredDependencies.push({entryPoint, dependencyPath});
          }
        });
      }

      if (deepImports.size) {
        const imports = Array.from(deepImports).map(i => `'${i}'`).join(', ');
        this.logger.warn(
            `Entry point '${entryPoint.name}' contains deep imports into ${imports}. ` +
            `This is probably not a problem, but may cause the compilation of entry points to be out of order.`);
      }
    });

    return {invalidEntryPoints, ignoredDependencies, graph};

    function removeNodes(entryPoint: EntryPoint, missingDependencies: string[]) {
      const nodesToRemove = [entryPoint.path, ...graph.dependantsOf(entryPoint.path)];
      nodesToRemove.forEach(node => {
        invalidEntryPoints.push({entryPoint: graph.getNodeData(node), missingDependencies});
        graph.removeNode(node);
      });
    }
  }
开发者ID:marclaval,项目名称:angular,代码行数:60,代码来源:dependency_resolver.ts


示例3: sortByDependency

export function sortByDependency(items: Object | any[], afterProp?: string, beforeProp?: string, nameProp: string = 'name') {

  let map = {};
  let depGraph = new DepGraph();

  let addDependencies = function(item, dependencyProp, addBefore: boolean = false) {
    if ( dependencyProp && item[dependencyProp]) {
      if ( !Array.isArray(item[dependencyProp]) ) {
        throw new Error('Error in item "' + item[nameProp] + '" - ' + dependencyProp + ' must be an array');
      }
      item[dependencyProp].forEach(function(dependency) {
        if ( !map[dependency] ) {
          throw new Error('Missing dependency: "' + dependency + '"  on "' + item[nameProp] + '"');
        }
        if ( addBefore ) {
          depGraph.addDependency(dependency, item[nameProp]);
        } else {
          depGraph.addDependency(item[nameProp], dependency);
        }
      });
    }
  };

  _.forEach(items, function(item, index) {
    if ( !item[nameProp] ) {
      throw new Error('Missing ' + nameProp + ' property on item #' + (index + 1));
    }
    map[item[nameProp]] = item;
    depGraph.addNode(item[nameProp]);
  });


  _.forEach(items, function(item) {
    addDependencies(item, afterProp);
    addDependencies(item, beforeProp, true);
  });

  return depGraph.overallOrder().map(function(itemName) {
    return map[itemName];
  });
};
开发者ID:angular,项目名称:dgeni,代码行数:41,代码来源:dependency-sort.ts


示例4: if

 dependencies.forEach(dependencyPath => {
   if (graph.hasNode(dependencyPath)) {
     // The dependency path maps to an entry point that exists in the graph
     // so add the dependency.
     graph.addDependency(entryPoint.path, dependencyPath);
   } else if (invalidEntryPoints.some(i => i.entryPoint.path === dependencyPath)) {
     // The dependency path maps to an entry-point that was previously removed
     // from the graph, so remove this entry-point as well.
     removeNodes(entryPoint, [dependencyPath]);
   } else {
     // The dependency path points to a package that ngcc does not care about.
     ignoredDependencies.push({entryPoint, dependencyPath});
   }
 });
开发者ID:jorgeucano,项目名称:angular,代码行数:14,代码来源:dependency_resolver.ts


示例5: removeNodes

 function removeNodes(entryPoint: EntryPoint, missingDependencies: string[]) {
   const nodesToRemove = [entryPoint.path, ...graph.dependantsOf(entryPoint.path)];
   nodesToRemove.forEach(node => {
     invalidEntryPoints.push({entryPoint: graph.getNodeData(node), missingDependencies});
     graph.removeNode(node);
   });
 }
开发者ID:jorgeucano,项目名称:angular,代码行数:7,代码来源:dependency_resolver.ts


示例6:

 nodesToRemove.forEach(node => {
   invalidEntryPoints.push({entryPoint: graph.getNodeData(node), missingDependencies});
   graph.removeNode(node);
 });
开发者ID:jorgeucano,项目名称:angular,代码行数:4,代码来源:dependency_resolver.ts



注:本文中的dependency-graph.DepGraph类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript detect-browser.detect函数代码示例发布时间:2022-05-25
下一篇:
TypeScript depcheck.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap