Module.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _lodash = _interopRequireDefault(require("lodash"));
  7. var _gzipSize = _interopRequireDefault(require("gzip-size"));
  8. var _Node = _interopRequireDefault(require("./Node"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. class Module extends _Node.default {
  11. constructor(name, data, parent) {
  12. super(name, parent);
  13. this.data = data;
  14. }
  15. get src() {
  16. return this.data.parsedSrc;
  17. }
  18. set src(value) {
  19. this.data.parsedSrc = value;
  20. delete this._gzipSize;
  21. }
  22. get size() {
  23. return this.data.size;
  24. }
  25. set size(value) {
  26. this.data.size = value;
  27. }
  28. get parsedSize() {
  29. return this.src ? this.src.length : undefined;
  30. }
  31. get gzipSize() {
  32. if (!_lodash.default.has(this, '_gzipSize')) {
  33. this._gzipSize = this.src ? _gzipSize.default.sync(this.src) : undefined;
  34. }
  35. return this._gzipSize;
  36. }
  37. mergeData(data) {
  38. if (data.size) {
  39. this.size += data.size;
  40. }
  41. if (data.parsedSrc) {
  42. this.src = (this.src || '') + data.parsedSrc;
  43. }
  44. }
  45. toChartData() {
  46. return {
  47. id: this.data.id,
  48. label: this.name,
  49. path: this.path,
  50. statSize: this.size,
  51. parsedSize: this.parsedSize,
  52. gzipSize: this.gzipSize
  53. };
  54. }
  55. }
  56. exports.default = Module;
  57. ;