binary-collections 2.0.6 → 2.0.8

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 (183) hide show
  1. package/bin/dir-tree.cmd +7 -0
  2. package/bin/git-diff +4 -0
  3. package/bin/git-diff.cmd +7 -0
  4. package/bin/{git-fix-encoding → git-fix} +1 -4
  5. package/bin/git-fix.cmd +7 -0
  6. package/bin/nodekill +0 -0
  7. package/bin/nodekill.cmd +0 -0
  8. package/bin/{submodule-install → submodule-install.txt} +0 -0
  9. package/bin/{submodule → submodule.txt} +0 -0
  10. package/lib/binary-collections-config.cjs +14 -0
  11. package/lib/binary-collections-config.d.mts +18 -0
  12. package/lib/binary-collections-config.d.ts +16 -0
  13. package/lib/binary-collections-config.js +39 -0
  14. package/lib/binary-collections-config.mjs +6 -0
  15. package/lib/binary-collections.cjs +105 -0
  16. package/lib/binary-collections.d.cts +2 -0
  17. package/lib/binary-collections.d.mts +121 -0
  18. package/lib/binary-collections.d.ts +121 -0
  19. package/lib/binary-collections.mjs +108 -0
  20. package/lib/chunk-4BYBVEYC.mjs +30 -0
  21. package/lib/chunk-AASHBCRW.mjs +57 -0
  22. package/lib/chunk-APBWENF6.mjs +135 -0
  23. package/lib/{chunk-M4IBUK4H.mjs → chunk-DPKAJKFO.mjs} +2 -4
  24. package/lib/chunk-EGSSKVDH.mjs +66 -0
  25. package/lib/{chunk-GA4DDV65.mjs → chunk-G3THLIDT.mjs} +3 -5
  26. package/lib/chunk-JGR2NW6D.mjs +187 -0
  27. package/lib/chunk-ONIBBBQ3.mjs +108 -0
  28. package/lib/chunk-SH3L6HHV.mjs +27 -0
  29. package/lib/chunk-VVEZVNIV.mjs +81 -0
  30. package/lib/{chunk-E75HJFJO.mjs → chunk-W3ENOM53.mjs} +2 -4
  31. package/lib/chunk-YV7DO3YV.mjs +48 -0
  32. package/lib/chunk-YX5U7XDR.mjs +58 -0
  33. package/lib/chunk-ZYAQRPUL.mjs +28 -0
  34. package/lib/clean-github-actions-caches.cjs +162 -0
  35. package/lib/clean-github-actions-caches.d.cts +1 -0
  36. package/lib/clean-github-actions-caches.d.mts +169 -0
  37. package/lib/clean-github-actions-caches.d.ts +169 -0
  38. package/lib/clean-github-actions-caches.mjs +132 -0
  39. package/lib/del-gradle.cjs +99 -15
  40. package/lib/del-gradle.d.ts +1 -2
  41. package/lib/del-gradle.js +12 -69
  42. package/lib/del-gradle.mjs +4 -6
  43. package/lib/del-node-modules.cjs +98 -14
  44. package/lib/del-node-modules.d.ts +1 -2
  45. package/lib/del-node-modules.js +11 -68
  46. package/lib/del-node-modules.mjs +3 -5
  47. package/lib/del-ps.cjs +98 -627
  48. package/lib/del-ps.d.ts +1 -2
  49. package/lib/del-ps.js +27 -702
  50. package/lib/del-ps.mjs +7 -12
  51. package/lib/del-yarn-caches.cjs +98 -14
  52. package/lib/del-yarn-caches.d.ts +1 -2
  53. package/lib/del-yarn-caches.js +6 -63
  54. package/lib/del-yarn-caches.mjs +3 -5
  55. package/lib/find-node-modules-cli.cjs +67 -0
  56. package/lib/find-node-modules-cli.d.mts +1 -0
  57. package/lib/find-node-modules-cli.d.ts +2 -0
  58. package/lib/find-node-modules-cli.js +3 -0
  59. package/lib/find-node-modules-cli.mjs +13 -0
  60. package/lib/find-node-modules.cjs +39 -9
  61. package/lib/find-node-modules.d.mts +12 -1
  62. package/lib/find-node-modules.d.ts +12 -2
  63. package/lib/find-node-modules.js +53 -12
  64. package/lib/find-node-modules.mjs +4 -19
  65. package/lib/git/gitattributes.cjs +171 -0
  66. package/lib/git/gitattributes.d.mts +35 -0
  67. package/lib/git/gitattributes.d.ts +33 -0
  68. package/lib/git/gitattributes.js +223 -0
  69. package/lib/git/gitattributes.mjs +6 -0
  70. package/lib/git/line-endings.cjs +74 -0
  71. package/lib/git/line-endings.d.cts +7 -0
  72. package/lib/git/line-endings.d.mts +83 -0
  73. package/lib/git/line-endings.d.ts +83 -0
  74. package/lib/git/line-endings.mjs +8 -0
  75. package/lib/git/normalize.cjs +42 -0
  76. package/lib/git/normalize.d.cts +6 -0
  77. package/lib/git/normalize.d.mts +43 -0
  78. package/lib/git/normalize.d.ts +43 -0
  79. package/lib/git/normalize.mjs +6 -0
  80. package/lib/git/permissions.cjs +15 -0
  81. package/lib/git/permissions.d.cts +6 -0
  82. package/lib/git/permissions.d.mts +17 -0
  83. package/lib/git/permissions.d.ts +17 -0
  84. package/lib/git/permissions.mjs +7 -0
  85. package/lib/git/pull-strategy.cjs +13 -0
  86. package/lib/git/pull-strategy.d.cts +5 -0
  87. package/lib/git/pull-strategy.d.mts +15 -0
  88. package/lib/git/pull-strategy.d.ts +15 -0
  89. package/lib/git/pull-strategy.mjs +7 -0
  90. package/lib/git/user-config.cjs +100 -0
  91. package/lib/git/user-config.d.cts +10 -0
  92. package/lib/git/user-config.d.mts +105 -0
  93. package/lib/git/user-config.d.ts +105 -0
  94. package/lib/git/user-config.mjs +8 -0
  95. package/lib/git/utils.cjs +70 -0
  96. package/lib/git/utils.d.cts +20 -0
  97. package/lib/git/utils.d.mts +69 -0
  98. package/lib/git/utils.d.ts +69 -0
  99. package/lib/git/utils.mjs +6 -0
  100. package/lib/git-diff.cjs +73 -0
  101. package/lib/git-diff.d.cts +2 -0
  102. package/lib/git-diff.d.mts +84 -0
  103. package/lib/git-diff.d.ts +84 -0
  104. package/lib/git-diff.mjs +88 -0
  105. package/lib/git-fix.cjs +129 -0
  106. package/lib/git-fix.d.cts +2 -0
  107. package/lib/git-fix.d.mts +141 -0
  108. package/lib/git-fix.d.ts +141 -0
  109. package/lib/git-fix.mjs +151 -0
  110. package/lib/git-purge.cjs +92 -621
  111. package/lib/git-purge.d.ts +1 -2
  112. package/lib/git-purge.js +53 -698
  113. package/lib/git-purge.mjs +4 -9
  114. package/lib/index.cjs +99 -1
  115. package/lib/index.d.mts +1 -2
  116. package/lib/index.d.ts +2 -2
  117. package/lib/index.js +8 -2
  118. package/lib/index.mjs +10 -3
  119. package/lib/npm-run-series.cjs +140 -1
  120. package/lib/npm-run-series.d.ts +1 -0
  121. package/lib/npm-run-series.js +81 -56
  122. package/lib/npm-run-series.mjs +7 -5
  123. package/lib/package-resolutions-updater.cjs +274 -0
  124. package/lib/package-resolutions-updater.d.mts +1 -0
  125. package/lib/package-resolutions-updater.d.ts +326 -0
  126. package/lib/package-resolutions-updater.mjs +316 -0
  127. package/lib/print-directory-tree.cjs +241 -0
  128. package/lib/print-directory-tree.d.cts +1 -0
  129. package/lib/print-directory-tree.d.mts +234 -0
  130. package/lib/print-directory-tree.d.ts +234 -0
  131. package/lib/print-directory-tree.mjs +182 -0
  132. package/lib/ps/connected-domain.cjs +0 -0
  133. package/lib/ps/connected-domain.d.ts +1 -2
  134. package/lib/ps/connected-domain.js +196 -150
  135. package/lib/ps/connected-domain.mjs +2 -3
  136. package/lib/ps/index.cjs +3 -3
  137. package/lib/ps/index.d.mjs +1 -2
  138. package/lib/ps/index.d.ts +2 -26
  139. package/lib/ps/index.js +233 -535
  140. package/lib/ps/index.mjs +9 -11
  141. package/lib/ps/isWin.cjs +0 -0
  142. package/lib/ps/isWin.d.ts +1 -2
  143. package/lib/ps/isWin.js +1 -2
  144. package/lib/ps/isWin.mjs +2 -3
  145. package/lib/ps/table-parser.cjs +0 -0
  146. package/lib/ps/table-parser.d.ts +1 -3
  147. package/lib/ps/table-parser.js +254 -345
  148. package/lib/ps/table-parser.mjs +3 -4
  149. package/lib/submodule-install.cjs +100 -0
  150. package/lib/submodule-install.d.cts +2 -0
  151. package/lib/submodule-install.d.mts +121 -0
  152. package/lib/submodule-install.d.ts +121 -0
  153. package/lib/submodule-install.mjs +107 -0
  154. package/lib/utils.cjs +98 -14
  155. package/lib/utils.d.mts +29 -9
  156. package/lib/utils.d.ts +30 -14
  157. package/lib/utils.js +173 -27
  158. package/lib/utils.mjs +2 -3
  159. package/lib/yarn-reinstall.cjs +44 -0
  160. package/lib/yarn-reinstall.d.cts +1 -0
  161. package/lib/yarn-reinstall.d.mts +49 -0
  162. package/lib/yarn-reinstall.d.ts +49 -0
  163. package/lib/yarn-reinstall.mjs +54 -0
  164. package/package.json +126 -99
  165. package/readme.md +238 -50
  166. package/src/package-resolutions-updater.mjs +325 -0
  167. package/src/print-directory-tree.cjs +234 -0
  168. package/src/ps/index.js +4 -3
  169. package/src/yarn-reinstall.cjs +49 -0
  170. package/test-project/package.json +16 -0
  171. package/tmp/test-repo/package.json +7 -0
  172. package/bin/git-fix-encoding.cmd +0 -6
  173. package/eslint.config.cjs +0 -97
  174. package/lib/chunk-7MSZ52XC.mjs +0 -14
  175. package/lib/chunk-AVDT32AY.mjs +0 -20
  176. package/lib/chunk-LPLPQBYP.mjs +0 -53
  177. package/lib/chunk-S4SJ7SDW.mjs +0 -625
  178. package/lib/package-resolutions.cjs +0 -28
  179. package/lib/package-resolutions.d.mts +0 -25
  180. package/lib/package-resolutions.d.ts +0 -25
  181. package/lib/package-resolutions.js +0 -28
  182. package/lib/package-resolutions.mjs +0 -31
  183. package/lib/ps/index.d.js +0 -17
package/lib/ps/index.js CHANGED
@@ -1,555 +1,253 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __esm = (fn, res) => function __init() {
3
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
- };
5
- var __commonJS = (cb, mod) => function __require() {
6
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7
- };
8
-
9
- // node_modules/tsup/assets/cjs_shims.js
10
- var init_cjs_shims = __esm({
11
- "node_modules/tsup/assets/cjs_shims.js"() {
12
- }
13
- });
14
-
15
- // src/ps/isWin.js
16
- var require_isWin = __commonJS({
17
- "src/ps/isWin.js"(exports2, module2) {
18
- init_cjs_shims();
19
- var isWin = process.platform === "win32";
20
- module2.exports = isWin;
21
- }
22
- });
23
-
24
- // src/ps/connected-domain.js
25
- var require_connected_domain = __commonJS({
26
- "src/ps/connected-domain.js"(exports2, module2) {
27
- init_cjs_shims();
28
- module2.exports = function(tdArray, indicator, hardlink) {
29
- hardlink = hardlink || false;
30
- if (!tdArray) {
31
- throw new Error("tdArray must be provided");
32
- }
33
- if (!indicator) {
34
- throw new Error("indicator must be provided");
35
- }
36
- tdArray = JSON.parse(JSON.stringify(tdArray));
37
- var domains = {};
38
- var domainUUID = 0;
39
- var pointsHash = {};
40
- tdArray.forEach(function(row, y) {
41
- row.forEach(function(colItem, x) {
42
- var identifier2 = indicator(colItem, x, y);
43
- var neighbours = [];
44
- if (tdArray[y - 1] && tdArray[y - 1][x] !== void 0) {
45
- neighbours.push(pointsHash[x + "_" + (y - 1)]);
46
- }
47
- if (row[x - 1] !== void 0) {
48
- neighbours.push(pointsHash[x - 1 + "_" + y]);
49
- }
50
- if (!hardlink) {
51
- if (tdArray[y - 1] && tdArray[y - 1][x - 1] !== void 0) {
52
- neighbours.push(pointsHash[x - 1 + "_" + (y - 1)]);
53
- }
54
- if (tdArray[y - 1] && tdArray[y - 1][x + 1] !== void 0) {
55
- neighbours.push(pointsHash[x + 1 + "_" + (y - 1)]);
1
+ var ChildProcess = require("child_process");
2
+ var IS_WIN = require("./isWin");
3
+ var TableParser = require("./table-parser");
4
+ /**
5
+ * End of line.
6
+ * Basically, the EOL should be:
7
+ * - windows: \r\n
8
+ * - *nix: \n
9
+ * But i'm trying to get every possibilities covered.
10
+ */
11
+ var EOL = /(\r\n)|(\n\r)|\n|\r/;
12
+ var SystemEOL = require("os").EOL;
13
+ // ps-node
14
+ /**
15
+ * Execute child process
16
+ * @type {Function}
17
+ * @param {String[]} args
18
+ * @param {Function} callback
19
+ * @param {Object=null} callback.err
20
+ * @param {Object[]} callback.stdout
21
+ */
22
+ var Exec = (module.exports =
23
+ exports =
24
+ function (args, callback) {
25
+ var spawn = ChildProcess.spawn;
26
+ // on windows, if use ChildProcess.exec(`wmic process get`), the stdout will gives you nothing
27
+ // that's why I use `cmd` instead
28
+ if (IS_WIN) {
29
+ var CMD = spawn("cmd");
30
+ var stdout = "";
31
+ var stderr = null;
32
+ CMD.stdout.on("data", function (data) {
33
+ stdout += data.toString();
34
+ });
35
+ CMD.stderr.on("data", function (data) {
36
+ if (stderr === null) {
37
+ stderr = data.toString();
38
+ }
39
+ else {
40
+ stderr += data.toString();
41
+ }
42
+ });
43
+ CMD.on("exit", function () {
44
+ var beginRow;
45
+ stdout = stdout.split(EOL);
46
+ // Find the line index for the titles
47
+ stdout.forEach(function (out, index) {
48
+ if (out && typeof beginRow == "undefined" && out.indexOf("CommandLine") === 0) {
49
+ beginRow = index;
50
+ }
51
+ });
52
+ // get rid of the start (copyright) and the end (current pwd)
53
+ stdout.splice(stdout.length - 1, 1);
54
+ stdout.splice(0, beginRow);
55
+ callback(stderr, stdout.join(SystemEOL) || false);
56
+ });
57
+ CMD.stdin.write("wmic process get ProcessId,ParentProcessId,CommandLine \n");
58
+ CMD.stdin.end();
56
59
  }
57
- }
58
- if (neighbours.length) {
59
- var matched = false;
60
- neighbours.forEach(function(neighbour) {
61
- if (neighbour.identifier == identifier2) {
62
- if (!matched) {
63
- addPointToDomain(colItem, x, y, neighbour.domainId);
64
- matched = true;
65
- } else {
66
- var colItemPoint = pointsHash[x + "_" + y];
67
- if (neighbour.domainId != colItemPoint.domainId) {
68
- mergeDomains(neighbour.domainId, colItemPoint.domainId);
69
- }
60
+ else {
61
+ if (typeof args === "string") {
62
+ args = args.split(/\s+/);
70
63
  }
71
- }
72
- });
73
- if (!matched) {
74
- addNewDomain(colItem, x, y, identifier2);
64
+ const child = spawn("ps", args);
65
+ stdout = "";
66
+ stderr = null;
67
+ child.stdout.on("data", function (data) {
68
+ stdout += data.toString();
69
+ });
70
+ child.stderr.on("data", function (data) {
71
+ if (stderr === null) {
72
+ stderr = data.toString();
73
+ }
74
+ else {
75
+ stderr += data.toString();
76
+ }
77
+ });
78
+ child.on("exit", function () {
79
+ if (stderr) {
80
+ return callback(stderr.toString());
81
+ }
82
+ else {
83
+ callback(null, stdout || false);
84
+ }
85
+ });
75
86
  }
76
- } else {
77
- addNewDomain(colItem, x, y, identifier2);
78
- }
79
87
  });
80
- });
81
- var result = {
82
- domains: [],
83
- totalDomains: 0,
84
- groupByIdentifier: {},
85
- totalIdentifiers: 0
86
- };
87
- var domainId = null;
88
- var identifier = null;
89
- var domain = null;
90
- for (domainId in domains) {
91
- domain = domains[domainId];
92
- domain.bounding = calculateBounding(domain.points);
93
- identifier = domain.identifier;
94
- result.domains.push(domain);
95
- result.totalDomains++;
96
- if (!(identifier in result.groupByIdentifier)) {
97
- result.groupByIdentifier[identifier] = [];
98
- result.totalIdentifiers++;
88
+ /**
89
+ * Query Process: Focus on pid & cmd
90
+ * @param query
91
+ * @param {String|String[]} query.pid
92
+ * @param {String} query.command RegExp String
93
+ * @param {String} query.arguments RegExp String
94
+ * @param {String|array} query.psargs
95
+ * @param {Function} callback
96
+ * @param {Object=null} callback.err
97
+ * @param {Object[]} callback.processList
98
+ * @return {Object}
99
+ */
100
+ exports.lookup = function (query, callback) {
101
+ /**
102
+ * add 'lx' as default ps arguments, since the default ps output in linux like "ubuntu", wont include command arguments
103
+ */
104
+ var exeArgs = query.psargs || ["lx"];
105
+ var filter = {};
106
+ var idList;
107
+ // Lookup by PID
108
+ if (query.pid) {
109
+ if (Array.isArray(query.pid)) {
110
+ idList = query.pid;
99
111
  }
100
- result.groupByIdentifier[identifier].push(domain);
101
- }
102
- function calculateBounding(points) {
103
- var minX = null;
104
- var minY = null;
105
- var maxX = null;
106
- var maxY = null;
107
- points.forEach(function(point) {
108
- if (minX === null || point.x < minX) {
109
- minX = point.x;
110
- }
111
- if (minY === null || point.y < minY) {
112
- minY = point.y;
113
- }
114
- if (maxX === null || point.x > maxX) {
115
- maxX = point.x;
116
- }
117
- if (maxY === null || point.y > maxY) {
118
- maxY = point.y;
119
- }
120
- });
121
- var w = maxX - minX;
122
- var h = maxY - minY;
123
- return {
124
- x: minX,
125
- y: minY,
126
- w,
127
- h
128
- };
129
- }
130
- function addNewDomain(point, x, y, identifier2) {
131
- var newDomain = {
132
- identifier: identifier2,
133
- domainId: ++domainUUID,
134
- bounding: {},
135
- points: []
136
- };
137
- var newPoint = {
138
- value: point,
139
- x,
140
- y,
141
- identifier: identifier2,
142
- domainId: newDomain.domainId
143
- };
144
- pointsHash[x + "_" + y] = {
145
- value: point,
146
- identifier: identifier2,
147
- domainId: newDomain.domainId
148
- };
149
- newDomain.points.push(newPoint);
150
- domains[newDomain.domainId] = newDomain;
151
- }
152
- function addPointToDomain(point, x, y, domainId2) {
153
- var domain2 = domains[domainId2];
154
- var newPoint = {
155
- value: point,
156
- x,
157
- y,
158
- identifier: domain2.identifier,
159
- domainId: domainId2
160
- };
161
- pointsHash[x + "_" + y] = {
162
- value: point,
163
- identifier: domain2.identifier,
164
- domainId: domainId2
165
- };
166
- domain2.points.push(newPoint);
167
- }
168
- function mergeDomains(domainAId, domainBId) {
169
- var domainA = domains[domainAId];
170
- var domainB = domains[domainBId];
171
- if (domainA.identifier == domainB.identifier) {
172
- domainB.domainId = domainA.domainId;
173
- domainB.points.forEach(function(point) {
174
- point.domainId = domainA.domainId;
175
- pointsHash[point.x + "_" + point.y].domainId = domainA.domainId;
176
- });
177
- domainA.points = domainA.points.concat(domainB.points);
178
- delete domains[domainBId];
112
+ else {
113
+ idList = [query.pid];
179
114
  }
180
- }
181
- return result;
182
- };
183
- }
184
- });
185
-
186
- // src/ps/table-parser.js
187
- var require_table_parser = __commonJS({
188
- "src/ps/table-parser.js"(exports2, module2) {
189
- init_cjs_shims();
190
- var ConnectedDomain = require_connected_domain();
191
- var EMPTY_EX = /\s/;
192
- module2.exports.parse = function(output) {
193
- var linesTmp = output.split(/(\r\n)|(\n\r)|\n|\r/);
194
- var lines = [];
195
- var titleInfo = {};
196
- var twoDimArray = [];
197
- linesTmp.forEach(function(line) {
198
- if (line && line.trim()) {
199
- lines.push(line);
200
- }
201
- });
202
- lines.forEach(function(line, index) {
203
- if (index == 0) {
204
- var fields = line.split(/\s+/);
205
- var currentIndex = 0;
206
- fields.forEach(function(field, idx) {
207
- if (field) {
208
- var info = titleInfo[field] = {};
209
- var indexBegin = line.indexOf(field, currentIndex);
210
- var indexEnd = currentIndex = indexBegin + field.length;
211
- if (idx == 0) {
212
- info.titleBegin = 0;
213
- } else {
214
- info.titleBegin = indexBegin;
215
- }
216
- if (idx == fields.length - 1) {
217
- info.titleEnd = line.length - 1;
218
- } else {
219
- info.titleEnd = indexEnd;
220
- }
221
- }
222
- });
223
- } else {
224
- twoDimArray[index - 1] = line.split("");
115
+ // Cast all PIDs as Strings
116
+ idList = idList.map(function (v) {
117
+ return String(v);
118
+ });
119
+ }
120
+ if (query.command) {
121
+ filter["command"] = new RegExp(query.command, "i");
122
+ }
123
+ if (query.arguments) {
124
+ filter["arguments"] = new RegExp(query.arguments, "i");
125
+ }
126
+ if (query.ppid) {
127
+ filter["ppid"] = new RegExp(query.ppid);
128
+ }
129
+ return Exec(exeArgs, function (err, output) {
130
+ if (err) {
131
+ return callback(err);
225
132
  }
226
- });
227
- var connectedDomains = ConnectedDomain(
228
- twoDimArray,
229
- function(value) {
230
- if (EMPTY_EX.test(value)) {
231
- return -1;
232
- } else {
233
- return 1;
234
- }
235
- },
236
- true
237
- );
238
- var valuesDomainsVerticalGroups = [];
239
- connectedDomains.domains.sort(function(a, b) {
240
- return a.bounding.x - b.bounding.x;
241
- });
242
- connectedDomains.domains.forEach(function(domain) {
243
- if (domain.identifier === 1) {
244
- var overlapped = false;
245
- valuesDomainsVerticalGroups.forEach(function(group) {
246
- var bounding = domain.bounding;
247
- var left = bounding.x;
248
- var right = bounding.x + bounding.w;
249
- if (overlap(left, right, group.begin, group.end)) {
250
- overlapped = true;
251
- group.domains.push(domain);
252
- group.begin = group.begin > left ? left : group.begin;
253
- group.end = group.end < right ? right : group.end;
254
- }
255
- });
256
- if (!overlapped) {
257
- valuesDomainsVerticalGroups.push({
258
- begin: domain.bounding.x,
259
- end: domain.bounding.x + domain.bounding.w,
260
- domains: [domain]
133
+ else {
134
+ var processList = parseGrid(output);
135
+ var resultList = [];
136
+ processList.forEach(function (p) {
137
+ var flt;
138
+ var type;
139
+ var result = true;
140
+ if (idList && idList.indexOf(String(p.pid)) < 0) {
141
+ return;
142
+ }
143
+ for (type in filter) {
144
+ flt = filter[type];
145
+ result = flt.test(p[type]) ? result : false;
146
+ }
147
+ if (result) {
148
+ resultList.push(p);
149
+ }
261
150
  });
262
- }
263
- }
264
- });
265
- valuesDomainsVerticalGroups.forEach(function(group) {
266
- var title = null;
267
- var info = null;
268
- var overlapped = false;
269
- var minimunLeftDistance = null;
270
- var nearestLeftTitle = null;
271
- var distance = null;
272
- for (title in titleInfo) {
273
- info = titleInfo[title];
274
- if (group.begin > info.titleBegin) {
275
- distance = group.begin - info.titleBegin;
276
- if (!nearestLeftTitle || distance < minimunLeftDistance) {
277
- nearestLeftTitle = title;
278
- minimunLeftDistance = distance;
279
- }
280
- }
281
- if (overlap(group.begin, group.end, info.titleBegin, info.titleEnd)) {
282
- overlapped = true;
283
- info.titleBegin = info.titleBegin > group.begin ? group.begin : info.titleBegin;
284
- info.titleEnd = info.titleEnd < group.end ? group.end : info.titleEnd;
285
- }
286
- }
287
- if (!overlapped && nearestLeftTitle) {
288
- var nearestTitleField = titleInfo[nearestLeftTitle];
289
- nearestTitleField.titleBegin = nearestTitleField.titleBegin > group.begin ? group.begin : nearestTitleField.titleBegin;
290
- nearestTitleField.titleEnd = nearestTitleField.titleEnd < group.end ? group.end : nearestTitleField.titleEnd;
151
+ callback(null, resultList);
291
152
  }
292
- });
293
- var result = [];
294
- lines.forEach(function(line, index) {
295
- if (index > 0) {
296
- var lineItem = {};
297
- var title = null;
298
- var info = null;
299
- var value = null;
300
- for (title in titleInfo) {
301
- info = titleInfo[title];
302
- value = line.substring(info.titleBegin, info.titleEnd + 1);
303
- lineItem[title] = splitValue(value.trim());
304
- }
305
- result.push(lineItem);
306
- }
307
- });
308
- return result;
309
- };
310
- function overlap(begin1, end1, begin2, end2) {
311
- return begin1 > begin2 && begin1 < end2 || // 2--1--2--1 or 2--1--1--2
312
- end1 > begin2 && end1 < end2 || // 1--2--1--2 or 2--1--1--2
313
- begin1 <= begin2 && end1 >= end2;
153
+ });
154
+ };
155
+ /**
156
+ * Kill process
157
+ * @param pid
158
+ * @param {Object|String} signal
159
+ * @param {String} signal.signal
160
+ * @param {number} signal.timeout
161
+ * @param next
162
+ */
163
+ exports.kill = function (pid, signal, next) {
164
+ //opts are optional
165
+ if (arguments.length == 2 && typeof signal == "function") {
166
+ next = signal;
167
+ signal = undefined;
168
+ }
169
+ var checkTimeoutSeconds = (signal && signal.timeout) || 30;
170
+ if (typeof signal === "object") {
171
+ signal = signal.signal;
314
172
  }
315
- function splitValue(value) {
316
- var match = value.match(/"/g);
317
- if (!match || match.length == 1) {
318
- return value.split(/\s+/);
319
- } else {
320
- var result = [];
321
- var chunk = null;
322
- var ifInWrappedChunk = false;
323
- var ifInPureWrappedChunk = false;
324
- var quotaCount = 0;
325
- var maxQuotaCount = match.length % 2 == 0 ? match.length : match.length - 1;
326
- var previousItem = null;
327
- var values = value.split("");
328
- values.forEach(function(item, index) {
329
- if (item !== " ") {
330
- if (item === '"') {
331
- if (ifInWrappedChunk === false && quotaCount <= maxQuotaCount) {
332
- ifInWrappedChunk = true;
333
- quotaCount++;
334
- if (previousItem === " " || previousItem === null) {
335
- ifInPureWrappedChunk = true;
336
- chunk = "";
337
- } else {
338
- chunk += item;
173
+ try {
174
+ process.kill(pid, signal);
175
+ }
176
+ catch (e) {
177
+ return next && next(e);
178
+ }
179
+ var checkConfident = 0;
180
+ var checkTimeoutTimer = null;
181
+ var checkIsTimeout = false;
182
+ function checkKilled(finishCallback) {
183
+ exports.lookup({ pid: pid }, function (err, list) {
184
+ if (checkIsTimeout)
185
+ return;
186
+ if (err) {
187
+ clearTimeout(checkTimeoutTimer);
188
+ if (finishCallback)
189
+ finishCallback(err);
190
+ }
191
+ else if (list.length > 0) {
192
+ checkConfident = checkConfident - 1 || 0;
193
+ checkKilled(finishCallback);
194
+ }
195
+ else {
196
+ checkConfident++;
197
+ if (checkConfident === 5) {
198
+ clearTimeout(checkTimeoutTimer);
199
+ if (finishCallback)
200
+ finishCallback();
339
201
  }
340
- } else if (ifInWrappedChunk === true) {
341
- ifInWrappedChunk = false;
342
- quotaCount++;
343
- if (ifInPureWrappedChunk === true) {
344
- ifInPureWrappedChunk = false;
345
- result.push(chunk);
346
- chunk = null;
347
- } else {
348
- chunk += item;
202
+ else {
203
+ checkKilled(finishCallback);
349
204
  }
350
- }
351
- } else if (ifInWrappedChunk === false && (previousItem === " " || previousItem === null)) {
352
- chunk = item;
353
- } else {
354
- chunk += item;
355
205
  }
356
- } else if (ifInWrappedChunk) {
357
- chunk += item;
358
- } else if (chunk !== null) {
359
- result.push(chunk);
360
- chunk = null;
361
- }
362
- previousItem = item;
363
- if (index == values.length - 1 && chunk !== null) {
364
- result.push(chunk);
365
- chunk = null;
366
- }
367
206
  });
368
- return result;
369
- }
370
- }
371
- }
372
- });
373
-
374
- // src/ps/index.js
375
- init_cjs_shims();
376
- var ChildProcess = require("child_process");
377
- var IS_WIN = require_isWin();
378
- var TableParser = require_table_parser();
379
- var EOL = /(\r\n)|(\n\r)|\n|\r/;
380
- var SystemEOL = require("os").EOL;
381
- var Exec = module.exports = exports = function(args, callback) {
382
- var spawn = ChildProcess.spawn;
383
- if (IS_WIN) {
384
- var CMD = spawn("cmd");
385
- var stdout = "";
386
- var stderr = null;
387
- CMD.stdout.on("data", function(data) {
388
- stdout += data.toString();
389
- });
390
- CMD.stderr.on("data", function(data) {
391
- if (stderr === null) {
392
- stderr = data.toString();
393
- } else {
394
- stderr += data.toString();
395
- }
396
- });
397
- CMD.on("exit", function() {
398
- var beginRow;
399
- stdout = stdout.split(EOL);
400
- stdout.forEach(function(out, index) {
401
- if (out && typeof beginRow == "undefined" && out.indexOf("CommandLine") === 0) {
402
- beginRow = index;
403
- }
404
- });
405
- stdout.splice(stdout.length - 1, 1);
406
- stdout.splice(0, beginRow);
407
- callback(stderr, stdout.join(SystemEOL) || false);
408
- });
409
- CMD.stdin.write("wmic process get ProcessId,ParentProcessId,CommandLine \n");
410
- CMD.stdin.end();
411
- } else {
412
- if (typeof args === "string") {
413
- args = args.split(/\s+/);
414
- }
415
- const child = spawn("ps", args);
416
- stdout = "";
417
- stderr = null;
418
- child.stdout.on("data", function(data) {
419
- stdout += data.toString();
420
- });
421
- child.stderr.on("data", function(data) {
422
- if (stderr === null) {
423
- stderr = data.toString();
424
- } else {
425
- stderr += data.toString();
426
- }
427
- });
428
- child.on("exit", function() {
429
- if (stderr) {
430
- return callback(stderr.toString());
431
- } else {
432
- callback(null, stdout || false);
433
- }
434
- });
435
- }
436
- };
437
- exports.lookup = function(query, callback) {
438
- var exeArgs = query.psargs || ["lx"];
439
- var filter = {};
440
- var idList;
441
- if (query.pid) {
442
- if (Array.isArray(query.pid)) {
443
- idList = query.pid;
444
- } else {
445
- idList = [query.pid];
446
207
  }
447
- idList = idList.map(function(v) {
448
- return String(v);
449
- });
450
- }
451
- if (query.command) {
452
- filter["command"] = new RegExp(query.command, "i");
453
- }
454
- if (query.arguments) {
455
- filter["arguments"] = new RegExp(query.arguments, "i");
456
- }
457
- if (query.ppid) {
458
- filter["ppid"] = new RegExp(query.ppid);
459
- }
460
- return Exec(exeArgs, function(err, output) {
461
- if (err) {
462
- return callback(err);
463
- } else {
464
- var processList = parseGrid(output);
465
- var resultList = [];
466
- processList.forEach(function(p) {
467
- var flt;
468
- var type;
469
- var result = true;
470
- if (idList && idList.indexOf(String(p.pid)) < 0) {
471
- return;
472
- }
473
- for (type in filter) {
474
- flt = filter[type];
475
- result = flt.test(p[type]) ? result : false;
476
- }
477
- if (result) {
478
- resultList.push(p);
479
- }
480
- });
481
- callback(null, resultList);
482
- }
483
- });
484
- };
485
- exports.kill = function(pid, signal, next) {
486
- if (arguments.length == 2 && typeof signal == "function") {
487
- next = signal;
488
- signal = void 0;
489
- }
490
- var checkTimeoutSeconds = signal && signal.timeout || 30;
491
- if (typeof signal === "object") {
492
- signal = signal.signal;
493
- }
494
- try {
495
- process.kill(pid, signal);
496
- } catch (e) {
497
- return next && next(e);
498
- }
499
- var checkConfident = 0;
500
- var checkTimeoutTimer = null;
501
- var checkIsTimeout = false;
502
- function checkKilled(finishCallback) {
503
- exports.lookup({ pid }, function(err, list) {
504
- if (checkIsTimeout) return;
505
- if (err) {
506
- clearTimeout(checkTimeoutTimer);
507
- finishCallback && finishCallback(err);
508
- } else if (list.length > 0) {
509
- checkConfident = checkConfident - 1 || 0;
510
- checkKilled(finishCallback);
511
- } else {
512
- checkConfident++;
513
- if (checkConfident === 5) {
514
- clearTimeout(checkTimeoutTimer);
515
- finishCallback && finishCallback();
516
- } else {
517
- checkKilled(finishCallback);
518
- }
519
- }
520
- });
521
- }
522
- next && checkKilled(next);
523
- checkTimeoutTimer = next && setTimeout(function() {
524
- checkIsTimeout = true;
525
- next(new Error("Kill process timeout"));
526
- }, checkTimeoutSeconds * 1e3);
208
+ if (next)
209
+ checkKilled(next);
210
+ checkTimeoutTimer =
211
+ next &&
212
+ setTimeout(function () {
213
+ checkIsTimeout = true;
214
+ next(new Error("Kill process timeout"));
215
+ }, checkTimeoutSeconds * 1000);
527
216
  };
217
+ /**
218
+ * Parse the stdout into readable object.
219
+ * @param {String} output
220
+ */
528
221
  function parseGrid(output) {
529
- if (!output) {
530
- return [];
531
- }
532
- return formatOutput(TableParser.parse(output));
222
+ if (!output) {
223
+ return [];
224
+ }
225
+ return formatOutput(TableParser.parse(output));
533
226
  }
227
+ /**
228
+ * format the structure, extract pid, command, arguments, ppid
229
+ * @param data
230
+ * @return {Array}
231
+ */
534
232
  function formatOutput(data) {
535
- var formatedData = [];
536
- data.forEach(function(d) {
537
- var pid = d.PID && d.PID[0] || d.ProcessId && d.ProcessId[0] || void 0;
538
- var cmd = d.CMD || d.CommandLine || d.COMMAND || void 0;
539
- var ppid = d.PPID && d.PPID[0] || d.ParentProcessId && d.ParentProcessId[0] || void 0;
540
- if (pid && cmd) {
541
- var command = cmd[0];
542
- var args = "";
543
- if (cmd.length > 1) {
544
- args = cmd.slice(1);
545
- }
546
- formatedData.push({
547
- pid,
548
- command,
549
- arguments: args,
550
- ppid
551
- });
552
- }
553
- });
554
- return formatedData;
233
+ var formatedData = [];
234
+ data.forEach(function (d) {
235
+ var pid = (d.PID && d.PID[0]) || (d.ProcessId && d.ProcessId[0]) || undefined;
236
+ var cmd = d.CMD || d.CommandLine || d.COMMAND || undefined;
237
+ var ppid = (d.PPID && d.PPID[0]) || (d.ParentProcessId && d.ParentProcessId[0]) || undefined;
238
+ if (pid && cmd) {
239
+ var command = cmd[0];
240
+ var args = "";
241
+ if (cmd.length > 1) {
242
+ args = cmd.slice(1);
243
+ }
244
+ formatedData.push({
245
+ pid: pid,
246
+ command: command,
247
+ arguments: args,
248
+ ppid: ppid
249
+ });
250
+ }
251
+ });
252
+ return formatedData;
555
253
  }