保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const NormalModule = require('webpack/lib/NormalModule');
 
const cachePrefix = require('./util').cachePrefix;
const pluginCompat = require('./util/plugin-compat');
 
function wrapSource(source, methods) {
  Object.keys(methods).forEach(key => {
    const _method = source[key];
    source[key] = function(...args) {
      methods[key].apply(this, args);
      _method && _method.apply(this, args);
    };
  });
  return source;
}
 
function spyMethod(name, mods) {
  return function(...args) {
    mods.push([name].concat([].slice.call(args)));
  };
}
 
function isEqual(a, b) {
  if (Array.isArray(a) && Array.isArray(b) && a.length === b.length) {
    return a.reduce(
      (carry, value, index) => carry && isEqual(value, b[index]),
      true,
    );
  } else if (a === b) {
    return true;
  }
  return false;
}
 
class HardModuleConcatenationPlugin {
  apply(compiler) {
    let store;
    let freeze;
 
    pluginCompat.tap(
      compiler,
      '_hardSourceMethods',
      'HardModuleConcatenationPlugin',
      methods => {
        store = methods.store;
        // fetch = methods.fetch;
        freeze = methods.freeze;
        // thaw = methods.thaw;
        // mapFreeze = methods.mapFreeze;
        // mapThaw = methods.mapThaw;
      },
    );
 
    pluginCompat.tap(
      compiler,
      '_hardSourceFreezeModule',
      'HardModuleConcatenationPlugin',
      (frozen, { modules }, extra) => {
        if (modules) {
          const compilation = extra.compilation;
 
          modules.forEach(module => {
            if (
              (module.cacheable ||
                (module.buildInfo && module.buildInfo.cacheable)) &&
              module instanceof NormalModule
            ) {
              const identifierPrefix = cachePrefix(compilation);
              if (identifierPrefix === null) {
                return;
              }
              const identifier = identifierPrefix + module.identifier();
 
              store('Module', identifier, module, {
                id: identifier,
                compilation,
              });
            }
          });
        }
 
        return frozen;
      },
    );
 
    pluginCompat.tap(
      compiler,
      '_hardSourceAfterFreezeModule',
      'HardModuleConcatenationPlugin',
      (frozen, module, { compilation }) => {
        return frozen;
        if (frozen && module.__hardSource_concatedSource) {
          const source = module.__hardSource_concatedSource;
          frozen.source = source.source();
          frozen.sourceMap = freeze('SourceMap', null, source, {
            module,
            compilation: compilation,
          });
          frozen.concatenatedSourceMods = module.__hardSource_sourceMods;
        }
        return frozen;
      },
    );
  }
}
 
module.exports = HardModuleConcatenationPlugin;