@monorepolint/utils 0.5.0-alpha.1 → 0.5.0-alpha.103
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/.turbo/turbo-clean.log +4 -0
- package/.turbo/turbo-compile-typescript.log +4 -0
- package/.turbo/turbo-lint.log +61 -0
- package/.turbo/turbo-test.log +26 -0
- package/.turbo/turbo-transpile-typescript.log +18 -0
- package/build/js/index.cjs +999 -0
- package/build/js/index.cjs.map +1 -0
- package/build/js/index.js +957 -0
- package/build/js/index.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types/AggregateTiming.d.ts +15 -0
- package/build/types/AggregateTiming.d.ts.map +1 -0
- package/build/types/CachingHost.d.ts +39 -0
- package/build/types/CachingHost.d.ts.map +1 -0
- package/build/types/Host.d.ts +38 -0
- package/build/types/Host.d.ts.map +1 -0
- package/{lib → build/types}/PackageJson.d.ts +0 -0
- package/build/types/PackageJson.d.ts.map +1 -0
- package/build/types/SimpleHost.d.ts +34 -0
- package/build/types/SimpleHost.d.ts.map +1 -0
- package/build/types/Table.d.ts +53 -0
- package/build/types/Table.d.ts.map +1 -0
- package/build/types/Timing.d.ts +9 -0
- package/build/types/Timing.d.ts.map +1 -0
- package/build/types/__tests__/CachingHost.spec.d.ts +2 -0
- package/build/types/__tests__/CachingHost.spec.d.ts.map +1 -0
- package/build/types/findWorkspaceDir.d.ts +10 -0
- package/build/types/findWorkspaceDir.d.ts.map +1 -0
- package/{lib → build/types}/getPackageNameToDir.d.ts +2 -1
- package/build/types/getPackageNameToDir.d.ts.map +1 -0
- package/build/types/getWorkspacePackageDirs.d.ts +9 -0
- package/build/types/getWorkspacePackageDirs.d.ts.map +1 -0
- package/build/types/index.d.ts +20 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/matchesAnyGlob.d.ts +17 -0
- package/build/types/matchesAnyGlob.d.ts.map +1 -0
- package/{lib → build/types}/mutateJson.d.ts +2 -1
- package/build/types/mutateJson.d.ts.map +1 -0
- package/build/types/nanosecondsToSanity.d.ts +8 -0
- package/build/types/nanosecondsToSanity.d.ts.map +1 -0
- package/{jest.config.js → jest.config.cjs} +0 -0
- package/package.json +37 -14
- package/src/AggregateTiming.ts +70 -0
- package/src/CachingHost.ts +490 -0
- package/src/Host.ts +34 -0
- package/src/SimpleHost.ts +56 -0
- package/src/Table.ts +318 -0
- package/src/Timing.ts +54 -0
- package/src/__tests__/CachingHost.spec.ts +244 -0
- package/src/findWorkspaceDir.ts +25 -7
- package/src/getPackageNameToDir.ts +11 -7
- package/src/getWorkspacePackageDirs.ts +39 -11
- package/src/index.ts +13 -7
- package/src/matchesAnyGlob.ts +146 -0
- package/src/mutateJson.ts +4 -6
- package/src/nanosecondsToSanity.ts +10 -0
- package/tsconfig.json +7 -2
- package/tsup.config.cjs +11 -0
- package/lib/PackageJson.d.ts.map +0 -1
- package/lib/PackageJson.js +0 -9
- package/lib/PackageJson.js.map +0 -1
- package/lib/findWorkspaceDir.d.ts +0 -8
- package/lib/findWorkspaceDir.d.ts.map +0 -1
- package/lib/findWorkspaceDir.js +0 -28
- package/lib/findWorkspaceDir.js.map +0 -1
- package/lib/getPackageNameToDir.d.ts.map +0 -1
- package/lib/getPackageNameToDir.js +0 -30
- package/lib/getPackageNameToDir.js.map +0 -1
- package/lib/getWorkspacePackageDirs.d.ts +0 -8
- package/lib/getWorkspacePackageDirs.d.ts.map +0 -1
- package/lib/getWorkspacePackageDirs.js +0 -39
- package/lib/getWorkspacePackageDirs.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -21
- package/lib/index.js.map +0 -1
- package/lib/mutateJson.d.ts.map +0 -1
- package/lib/mutateJson.js +0 -17
- package/lib/mutateJson.js.map +0 -1
- package/lib/readJson.d.ts +0 -8
- package/lib/readJson.d.ts.map +0 -1
- package/lib/readJson.js +0 -15
- package/lib/readJson.js.map +0 -1
- package/lib/writeJson.d.ts +0 -8
- package/lib/writeJson.d.ts.map +0 -1
- package/lib/writeJson.js +0 -14
- package/lib/writeJson.js.map +0 -1
- package/src/readJson.ts +0 -13
- package/src/writeJson.ts +0 -12
- package/tsconfig.tsbuildinfo +0 -1340
|
@@ -0,0 +1,957 @@
|
|
|
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
|
+
// src/getWorkspacePackageDirs.ts
|
|
25
|
+
import { existsSync } from "fs";
|
|
26
|
+
import * as glob from "glob";
|
|
27
|
+
import * as path from "path";
|
|
28
|
+
import * as fs from "fs";
|
|
29
|
+
import * as readYamlFile from "read-yaml-file";
|
|
30
|
+
import { findPackages } from "find-packages";
|
|
31
|
+
async function findPNPMWorkspacePackages(workspaceRoot) {
|
|
32
|
+
workspaceRoot = fs.realpathSync(workspaceRoot);
|
|
33
|
+
const workspaceManifest = await readYamlFile.default(
|
|
34
|
+
path.join(workspaceRoot, "pnpm-workspace.yaml")
|
|
35
|
+
);
|
|
36
|
+
return findPackages(workspaceRoot, {
|
|
37
|
+
ignore: ["**/node_modules/**", "**/bower_components/**"],
|
|
38
|
+
includeRoot: true,
|
|
39
|
+
patterns: workspaceManifest.packages
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function getWorkspacePackageDirs(host, workspaceDir, resolvePaths = false) {
|
|
43
|
+
const packageJson = host.readJson(path.join(workspaceDir, "package.json"));
|
|
44
|
+
const isPnpmWorkspace = host.exists(path.join(workspaceDir, "pnpm-workspace.yaml"));
|
|
45
|
+
if (isPnpmWorkspace) {
|
|
46
|
+
const workspacePackages = await findPNPMWorkspacePackages(workspaceDir);
|
|
47
|
+
if (workspacePackages.length === 0) {
|
|
48
|
+
throw new Error("Invalid workspaceDir: " + workspaceDir);
|
|
49
|
+
}
|
|
50
|
+
return workspacePackages.map((project) => project.dir).filter((d) => d !== workspaceDir);
|
|
51
|
+
}
|
|
52
|
+
if (!packageJson.workspaces) {
|
|
53
|
+
throw new Error("Unsupported! Monorepo is not backed by either pnpm nor yarn workspaces.");
|
|
54
|
+
}
|
|
55
|
+
const ret = [];
|
|
56
|
+
const packageGlobs = Array.isArray(packageJson.workspaces) ? packageJson.workspaces : packageJson.workspaces.packages || [];
|
|
57
|
+
for (const pattern of packageGlobs) {
|
|
58
|
+
for (const packagePath of glob.sync(pattern, { cwd: workspaceDir })) {
|
|
59
|
+
const packageJsonPath = path.join(workspaceDir, packagePath, "package.json");
|
|
60
|
+
if (existsSync(packageJsonPath)) {
|
|
61
|
+
if (resolvePaths === true) {
|
|
62
|
+
ret.push(path.resolve(path.join(workspaceDir, packagePath)));
|
|
63
|
+
} else {
|
|
64
|
+
ret.push(packagePath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return ret;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/mutateJson.ts
|
|
73
|
+
function mutateJson(path4, host, mutator) {
|
|
74
|
+
let file = host.readJson(path4);
|
|
75
|
+
file = mutator(file);
|
|
76
|
+
host.writeJson(path4, file);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/findWorkspaceDir.ts
|
|
80
|
+
import * as path2 from "path";
|
|
81
|
+
import * as fs2 from "fs";
|
|
82
|
+
import { findUp } from "find-up";
|
|
83
|
+
async function findPnpmWorkspaceDir(cwd) {
|
|
84
|
+
const workspaceManifestLocation = await findUp("pnpm-workspace.yaml", {
|
|
85
|
+
cwd: await fs2.promises.realpath(cwd)
|
|
86
|
+
});
|
|
87
|
+
return workspaceManifestLocation && path2.dirname(workspaceManifestLocation);
|
|
88
|
+
}
|
|
89
|
+
async function findWorkspaceDir(host, dir) {
|
|
90
|
+
const maybePnpmWorkspaceDir = await findPnpmWorkspaceDir(dir);
|
|
91
|
+
if (maybePnpmWorkspaceDir != null) {
|
|
92
|
+
return maybePnpmWorkspaceDir;
|
|
93
|
+
}
|
|
94
|
+
const packagePath = path2.join(dir, "package.json");
|
|
95
|
+
if (host.exists(packagePath)) {
|
|
96
|
+
const packageJson = host.readJson(packagePath);
|
|
97
|
+
if (packageJson.workspaces !== void 0) {
|
|
98
|
+
return dir;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const nextDir = path2.normalize(path2.join(dir, ".."));
|
|
102
|
+
if (nextDir === dir) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
return findWorkspaceDir(host, nextDir);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/getPackageNameToDir.ts
|
|
109
|
+
import { join as pathJoin } from "path";
|
|
110
|
+
async function getPackageNameToDir(host, workspaceDir, resolvePaths = false) {
|
|
111
|
+
const ret = /* @__PURE__ */ new Map();
|
|
112
|
+
const workspacePackages = await getWorkspacePackageDirs(host, workspaceDir, resolvePaths);
|
|
113
|
+
for (const packageDir of workspacePackages) {
|
|
114
|
+
const packagePath = pathJoin(packageDir, "package.json");
|
|
115
|
+
const { name } = host.readJson(packagePath);
|
|
116
|
+
if (name === void 0) {
|
|
117
|
+
throw new Error(`Package needs a name: ${packagePath}`);
|
|
118
|
+
}
|
|
119
|
+
ret.set(name, packageDir);
|
|
120
|
+
}
|
|
121
|
+
return ret;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/SimpleHost.ts
|
|
125
|
+
import * as realFs from "fs";
|
|
126
|
+
var SimpleHost = class {
|
|
127
|
+
constructor(fs3 = realFs) {
|
|
128
|
+
this.fs = fs3;
|
|
129
|
+
}
|
|
130
|
+
mkdir(directoryPath, opts) {
|
|
131
|
+
this.fs.mkdirSync(directoryPath, { recursive: opts?.recursive ?? false });
|
|
132
|
+
}
|
|
133
|
+
rmdir(directoryPath) {
|
|
134
|
+
this.fs.rmdirSync(directoryPath);
|
|
135
|
+
}
|
|
136
|
+
exists(path4) {
|
|
137
|
+
return this.fs.existsSync(path4);
|
|
138
|
+
}
|
|
139
|
+
writeFile(path4, body, opts) {
|
|
140
|
+
if (opts) {
|
|
141
|
+
this.fs.writeFileSync(path4, body, { encoding: opts.encoding });
|
|
142
|
+
} else {
|
|
143
|
+
this.fs.writeFileSync(path4, body);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
readFile(path4, opts) {
|
|
147
|
+
if (opts?.asJson) {
|
|
148
|
+
return JSON.parse(this.fs.readFileSync(path4, "utf-8"));
|
|
149
|
+
}
|
|
150
|
+
return this.fs.readFileSync(path4, opts?.encoding);
|
|
151
|
+
}
|
|
152
|
+
deleteFile(path4) {
|
|
153
|
+
this.fs.unlinkSync(path4);
|
|
154
|
+
}
|
|
155
|
+
readJson(filename) {
|
|
156
|
+
const contents = this.fs.readFileSync(filename, "utf-8");
|
|
157
|
+
return JSON.parse(contents);
|
|
158
|
+
}
|
|
159
|
+
writeJson(path4, o) {
|
|
160
|
+
return this.fs.writeFileSync(path4, JSON.stringify(o, void 0, 2) + "\n");
|
|
161
|
+
}
|
|
162
|
+
flush() {
|
|
163
|
+
return Promise.resolve();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/CachingHost.ts
|
|
168
|
+
import * as realFs2 from "fs";
|
|
169
|
+
import * as path3 from "path";
|
|
170
|
+
function assertNoTombstone(node) {
|
|
171
|
+
if (node.tombstone) {
|
|
172
|
+
throw new Error(`Unexpected tombstone ${JSON.stringify(node)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function assertNotType(node, type) {
|
|
176
|
+
if (node.type === type) {
|
|
177
|
+
throw new Error(`Unexpected node type ${JSON.stringify(node)}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function assertType(node, type) {
|
|
181
|
+
if (node.type !== type) {
|
|
182
|
+
throw new Error(`Unexpected node type ${JSON.stringify(node)}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function assertExists(node) {
|
|
186
|
+
if (!node) {
|
|
187
|
+
throw new Error(`Expected node to exist`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function assertHasParent(node) {
|
|
191
|
+
if (!node.parent) {
|
|
192
|
+
throw new Error("Expected node to have a parent directory");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
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
|
+
var CachingHost = class {
|
|
197
|
+
constructor(fs3 = realFs2) {
|
|
198
|
+
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());
|
|
209
|
+
}
|
|
210
|
+
mkdir(filePath, opts = { recursive: false }) {
|
|
211
|
+
const canonicalPath = path3.resolve(filePath);
|
|
212
|
+
const { node, pathWithSymlinks } = __privateMethod(this, _getNearestAncestorNode, getNearestAncestorNode_fn).call(this, canonicalPath);
|
|
213
|
+
if (filePath === pathWithSymlinks) {
|
|
214
|
+
assertType(node, "dir");
|
|
215
|
+
assertHasParent(node);
|
|
216
|
+
if (!node.tombstone)
|
|
217
|
+
return;
|
|
218
|
+
} else if (path3.dirname(filePath) === pathWithSymlinks) {
|
|
219
|
+
assertType(node, "dir");
|
|
220
|
+
assertNoTombstone(node);
|
|
221
|
+
node.dir.set(path3.basename(filePath), {
|
|
222
|
+
type: "dir",
|
|
223
|
+
fullPath: filePath,
|
|
224
|
+
parent: node,
|
|
225
|
+
dir: /* @__PURE__ */ new Map(),
|
|
226
|
+
needsFlush: true
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (!opts.recursive && path3.dirname(canonicalPath) !== pathWithSymlinks) {
|
|
231
|
+
throw new Error("no such file or directory");
|
|
232
|
+
}
|
|
233
|
+
const rootPath = pathWithSymlinks;
|
|
234
|
+
let maybePath = canonicalPath;
|
|
235
|
+
const toMake = [];
|
|
236
|
+
while (maybePath !== rootPath) {
|
|
237
|
+
toMake.unshift(path3.resolve(node.fullPath, path3.relative(rootPath, maybePath)));
|
|
238
|
+
maybePath = path3.dirname(maybePath);
|
|
239
|
+
}
|
|
240
|
+
for (const dirToMake of toMake) {
|
|
241
|
+
this.mkdir(dirToMake);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
rmdir(directoryPath) {
|
|
245
|
+
const node = __privateMethod(this, _getNode, getNode_fn).call(this, directoryPath);
|
|
246
|
+
if (!node || node.tombstone) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
assertType(node, "dir");
|
|
250
|
+
if (node.stub) {
|
|
251
|
+
__privateMethod(this, _unstubDirectory, unstubDirectory_fn).call(this, node);
|
|
252
|
+
}
|
|
253
|
+
if (node.dir.size === 0) {
|
|
254
|
+
__privateMethod(this, _replaceNode, replaceNode_fn).call(this, node, {
|
|
255
|
+
type: "dir",
|
|
256
|
+
tombstone: true,
|
|
257
|
+
needsFlush: true
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
throw new Error("directory not empty");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exists(filePath) {
|
|
264
|
+
const node = __privateMethod(this, _getNode, getNode_fn).call(this, filePath);
|
|
265
|
+
return !!node && !node.tombstone;
|
|
266
|
+
}
|
|
267
|
+
readFile(filePath, opts) {
|
|
268
|
+
let node = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, filePath);
|
|
269
|
+
if (!node) {
|
|
270
|
+
return void 0;
|
|
271
|
+
}
|
|
272
|
+
assertNotType(node, "dir");
|
|
273
|
+
assertNoTombstone(node);
|
|
274
|
+
if (node.stub) {
|
|
275
|
+
node = __privateMethod(this, _replaceNode, replaceNode_fn).call(this, node, {
|
|
276
|
+
type: "file",
|
|
277
|
+
file: this.fs.readFileSync(filePath),
|
|
278
|
+
needsFlush: false
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (!opts) {
|
|
282
|
+
return Buffer.from(node.file);
|
|
283
|
+
} else if (opts.asJson) {
|
|
284
|
+
return JSON.parse(node.file.toString("utf-8"));
|
|
285
|
+
} else {
|
|
286
|
+
return node.file.toString(opts.encoding);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
writeFile(filePath, body, opts) {
|
|
290
|
+
const fileContentsAsBuffer = typeof body === "string" ? Buffer.from(body, opts?.encoding) : Buffer.from(body);
|
|
291
|
+
const canonicalPath = path3.resolve(filePath);
|
|
292
|
+
const existingNode = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, canonicalPath);
|
|
293
|
+
if (existingNode) {
|
|
294
|
+
if (existingNode.type === "dir") {
|
|
295
|
+
throw new Error("cant write file to a dir");
|
|
296
|
+
}
|
|
297
|
+
__privateMethod(this, _replaceNode, replaceNode_fn).call(this, existingNode, {
|
|
298
|
+
file: fileContentsAsBuffer,
|
|
299
|
+
type: "file",
|
|
300
|
+
needsFlush: true
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const maybeDirNode = __privateMethod(this, _getNodeResolvingSymlinks, getNodeResolvingSymlinks_fn).call(this, path3.dirname(canonicalPath));
|
|
305
|
+
assertExists(maybeDirNode);
|
|
306
|
+
assertType(maybeDirNode, "dir");
|
|
307
|
+
assertNoTombstone(maybeDirNode);
|
|
308
|
+
maybeDirNode.dir.set(path3.basename(canonicalPath), {
|
|
309
|
+
type: "file",
|
|
310
|
+
fullPath: canonicalPath,
|
|
311
|
+
parent: maybeDirNode,
|
|
312
|
+
file: fileContentsAsBuffer,
|
|
313
|
+
needsFlush: true
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
deleteFile(filePath) {
|
|
317
|
+
const canonicalPath = path3.resolve(filePath);
|
|
318
|
+
const node = __privateMethod(this, _getNode, getNode_fn).call(this, canonicalPath);
|
|
319
|
+
if (!node || node.type === "file" && node.tombstone === true)
|
|
320
|
+
return;
|
|
321
|
+
assertNotType(node, "dir");
|
|
322
|
+
__privateMethod(this, _replaceNode, replaceNode_fn).call(this, node, {
|
|
323
|
+
type: "file",
|
|
324
|
+
tombstone: true,
|
|
325
|
+
needsFlush: true
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
readJson(filePath) {
|
|
329
|
+
return this.readFile(filePath, { asJson: true });
|
|
330
|
+
}
|
|
331
|
+
writeJson(filePath, o) {
|
|
332
|
+
return this.writeFile(filePath, JSON.stringify(o, void 0, 2) + "\n", {
|
|
333
|
+
encoding: "utf-8"
|
|
334
|
+
});
|
|
335
|
+
}
|
|
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;
|
|
433
|
+
}
|
|
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) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
} else if (node.stub === true || node.needsFlush === false) {
|
|
470
|
+
return;
|
|
471
|
+
} else {
|
|
472
|
+
return this.fs.promises.writeFile(node.fullPath, node.file);
|
|
473
|
+
}
|
|
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) {
|
|
482
|
+
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
|
+
try {
|
|
492
|
+
await this.fs.promises.access(node.fullPath);
|
|
493
|
+
} catch (e) {
|
|
494
|
+
await this.fs.promises.mkdir(node.fullPath);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
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");
|
|
501
|
+
}
|
|
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");
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
await Promise.all(promises2);
|
|
513
|
+
if (node.tombstone) {
|
|
514
|
+
return this.fs.promises.rmdir(node.fullPath);
|
|
515
|
+
}
|
|
516
|
+
return;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// src/matchesAnyGlob.ts
|
|
520
|
+
import micromatch from "micromatch";
|
|
521
|
+
|
|
522
|
+
// src/nanosecondsToSanity.ts
|
|
523
|
+
function nanosecondsToSanity(n, precision = 9) {
|
|
524
|
+
return n / BigInt(1e9) + "." + ("" + n % BigInt(1e9)).padStart(9, "0").substring(0, precision) + "s";
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// 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
|
+
var Table = class {
|
|
530
|
+
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, {
|
|
546
|
+
padding: 2,
|
|
547
|
+
...config
|
|
548
|
+
});
|
|
549
|
+
__privateGet(this, _columnWidths).fill(0, 0, config.columns.length);
|
|
550
|
+
if (config.showFooter) {
|
|
551
|
+
__privateSet(this, _footerRowConfig, []);
|
|
552
|
+
for (const columnConfig of config.columns) {
|
|
553
|
+
if (columnConfig.footer === void 0) {
|
|
554
|
+
throw new Error("Must specify footer fields when showFooter is true");
|
|
555
|
+
} else if (typeof columnConfig.footer === "string") {
|
|
556
|
+
__privateGet(this, _footerRowConfig).push({
|
|
557
|
+
type: "string",
|
|
558
|
+
alignment: "left",
|
|
559
|
+
aggregate: "static",
|
|
560
|
+
value: columnConfig.footer
|
|
561
|
+
});
|
|
562
|
+
} else if ("value" in columnConfig.footer) {
|
|
563
|
+
__privateGet(this, _footerRowConfig).push({
|
|
564
|
+
type: "string",
|
|
565
|
+
alignment: "left",
|
|
566
|
+
...columnConfig.footer
|
|
567
|
+
});
|
|
568
|
+
} else if ("aggregate" in columnConfig.footer) {
|
|
569
|
+
if (columnConfig.type !== "bigint")
|
|
570
|
+
throw new Error("expecting bigint for aggregate");
|
|
571
|
+
__privateGet(this, _footerRowConfig).push({
|
|
572
|
+
type: columnConfig.type,
|
|
573
|
+
renderAs: columnConfig.renderAs,
|
|
574
|
+
precision: columnConfig.precision,
|
|
575
|
+
alignment: "right",
|
|
576
|
+
...columnConfig.footer
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
addRow(...data) {
|
|
583
|
+
__privateGet(this, _rows).push(data);
|
|
584
|
+
}
|
|
585
|
+
print() {
|
|
586
|
+
if (__privateGet(this, _config).sortColumn !== void 0) {
|
|
587
|
+
}
|
|
588
|
+
__privateMethod(this, _updateFooterRow, updateFooterRow_fn).call(this);
|
|
589
|
+
__privateMethod(this, _calculateColumnWidths, calculateColumnWidths_fn).call(this);
|
|
590
|
+
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);
|
|
596
|
+
}
|
|
597
|
+
for (let r = 0; r < __privateGet(this, _rows).length; r++) {
|
|
598
|
+
let rowText = "";
|
|
599
|
+
for (let c = 0; c < __privateGet(this, _config).columns.length; c++) {
|
|
600
|
+
rowText += this.getEntryAsStringAligned(c, r) + paddingString;
|
|
601
|
+
}
|
|
602
|
+
rowText.trim();
|
|
603
|
+
console.log(rowText);
|
|
604
|
+
}
|
|
605
|
+
if (__privateGet(this, _config).showFooter)
|
|
606
|
+
__privateMethod(this, _printFooterRow, printFooterRow_fn).call(this);
|
|
607
|
+
console.log();
|
|
608
|
+
}
|
|
609
|
+
getEntryAsString(colNum, rowNum) {
|
|
610
|
+
const config = __privateGet(this, _config).columns[colNum];
|
|
611
|
+
if (config.type === "bigint" && config.renderAs === "nanoseconds") {
|
|
612
|
+
return nanosecondsToSanity(__privateGet(this, _rows)[rowNum][colNum], config.precision ?? 9);
|
|
613
|
+
} else {
|
|
614
|
+
return "" + __privateGet(this, _rows)[rowNum][colNum];
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
getEntryAsStringAligned(colNum, rowNum) {
|
|
618
|
+
const config = __privateGet(this, _config).columns[colNum];
|
|
619
|
+
let result;
|
|
620
|
+
if (config.type === "bigint" && config.renderAs === "nanoseconds") {
|
|
621
|
+
result = nanosecondsToSanity(__privateGet(this, _rows)[rowNum][colNum], config.precision ?? 9);
|
|
622
|
+
} else {
|
|
623
|
+
result = "" + __privateGet(this, _rows)[rowNum][colNum];
|
|
624
|
+
}
|
|
625
|
+
if (config.alignment === "left") {
|
|
626
|
+
return result.padEnd(__privateGet(this, _columnWidths)[colNum]);
|
|
627
|
+
} else {
|
|
628
|
+
return result.padStart(__privateGet(this, _columnWidths)[colNum]);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
getColumnWidth(colNum, config) {
|
|
632
|
+
let maxWidth = Math.max(
|
|
633
|
+
(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
|
|
635
|
+
);
|
|
636
|
+
for (let r = 0; r < __privateGet(this, _rows).length; r++) {
|
|
637
|
+
maxWidth = Math.max(maxWidth, this.getEntryAsString(colNum, r).length);
|
|
638
|
+
}
|
|
639
|
+
return maxWidth;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
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
|
+
|
|
755
|
+
// src/matchesAnyGlob.ts
|
|
756
|
+
var cache = /* @__PURE__ */ new Map();
|
|
757
|
+
var singleMatcherCache = /* @__PURE__ */ new Map();
|
|
758
|
+
var compiledGlobCache = /* @__PURE__ */ new Map();
|
|
759
|
+
var haystackMiss = 0;
|
|
760
|
+
var haystackHit = 0;
|
|
761
|
+
var matchTime = BigInt(0);
|
|
762
|
+
var singleMatcherHits = 0;
|
|
763
|
+
var singleMatcherMisses = 0;
|
|
764
|
+
var singleMatcherSaves = 0;
|
|
765
|
+
var matchesAnyGlob = function matchesAnyGlobFunc(needle, haystack) {
|
|
766
|
+
matchTime -= process.hrtime.bigint();
|
|
767
|
+
let cacheForHaystack = cache.get(haystack);
|
|
768
|
+
if (cacheForHaystack === void 0) {
|
|
769
|
+
cacheForHaystack = /* @__PURE__ */ new Map();
|
|
770
|
+
cache.set(haystack, cacheForHaystack);
|
|
771
|
+
}
|
|
772
|
+
let result = cacheForHaystack.get(needle);
|
|
773
|
+
if (result === void 0) {
|
|
774
|
+
haystackMiss++;
|
|
775
|
+
result = false;
|
|
776
|
+
for (const pattern of haystack) {
|
|
777
|
+
let patternCache = singleMatcherCache.get(pattern);
|
|
778
|
+
if (patternCache === void 0) {
|
|
779
|
+
patternCache = /* @__PURE__ */ new Map();
|
|
780
|
+
singleMatcherCache.set(pattern, patternCache);
|
|
781
|
+
}
|
|
782
|
+
result = patternCache.get(needle);
|
|
783
|
+
if (result === void 0) {
|
|
784
|
+
let regexp = compiledGlobCache.get(pattern);
|
|
785
|
+
if (regexp === void 0) {
|
|
786
|
+
regexp = micromatch.makeRe(pattern);
|
|
787
|
+
compiledGlobCache.set(pattern, regexp);
|
|
788
|
+
}
|
|
789
|
+
singleMatcherMisses++;
|
|
790
|
+
result = regexp.test(needle);
|
|
791
|
+
patternCache.set(needle, result);
|
|
792
|
+
} else {
|
|
793
|
+
singleMatcherHits++;
|
|
794
|
+
singleMatcherSaves++;
|
|
795
|
+
}
|
|
796
|
+
if (result)
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
cacheForHaystack.set(needle, result);
|
|
800
|
+
} else {
|
|
801
|
+
singleMatcherSaves += haystack.length;
|
|
802
|
+
haystackHit++;
|
|
803
|
+
}
|
|
804
|
+
matchTime += process.hrtime.bigint();
|
|
805
|
+
return result;
|
|
806
|
+
};
|
|
807
|
+
matchesAnyGlob.printStats = () => {
|
|
808
|
+
const table = new Table({
|
|
809
|
+
title: "matchesAnyGlob stats",
|
|
810
|
+
showHeader: true,
|
|
811
|
+
showFooter: false,
|
|
812
|
+
columns: [
|
|
813
|
+
{ header: "Stat", type: "string" },
|
|
814
|
+
{ header: "Value", type: "string" }
|
|
815
|
+
]
|
|
816
|
+
});
|
|
817
|
+
table.addRow("Haystack Miss", "" + haystackMiss);
|
|
818
|
+
table.addRow("Haystack Hit", "" + haystackHit);
|
|
819
|
+
table.addRow("Single Glob Hits", "" + singleMatcherHits);
|
|
820
|
+
table.addRow("Single Glob Misses", "" + singleMatcherMisses);
|
|
821
|
+
table.addRow("Single Glob Saves", "" + singleMatcherSaves);
|
|
822
|
+
table.addRow("Total Time", nanosecondsToSanity(matchTime, 6));
|
|
823
|
+
table.print();
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
// src/AggregateTiming.ts
|
|
827
|
+
var _data, _last;
|
|
828
|
+
var AggregateTiming = class {
|
|
829
|
+
constructor(title) {
|
|
830
|
+
this.title = title;
|
|
831
|
+
__privateAdd(this, _data, /* @__PURE__ */ new Map());
|
|
832
|
+
__privateAdd(this, _last, void 0);
|
|
833
|
+
}
|
|
834
|
+
start(name) {
|
|
835
|
+
const time = process.hrtime.bigint();
|
|
836
|
+
if (__privateGet(this, _last)) {
|
|
837
|
+
__privateGet(this, _last).total += time;
|
|
838
|
+
}
|
|
839
|
+
let data = __privateGet(this, _data).get(name);
|
|
840
|
+
if (data === void 0) {
|
|
841
|
+
data = { count: 1, total: -time };
|
|
842
|
+
__privateGet(this, _data).set(name, data);
|
|
843
|
+
} else {
|
|
844
|
+
data.total -= time;
|
|
845
|
+
data.count++;
|
|
846
|
+
}
|
|
847
|
+
__privateSet(this, _last, data);
|
|
848
|
+
}
|
|
849
|
+
stop() {
|
|
850
|
+
const time = process.hrtime.bigint();
|
|
851
|
+
if (__privateGet(this, _last)) {
|
|
852
|
+
__privateGet(this, _last).total += time;
|
|
853
|
+
__privateSet(this, _last, void 0);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
printResults() {
|
|
857
|
+
const table = new Table({
|
|
858
|
+
sortColumn: -1,
|
|
859
|
+
showFooter: true,
|
|
860
|
+
showHeader: true,
|
|
861
|
+
title: this.title,
|
|
862
|
+
columns: [
|
|
863
|
+
{
|
|
864
|
+
header: "Duration",
|
|
865
|
+
type: "bigint",
|
|
866
|
+
renderAs: "nanoseconds",
|
|
867
|
+
footer: { aggregate: "sum" }
|
|
868
|
+
},
|
|
869
|
+
{ header: "Task", type: "string", alignment: "left", footer: "TOTAL" },
|
|
870
|
+
{ header: "Count", type: "bigint", footer: { aggregate: "sum" } },
|
|
871
|
+
{ header: "Avg", type: "bigint", footer: { aggregate: "average" } }
|
|
872
|
+
]
|
|
873
|
+
});
|
|
874
|
+
for (const [name, value] of __privateGet(this, _data)) {
|
|
875
|
+
table.addRow(
|
|
876
|
+
value.total,
|
|
877
|
+
name,
|
|
878
|
+
BigInt(value.count),
|
|
879
|
+
value.total / BigInt(value.count)
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
table.print();
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
_data = new WeakMap();
|
|
886
|
+
_last = new WeakMap();
|
|
887
|
+
|
|
888
|
+
// src/Timing.ts
|
|
889
|
+
var _starts;
|
|
890
|
+
var Timing = class {
|
|
891
|
+
constructor(title) {
|
|
892
|
+
this.title = title;
|
|
893
|
+
__privateAdd(this, _starts, []);
|
|
894
|
+
this.stop();
|
|
895
|
+
}
|
|
896
|
+
start(name) {
|
|
897
|
+
__privateGet(this, _starts).push({ name, start: process.hrtime.bigint() });
|
|
898
|
+
}
|
|
899
|
+
stop() {
|
|
900
|
+
__privateGet(this, _starts).push({ start: process.hrtime.bigint() });
|
|
901
|
+
}
|
|
902
|
+
printResults() {
|
|
903
|
+
const table = new Table({
|
|
904
|
+
sortColumn: -1,
|
|
905
|
+
showFooter: true,
|
|
906
|
+
showHeader: true,
|
|
907
|
+
title: this.title,
|
|
908
|
+
columns: [
|
|
909
|
+
{
|
|
910
|
+
header: "Duration",
|
|
911
|
+
type: "bigint",
|
|
912
|
+
renderAs: "nanoseconds",
|
|
913
|
+
precision: 4,
|
|
914
|
+
footer: { aggregate: "sum" }
|
|
915
|
+
},
|
|
916
|
+
{ header: "Task", type: "string", footer: "TOTAL" }
|
|
917
|
+
]
|
|
918
|
+
});
|
|
919
|
+
this.stop();
|
|
920
|
+
let cur = __privateGet(this, _starts)[0];
|
|
921
|
+
for (const entry of __privateGet(this, _starts)) {
|
|
922
|
+
if (cur.name) {
|
|
923
|
+
const span = entry.start - cur.start;
|
|
924
|
+
table.addRow(span, cur.name);
|
|
925
|
+
}
|
|
926
|
+
cur = entry;
|
|
927
|
+
}
|
|
928
|
+
table.print();
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
_starts = new WeakMap();
|
|
932
|
+
export {
|
|
933
|
+
AggregateTiming,
|
|
934
|
+
CachingHost,
|
|
935
|
+
SimpleHost,
|
|
936
|
+
Table,
|
|
937
|
+
Timing,
|
|
938
|
+
findWorkspaceDir,
|
|
939
|
+
getPackageNameToDir,
|
|
940
|
+
getWorkspacePackageDirs,
|
|
941
|
+
matchesAnyGlob,
|
|
942
|
+
mutateJson,
|
|
943
|
+
nanosecondsToSanity
|
|
944
|
+
};
|
|
945
|
+
/*!
|
|
946
|
+
* Copyright 2019 Palantir Technologies, Inc.
|
|
947
|
+
*
|
|
948
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
949
|
+
*
|
|
950
|
+
*/
|
|
951
|
+
/*!
|
|
952
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
953
|
+
*
|
|
954
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
955
|
+
*
|
|
956
|
+
*/
|
|
957
|
+
//# sourceMappingURL=index.js.map
|