@memlab/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +11 -0
  2. package/bin/memlab +14 -0
  3. package/dist/BaseCommand.d.ts +37 -0
  4. package/dist/BaseCommand.d.ts.map +1 -0
  5. package/dist/BaseCommand.js +132 -0
  6. package/dist/Dispatcher.d.ts +35 -0
  7. package/dist/Dispatcher.d.ts.map +1 -0
  8. package/dist/Dispatcher.js +205 -0
  9. package/dist/TypesThirdParty.d.ts +17 -0
  10. package/dist/TypesThirdParty.d.ts.map +1 -0
  11. package/dist/TypesThirdParty.js +10 -0
  12. package/dist/commands/CleanLoggerDataCommand.d.ts +20 -0
  13. package/dist/commands/CleanLoggerDataCommand.d.ts.map +1 -0
  14. package/dist/commands/CleanLoggerDataCommand.js +50 -0
  15. package/dist/commands/CleanRunDataCommand.d.ts +20 -0
  16. package/dist/commands/CleanRunDataCommand.d.ts.map +1 -0
  17. package/dist/commands/CleanRunDataCommand.js +48 -0
  18. package/dist/commands/InitDirectoryCommand.d.ts +20 -0
  19. package/dist/commands/InitDirectoryCommand.d.ts.map +1 -0
  20. package/dist/commands/InitDirectoryCommand.js +48 -0
  21. package/dist/commands/ListScenariosCommand.d.ts +17 -0
  22. package/dist/commands/ListScenariosCommand.d.ts.map +1 -0
  23. package/dist/commands/ListScenariosCommand.js +51 -0
  24. package/dist/commands/MemLabRunCommand.d.ts +20 -0
  25. package/dist/commands/MemLabRunCommand.d.ts.map +1 -0
  26. package/dist/commands/MemLabRunCommand.js +66 -0
  27. package/dist/commands/PrintSummaryCommand.d.ts +20 -0
  28. package/dist/commands/PrintSummaryCommand.d.ts.map +1 -0
  29. package/dist/commands/PrintSummaryCommand.js +55 -0
  30. package/dist/commands/ResetDirectoryCommand.d.ts +19 -0
  31. package/dist/commands/ResetDirectoryCommand.d.ts.map +1 -0
  32. package/dist/commands/ResetDirectoryCommand.js +46 -0
  33. package/dist/commands/RunMeasureCommand.d.ts +20 -0
  34. package/dist/commands/RunMeasureCommand.d.ts.map +1 -0
  35. package/dist/commands/RunMeasureCommand.js +82 -0
  36. package/dist/commands/WarmupAppCommand.d.ts +20 -0
  37. package/dist/commands/WarmupAppCommand.d.ts.map +1 -0
  38. package/dist/commands/WarmupAppCommand.js +65 -0
  39. package/dist/commands/heap/CheckLeakCommand.d.ts +21 -0
  40. package/dist/commands/heap/CheckLeakCommand.d.ts.map +1 -0
  41. package/dist/commands/heap/CheckLeakCommand.js +94 -0
  42. package/dist/commands/heap/GetRetainerTraceCommand.d.ts +21 -0
  43. package/dist/commands/heap/GetRetainerTraceCommand.d.ts.map +1 -0
  44. package/dist/commands/heap/GetRetainerTraceCommand.js +92 -0
  45. package/dist/commands/heap/HeapAnalysisCommand.d.ts +21 -0
  46. package/dist/commands/heap/HeapAnalysisCommand.d.ts.map +1 -0
  47. package/dist/commands/heap/HeapAnalysisCommand.js +98 -0
  48. package/dist/commands/heap/HeapAnalysisSubCommandWrapper.d.ts +23 -0
  49. package/dist/commands/heap/HeapAnalysisSubCommandWrapper.d.ts.map +1 -0
  50. package/dist/commands/heap/HeapAnalysisSubCommandWrapper.js +68 -0
  51. package/dist/commands/helper/HelperCommand.d.ts +37 -0
  52. package/dist/commands/helper/HelperCommand.d.ts.map +1 -0
  53. package/dist/commands/helper/HelperCommand.js +262 -0
  54. package/dist/commands/helper/lib/CommandOrder.d.ts +13 -0
  55. package/dist/commands/helper/lib/CommandOrder.d.ts.map +1 -0
  56. package/dist/commands/helper/lib/CommandOrder.js +42 -0
  57. package/dist/commands/helper/lib/Types.d.ts +16 -0
  58. package/dist/commands/helper/lib/Types.d.ts.map +1 -0
  59. package/dist/commands/helper/lib/Types.js +11 -0
  60. package/dist/commands/query/QueryDefaultWorkDirCommand.d.ts +20 -0
  61. package/dist/commands/query/QueryDefaultWorkDirCommand.d.ts.map +1 -0
  62. package/dist/commands/query/QueryDefaultWorkDirCommand.js +67 -0
  63. package/dist/commands/snapshot/CheckXvfbSupportCommand.d.ts +18 -0
  64. package/dist/commands/snapshot/CheckXvfbSupportCommand.d.ts.map +1 -0
  65. package/dist/commands/snapshot/CheckXvfbSupportCommand.js +55 -0
  66. package/dist/commands/snapshot/Snapshot.d.ts +11 -0
  67. package/dist/commands/snapshot/Snapshot.d.ts.map +1 -0
  68. package/dist/commands/snapshot/Snapshot.js +47 -0
  69. package/dist/commands/snapshot/TakeSnapshotCommand.d.ts +20 -0
  70. package/dist/commands/snapshot/TakeSnapshotCommand.d.ts.map +1 -0
  71. package/dist/commands/snapshot/TakeSnapshotCommand.js +80 -0
  72. package/dist/commands/snapshot/WarmupAndSnapshotCommand.d.ts +18 -0
  73. package/dist/commands/snapshot/WarmupAndSnapshotCommand.d.ts.map +1 -0
  74. package/dist/commands/snapshot/WarmupAndSnapshotCommand.js +49 -0
  75. package/dist/commands/test/BrowserTest.d.ts +11 -0
  76. package/dist/commands/test/BrowserTest.d.ts.map +1 -0
  77. package/dist/commands/test/BrowserTest.js +41 -0
  78. package/dist/commands/test/RunAllInteractionTestsCommand.d.ts +19 -0
  79. package/dist/commands/test/RunAllInteractionTestsCommand.d.ts.map +1 -0
  80. package/dist/commands/test/RunAllInteractionTestsCommand.js +71 -0
  81. package/dist/commands/test/RunInteractionTestCommand.d.ts +19 -0
  82. package/dist/commands/test/RunInteractionTestCommand.d.ts.map +1 -0
  83. package/dist/commands/test/RunInteractionTestCommand.js +75 -0
  84. package/dist/index.d.ts +11 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +26 -0
  87. package/dist/options/AppOption.d.ts +19 -0
  88. package/dist/options/AppOption.d.ts.map +1 -0
  89. package/dist/options/AppOption.js +42 -0
  90. package/dist/options/DebugOption.d.ts +18 -0
  91. package/dist/options/DebugOption.d.ts.map +1 -0
  92. package/dist/options/DebugOption.js +37 -0
  93. package/dist/options/DisableXvfbOption.d.ts +18 -0
  94. package/dist/options/DisableXvfbOption.d.ts.map +1 -0
  95. package/dist/options/DisableXvfbOption.js +37 -0
  96. package/dist/options/FullExecutionOption.d.ts +18 -0
  97. package/dist/options/FullExecutionOption.d.ts.map +1 -0
  98. package/dist/options/FullExecutionOption.js +37 -0
  99. package/dist/options/HeapNodeIdOption.d.ts +19 -0
  100. package/dist/options/HeapNodeIdOption.d.ts.map +1 -0
  101. package/dist/options/HeapNodeIdOption.js +46 -0
  102. package/dist/options/HelperOption.d.ts +19 -0
  103. package/dist/options/HelperOption.d.ts.map +1 -0
  104. package/dist/options/HelperOption.js +39 -0
  105. package/dist/options/InteractionOption.d.ts +19 -0
  106. package/dist/options/InteractionOption.d.ts.map +1 -0
  107. package/dist/options/InteractionOption.js +42 -0
  108. package/dist/options/NumberOfRunsOption.d.ts +20 -0
  109. package/dist/options/NumberOfRunsOption.d.ts.map +1 -0
  110. package/dist/options/NumberOfRunsOption.js +44 -0
  111. package/dist/options/RemoteBrowserDebugOption.d.ts +18 -0
  112. package/dist/options/RemoteBrowserDebugOption.d.ts.map +1 -0
  113. package/dist/options/RemoteBrowserDebugOption.js +37 -0
  114. package/dist/options/RunningModeOption.d.ts +19 -0
  115. package/dist/options/RunningModeOption.d.ts.map +1 -0
  116. package/dist/options/RunningModeOption.js +40 -0
  117. package/dist/options/ScenarioFileOption.d.ts +19 -0
  118. package/dist/options/ScenarioFileOption.d.ts.map +1 -0
  119. package/dist/options/ScenarioFileOption.js +44 -0
  120. package/dist/options/SetContinuousTestOption.d.ts +18 -0
  121. package/dist/options/SetContinuousTestOption.d.ts.map +1 -0
  122. package/dist/options/SetContinuousTestOption.js +37 -0
  123. package/dist/options/SetDeviceOption.d.ts +19 -0
  124. package/dist/options/SetDeviceOption.d.ts.map +1 -0
  125. package/dist/options/SetDeviceOption.js +46 -0
  126. package/dist/options/SetWorkingDirectoryOption.d.ts +20 -0
  127. package/dist/options/SetWorkingDirectoryOption.d.ts.map +1 -0
  128. package/dist/options/SetWorkingDirectoryOption.js +40 -0
  129. package/dist/options/SilentOption.d.ts +19 -0
  130. package/dist/options/SilentOption.d.ts.map +1 -0
  131. package/dist/options/SilentOption.js +40 -0
  132. package/dist/options/SkipExtraOperationOption.d.ts +18 -0
  133. package/dist/options/SkipExtraOperationOption.d.ts.map +1 -0
  134. package/dist/options/SkipExtraOperationOption.js +37 -0
  135. package/dist/options/SkipGCOption.d.ts +18 -0
  136. package/dist/options/SkipGCOption.d.ts.map +1 -0
  137. package/dist/options/SkipGCOption.js +37 -0
  138. package/dist/options/SkipScreenshotOption.d.ts +18 -0
  139. package/dist/options/SkipScreenshotOption.d.ts.map +1 -0
  140. package/dist/options/SkipScreenshotOption.js +37 -0
  141. package/dist/options/SkipScrollOption.d.ts +18 -0
  142. package/dist/options/SkipScrollOption.d.ts.map +1 -0
  143. package/dist/options/SkipScrollOption.js +37 -0
  144. package/dist/options/SkipSnapshotOption.d.ts +18 -0
  145. package/dist/options/SkipSnapshotOption.d.ts.map +1 -0
  146. package/dist/options/SkipSnapshotOption.js +37 -0
  147. package/dist/options/SkipWarmupOption.d.ts +18 -0
  148. package/dist/options/SkipWarmupOption.d.ts.map +1 -0
  149. package/dist/options/SkipWarmupOption.js +37 -0
  150. package/dist/options/VerboseOption.d.ts +19 -0
  151. package/dist/options/VerboseOption.d.ts.map +1 -0
  152. package/dist/options/VerboseOption.js +40 -0
  153. package/dist/options/heap/BaselineFileOption.d.ts +18 -0
  154. package/dist/options/heap/BaselineFileOption.d.ts.map +1 -0
  155. package/dist/options/heap/BaselineFileOption.js +53 -0
  156. package/dist/options/heap/FinalFileOption.d.ts +18 -0
  157. package/dist/options/heap/FinalFileOption.d.ts.map +1 -0
  158. package/dist/options/heap/FinalFileOption.js +53 -0
  159. package/dist/options/heap/JSEngineOption.d.ts +18 -0
  160. package/dist/options/heap/JSEngineOption.d.ts.map +1 -0
  161. package/dist/options/heap/JSEngineOption.js +46 -0
  162. package/dist/options/heap/LogTraceAsClusterOption.d.ts +18 -0
  163. package/dist/options/heap/LogTraceAsClusterOption.d.ts.map +1 -0
  164. package/dist/options/heap/LogTraceAsClusterOption.js +37 -0
  165. package/dist/options/heap/OversizeThresholdOption.d.ts +19 -0
  166. package/dist/options/heap/OversizeThresholdOption.d.ts.map +1 -0
  167. package/dist/options/heap/OversizeThresholdOption.js +45 -0
  168. package/dist/options/heap/SnapshotDirectoryOption.d.ts +18 -0
  169. package/dist/options/heap/SnapshotDirectoryOption.d.ts.map +1 -0
  170. package/dist/options/heap/SnapshotDirectoryOption.js +50 -0
  171. package/dist/options/heap/SnapshotFileOption.d.ts +18 -0
  172. package/dist/options/heap/SnapshotFileOption.d.ts.map +1 -0
  173. package/dist/options/heap/SnapshotFileOption.js +50 -0
  174. package/dist/options/heap/TargetFileOption.d.ts +18 -0
  175. package/dist/options/heap/TargetFileOption.d.ts.map +1 -0
  176. package/dist/options/heap/TargetFileOption.js +53 -0
  177. package/dist/options/heap/TraceAllObjectsOption.d.ts +18 -0
  178. package/dist/options/heap/TraceAllObjectsOption.d.ts.map +1 -0
  179. package/dist/options/heap/TraceAllObjectsOption.js +38 -0
  180. package/dist/options/heap/leak-filter/LeakFilterFileOption.d.ts +19 -0
  181. package/dist/options/heap/leak-filter/LeakFilterFileOption.d.ts.map +1 -0
  182. package/dist/options/heap/leak-filter/LeakFilterFileOption.js +41 -0
  183. package/dist/options/heap/leak-filter/examples/FilterLib.d.ts +12 -0
  184. package/dist/options/heap/leak-filter/examples/FilterLib.d.ts.map +1 -0
  185. package/dist/options/heap/leak-filter/examples/FilterLib.js +30 -0
  186. package/dist/options/heap/leak-filter/examples/dup-string-as-leak.example-1.d.ts +13 -0
  187. package/dist/options/heap/leak-filter/examples/dup-string-as-leak.example-1.d.ts.map +1 -0
  188. package/dist/options/heap/leak-filter/examples/dup-string-as-leak.example-1.js +30 -0
  189. package/dist/options/heap/leak-filter/examples/dup-string-as-leak.example-2.d.ts +16 -0
  190. package/dist/options/heap/leak-filter/examples/dup-string-as-leak.example-2.d.ts.map +1 -0
  191. package/dist/options/heap/leak-filter/examples/dup-string-as-leak.example-2.js +28 -0
  192. package/dist/options/heap/leak-filter/examples/large-object-as-leak.example.d.ts +3 -0
  193. package/dist/options/heap/leak-filter/examples/large-object-as-leak.example.d.ts.map +1 -0
  194. package/dist/options/heap/leak-filter/examples/large-object-as-leak.example.js +13 -0
  195. package/dist/runner.d.ts +11 -0
  196. package/dist/runner.d.ts.map +1 -0
  197. package/dist/runner.js +38 -0
  198. package/package.json +59 -0
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
35
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ };
43
+ var __importDefault = (this && this.__importDefault) || function (mod) {
44
+ return (mod && mod.__esModule) ? mod : { "default": mod };
45
+ };
46
+ var _a;
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ const chalk_1 = __importDefault(require("chalk"));
49
+ const string_width_1 = __importDefault(require("string-width"));
50
+ const core_1 = require("@memlab/core");
51
+ const CommandOrder_1 = __importDefault(require("./lib/CommandOrder"));
52
+ const BaseCommand_1 = __importStar(require("../../BaseCommand"));
53
+ class HelperCommand extends BaseCommand_1.default {
54
+ constructor() {
55
+ super(...arguments);
56
+ this.printedCommand = new Set();
57
+ this.universalOptions = [];
58
+ }
59
+ // The following terminal command will initiate with this command
60
+ // `memlab <command-name>`
61
+ getCommandName() {
62
+ return 'help';
63
+ }
64
+ // The description of this analysis will be printed by
65
+ // `memlab` or `memlab help`
66
+ getDescription() {
67
+ return 'list all MemLab CLI commands or print helper text for a specific command';
68
+ }
69
+ getExamples() {
70
+ return ['<COMMAND> [SUB-COMMANDS]'];
71
+ }
72
+ setUniversalOptions(options) {
73
+ this.universalOptions = options;
74
+ }
75
+ printHeader(options) {
76
+ var _a;
77
+ const indent = (_a = options.indent) !== null && _a !== void 0 ? _a : '';
78
+ core_1.info.topLevel(`\n${indent}memlab: memory leak detector for front-end JS\n`);
79
+ }
80
+ printCommandCategories(options) {
81
+ for (const category in BaseCommand_1.CommandCategory) {
82
+ const item = CommandOrder_1.default.find(item => item.category === category);
83
+ const commandsToPrintFirst = item ? item.commands : [];
84
+ this.printCategory(category, commandsToPrintFirst, options);
85
+ }
86
+ }
87
+ printCategoryHeader(category, options) {
88
+ var _a;
89
+ const indent = (_a = options.indent) !== null && _a !== void 0 ? _a : ' ';
90
+ const categoryName = category.toUpperCase();
91
+ core_1.info.topLevel(chalk_1.default.bold(`${indent}${categoryName} COMMANDS`));
92
+ core_1.info.topLevel('');
93
+ }
94
+ printCategory(category, commandsToPrintFirst, options) {
95
+ this.printCategoryHeader(category, options);
96
+ for (const command of commandsToPrintFirst) {
97
+ const name = command.getCommandName();
98
+ if (this.printedCommand.has(name)) {
99
+ continue;
100
+ }
101
+ this.printCommand(command, options.indent);
102
+ this.printedCommand.add(name);
103
+ }
104
+ // print other commands in this category
105
+ for (const moduleEntries of options.modules) {
106
+ const command = moduleEntries[1];
107
+ if (category !== command.getCategory()) {
108
+ continue;
109
+ }
110
+ if (command.isInternalCommand() && !core_1.config.verbose) {
111
+ continue;
112
+ }
113
+ const name = command.getCommandName();
114
+ if (this.printedCommand.has(name)) {
115
+ continue;
116
+ }
117
+ this.printCommand(command, options.indent);
118
+ this.printedCommand.add(name);
119
+ }
120
+ core_1.info.topLevel('');
121
+ }
122
+ getCommandOptionsSummary(command, indent = '') {
123
+ const options = command.getFullOptionsFromPrerequisiteChain();
124
+ if (options.length === 0) {
125
+ return '';
126
+ }
127
+ const width = Math.min(70, process.stdout.columns);
128
+ let summary = '';
129
+ let curLine = chalk_1.default.bold(`${indent}Options:`);
130
+ for (const option of options) {
131
+ const optionToAppend = ' --' + option.getOptionName();
132
+ if ((0, string_width_1.default)(curLine + optionToAppend) > width) {
133
+ summary += (summary.length > 0 ? '\n' : '') + curLine;
134
+ curLine = indent + ' ';
135
+ }
136
+ curLine += optionToAppend;
137
+ }
138
+ return summary + (summary.length > 0 ? '\n' : '') + curLine;
139
+ }
140
+ printOptions(command, extraIndent = '') {
141
+ const options = [
142
+ ...command.getFullOptionsFromPrerequisiteChain(),
143
+ ...this.universalOptions,
144
+ ];
145
+ if (options.length === 0) {
146
+ return;
147
+ }
148
+ const indent = ' ' + extraIndent;
149
+ core_1.info.topLevel('\n' + extraIndent + chalk_1.default.bold('COMMAND LINE OPTIONS'));
150
+ const optionsText = [];
151
+ for (const option of options) {
152
+ let header = `--${option.getOptionName()}`;
153
+ if (option.getOptionShortcut()) {
154
+ header += `, -${option.getOptionShortcut()}`;
155
+ }
156
+ const desc = option.getDescription();
157
+ optionsText.push({ header, desc });
158
+ }
159
+ const headerLength = optionsText.reduce((acc, cur) => Math.max(acc, cur.header.length), 0);
160
+ for (const optionText of optionsText) {
161
+ const header = chalk_1.default.green(optionText.header);
162
+ const prefix = core_1.utils.repeat(' ', headerLength - optionText.header.length);
163
+ const msg = `${indent}${prefix}${header} ${optionText.desc}`;
164
+ core_1.info.topLevel(`\n${msg}`);
165
+ }
166
+ }
167
+ printCommand(command, extraIndent = '', printOptions = false) {
168
+ const indent = ' ' + extraIndent;
169
+ const name = command.getFullCommand();
170
+ const desc = core_1.utils.upperCaseFirstCharacter(command.getDescription());
171
+ // get example
172
+ const examples = command.getExamples();
173
+ let example = '';
174
+ if (examples.length > 0) {
175
+ example = ' ' + examples[0].trim();
176
+ }
177
+ const cmd = chalk_1.default.green(`memlab ${name}${example}`);
178
+ let msg = `${indent}${cmd}`;
179
+ msg += `\n${indent}${desc}`;
180
+ core_1.info.topLevel(msg);
181
+ // print options info
182
+ if (printOptions) {
183
+ // print full options description
184
+ this.printOptions(command, indent);
185
+ }
186
+ else {
187
+ // print options list summary
188
+ const options = this.getCommandOptionsSummary(command, indent);
189
+ if (options.length > 0) {
190
+ core_1.info.topLevel(chalk_1.default.grey(`${options}`));
191
+ }
192
+ }
193
+ core_1.info.topLevel('');
194
+ }
195
+ printHelperTextForCommand(command, options) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ // print helper text for a specific command
198
+ this.printCommand(command, options.indent, options.printOptions);
199
+ // print helper text for its subcommands
200
+ const subcommands = command.getSubCommands();
201
+ const subOptions = Object.assign({}, options);
202
+ subOptions.indent = (subOptions.indent || '') + ' ';
203
+ for (const subcommand of subcommands) {
204
+ subOptions.command = subcommand;
205
+ yield this.run(subOptions);
206
+ }
207
+ });
208
+ }
209
+ printFullHelperTextForCommand(args, modules) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ // get the command to print
212
+ let map = modules;
213
+ let command;
214
+ const commandNames = [...args._];
215
+ while (commandNames.length > 0) {
216
+ const name = commandNames.shift();
217
+ if (!name) {
218
+ break;
219
+ }
220
+ command = map.get(name);
221
+ if (!command) {
222
+ break;
223
+ }
224
+ const subCommands = command.getSubCommands();
225
+ map = new Map(subCommands.map((cmd) => [cmd.getCommandName(), cmd]));
226
+ }
227
+ if (!command) {
228
+ throw core_1.utils.haltOrThrow(`Could not find command: memlab ${args._.join(' ')}`);
229
+ }
230
+ // print the helper text of the command
231
+ core_1.info.topLevel('');
232
+ this.printCommand(command, '', true);
233
+ // print the helper text of the subcommands
234
+ const subCommands = command.getSubCommands();
235
+ if (subCommands.length > 0) {
236
+ core_1.info.topLevel(chalk_1.default.bold(' SUB-COMMANDS\n'));
237
+ for (const subCommand of subCommands) {
238
+ this.printCommand(subCommand, ' ');
239
+ }
240
+ }
241
+ });
242
+ }
243
+ run(options) {
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ this.printedCommand.clear();
246
+ if (options.command) {
247
+ yield this.printHelperTextForCommand(options.command, options);
248
+ }
249
+ else if (options.cliArgs && options.cliArgs._.length > 0) {
250
+ yield this.printFullHelperTextForCommand(options.cliArgs, options.modules);
251
+ }
252
+ else {
253
+ // print helper text for all commands
254
+ this.printHeader(options);
255
+ this.printCommandCategories(options);
256
+ }
257
+ });
258
+ }
259
+ }
260
+ exports.default = HelperCommand;
261
+ // add the helper command into the common commands
262
+ (_a = CommandOrder_1.default === null || CommandOrder_1.default === void 0 ? void 0 : CommandOrder_1.default.find(item => item.category === BaseCommand_1.CommandCategory.COMMON)) === null || _a === void 0 ? void 0 : _a.commands.push(new HelperCommand());
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import type { CommandOrder } from './Types';
11
+ declare const _default: CommandOrder;
12
+ export default _default;
13
+ //# sourceMappingURL=CommandOrder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandOrder.d.ts","sourceRoot":"","sources":["../../../../src/commands/helper/lib/CommandOrder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;;AA8B1C,wBAAgF"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const core_1 = require("@memlab/core");
16
+ const BaseCommand_1 = require("../../../BaseCommand");
17
+ const MemLabRunCommand_1 = __importDefault(require("../../MemLabRunCommand"));
18
+ const ListScenariosCommand_1 = __importDefault(require("../../ListScenariosCommand"));
19
+ const CheckLeakCommand_1 = __importDefault(require("../../heap/CheckLeakCommand"));
20
+ const GetRetainerTraceCommand_1 = __importDefault(require("../../heap/GetRetainerTraceCommand"));
21
+ const HeapAnalysisCommand_1 = __importDefault(require("../../heap/HeapAnalysisCommand"));
22
+ const commandOrder = [
23
+ {
24
+ category: BaseCommand_1.CommandCategory.COMMON,
25
+ commands: [
26
+ new MemLabRunCommand_1.default(),
27
+ new ListScenariosCommand_1.default(),
28
+ new GetRetainerTraceCommand_1.default(),
29
+ new CheckLeakCommand_1.default(),
30
+ new HeapAnalysisCommand_1.default(),
31
+ ],
32
+ },
33
+ {
34
+ category: BaseCommand_1.CommandCategory.DEV,
35
+ commands: [],
36
+ },
37
+ {
38
+ category: BaseCommand_1.CommandCategory.MISC,
39
+ commands: [],
40
+ },
41
+ ];
42
+ exports.default = (0, core_1.setInternalValue)(commandOrder, __filename, core_1.constant.internalDir);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import BaseCommand, { CommandCategory } from '../../../BaseCommand';
11
+ export declare type CommandOrderItem = {
12
+ category: CommandCategory;
13
+ commands: BaseCommand[];
14
+ };
15
+ export declare type CommandOrder = Array<CommandOrderItem>;
16
+ //# sourceMappingURL=Types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../../src/commands/helper/lib/Types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,WAAW,EAAE,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAElE,oBAAY,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB,CAAC;AAEF,oBAAY,YAAY,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import { CLIOptions } from '@memlab/core';
11
+ import BaseCommand, { CommandCategory } from '../../BaseCommand';
12
+ import { BaseOption } from '@memlab/core';
13
+ export default class QueryDefaultWorkDirCommand extends BaseCommand {
14
+ getCommandName(): string;
15
+ getDescription(): string;
16
+ getCategory(): CommandCategory;
17
+ getOptions(): BaseOption[];
18
+ run(_options: CLIOptions): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=QueryDefaultWorkDirCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryDefaultWorkDirCommand.d.ts","sourceRoot":"","sources":["../../../src/commands/query/QueryDefaultWorkDirCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAC,UAAU,EAAO,MAAM,cAAc,CAAC;AAE9C,OAAO,WAAW,EAAE,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAc,UAAU,EAAC,MAAM,cAAc,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,WAAW;IACjE,cAAc,IAAI,MAAM;IAIxB,cAAc,IAAI,MAAM;IAIxB,WAAW,IAAI,eAAe;IAI9B,UAAU,IAAI,UAAU,EAAE;IAKpB,GAAG,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/C"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
35
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ const core_1 = require("@memlab/core");
45
+ const BaseCommand_1 = __importStar(require("../../BaseCommand"));
46
+ const core_2 = require("@memlab/core");
47
+ class QueryDefaultWorkDirCommand extends BaseCommand_1.default {
48
+ getCommandName() {
49
+ return 'get-default-work-dir';
50
+ }
51
+ getDescription() {
52
+ return 'query the default working directory';
53
+ }
54
+ getCategory() {
55
+ return BaseCommand_1.CommandCategory.MISC;
56
+ }
57
+ getOptions() {
58
+ return [];
59
+ }
60
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
+ run(_options) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ core_1.info.topLevel(core_2.fileManager.getWorkDir());
64
+ });
65
+ }
66
+ }
67
+ exports.default = QueryDefaultWorkDirCommand;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import type { CLIOptions } from '@memlab/core';
11
+ import BaseCommand from '../../BaseCommand';
12
+ export default class CheckXvfbSupportCommand extends BaseCommand {
13
+ getCommandName(): string;
14
+ getDescription(): string;
15
+ isInternalCommand(): boolean;
16
+ run(_options: CLIOptions): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=CheckXvfbSupportCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckXvfbSupportCommand.d.ts","sourceRoot":"","sources":["../../../src/commands/snapshot/CheckXvfbSupportCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAG7C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAG5C,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,WAAW;IAC9D,cAAc,IAAI,MAAM;IAIxB,cAAc,IAAI,MAAM;IAIxB,iBAAiB,IAAI,OAAO;IAKtB,GAAG,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAa/C"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ const child_process_1 = __importDefault(require("child_process"));
25
+ const BaseCommand_1 = __importDefault(require("../../BaseCommand"));
26
+ const core_1 = require("@memlab/core");
27
+ class CheckXvfbSupportCommand extends BaseCommand_1.default {
28
+ getCommandName() {
29
+ return 'check-xvfb';
30
+ }
31
+ getDescription() {
32
+ return 'if Xvfb is installed on the machine, enable it';
33
+ }
34
+ isInternalCommand() {
35
+ return true;
36
+ }
37
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ run(_options) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ try {
41
+ const ret = child_process_1.default.execSync('command -v xvfb-run').toString();
42
+ if (ret) {
43
+ core_1.config.machineSupportsXVFB = true;
44
+ }
45
+ }
46
+ catch (_a) {
47
+ // the env doesn't support XVFB, no need to do anything;
48
+ }
49
+ if (core_1.config.verbose) {
50
+ core_1.info.lowLevel(`Xvfb supports: ${core_1.config.machineSupportsXVFB}`);
51
+ }
52
+ });
53
+ }
54
+ }
55
+ exports.default = CheckXvfbSupportCommand;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ export declare function runPageInteractionFromCLI(): Promise<void>;
11
+ //# sourceMappingURL=Snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Snapshot.d.ts","sourceRoot":"","sources":["../../../src/commands/snapshot/Snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAoB/D"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @emails oncall+ws_labs
9
+ * @format
10
+ */
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.runPageInteractionFromCLI = void 0;
22
+ const core_1 = require("@memlab/core");
23
+ const api_1 = require("@memlab/api");
24
+ function runPageInteractionFromCLI() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const start = Date.now();
27
+ try {
28
+ yield (0, api_1.testInBrowser)();
29
+ }
30
+ catch (e) {
31
+ const error = core_1.utils.getError(e);
32
+ if (error.message.indexOf('cannot open display') < 0) {
33
+ // fail due to other errors
34
+ core_1.utils.haltOrThrow(error);
35
+ }
36
+ if (core_1.config.verbose) {
37
+ core_1.info.lowLevel('failed to start Chrome with display, disabling xvfb...');
38
+ }
39
+ core_1.config.machineSupportsXVFB = false;
40
+ core_1.config.disableXvfb();
41
+ yield (0, api_1.testInBrowser)();
42
+ }
43
+ const end = Date.now();
44
+ core_1.info.topLevel(`total time: ${core_1.utils.getReadableTime(end - start)}`);
45
+ });
46
+ }
47
+ exports.runPageInteractionFromCLI = runPageInteractionFromCLI;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails oncall+ws_labs
8
+ * @format
9
+ */
10
+ import type { CLIOptions } from '@memlab/core';
11
+ import BaseCommand from '../../BaseCommand';
12
+ import { BaseOption } from '@memlab/core';
13
+ export default class TakeSnapshotCommand extends BaseCommand {
14
+ getCommandName(): string;
15
+ getDescription(): string;
16
+ getPrerequisites(): BaseCommand[];
17
+ getOptions(): BaseOption[];
18
+ run(_options: CLIOptions): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=TakeSnapshotCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TakeSnapshotCommand.d.ts","sourceRoot":"","sources":["../../../src/commands/snapshot/TakeSnapshotCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAE7C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAiBxC,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,WAAW;IAC1D,cAAc,IAAI,MAAM;IAIxB,cAAc,IAAI,MAAM;IAIxB,gBAAgB,IAAI,WAAW,EAAE;IAQjC,UAAU,IAAI,UAAU,EAAE;IAmBpB,GAAG,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/C"}