forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFixtures2.js
56 lines (47 loc) · 1.6 KB
/
createFixtures2.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
var path = require("path");
var fs = require("fs");
var fixtures = path.join(__dirname, "fixtures");
try {
fs.mkdirSync(fixtures);
} catch(e) {}
function genModule(prefix, depth, asyncDepth, multiplex, r, circular) {
var source = [];
var async = depth >= asyncDepth;
if(!async)
circular.push(path.resolve(fixtures, prefix + "/index.js"));
source.push("(function() {");
var m = (r % multiplex) + 1;
var sum = 1;
try {
fs.mkdirSync(path.resolve(fixtures, prefix));
} catch(e) {}
if(depth > 0) {
for(var i = 0; i < m; i++) {
sum += genModule(prefix + "/" + i, depth - 1, asyncDepth, multiplex, (r + i + depth) * m + i + depth, circular);
source.push("require(" + JSON.stringify("./" + i) + ");");
if(i === 0) {
if(async)
source.push("}); require.ensure([], function() {");
}
}
var item = circular[r % circular.length];
}
source.push("}, " + JSON.stringify(prefix) + ");");
if(item)
source.push("require(" + JSON.stringify(item) + ");");
source.push("module.exports = " + JSON.stringify(prefix) + ";");
fs.writeFileSync(path.resolve(fixtures, prefix + "/index.js"), source.join("\n"), "utf-8");
return sum;
}
for(var i = 2; i < 14; i++) {
var count = genModule("tree-" + i, 6, 100, i, 0, []);
console.log("generated tree", i, count);
}
for(var i = 2; i < 14; i++) {
var count = genModule("async-tree-" + i, 6, 1, i, 0, []);
console.log("generated async tree", i, count);
}
var a = genModule("module-async", 7, 1, 3, 2, []);
var b = genModule("module-big-async", 5, 2, 9, 2, []);
var c = genModule("module-broad-async", 3, 3, 20, 10, []);
console.log("generated modules", a, b, c);