-
Notifications
You must be signed in to change notification settings - Fork 161
/
index.js
89 lines (76 loc) · 2.45 KB
/
index.js
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
const fs = require('graceful-fs');
const path = require('path');
const logMessages = require('./log-messages');
exports.cachePrefix = cachePrefix;
const NS = fs.realpathSync(path.dirname(__dirname));
const cachePrefixNS = `${NS}/cachePrefix`;
function cachePrefix(compilation) {
if (typeof compilation[cachePrefixNS] === 'undefined') {
let prefix = '';
let nextCompilation = compilation;
while (nextCompilation.compiler.parentCompilation) {
const parentCompilation = nextCompilation.compiler.parentCompilation;
if (!nextCompilation.cache) {
logMessages.childCompilerWithoutCache(compilation);
prefix = null;
break;
}
const cache = nextCompilation.cache;
let parentCache = parentCompilation.cache;
if (cache === parentCache) {
nextCompilation = parentCompilation;
continue;
}
let cacheKey;
for (var key in parentCache) {
if (key && parentCache[key] === cache) {
cacheKey = key;
break;
}
}
// webpack 3 adds the children member containing compiler names paired
// with arrays of compilation caches, one for each compilation sharing the
// same name.
if (!cacheKey && parentCache.children) {
parentCache = parentCache.children;
for (var key in parentCache) {
if (key && parentCache[key]) {
for (const index in parentCache[key]) {
if (parentCache[key][index] === cache) {
cacheKey = `${key}.${index}`;
break;
}
if (
parentCache[key][index] &&
typeof parentCache[key][index] === 'object'
) {
for (const subkey in parentCache[key][index]) {
if (parentCache[key][index][subkey] === cache) {
cacheKey = `${key}.${index}.${subkey}`;
break;
}
}
}
}
}
}
}
if (!cacheKey) {
logMessages.childCompilerUnnamedCache(compilation);
prefix = null;
break;
} else {
prefix = cacheKey + prefix;
}
nextCompilation = parentCompilation;
}
compilation[cachePrefixNS] =
prefix !== null
? require('crypto')
.createHash('md5')
.update(prefix)
.digest('base64')
: null;
}
return compilation[cachePrefixNS];
}