@monorepolint/utils 0.5.0-alpha.103 → 0.5.0-alpha.106

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.
package/build/js/index.js CHANGED
@@ -1,31 +1,8 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var __privateMethod = (obj, member, method) => {
20
- __accessCheck(obj, member, "access private method");
21
- return method;
22
- };
23
-
24
1
  // src/getWorkspacePackageDirs.ts
25
2
  import { existsSync } from "fs";
26
3
  import * as glob from "glob";
27
- import * as path from "path";
28
- import * as fs from "fs";
4
+ import * as path from "node:path";
5
+ import * as fs from "node:fs";
29
6
  import * as readYamlFile from "read-yaml-file";
30
7
  import { findPackages } from "find-packages";
31
8
  async function findPNPMWorkspacePackages(workspaceRoot) {
@@ -128,7 +105,7 @@ var SimpleHost = class {
128
105
  this.fs = fs3;
129
106
  }
130
107
  mkdir(directoryPath, opts) {
131
- this.fs.mkdirSync(directoryPath, { recursive: opts?.recursive ?? false });
108
+ this.fs.mkdirSync(directoryPath, { recursive: (opts == null ? void 0 : opts.recursive) ?? false });
132
109
  }
133
110
  rmdir(directoryPath) {
134
111
  this.fs.rmdirSync(directoryPath);
@@ -144,10 +121,10 @@ var SimpleHost = class {
144
121
  }
145
122
  }
146
123
  readFile(path4, opts) {
147
- if (opts?.asJson) {
124
+ if (opts == null ? void 0 : opts.asJson) {
148
125
  return JSON.parse(this.fs.readFileSync(path4, "utf-8"));
149
126
  }
150
- return this.fs.readFileSync(path4, opts?.encoding);
127
+ return this.fs.readFileSync(path4, opts == null ? void 0 : opts.encoding);
151
128
  }
152
129
  deleteFile(path4) {
153
130
  this.fs.unlinkSync(path4);
@@ -165,8 +142,8 @@ var SimpleHost = class {
165
142
  };
166
143
 
167
144
  // src/CachingHost.ts
168
- import * as realFs2 from "fs";
169
- import * as path3 from "path";
145
+ import * as realFs2 from "node:fs";
146
+ import * as path3 from "node:path";
170
147
  function assertNoTombstone(node) {
171
148
  if (node.tombstone) {
172
149
  throw new Error(`Unexpected tombstone ${JSON.stringify(node)}`);
@@ -192,24 +169,123 @@ function assertHasParent(node) {
192
169
  throw new Error("Expected node to have a parent directory");
193
170
  }
194
171
  }
195
- var _trees, _replaceNode, replaceNode_fn, _unstubDirectory, unstubDirectory_fn, _stubify, stubify_fn, _getNearestAncestorNode, getNearestAncestorNode_fn, _getNode, getNode_fn, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn, _flushFileNode, flushFileNode_fn, _flushSymlinkNode, flushSymlinkNode_fn, _flushDirNode, flushDirNode_fn;
196
172
  var CachingHost = class {
197
173
  constructor(fs3 = realFs2) {
198
174
  this.fs = fs3;
199
- __privateAdd(this, _replaceNode);
200
- __privateAdd(this, _unstubDirectory);
201
- __privateAdd(this, _stubify);
202
- __privateAdd(this, _getNearestAncestorNode);
203
- __privateAdd(this, _getNode);
204
- __privateAdd(this, _getNodeResolvingSymlinks);
205
- __privateAdd(this, _flushFileNode);
206
- __privateAdd(this, _flushSymlinkNode);
207
- __privateAdd(this, _flushDirNode);
208
- __privateAdd(this, _trees, /* @__PURE__ */ new Map());
175
+ }
176
+ #trees = /* @__PURE__ */ new Map();
177
+ #replaceNode(node, partialNewNode) {
178
+ if (!node.parent)
179
+ throw new Error("Cannot replace root node");
180
+ const newNode = {
181
+ ...partialNewNode,
182
+ fullPath: node.fullPath,
183
+ parent: node.parent,
184
+ dir: node.dir
185
+ };
186
+ node.parent.dir.set(path3.basename(node.fullPath), newNode);
187
+ return newNode;
188
+ }
189
+ #unstubDirectory(node) {
190
+ for (const child of this.fs.readdirSync(node.fullPath)) {
191
+ this.#getNode(path3.join(node.fullPath, child));
192
+ }
193
+ node.stub = false;
194
+ }
195
+ #stubify(filePath, parent) {
196
+ const canonicalPath = path3.resolve(filePath);
197
+ if (!parent && canonicalPath !== path3.parse(canonicalPath).root) {
198
+ throw new Error(`parent can only be null if path is root. Instead got: ${canonicalPath}`);
199
+ }
200
+ const stat = this.fs.lstatSync(canonicalPath);
201
+ let node;
202
+ if (stat.isDirectory()) {
203
+ node = {
204
+ fullPath: canonicalPath,
205
+ type: "dir",
206
+ stub: true,
207
+ dir: /* @__PURE__ */ new Map(),
208
+ parent,
209
+ needsFlush: false
210
+ };
211
+ } else if (stat.isSymbolicLink()) {
212
+ node = {
213
+ fullPath: canonicalPath,
214
+ type: "symlink",
215
+ symlink: this.fs.readlinkSync(canonicalPath),
216
+ parent,
217
+ needsFlush: false
218
+ };
219
+ } else if (stat.isFile()) {
220
+ node = {
221
+ fullPath: canonicalPath,
222
+ type: "file",
223
+ stub: true,
224
+ parent,
225
+ needsFlush: false
226
+ };
227
+ } else {
228
+ throw new Error(`what is not a file nor symlink nor directory? nothing we care about: ${canonicalPath}`);
229
+ }
230
+ if (!parent && node.type === "dir") {
231
+ this.#trees.set(canonicalPath, node);
232
+ return node;
233
+ } else if (parent) {
234
+ parent.dir.set(path3.basename(canonicalPath), node);
235
+ } else {
236
+ throw new Error(`root can only be a dir, got ${JSON.stringify(node)} for path: ${canonicalPath}`);
237
+ }
238
+ return node;
239
+ }
240
+ #getNearestAncestorNode(filePath) {
241
+ const canonicalPath = path3.resolve(filePath);
242
+ const { root } = path3.parse(canonicalPath);
243
+ const parts = [];
244
+ let maybePath = canonicalPath;
245
+ while (maybePath !== root) {
246
+ parts.unshift(path3.basename(maybePath));
247
+ maybePath = path3.dirname(maybePath);
248
+ }
249
+ let curPath = root;
250
+ let curNode = this.#trees.get(root) ?? this.#stubify(curPath, void 0);
251
+ try {
252
+ for (const part of parts) {
253
+ assertNoTombstone(curNode);
254
+ assertNotType(curNode, "file");
255
+ if (curNode.type === "symlink") {
256
+ const linkedNode = this.#getNodeResolvingSymlinks(path3.resolve(path3.dirname(curPath), curNode.symlink));
257
+ assertExists(linkedNode);
258
+ assertNoTombstone(linkedNode);
259
+ assertType(linkedNode, "dir");
260
+ curNode = linkedNode;
261
+ }
262
+ assertType(curNode, "dir");
263
+ curNode = curNode.dir.get(part) ?? this.#stubify(path3.join(curNode.fullPath, part), curNode);
264
+ curPath = path3.join(curPath, part);
265
+ }
266
+ } catch (e) {
267
+ }
268
+ return { pathWithSymlinks: curPath, node: curNode };
269
+ }
270
+ #getNode(filePath) {
271
+ const canonicalPath = path3.resolve(filePath);
272
+ const { pathWithSymlinks, node } = this.#getNearestAncestorNode(canonicalPath);
273
+ if (pathWithSymlinks === canonicalPath) {
274
+ return node;
275
+ }
276
+ return void 0;
277
+ }
278
+ #getNodeResolvingSymlinks(filePath, follows = 100) {
279
+ const node = this.#getNode(filePath);
280
+ if (!node || node.type !== "symlink")
281
+ return node;
282
+ if (follows === 0)
283
+ throw new Error("Exhausted symlink follows");
284
+ return this.#getNodeResolvingSymlinks(node.symlink, follows--);
209
285
  }
210
286
  mkdir(filePath, opts = { recursive: false }) {
211
287
  const canonicalPath = path3.resolve(filePath);
212
- const { node, pathWithSymlinks } = __privateMethod(this, _getNearestAncestorNode, getNearestAncestorNode_fn).call(this, canonicalPath);
288
+ const { node, pathWithSymlinks } = this.#getNearestAncestorNode(canonicalPath);
213
289
  if (filePath === pathWithSymlinks) {
214
290
  assertType(node, "dir");
215
291
  assertHasParent(node);
@@ -242,16 +318,16 @@ var CachingHost = class {
242
318
  }
243
319
  }
244
320
  rmdir(directoryPath) {
245
- const node = __privateMethod(this, _getNode, getNode_fn).call(this, directoryPath);
321
+ const node = this.#getNode(directoryPath);
246
322
  if (!node || node.tombstone) {
247
323
  return;
248
324
  }
249
325
  assertType(node, "dir");
250
326
  if (node.stub) {
251
- __privateMethod(this, _unstubDirectory, unstubDirectory_fn).call(this, node);
327
+ this.#unstubDirectory(node);
252
328
  }
253
329
  if (node.dir.size === 0) {
254
- __privateMethod(this, _replaceNode, replaceNode_fn).call(this, node, {
330
+ this.#replaceNode(node, {
255
331
  type: "dir",
256
332
  tombstone: true,
257
333
  needsFlush: true
@@ -261,18 +337,18 @@ var CachingHost = class {
261
337
  }
262
338
  }
263
339
  exists(filePath) {
264
- const node = __privateMethod(this, _getNode, getNode_fn).call(this, filePath);
340
+ const node = this.#getNode(filePath);
265
341
  return !!node && !node.tombstone;
266
342
  }
267
343
  readFile(filePath, opts) {
268
- let node = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, filePath);
344
+ let node = this.#getNodeResolvingSymlinks(filePath);
269
345
  if (!node) {
270
346
  return void 0;
271
347
  }
272
348
  assertNotType(node, "dir");
273
349
  assertNoTombstone(node);
274
350
  if (node.stub) {
275
- node = __privateMethod(this, _replaceNode, replaceNode_fn).call(this, node, {
351
+ node = this.#replaceNode(node, {
276
352
  type: "file",
277
353
  file: this.fs.readFileSync(filePath),
278
354
  needsFlush: false
@@ -287,21 +363,21 @@ var CachingHost = class {
287
363
  }
288
364
  }
289
365
  writeFile(filePath, body, opts) {
290
- const fileContentsAsBuffer = typeof body === "string" ? Buffer.from(body, opts?.encoding) : Buffer.from(body);
366
+ const fileContentsAsBuffer = typeof body === "string" ? Buffer.from(body, opts == null ? void 0 : opts.encoding) : Buffer.from(body);
291
367
  const canonicalPath = path3.resolve(filePath);
292
- const existingNode = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, canonicalPath);
368
+ const existingNode = this.#getNodeResolvingSymlinks(canonicalPath);
293
369
  if (existingNode) {
294
370
  if (existingNode.type === "dir") {
295
371
  throw new Error("cant write file to a dir");
296
372
  }
297
- __privateMethod(this, _replaceNode, replaceNode_fn).call(this, existingNode, {
373
+ this.#replaceNode(existingNode, {
298
374
  file: fileContentsAsBuffer,
299
375
  type: "file",
300
376
  needsFlush: true
301
377
  });
302
378
  return;
303
379
  }
304
- const maybeDirNode = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, path3.dirname(canonicalPath));
380
+ const maybeDirNode = this.#getNodeResolvingSymlinks(path3.dirname(canonicalPath));
305
381
  assertExists(maybeDirNode);
306
382
  assertType(maybeDirNode, "dir");
307
383
  assertNoTombstone(maybeDirNode);
@@ -315,11 +391,11 @@ var CachingHost = class {
315
391
  }
316
392
  deleteFile(filePath) {
317
393
  const canonicalPath = path3.resolve(filePath);
318
- const node = __privateMethod(this, _getNode, getNode_fn).call(this, canonicalPath);
394
+ const node = this.#getNode(canonicalPath);
319
395
  if (!node || node.type === "file" && node.tombstone === true)
320
396
  return;
321
397
  assertNotType(node, "dir");
322
- __privateMethod(this, _replaceNode, replaceNode_fn).call(this, node, {
398
+ this.#replaceNode(node, {
323
399
  type: "file",
324
400
  tombstone: true,
325
401
  needsFlush: true
@@ -333,187 +409,68 @@ var CachingHost = class {
333
409
  encoding: "utf-8"
334
410
  });
335
411
  }
336
- flush() {
337
- const promises2 = [];
338
- for (const rootNode of __privateGet(this, _trees).values()) {
339
- promises2.push(__privateMethod(this, _flushDirNode, flushDirNode_fn).call(this, rootNode));
340
- }
341
- return Promise.all(promises2);
342
- }
343
- };
344
- _trees = new WeakMap();
345
- _replaceNode = new WeakSet();
346
- replaceNode_fn = function(node, partialNewNode) {
347
- if (!node.parent)
348
- throw new Error("Cannot replace root node");
349
- const newNode = {
350
- ...partialNewNode,
351
- fullPath: node.fullPath,
352
- parent: node.parent,
353
- dir: node.dir
354
- };
355
- node.parent.dir.set(path3.basename(node.fullPath), newNode);
356
- return newNode;
357
- };
358
- _unstubDirectory = new WeakSet();
359
- unstubDirectory_fn = function(node) {
360
- for (const child of this.fs.readdirSync(node.fullPath)) {
361
- __privateMethod(this, _getNode, getNode_fn).call(this, path3.join(node.fullPath, child));
362
- }
363
- node.stub = false;
364
- };
365
- _stubify = new WeakSet();
366
- stubify_fn = function(filePath, parent) {
367
- const canonicalPath = path3.resolve(filePath);
368
- if (!parent && canonicalPath !== path3.parse(canonicalPath).root) {
369
- throw new Error(`parent can only be null if path is root. Instead got: ${canonicalPath}`);
370
- }
371
- const stat = this.fs.lstatSync(canonicalPath);
372
- let node;
373
- if (stat.isDirectory()) {
374
- node = {
375
- fullPath: canonicalPath,
376
- type: "dir",
377
- stub: true,
378
- dir: /* @__PURE__ */ new Map(),
379
- parent,
380
- needsFlush: false
381
- };
382
- } else if (stat.isSymbolicLink()) {
383
- node = {
384
- fullPath: canonicalPath,
385
- type: "symlink",
386
- symlink: this.fs.readlinkSync(canonicalPath),
387
- parent,
388
- needsFlush: false
389
- };
390
- } else if (stat.isFile()) {
391
- node = {
392
- fullPath: canonicalPath,
393
- type: "file",
394
- stub: true,
395
- parent,
396
- needsFlush: false
397
- };
398
- } else {
399
- throw new Error(`what is not a file nor symlink nor directory? nothing we care about: ${canonicalPath}`);
400
- }
401
- if (!parent && node.type === "dir") {
402
- __privateGet(this, _trees).set(canonicalPath, node);
403
- return node;
404
- } else if (parent) {
405
- parent.dir.set(path3.basename(canonicalPath), node);
406
- } else {
407
- throw new Error(`root can only be a dir, got ${JSON.stringify(node)} for path: ${canonicalPath}`);
408
- }
409
- return node;
410
- };
411
- _getNearestAncestorNode = new WeakSet();
412
- getNearestAncestorNode_fn = function(filePath) {
413
- const canonicalPath = path3.resolve(filePath);
414
- const { root } = path3.parse(canonicalPath);
415
- const parts = [];
416
- let maybePath = canonicalPath;
417
- while (maybePath !== root) {
418
- parts.unshift(path3.basename(maybePath));
419
- maybePath = path3.dirname(maybePath);
420
- }
421
- let curPath = root;
422
- let curNode = __privateGet(this, _trees).get(root) ?? __privateMethod(this, _stubify, stubify_fn).call(this, curPath, void 0);
423
- try {
424
- for (const part of parts) {
425
- assertNoTombstone(curNode);
426
- assertNotType(curNode, "file");
427
- if (curNode.type === "symlink") {
428
- const linkedNode = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, path3.resolve(path3.dirname(curPath), curNode.symlink));
429
- assertExists(linkedNode);
430
- assertNoTombstone(linkedNode);
431
- assertType(linkedNode, "dir");
432
- curNode = linkedNode;
412
+ async #flushFileNode(node) {
413
+ if (node.tombstone) {
414
+ try {
415
+ await this.fs.promises.access(node.fullPath);
416
+ return this.fs.promises.unlink(node.fullPath);
417
+ } catch (e) {
418
+ return;
433
419
  }
434
- assertType(curNode, "dir");
435
- curNode = curNode.dir.get(part) ?? __privateMethod(this, _stubify, stubify_fn).call(this, path3.join(curNode.fullPath, part), curNode);
436
- curPath = path3.join(curPath, part);
437
- }
438
- } catch (e) {
439
- }
440
- return { pathWithSymlinks: curPath, node: curNode };
441
- };
442
- _getNode = new WeakSet();
443
- getNode_fn = function(filePath) {
444
- const canonicalPath = path3.resolve(filePath);
445
- const { pathWithSymlinks, node } = __privateMethod(this, _getNearestAncestorNode, getNearestAncestorNode_fn).call(this, canonicalPath);
446
- if (pathWithSymlinks === canonicalPath) {
447
- return node;
448
- }
449
- return void 0;
450
- };
451
- _getNodeResolvingSymlinks = new WeakSet();
452
- getNodeResolvingSymlinks_fn = function(filePath, follows = 100) {
453
- const node = __privateMethod(this, _getNode, getNode_fn).call(this, filePath);
454
- if (!node || node.type !== "symlink")
455
- return node;
456
- if (follows === 0)
457
- throw new Error("Exhausted symlink follows");
458
- return __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, node.symlink, follows--);
459
- };
460
- _flushFileNode = new WeakSet();
461
- flushFileNode_fn = async function(node) {
462
- if (node.tombstone) {
463
- try {
464
- await this.fs.promises.access(node.fullPath);
465
- return this.fs.promises.unlink(node.fullPath);
466
- } catch (e) {
420
+ } else if (node.stub === true || node.needsFlush === false) {
467
421
  return;
422
+ } else {
423
+ return this.fs.promises.writeFile(node.fullPath, node.file);
468
424
  }
469
- } else if (node.stub === true || node.needsFlush === false) {
470
- return;
471
- } else {
472
- return this.fs.promises.writeFile(node.fullPath, node.file);
473
425
  }
474
- };
475
- _flushSymlinkNode = new WeakSet();
476
- flushSymlinkNode_fn = async function(node) {
477
- if (!node.needsFlush)
478
- return;
479
- try {
480
- const linkValue = await this.fs.promises.readlink(node.fullPath);
481
- if (linkValue === node.symlink) {
426
+ async #flushSymlinkNode(node) {
427
+ if (!node.needsFlush)
482
428
  return;
483
- }
484
- } catch (e) {
485
- }
486
- return this.fs.promises.symlink(node.symlink, node.fullPath);
487
- };
488
- _flushDirNode = new WeakSet();
489
- flushDirNode_fn = async function(node) {
490
- if (!node.tombstone && node.needsFlush) {
491
429
  try {
492
- await this.fs.promises.access(node.fullPath);
430
+ const linkValue = await this.fs.promises.readlink(node.fullPath);
431
+ if (linkValue === node.symlink) {
432
+ return;
433
+ }
493
434
  } catch (e) {
494
- await this.fs.promises.mkdir(node.fullPath);
495
435
  }
436
+ return this.fs.promises.symlink(node.symlink, node.fullPath);
496
437
  }
497
- const promises2 = [];
498
- for (const child of node.dir.values()) {
499
- if (node.tombstone && !child.tombstone) {
500
- throw new Error("Unexpected failure during sanity check. A non-deleted child is on a deleted dir");
438
+ async #flushDirNode(node) {
439
+ if (!node.tombstone && node.needsFlush) {
440
+ try {
441
+ await this.fs.promises.access(node.fullPath);
442
+ } catch (e) {
443
+ await this.fs.promises.mkdir(node.fullPath);
444
+ }
501
445
  }
502
- if (child.type === "dir") {
503
- promises2.push(__privateMethod(this, _flushDirNode, flushDirNode_fn).call(this, child));
504
- } else if (child.type === "file") {
505
- promises2.push(__privateMethod(this, _flushFileNode, flushFileNode_fn).call(this, child));
506
- } else if (child.type === "symlink") {
507
- promises2.push(__privateMethod(this, _flushSymlinkNode, flushSymlinkNode_fn).call(this, child));
508
- } else {
509
- throw new Error("should never happen");
446
+ const promises2 = [];
447
+ for (const child of node.dir.values()) {
448
+ if (node.tombstone && !child.tombstone) {
449
+ throw new Error("Unexpected failure during sanity check. A non-deleted child is on a deleted dir");
450
+ }
451
+ if (child.type === "dir") {
452
+ promises2.push(this.#flushDirNode(child));
453
+ } else if (child.type === "file") {
454
+ promises2.push(this.#flushFileNode(child));
455
+ } else if (child.type === "symlink") {
456
+ promises2.push(this.#flushSymlinkNode(child));
457
+ } else {
458
+ throw new Error("should never happen");
459
+ }
510
460
  }
461
+ await Promise.all(promises2);
462
+ if (node.tombstone) {
463
+ return this.fs.promises.rmdir(node.fullPath);
464
+ }
465
+ return;
511
466
  }
512
- await Promise.all(promises2);
513
- if (node.tombstone) {
514
- return this.fs.promises.rmdir(node.fullPath);
467
+ flush() {
468
+ const promises2 = [];
469
+ for (const rootNode of this.#trees.values()) {
470
+ promises2.push(this.#flushDirNode(rootNode));
471
+ }
472
+ return Promise.all(promises2);
515
473
  }
516
- return;
517
474
  };
518
475
 
519
476
  // src/matchesAnyGlob.ts
@@ -525,42 +482,33 @@ function nanosecondsToSanity(n, precision = 9) {
525
482
  }
526
483
 
527
484
  // src/Table.ts
528
- var _rows, _config, _columnWidths, _footer, _footerRowConfig, _totalWidth, _sumColumn, sumColumn_fn, _updateFooterRow, updateFooterRow_fn, _calculateColumnWidths, calculateColumnWidths_fn, _printSeparator, printSeparator_fn, _printHeaderRow, printHeaderRow_fn, _printFooterRow, printFooterRow_fn, _getCellValueAsString, getCellValueAsString_fn, _getCellValueAligned, getCellValueAligned_fn;
529
485
  var Table = class {
486
+ #rows = [];
487
+ #config;
488
+ #columnWidths = [];
489
+ #footer = [];
490
+ #footerRowConfig;
491
+ #totalWidth = 0;
530
492
  constructor(config) {
531
- __privateAdd(this, _sumColumn);
532
- __privateAdd(this, _updateFooterRow);
533
- __privateAdd(this, _calculateColumnWidths);
534
- __privateAdd(this, _printSeparator);
535
- __privateAdd(this, _printHeaderRow);
536
- __privateAdd(this, _printFooterRow);
537
- __privateAdd(this, _getCellValueAsString);
538
- __privateAdd(this, _getCellValueAligned);
539
- __privateAdd(this, _rows, []);
540
- __privateAdd(this, _config, void 0);
541
- __privateAdd(this, _columnWidths, []);
542
- __privateAdd(this, _footer, []);
543
- __privateAdd(this, _footerRowConfig, void 0);
544
- __privateAdd(this, _totalWidth, 0);
545
- __privateSet(this, _config, {
493
+ this.#config = {
546
494
  padding: 2,
547
495
  ...config
548
- });
549
- __privateGet(this, _columnWidths).fill(0, 0, config.columns.length);
496
+ };
497
+ this.#columnWidths.fill(0, 0, config.columns.length);
550
498
  if (config.showFooter) {
551
- __privateSet(this, _footerRowConfig, []);
499
+ this.#footerRowConfig = [];
552
500
  for (const columnConfig of config.columns) {
553
501
  if (columnConfig.footer === void 0) {
554
502
  throw new Error("Must specify footer fields when showFooter is true");
555
503
  } else if (typeof columnConfig.footer === "string") {
556
- __privateGet(this, _footerRowConfig).push({
504
+ this.#footerRowConfig.push({
557
505
  type: "string",
558
506
  alignment: "left",
559
507
  aggregate: "static",
560
508
  value: columnConfig.footer
561
509
  });
562
510
  } else if ("value" in columnConfig.footer) {
563
- __privateGet(this, _footerRowConfig).push({
511
+ this.#footerRowConfig.push({
564
512
  type: "string",
565
513
  alignment: "left",
566
514
  ...columnConfig.footer
@@ -568,7 +516,7 @@ var Table = class {
568
516
  } else if ("aggregate" in columnConfig.footer) {
569
517
  if (columnConfig.type !== "bigint")
570
518
  throw new Error("expecting bigint for aggregate");
571
- __privateGet(this, _footerRowConfig).push({
519
+ this.#footerRowConfig.push({
572
520
  type: columnConfig.type,
573
521
  renderAs: columnConfig.renderAs,
574
522
  precision: columnConfig.precision,
@@ -580,177 +528,164 @@ var Table = class {
580
528
  }
581
529
  }
582
530
  addRow(...data) {
583
- __privateGet(this, _rows).push(data);
531
+ this.#rows.push(data);
532
+ }
533
+ #sumColumn(c) {
534
+ let total = BigInt(0);
535
+ for (const row of this.#rows) {
536
+ total += row[c];
537
+ }
538
+ return total;
539
+ }
540
+ #updateFooterRow() {
541
+ const footerRowConfig = this.#footerRowConfig;
542
+ if (footerRowConfig) {
543
+ for (let c = 0; c < footerRowConfig.length; c++) {
544
+ const footerColConfig = footerRowConfig[c];
545
+ switch (footerColConfig.aggregate) {
546
+ case "sum":
547
+ this.#footer[c] = this.#sumColumn(c);
548
+ break;
549
+ case "average":
550
+ this.#footer[c] = this.#sumColumn(c) / BigInt(this.#rows.length);
551
+ break;
552
+ case "static":
553
+ this.#footer[c] = footerColConfig.value;
554
+ break;
555
+ }
556
+ }
557
+ }
558
+ }
559
+ #calculateColumnWidths() {
560
+ var _a;
561
+ this.#columnWidths.fill(0, 0, this.#config.columns.length);
562
+ for (let c = 0; c < this.#config.columns.length; c++) {
563
+ const colConfig = this.#config.columns[c];
564
+ this.#columnWidths[c] = Math.max(
565
+ (this.#config.columns[c].header ?? "").length,
566
+ ...this.#rows.map((a) => this.#getCellValueAsString(a[c], colConfig).length),
567
+ this.#footer && this.#footerRowConfig ? this.#getCellValueAsString(((_a = this.#footer) == null ? void 0 : _a[c]) ?? "", this.#footerRowConfig[c]).length : 0
568
+ );
569
+ }
570
+ this.#totalWidth = 0;
571
+ for (const colWidth of this.#columnWidths) {
572
+ this.#totalWidth += colWidth;
573
+ }
574
+ this.#totalWidth += (this.#columnWidths.length - 1) * this.#config.padding;
575
+ }
576
+ #printSeparator(fillString) {
577
+ const paddingString = "".padStart(this.#config.padding, " ");
578
+ let hr2 = "";
579
+ for (let c = 0; c < this.#columnWidths.length; c++) {
580
+ hr2 += "".padStart(this.#columnWidths[c], fillString) + paddingString;
581
+ }
582
+ hr2 = hr2.trimRight();
583
+ console.log(hr2);
584
+ }
585
+ #printHeaderRow() {
586
+ if (this.#config.showHeader) {
587
+ const colConfigs = this.#config.columns;
588
+ const paddingString = "".padStart(this.#config.padding, " ");
589
+ let hr = "";
590
+ for (let c = 0; c < colConfigs.length; c++) {
591
+ const heading = colConfigs[c].header ?? "";
592
+ hr += heading.padEnd(this.#columnWidths[c], " ") + paddingString;
593
+ }
594
+ hr = hr.trimRight();
595
+ console.log(hr);
596
+ this.#printSeparator("-");
597
+ }
598
+ }
599
+ #printFooterRow() {
600
+ const footerRow = this.#footer;
601
+ if (footerRow) {
602
+ this.#printSeparator("=");
603
+ const paddingString = "".padStart(this.#config.padding, " ");
604
+ let hr = "";
605
+ for (let c = 0; c < footerRow.length; c++) {
606
+ hr += this.#getCellValueAligned(footerRow[c], this.#footerRowConfig[c], c) + paddingString;
607
+ }
608
+ hr = hr.trimRight();
609
+ console.log(hr);
610
+ }
584
611
  }
585
612
  print() {
586
- if (__privateGet(this, _config).sortColumn !== void 0) {
613
+ if (this.#config.sortColumn !== void 0) {
587
614
  }
588
- __privateMethod(this, _updateFooterRow, updateFooterRow_fn).call(this);
589
- __privateMethod(this, _calculateColumnWidths, calculateColumnWidths_fn).call(this);
615
+ this.#updateFooterRow();
616
+ this.#calculateColumnWidths();
590
617
  console.log();
591
- console.log(`${__privateGet(this, _config).title}`);
592
- console.log("".padStart(__privateGet(this, _totalWidth), "="));
593
- const paddingString = "".padStart(__privateGet(this, _config).padding, " ");
594
- if (__privateGet(this, _config).showHeader) {
595
- __privateMethod(this, _printHeaderRow, printHeaderRow_fn).call(this);
618
+ console.log(`${this.#config.title}`);
619
+ console.log("".padStart(this.#totalWidth, "="));
620
+ const paddingString = "".padStart(this.#config.padding, " ");
621
+ if (this.#config.showHeader) {
622
+ this.#printHeaderRow();
596
623
  }
597
- for (let r = 0; r < __privateGet(this, _rows).length; r++) {
624
+ for (let r = 0; r < this.#rows.length; r++) {
598
625
  let rowText = "";
599
- for (let c = 0; c < __privateGet(this, _config).columns.length; c++) {
626
+ for (let c = 0; c < this.#config.columns.length; c++) {
600
627
  rowText += this.getEntryAsStringAligned(c, r) + paddingString;
601
628
  }
602
629
  rowText.trim();
603
630
  console.log(rowText);
604
631
  }
605
- if (__privateGet(this, _config).showFooter)
606
- __privateMethod(this, _printFooterRow, printFooterRow_fn).call(this);
632
+ if (this.#config.showFooter)
633
+ this.#printFooterRow();
607
634
  console.log();
608
635
  }
636
+ #getCellValueAsString(value, config) {
637
+ if (config.type === "bigint" && config.renderAs === "nanoseconds") {
638
+ return nanosecondsToSanity(value, config.precision ?? 9);
639
+ } else {
640
+ return "" + value;
641
+ }
642
+ }
643
+ #getCellValueAligned(value, config, column) {
644
+ let result;
645
+ if (config.type === "bigint" && config.renderAs === "nanoseconds") {
646
+ result = nanosecondsToSanity(value, config.precision ?? 9);
647
+ } else {
648
+ result = "" + value;
649
+ }
650
+ if (config.alignment === "left") {
651
+ return result.padEnd(this.#columnWidths[column]);
652
+ } else {
653
+ return result.padStart(this.#columnWidths[column]);
654
+ }
655
+ }
609
656
  getEntryAsString(colNum, rowNum) {
610
- const config = __privateGet(this, _config).columns[colNum];
657
+ const config = this.#config.columns[colNum];
611
658
  if (config.type === "bigint" && config.renderAs === "nanoseconds") {
612
- return nanosecondsToSanity(__privateGet(this, _rows)[rowNum][colNum], config.precision ?? 9);
659
+ return nanosecondsToSanity(this.#rows[rowNum][colNum], config.precision ?? 9);
613
660
  } else {
614
- return "" + __privateGet(this, _rows)[rowNum][colNum];
661
+ return "" + this.#rows[rowNum][colNum];
615
662
  }
616
663
  }
617
664
  getEntryAsStringAligned(colNum, rowNum) {
618
- const config = __privateGet(this, _config).columns[colNum];
665
+ const config = this.#config.columns[colNum];
619
666
  let result;
620
667
  if (config.type === "bigint" && config.renderAs === "nanoseconds") {
621
- result = nanosecondsToSanity(__privateGet(this, _rows)[rowNum][colNum], config.precision ?? 9);
668
+ result = nanosecondsToSanity(this.#rows[rowNum][colNum], config.precision ?? 9);
622
669
  } else {
623
- result = "" + __privateGet(this, _rows)[rowNum][colNum];
670
+ result = "" + this.#rows[rowNum][colNum];
624
671
  }
625
672
  if (config.alignment === "left") {
626
- return result.padEnd(__privateGet(this, _columnWidths)[colNum]);
673
+ return result.padEnd(this.#columnWidths[colNum]);
627
674
  } else {
628
- return result.padStart(__privateGet(this, _columnWidths)[colNum]);
675
+ return result.padStart(this.#columnWidths[colNum]);
629
676
  }
630
677
  }
631
678
  getColumnWidth(colNum, config) {
632
679
  let maxWidth = Math.max(
633
680
  (config.header ?? "").length,
634
- __privateGet(this, _footer) && __privateGet(this, _footerRowConfig) ? __privateMethod(this, _getCellValueAsString, getCellValueAsString_fn).call(this, __privateGet(this, _footer)[colNum], __privateGet(this, _footerRowConfig)[colNum]).length : 0
681
+ this.#footer && this.#footerRowConfig ? this.#getCellValueAsString(this.#footer[colNum], this.#footerRowConfig[colNum]).length : 0
635
682
  );
636
- for (let r = 0; r < __privateGet(this, _rows).length; r++) {
683
+ for (let r = 0; r < this.#rows.length; r++) {
637
684
  maxWidth = Math.max(maxWidth, this.getEntryAsString(colNum, r).length);
638
685
  }
639
686
  return maxWidth;
640
687
  }
641
688
  };
642
- _rows = new WeakMap();
643
- _config = new WeakMap();
644
- _columnWidths = new WeakMap();
645
- _footer = new WeakMap();
646
- _footerRowConfig = new WeakMap();
647
- _totalWidth = new WeakMap();
648
- _sumColumn = new WeakSet();
649
- sumColumn_fn = function(c) {
650
- let total = BigInt(0);
651
- for (const row of __privateGet(this, _rows)) {
652
- total += row[c];
653
- }
654
- return total;
655
- };
656
- _updateFooterRow = new WeakSet();
657
- updateFooterRow_fn = function() {
658
- const footerRowConfig = __privateGet(this, _footerRowConfig);
659
- if (footerRowConfig) {
660
- for (let c = 0; c < footerRowConfig.length; c++) {
661
- const footerColConfig = footerRowConfig[c];
662
- switch (footerColConfig.aggregate) {
663
- case "sum":
664
- __privateGet(this, _footer)[c] = __privateMethod(this, _sumColumn, sumColumn_fn).call(this, c);
665
- break;
666
- case "average":
667
- __privateGet(this, _footer)[c] = __privateMethod(this, _sumColumn, sumColumn_fn).call(this, c) / BigInt(__privateGet(this, _rows).length);
668
- break;
669
- case "static":
670
- __privateGet(this, _footer)[c] = footerColConfig.value;
671
- break;
672
- }
673
- }
674
- }
675
- };
676
- _calculateColumnWidths = new WeakSet();
677
- calculateColumnWidths_fn = function() {
678
- __privateGet(this, _columnWidths).fill(0, 0, __privateGet(this, _config).columns.length);
679
- for (let c = 0; c < __privateGet(this, _config).columns.length; c++) {
680
- const colConfig = __privateGet(this, _config).columns[c];
681
- __privateGet(this, _columnWidths)[c] = Math.max(
682
- (__privateGet(this, _config).columns[c].header ?? "").length,
683
- ...__privateGet(this, _rows).map((a) => __privateMethod(this, _getCellValueAsString, getCellValueAsString_fn).call(this, a[c], colConfig).length),
684
- __privateGet(this, _footer) && __privateGet(this, _footerRowConfig) ? __privateMethod(this, _getCellValueAsString, getCellValueAsString_fn).call(this, __privateGet(this, _footer)?.[c] ?? "", __privateGet(this, _footerRowConfig)[c]).length : 0
685
- );
686
- }
687
- __privateSet(this, _totalWidth, 0);
688
- for (const colWidth of __privateGet(this, _columnWidths)) {
689
- __privateSet(this, _totalWidth, __privateGet(this, _totalWidth) + colWidth);
690
- }
691
- __privateSet(this, _totalWidth, __privateGet(this, _totalWidth) + (__privateGet(this, _columnWidths).length - 1) * __privateGet(this, _config).padding);
692
- };
693
- _printSeparator = new WeakSet();
694
- printSeparator_fn = function(fillString) {
695
- const paddingString = "".padStart(__privateGet(this, _config).padding, " ");
696
- let hr2 = "";
697
- for (let c = 0; c < __privateGet(this, _columnWidths).length; c++) {
698
- hr2 += "".padStart(__privateGet(this, _columnWidths)[c], fillString) + paddingString;
699
- }
700
- hr2 = hr2.trimRight();
701
- console.log(hr2);
702
- };
703
- _printHeaderRow = new WeakSet();
704
- printHeaderRow_fn = function() {
705
- if (__privateGet(this, _config).showHeader) {
706
- const colConfigs = __privateGet(this, _config).columns;
707
- const paddingString = "".padStart(__privateGet(this, _config).padding, " ");
708
- let hr = "";
709
- for (let c = 0; c < colConfigs.length; c++) {
710
- const heading = colConfigs[c].header ?? "";
711
- hr += heading.padEnd(__privateGet(this, _columnWidths)[c], " ") + paddingString;
712
- }
713
- hr = hr.trimRight();
714
- console.log(hr);
715
- __privateMethod(this, _printSeparator, printSeparator_fn).call(this, "-");
716
- }
717
- };
718
- _printFooterRow = new WeakSet();
719
- printFooterRow_fn = function() {
720
- const footerRow = __privateGet(this, _footer);
721
- if (footerRow) {
722
- __privateMethod(this, _printSeparator, printSeparator_fn).call(this, "=");
723
- const paddingString = "".padStart(__privateGet(this, _config).padding, " ");
724
- let hr = "";
725
- for (let c = 0; c < footerRow.length; c++) {
726
- hr += __privateMethod(this, _getCellValueAligned, getCellValueAligned_fn).call(this, footerRow[c], __privateGet(this, _footerRowConfig)[c], c) + paddingString;
727
- }
728
- hr = hr.trimRight();
729
- console.log(hr);
730
- }
731
- };
732
- _getCellValueAsString = new WeakSet();
733
- getCellValueAsString_fn = function(value, config) {
734
- if (config.type === "bigint" && config.renderAs === "nanoseconds") {
735
- return nanosecondsToSanity(value, config.precision ?? 9);
736
- } else {
737
- return "" + value;
738
- }
739
- };
740
- _getCellValueAligned = new WeakSet();
741
- getCellValueAligned_fn = function(value, config, column) {
742
- let result;
743
- if (config.type === "bigint" && config.renderAs === "nanoseconds") {
744
- result = nanosecondsToSanity(value, config.precision ?? 9);
745
- } else {
746
- result = "" + value;
747
- }
748
- if (config.alignment === "left") {
749
- return result.padEnd(__privateGet(this, _columnWidths)[column]);
750
- } else {
751
- return result.padStart(__privateGet(this, _columnWidths)[column]);
752
- }
753
- };
754
689
 
755
690
  // src/matchesAnyGlob.ts
756
691
  var cache = /* @__PURE__ */ new Map();
@@ -824,33 +759,32 @@ matchesAnyGlob.printStats = () => {
824
759
  };
825
760
 
826
761
  // src/AggregateTiming.ts
827
- var _data, _last;
828
762
  var AggregateTiming = class {
829
763
  constructor(title) {
830
764
  this.title = title;
831
- __privateAdd(this, _data, /* @__PURE__ */ new Map());
832
- __privateAdd(this, _last, void 0);
833
765
  }
766
+ #data = /* @__PURE__ */ new Map();
767
+ #last;
834
768
  start(name) {
835
769
  const time = process.hrtime.bigint();
836
- if (__privateGet(this, _last)) {
837
- __privateGet(this, _last).total += time;
770
+ if (this.#last) {
771
+ this.#last.total += time;
838
772
  }
839
- let data = __privateGet(this, _data).get(name);
773
+ let data = this.#data.get(name);
840
774
  if (data === void 0) {
841
775
  data = { count: 1, total: -time };
842
- __privateGet(this, _data).set(name, data);
776
+ this.#data.set(name, data);
843
777
  } else {
844
778
  data.total -= time;
845
779
  data.count++;
846
780
  }
847
- __privateSet(this, _last, data);
781
+ this.#last = data;
848
782
  }
849
783
  stop() {
850
784
  const time = process.hrtime.bigint();
851
- if (__privateGet(this, _last)) {
852
- __privateGet(this, _last).total += time;
853
- __privateSet(this, _last, void 0);
785
+ if (this.#last) {
786
+ this.#last.total += time;
787
+ this.#last = void 0;
854
788
  }
855
789
  }
856
790
  printResults() {
@@ -871,7 +805,7 @@ var AggregateTiming = class {
871
805
  { header: "Avg", type: "bigint", footer: { aggregate: "average" } }
872
806
  ]
873
807
  });
874
- for (const [name, value] of __privateGet(this, _data)) {
808
+ for (const [name, value] of this.#data) {
875
809
  table.addRow(
876
810
  value.total,
877
811
  name,
@@ -882,22 +816,19 @@ var AggregateTiming = class {
882
816
  table.print();
883
817
  }
884
818
  };
885
- _data = new WeakMap();
886
- _last = new WeakMap();
887
819
 
888
820
  // src/Timing.ts
889
- var _starts;
890
821
  var Timing = class {
891
822
  constructor(title) {
892
823
  this.title = title;
893
- __privateAdd(this, _starts, []);
894
824
  this.stop();
895
825
  }
826
+ #starts = [];
896
827
  start(name) {
897
- __privateGet(this, _starts).push({ name, start: process.hrtime.bigint() });
828
+ this.#starts.push({ name, start: process.hrtime.bigint() });
898
829
  }
899
830
  stop() {
900
- __privateGet(this, _starts).push({ start: process.hrtime.bigint() });
831
+ this.#starts.push({ start: process.hrtime.bigint() });
901
832
  }
902
833
  printResults() {
903
834
  const table = new Table({
@@ -917,8 +848,8 @@ var Timing = class {
917
848
  ]
918
849
  });
919
850
  this.stop();
920
- let cur = __privateGet(this, _starts)[0];
921
- for (const entry of __privateGet(this, _starts)) {
851
+ let cur = this.#starts[0];
852
+ for (const entry of this.#starts) {
922
853
  if (cur.name) {
923
854
  const span = entry.start - cur.start;
924
855
  table.addRow(span, cur.name);
@@ -928,7 +859,6 @@ var Timing = class {
928
859
  table.print();
929
860
  }
930
861
  };
931
- _starts = new WeakMap();
932
862
  export {
933
863
  AggregateTiming,
934
864
  CachingHost,