You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HarmonyInitDependency.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const NullDependency = require("./NullDependency");
  7. class HarmonyInitDependency extends NullDependency {
  8. constructor(originModule) {
  9. super();
  10. this.originModule = originModule;
  11. }
  12. get type() {
  13. return "harmony init";
  14. }
  15. }
  16. module.exports = HarmonyInitDependency;
  17. HarmonyInitDependency.Template = class HarmonyInitDependencyTemplate {
  18. apply(dep, source, runtime, dependencyTemplates) {
  19. const module = dep.originModule;
  20. const list = [];
  21. for (const dependency of module.dependencies) {
  22. const template = dependencyTemplates.get(dependency.constructor);
  23. if (
  24. template &&
  25. typeof template.harmonyInit === "function" &&
  26. typeof template.getHarmonyInitOrder === "function"
  27. ) {
  28. const order = template.getHarmonyInitOrder(dependency);
  29. if (!isNaN(order)) {
  30. list.push({
  31. order,
  32. listOrder: list.length,
  33. dependency,
  34. template
  35. });
  36. }
  37. }
  38. }
  39. list.sort((a, b) => {
  40. const x = a.order - b.order;
  41. if (x) return x;
  42. return a.listOrder - b.listOrder;
  43. });
  44. for (const item of list) {
  45. item.template.harmonyInit(
  46. item.dependency,
  47. source,
  48. runtime,
  49. dependencyTemplates
  50. );
  51. }
  52. }
  53. };