2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const path = require("path");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const fs = require("fs");
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const fixtures = path.join(__dirname, "fixtures");
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								try {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									fs.mkdirSync(fixtures);
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} catch (e) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-14 16:09:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// The directory already exists
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function genModule(prefix, depth, asyncDepth, multiplex, r, circular) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									const source = [];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									const isAsync = depth >= asyncDepth;
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if (!isAsync) circular.push(path.resolve(fixtures, prefix + "/index.js"));
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									source.push("(function() {");
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:35:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									const m = (r % multiplex) + 1;
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									let sum = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									let item;
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									try {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										fs.mkdirSync(path.resolve(fixtures, prefix));
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									} catch (e) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-14 16:09:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// The directory already exists
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									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
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											source.push("require(" + JSON.stringify("./" + i) + ");");
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											if (i === 0) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												if (isAsync) source.push("}); require.ensure([], function() {");
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										item = circular[r % circular.length];
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									source.push("}, " + JSON.stringify(prefix) + ");");
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if (item) source.push("require(" + JSON.stringify(item) + ");");
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									source.push("module.exports = " + JSON.stringify(prefix) + ";");
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									fs.writeFileSync(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										path.resolve(fixtures, prefix + "/index.js"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										source.join("\n"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"utf-8"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return sum;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								for (let i = 2; i < 14; i++) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									const count = genModule("tree-" + i, 6, 100, i, 0, []);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									console.log("generated tree", i, count);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-13 19:04:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								for (let i = 2; i < 14; i++) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									const count = genModule("async-tree-" + i, 6, 1, i, 0, []);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									console.log("generated async tree", i, count);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const a = genModule("module-async", 7, 1, 3, 2, []);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const b = genModule("module-big-async", 5, 2, 9, 2, []);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-27 22:54:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const c = genModule("module-broad-async", 3, 3, 20, 10, []);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 07:05:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								console.log("generated modules", a, b, c);
							 |