e9a66c77cac9419eeaebc5b40c224d4532bdc9853122eb3cb1309445b0dfa03cc5042bcbbc156ea227c5964ce0ac1f0ef707a88296cfade1fb4c5a2f682ea7 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import _ from 'lodash';
  2. import gzipSize from 'gzip-size';
  3. import Node from './Node';
  4. export default class Module extends Node {
  5. constructor(name, data, parent) {
  6. super(name, parent);
  7. this.data = data;
  8. }
  9. get src() {
  10. return this.data.parsedSrc;
  11. }
  12. set src(value) {
  13. this.data.parsedSrc = value;
  14. delete this._gzipSize;
  15. }
  16. get size() {
  17. return this.data.size;
  18. }
  19. set size(value) {
  20. this.data.size = value;
  21. }
  22. get parsedSize() {
  23. return this.src ? this.src.length : undefined;
  24. }
  25. get gzipSize() {
  26. if (!_.has(this, '_gzipSize')) {
  27. this._gzipSize = this.src ? gzipSize.sync(this.src) : undefined;
  28. }
  29. return this._gzipSize;
  30. }
  31. mergeData(data) {
  32. if (data.size) {
  33. this.size += data.size;
  34. }
  35. if (data.parsedSrc) {
  36. this.src = (this.src || '') + data.parsedSrc;
  37. }
  38. }
  39. toChartData() {
  40. return {
  41. id: this.data.id,
  42. label: this.name,
  43. path: this.path,
  44. statSize: this.size,
  45. parsedSize: this.parsedSize,
  46. gzipSize: this.gzipSize
  47. };
  48. }
  49. };