forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateFixtures2.js
More file actions
69 lines (60 loc) · 1.74 KB
/
createFixtures2.js
File metadata and controls
69 lines (60 loc) · 1.74 KB
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
const path = require("path");
const fs = require("fs");
const fixtures = path.join(__dirname, "fixtures");
try {
fs.mkdirSync(fixtures);
} catch (e) {
// The directory already exists
}
function genModule(prefix, depth, asyncDepth, multiplex, r, circular) {
const source = [];
const isAsync = depth >= asyncDepth;
if (!isAsync) circular.push(path.resolve(fixtures, prefix + "/index.js"));
source.push("(function() {");
const m = (r % multiplex) + 1;
let sum = 1;
let item;
try {
fs.mkdirSync(path.resolve(fixtures, prefix));
} catch (e) {
// The directory already exists
}
if (depth > 0) {
for (let 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 (isAsync) source.push("}); require.ensure([], function() {");
}
}
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 (let i = 2; i < 14; i++) {
const count = genModule("tree-" + i, 6, 100, i, 0, []);
console.log("generated tree", i, count);
}
for (let i = 2; i < 14; i++) {
const count = genModule("async-tree-" + i, 6, 1, i, 0, []);
console.log("generated async tree", i, count);
}
const a = genModule("module-async", 7, 1, 3, 2, []);
const b = genModule("module-big-async", 5, 2, 9, 2, []);
const c = genModule("module-broad-async", 3, 3, 20, 10, []);
console.log("generated modules", a, b, c);