Module.js 1.4 KB

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