@monorepolint/utils 0.5.0-alpha.9 → 0.5.0-alpha.95
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/lib/AggregateTiming.d.ts +15 -0
- package/lib/AggregateTiming.d.ts.map +1 -0
- package/lib/AggregateTiming.js +70 -0
- package/lib/AggregateTiming.js.map +1 -0
- package/lib/CachingHost.d.ts +39 -0
- package/lib/CachingHost.d.ts.map +1 -0
- package/lib/CachingHost.js +366 -0
- package/lib/CachingHost.js.map +1 -0
- package/lib/Host.d.ts +38 -0
- package/lib/Host.d.ts.map +1 -0
- package/lib/Host.js +9 -0
- package/lib/Host.js.map +1 -0
- package/lib/SimpleHost.d.ts +35 -0
- package/lib/SimpleHost.d.ts.map +1 -0
- package/lib/SimpleHost.js +56 -0
- package/lib/SimpleHost.js.map +1 -0
- package/lib/Table.d.ts +53 -0
- package/lib/Table.d.ts.map +1 -0
- package/lib/Table.js +234 -0
- package/lib/Table.js.map +1 -0
- package/lib/Timing.d.ts +9 -0
- package/lib/Timing.d.ts.map +1 -0
- package/lib/Timing.js +57 -0
- package/lib/Timing.js.map +1 -0
- package/lib/__tests__/CachingHost.spec.d.ts +8 -0
- package/lib/__tests__/CachingHost.spec.d.ts.map +1 -0
- package/lib/__tests__/CachingHost.spec.js +178 -0
- package/lib/__tests__/CachingHost.spec.js.map +1 -0
- package/lib/findWorkspaceDir.d.ts +2 -1
- package/lib/findWorkspaceDir.d.ts.map +1 -1
- package/lib/findWorkspaceDir.js +5 -6
- package/lib/findWorkspaceDir.js.map +1 -1
- package/lib/getPackageNameToDir.d.ts +2 -1
- package/lib/getPackageNameToDir.d.ts.map +1 -1
- package/lib/getPackageNameToDir.js +5 -5
- package/lib/getPackageNameToDir.js.map +1 -1
- package/lib/getWorkspacePackageDirs.d.ts +2 -1
- package/lib/getWorkspacePackageDirs.d.ts.map +1 -1
- package/lib/getWorkspacePackageDirs.js +6 -6
- package/lib/getWorkspacePackageDirs.js.map +1 -1
- package/lib/index.d.ts +8 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -8
- package/lib/index.js.map +1 -1
- package/lib/matchesAnyGlob.d.ts +17 -0
- package/lib/matchesAnyGlob.d.ts.map +1 -0
- package/lib/matchesAnyGlob.js +131 -0
- package/lib/matchesAnyGlob.js.map +1 -0
- package/lib/mutateJson.d.ts +2 -1
- package/lib/mutateJson.d.ts.map +1 -1
- package/lib/mutateJson.js +4 -5
- package/lib/mutateJson.js.map +1 -1
- package/lib/nanosecondsToSanity.d.ts +8 -0
- package/lib/nanosecondsToSanity.d.ts.map +1 -0
- package/lib/nanosecondsToSanity.js +14 -0
- package/lib/nanosecondsToSanity.js.map +1 -0
- package/package.json +12 -10
- package/src/AggregateTiming.ts +71 -0
- package/src/CachingHost.ts +489 -0
- package/src/Host.ts +34 -0
- package/src/SimpleHost.ts +57 -0
- package/src/Table.ts +319 -0
- package/src/Timing.ts +55 -0
- package/src/__tests__/CachingHost.spec.ts +244 -0
- package/src/findWorkspaceDir.ts +5 -6
- package/src/getPackageNameToDir.ts +4 -4
- package/src/getWorkspacePackageDirs.ts +7 -3
- package/src/index.ts +8 -2
- package/src/matchesAnyGlob.ts +145 -0
- package/src/mutateJson.ts +4 -5
- package/src/nanosecondsToSanity.ts +10 -0
- package/tsconfig.tsbuildinfo +1 -1586
- 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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SimpleHost = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const realFs = tslib_1.__importStar(require("fs"));
|
|
12
|
+
class SimpleHost {
|
|
13
|
+
constructor(fs = realFs) {
|
|
14
|
+
this.fs = fs;
|
|
15
|
+
}
|
|
16
|
+
mkdir(directoryPath, opts) {
|
|
17
|
+
var _a;
|
|
18
|
+
this.fs.mkdirSync(directoryPath, { recursive: (_a = opts === null || opts === void 0 ? void 0 : opts.recursive) !== null && _a !== void 0 ? _a : false });
|
|
19
|
+
}
|
|
20
|
+
rmdir(directoryPath) {
|
|
21
|
+
this.fs.rmdirSync(directoryPath);
|
|
22
|
+
}
|
|
23
|
+
exists(path) {
|
|
24
|
+
return this.fs.existsSync(path);
|
|
25
|
+
}
|
|
26
|
+
writeFile(path, body, opts) {
|
|
27
|
+
if (opts) {
|
|
28
|
+
this.fs.writeFileSync(path, body, { encoding: opts.encoding });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.fs.writeFileSync(path, body);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
readFile(path, opts) {
|
|
35
|
+
if (opts === null || opts === void 0 ? void 0 : opts.asJson) {
|
|
36
|
+
return JSON.parse(this.fs.readFileSync(path, "utf-8"));
|
|
37
|
+
}
|
|
38
|
+
return this.fs.readFileSync(path, opts === null || opts === void 0 ? void 0 : opts.encoding);
|
|
39
|
+
}
|
|
40
|
+
deleteFile(path) {
|
|
41
|
+
this.fs.unlinkSync(path);
|
|
42
|
+
}
|
|
43
|
+
readJson(filename) {
|
|
44
|
+
const contents = this.fs.readFileSync(filename, "utf-8");
|
|
45
|
+
return JSON.parse(contents);
|
|
46
|
+
}
|
|
47
|
+
writeJson(path, o) {
|
|
48
|
+
return this.fs.writeFileSync(path, JSON.stringify(o, undefined, 2) + "\n");
|
|
49
|
+
}
|
|
50
|
+
flush() {
|
|
51
|
+
// noop in the simple case
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.SimpleHost = SimpleHost;
|
|
56
|
+
//# sourceMappingURL=SimpleHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleHost.js","sourceRoot":"","sources":["../src/SimpleHost.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mDAA6B;AAI7B,MAAa,UAAU;IACrB,YAAoB,KAAoB,MAAM;QAA1B,OAAE,GAAF,EAAE,CAAwB;IAAG,CAAC;IAClD,KAAK,CAAC,aAAqB,EAAE,IAA6B;;QACxD,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,mCAAI,KAAK,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,KAAK,CAAC,aAAqB;QACzB,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAID,SAAS,CAAC,IAAS,EAAE,IAAS,EAAE,IAAmC;QACjE,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;SAChE;aAAM;YACL,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACnC;IACH,CAAC;IAID,QAAQ,CAAC,IAAS,EAAE,IAAsD;QACxE,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAE;YAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;SACxD;QACD,OAAO,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IACD,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,QAAQ,CAAC,QAAgB;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IACD,SAAS,CAAC,IAAY,EAAE,CAAS;QAC/B,OAAO,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7E,CAAC;IACD,KAAK;QACH,0BAA0B;QAC1B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AA7CD,gCA6CC"}
|
package/lib/Table.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare type HeaderFooterHelper<HB, FB, H, F> = (HB extends true ? {
|
|
2
|
+
header: H;
|
|
3
|
+
} : {
|
|
4
|
+
header?: H;
|
|
5
|
+
}) & (FB extends true ? {
|
|
6
|
+
footer: F;
|
|
7
|
+
} : {
|
|
8
|
+
footer?: F;
|
|
9
|
+
});
|
|
10
|
+
declare type WithAlignemnt = {
|
|
11
|
+
alignment?: "right" | "left";
|
|
12
|
+
};
|
|
13
|
+
declare type BaseBigIntCellConfig = {
|
|
14
|
+
type: "bigint";
|
|
15
|
+
renderAs?: "nanoseconds";
|
|
16
|
+
precision?: number;
|
|
17
|
+
} & WithAlignemnt;
|
|
18
|
+
declare type BaseStringCellConfig = {
|
|
19
|
+
type: "string";
|
|
20
|
+
} & WithAlignemnt;
|
|
21
|
+
declare type BigIntColumnConfig<H, F> = WithAlignemnt & BaseBigIntCellConfig & HeaderFooterHelper<H, F, string, AggregateFooterConfig | StaticFooterConfig>;
|
|
22
|
+
declare type StringColumnConfig<H, F> = WithAlignemnt & BaseStringCellConfig & HeaderFooterHelper<H, F, string, StaticFooterConfig>;
|
|
23
|
+
declare type AggregateFooterConfig = {
|
|
24
|
+
aggregate: "sum" | "average";
|
|
25
|
+
renderAs?: "nanoseconds";
|
|
26
|
+
precision?: number;
|
|
27
|
+
} & WithAlignemnt;
|
|
28
|
+
declare type StaticFooterConfig = StrictStaticFooterConfig | string;
|
|
29
|
+
declare type StrictStaticFooterConfig = {
|
|
30
|
+
aggregate: "static";
|
|
31
|
+
value: string;
|
|
32
|
+
} & WithAlignemnt;
|
|
33
|
+
declare type TableConfig<T extends any[], H extends boolean, F extends boolean> = {
|
|
34
|
+
sortColumn?: number;
|
|
35
|
+
padding?: number;
|
|
36
|
+
showHeader: H;
|
|
37
|
+
showFooter: F;
|
|
38
|
+
columns: {
|
|
39
|
+
[K in keyof T]: T[K] extends bigint ? BigIntColumnConfig<H, F> : StringColumnConfig<H, F>;
|
|
40
|
+
};
|
|
41
|
+
title: string;
|
|
42
|
+
};
|
|
43
|
+
export declare class Table<T extends any[]> {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(config: TableConfig<T, true, true> | TableConfig<T, true, false> | TableConfig<T, false, true> | TableConfig<T, false, false>);
|
|
46
|
+
addRow(...data: T): void;
|
|
47
|
+
print(): void;
|
|
48
|
+
getEntryAsString(colNum: number, rowNum: number): string;
|
|
49
|
+
getEntryAsStringAligned(colNum: number, rowNum: number): string;
|
|
50
|
+
getColumnWidth(colNum: number, config: BigIntColumnConfig<boolean, boolean> | StringColumnConfig<boolean, boolean>): number;
|
|
51
|
+
}
|
|
52
|
+
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AAC,GAAG,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC;CAmBnH"}
|
package/lib/Table.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _Table_instances, _Table_rows, _Table_config, _Table_columnWidths, _Table_footer, _Table_footerRowConfig, _Table_totalWidth, _Table_sumColumn, _Table_updateFooterRow, _Table_calculateColumnWidths, _Table_printSeparator, _Table_printHeaderRow, _Table_printFooterRow, _Table_getCellValueAsString, _Table_getCellValueAligned;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Table = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
/*!
|
|
7
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
// tslint:disable:no-console
|
|
13
|
+
const nanosecondsToSanity_1 = require("./nanosecondsToSanity");
|
|
14
|
+
class Table {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
_Table_instances.add(this);
|
|
17
|
+
_Table_rows.set(this, []);
|
|
18
|
+
_Table_config.set(this, void 0);
|
|
19
|
+
_Table_columnWidths.set(this, []);
|
|
20
|
+
_Table_footer.set(this, []);
|
|
21
|
+
_Table_footerRowConfig.set(this, void 0);
|
|
22
|
+
_Table_totalWidth.set(this, 0);
|
|
23
|
+
tslib_1.__classPrivateFieldSet(this, _Table_config, {
|
|
24
|
+
padding: 2,
|
|
25
|
+
...config,
|
|
26
|
+
}, "f");
|
|
27
|
+
tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f").fill(0, 0, config.columns.length);
|
|
28
|
+
if (config.showFooter) {
|
|
29
|
+
tslib_1.__classPrivateFieldSet(this, _Table_footerRowConfig, [], "f");
|
|
30
|
+
for (const columnConfig of config.columns) {
|
|
31
|
+
if (columnConfig.footer === undefined) {
|
|
32
|
+
throw new Error("Must specify footer fields when showFooter is true");
|
|
33
|
+
}
|
|
34
|
+
else if (typeof columnConfig.footer === "string") {
|
|
35
|
+
tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f").push({
|
|
36
|
+
type: "string",
|
|
37
|
+
alignment: "left",
|
|
38
|
+
aggregate: "static",
|
|
39
|
+
value: columnConfig.footer,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else if ("value" in columnConfig.footer) {
|
|
43
|
+
tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f").push({
|
|
44
|
+
type: "string",
|
|
45
|
+
alignment: "left",
|
|
46
|
+
...columnConfig.footer,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if ("aggregate" in columnConfig.footer) {
|
|
50
|
+
if (columnConfig.type !== "bigint")
|
|
51
|
+
throw new Error("expecting bigint for aggregate");
|
|
52
|
+
tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f").push({
|
|
53
|
+
type: columnConfig.type,
|
|
54
|
+
renderAs: columnConfig.renderAs,
|
|
55
|
+
precision: columnConfig.precision,
|
|
56
|
+
alignment: "right",
|
|
57
|
+
...columnConfig.footer,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
addRow(...data) {
|
|
64
|
+
// TODO: maybe clone the data
|
|
65
|
+
tslib_1.__classPrivateFieldGet(this, _Table_rows, "f").push(data);
|
|
66
|
+
}
|
|
67
|
+
print() {
|
|
68
|
+
// let data = [...this.#rows];
|
|
69
|
+
if (tslib_1.__classPrivateFieldGet(this, _Table_config, "f").sortColumn !== undefined) {
|
|
70
|
+
// todo
|
|
71
|
+
}
|
|
72
|
+
tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_updateFooterRow).call(this);
|
|
73
|
+
tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_calculateColumnWidths).call(this);
|
|
74
|
+
console.log();
|
|
75
|
+
console.log(`${tslib_1.__classPrivateFieldGet(this, _Table_config, "f").title}`);
|
|
76
|
+
console.log("".padStart(tslib_1.__classPrivateFieldGet(this, _Table_totalWidth, "f"), "="));
|
|
77
|
+
const paddingString = "".padStart(tslib_1.__classPrivateFieldGet(this, _Table_config, "f").padding, " ");
|
|
78
|
+
if (tslib_1.__classPrivateFieldGet(this, _Table_config, "f").showHeader) {
|
|
79
|
+
tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_printHeaderRow).call(this);
|
|
80
|
+
}
|
|
81
|
+
for (let r = 0; r < tslib_1.__classPrivateFieldGet(this, _Table_rows, "f").length; r++) {
|
|
82
|
+
let rowText = "";
|
|
83
|
+
for (let c = 0; c < tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns.length; c++) {
|
|
84
|
+
rowText += this.getEntryAsStringAligned(c, r) + paddingString;
|
|
85
|
+
}
|
|
86
|
+
rowText.trim();
|
|
87
|
+
console.log(rowText);
|
|
88
|
+
}
|
|
89
|
+
if (tslib_1.__classPrivateFieldGet(this, _Table_config, "f").showFooter)
|
|
90
|
+
tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_printFooterRow).call(this);
|
|
91
|
+
console.log();
|
|
92
|
+
}
|
|
93
|
+
getEntryAsString(colNum, rowNum) {
|
|
94
|
+
var _a;
|
|
95
|
+
const config = tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns[colNum];
|
|
96
|
+
if (config.type === "bigint" && config.renderAs === "nanoseconds") {
|
|
97
|
+
return (0, nanosecondsToSanity_1.nanosecondsToSanity)(tslib_1.__classPrivateFieldGet(this, _Table_rows, "f")[rowNum][colNum], (_a = config.precision) !== null && _a !== void 0 ? _a : 9);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return "" + tslib_1.__classPrivateFieldGet(this, _Table_rows, "f")[rowNum][colNum];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
getEntryAsStringAligned(colNum, rowNum) {
|
|
104
|
+
var _a;
|
|
105
|
+
const config = tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns[colNum];
|
|
106
|
+
let result;
|
|
107
|
+
if (config.type === "bigint" && config.renderAs === "nanoseconds") {
|
|
108
|
+
result = (0, nanosecondsToSanity_1.nanosecondsToSanity)(tslib_1.__classPrivateFieldGet(this, _Table_rows, "f")[rowNum][colNum], (_a = config.precision) !== null && _a !== void 0 ? _a : 9);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
result = "" + tslib_1.__classPrivateFieldGet(this, _Table_rows, "f")[rowNum][colNum];
|
|
112
|
+
}
|
|
113
|
+
if (config.alignment === "left") {
|
|
114
|
+
return result.padEnd(tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[colNum]);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return result.padStart(tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[colNum]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
getColumnWidth(colNum, config) {
|
|
121
|
+
var _a;
|
|
122
|
+
let maxWidth = Math.max(((_a = config.header) !== null && _a !== void 0 ? _a : "").length, tslib_1.__classPrivateFieldGet(this, _Table_footer, "f") && tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f")
|
|
123
|
+
? tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_getCellValueAsString).call(this, tslib_1.__classPrivateFieldGet(this, _Table_footer, "f")[colNum], tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f")[colNum]).length
|
|
124
|
+
: 0);
|
|
125
|
+
for (let r = 0; r < tslib_1.__classPrivateFieldGet(this, _Table_rows, "f").length; r++) {
|
|
126
|
+
maxWidth = Math.max(maxWidth, this.getEntryAsString(colNum, r).length);
|
|
127
|
+
// if (config.type == "bigint" && config.renderAs === "nanoseconds") {
|
|
128
|
+
// maxWidth = Math.max(maxWidth, Number(row[colNum] / BigInt(1000000000)) + 10); // 1 for period, 9 for digits
|
|
129
|
+
// } else if (config.type == "bigint" || config.type == "string") {
|
|
130
|
+
// maxWidth = Math.max(maxWidth, ("" + row[colNum]).length);
|
|
131
|
+
// }
|
|
132
|
+
}
|
|
133
|
+
return maxWidth;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.Table = Table;
|
|
137
|
+
_Table_rows = new WeakMap(), _Table_config = new WeakMap(), _Table_columnWidths = new WeakMap(), _Table_footer = new WeakMap(), _Table_footerRowConfig = new WeakMap(), _Table_totalWidth = new WeakMap(), _Table_instances = new WeakSet(), _Table_sumColumn = function _Table_sumColumn(c) {
|
|
138
|
+
let total = BigInt(0);
|
|
139
|
+
for (const row of tslib_1.__classPrivateFieldGet(this, _Table_rows, "f")) {
|
|
140
|
+
total += row[c];
|
|
141
|
+
}
|
|
142
|
+
return total;
|
|
143
|
+
}, _Table_updateFooterRow = function _Table_updateFooterRow() {
|
|
144
|
+
const footerRowConfig = tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f");
|
|
145
|
+
if (footerRowConfig) {
|
|
146
|
+
for (let c = 0; c < footerRowConfig.length; c++) {
|
|
147
|
+
const footerColConfig = footerRowConfig[c];
|
|
148
|
+
switch (footerColConfig.aggregate) {
|
|
149
|
+
case "sum":
|
|
150
|
+
tslib_1.__classPrivateFieldGet(this, _Table_footer, "f")[c] = tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_sumColumn).call(this, c);
|
|
151
|
+
break;
|
|
152
|
+
case "average":
|
|
153
|
+
tslib_1.__classPrivateFieldGet(this, _Table_footer, "f")[c] = tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_sumColumn).call(this, c) / BigInt(tslib_1.__classPrivateFieldGet(this, _Table_rows, "f").length);
|
|
154
|
+
break;
|
|
155
|
+
case "static":
|
|
156
|
+
tslib_1.__classPrivateFieldGet(this, _Table_footer, "f")[c] = footerColConfig.value;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}, _Table_calculateColumnWidths = function _Table_calculateColumnWidths() {
|
|
162
|
+
var _a, _b, _c;
|
|
163
|
+
tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f").fill(0, 0, tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns.length);
|
|
164
|
+
for (let c = 0; c < tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns.length; c++) {
|
|
165
|
+
const colConfig = tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns[c];
|
|
166
|
+
tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[c] = Math.max(((_a = tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns[c].header) !== null && _a !== void 0 ? _a : "").length, ...tslib_1.__classPrivateFieldGet(this, _Table_rows, "f").map((a) => tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_getCellValueAsString).call(this, a[c], colConfig).length), tslib_1.__classPrivateFieldGet(this, _Table_footer, "f") && tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f")
|
|
167
|
+
? tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_getCellValueAsString).call(this, (_c = (_b = tslib_1.__classPrivateFieldGet(this, _Table_footer, "f")) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : "", tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f")[c]).length
|
|
168
|
+
: 0);
|
|
169
|
+
}
|
|
170
|
+
tslib_1.__classPrivateFieldSet(this, _Table_totalWidth, 0, "f");
|
|
171
|
+
for (const colWidth of tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")) {
|
|
172
|
+
tslib_1.__classPrivateFieldSet(this, _Table_totalWidth, tslib_1.__classPrivateFieldGet(this, _Table_totalWidth, "f") + colWidth, "f");
|
|
173
|
+
}
|
|
174
|
+
tslib_1.__classPrivateFieldSet(this, _Table_totalWidth, tslib_1.__classPrivateFieldGet(this, _Table_totalWidth, "f") + (tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f").length - 1) * tslib_1.__classPrivateFieldGet(this, _Table_config, "f").padding, "f");
|
|
175
|
+
}, _Table_printSeparator = function _Table_printSeparator(fillString) {
|
|
176
|
+
const paddingString = "".padStart(tslib_1.__classPrivateFieldGet(this, _Table_config, "f").padding, " ");
|
|
177
|
+
let hr2 = "";
|
|
178
|
+
// tslint:disable-next-line: prefer-for-of
|
|
179
|
+
for (let c = 0; c < tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f").length; c++) {
|
|
180
|
+
hr2 += "".padStart(tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[c], fillString) + paddingString;
|
|
181
|
+
}
|
|
182
|
+
hr2 = hr2.trimRight();
|
|
183
|
+
console.log(hr2);
|
|
184
|
+
}, _Table_printHeaderRow = function _Table_printHeaderRow() {
|
|
185
|
+
var _a;
|
|
186
|
+
if (tslib_1.__classPrivateFieldGet(this, _Table_config, "f").showHeader) {
|
|
187
|
+
const colConfigs = tslib_1.__classPrivateFieldGet(this, _Table_config, "f").columns;
|
|
188
|
+
const paddingString = "".padStart(tslib_1.__classPrivateFieldGet(this, _Table_config, "f").padding, " ");
|
|
189
|
+
let hr = "";
|
|
190
|
+
for (let c = 0; c < colConfigs.length; c++) {
|
|
191
|
+
const heading = (_a = colConfigs[c].header) !== null && _a !== void 0 ? _a : "";
|
|
192
|
+
hr += heading.padEnd(tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[c], " ") + paddingString;
|
|
193
|
+
}
|
|
194
|
+
hr = hr.trimRight();
|
|
195
|
+
console.log(hr);
|
|
196
|
+
tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_printSeparator).call(this, "-");
|
|
197
|
+
}
|
|
198
|
+
}, _Table_printFooterRow = function _Table_printFooterRow() {
|
|
199
|
+
const footerRow = tslib_1.__classPrivateFieldGet(this, _Table_footer, "f");
|
|
200
|
+
if (footerRow) {
|
|
201
|
+
tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_printSeparator).call(this, "=");
|
|
202
|
+
const paddingString = "".padStart(tslib_1.__classPrivateFieldGet(this, _Table_config, "f").padding, " ");
|
|
203
|
+
let hr = "";
|
|
204
|
+
for (let c = 0; c < footerRow.length; c++) {
|
|
205
|
+
hr += tslib_1.__classPrivateFieldGet(this, _Table_instances, "m", _Table_getCellValueAligned).call(this, footerRow[c], tslib_1.__classPrivateFieldGet(this, _Table_footerRowConfig, "f")[c], c) + paddingString; // .padEnd(this.#columnWidths[c], " ") + paddingString;
|
|
206
|
+
}
|
|
207
|
+
hr = hr.trimRight();
|
|
208
|
+
console.log(hr);
|
|
209
|
+
}
|
|
210
|
+
}, _Table_getCellValueAsString = function _Table_getCellValueAsString(value, config) {
|
|
211
|
+
var _a;
|
|
212
|
+
if (config.type === "bigint" && config.renderAs === "nanoseconds") {
|
|
213
|
+
return (0, nanosecondsToSanity_1.nanosecondsToSanity)(value, (_a = config.precision) !== null && _a !== void 0 ? _a : 9);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return "" + value;
|
|
217
|
+
}
|
|
218
|
+
}, _Table_getCellValueAligned = function _Table_getCellValueAligned(value, config, column) {
|
|
219
|
+
var _a;
|
|
220
|
+
let result;
|
|
221
|
+
if (config.type === "bigint" && config.renderAs === "nanoseconds") {
|
|
222
|
+
result = (0, nanosecondsToSanity_1.nanosecondsToSanity)(value, (_a = config.precision) !== null && _a !== void 0 ? _a : 9);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
result = "" + value;
|
|
226
|
+
}
|
|
227
|
+
if (config.alignment === "left") {
|
|
228
|
+
return result.padEnd(tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[column]);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
return result.padStart(tslib_1.__classPrivateFieldGet(this, _Table_columnWidths, "f")[column]);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
//# sourceMappingURL=Table.js.map
|
package/lib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A,IAAI,2BAAc,CAAC,MAAM,CAAC,CAAC,CAAC;KAClD;SAAM;QACL,OAAO,MAAM,CAAC,QAAQ,CAAC,+BAAA,IAAI,2BAAc,CAAC,MAAM,CAAC,CAAC,CAAC;KACpD;AACH,CAAC"}
|
package/lib/Timing.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Timing.d.ts","sourceRoot":"","sources":["../src/Timing.ts"],"names":[],"mappings":"AASA,qBAAa,MAAM;;IAEL,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,MAAM;IAI1B,KAAK,CAAC,IAAI,EAAE,MAAM;IAIlB,IAAI;IAIJ,YAAY;CA+BpB"}
|
package/lib/Timing.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _Timing_starts;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Timing = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
/*!
|
|
7
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
// tslint:disable:no-console
|
|
13
|
+
const Table_1 = require("./Table");
|
|
14
|
+
class Timing {
|
|
15
|
+
constructor(title) {
|
|
16
|
+
this.title = title;
|
|
17
|
+
_Timing_starts.set(this, []);
|
|
18
|
+
this.stop(); // make sure we have starting point
|
|
19
|
+
}
|
|
20
|
+
start(name) {
|
|
21
|
+
tslib_1.__classPrivateFieldGet(this, _Timing_starts, "f").push({ name, start: process.hrtime.bigint() });
|
|
22
|
+
}
|
|
23
|
+
stop() {
|
|
24
|
+
tslib_1.__classPrivateFieldGet(this, _Timing_starts, "f").push({ start: process.hrtime.bigint() });
|
|
25
|
+
}
|
|
26
|
+
printResults() {
|
|
27
|
+
const table = new Table_1.Table({
|
|
28
|
+
sortColumn: -1,
|
|
29
|
+
showFooter: true,
|
|
30
|
+
showHeader: true,
|
|
31
|
+
title: this.title,
|
|
32
|
+
columns: [
|
|
33
|
+
{
|
|
34
|
+
header: "Duration",
|
|
35
|
+
type: "bigint",
|
|
36
|
+
renderAs: "nanoseconds",
|
|
37
|
+
precision: 4,
|
|
38
|
+
footer: { aggregate: "sum" },
|
|
39
|
+
},
|
|
40
|
+
{ header: "Task", type: "string", footer: "TOTAL" },
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
this.stop(); // be sure we stopped the last one
|
|
44
|
+
let cur = tslib_1.__classPrivateFieldGet(this, _Timing_starts, "f")[0];
|
|
45
|
+
for (const entry of tslib_1.__classPrivateFieldGet(this, _Timing_starts, "f")) {
|
|
46
|
+
if (cur.name) {
|
|
47
|
+
const span = entry.start - cur.start;
|
|
48
|
+
table.addRow(span, cur.name);
|
|
49
|
+
}
|
|
50
|
+
cur = entry;
|
|
51
|
+
}
|
|
52
|
+
table.print();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.Timing = Timing;
|
|
56
|
+
_Timing_starts = new WeakMap();
|
|
57
|
+
//# sourceMappingURL=Timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Timing.js","sourceRoot":"","sources":["../src/Timing.ts"],"names":[],"mappings":";;;;;AAAA;;;;;GAKG;AACH,4BAA4B;AAC5B,mCAAgC;AAEhC,MAAa,MAAM;IAEjB,YAAoB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;QADjC,yBAAmD,EAAE,EAAC;QAEpD,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,mCAAmC;IAClD,CAAC;IAEM,KAAK,CAAC,IAAY;QACvB,+BAAA,IAAI,sBAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IAEM,IAAI;QACT,+BAAA,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strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const CachingHost_1 = require("../CachingHost");
|
|
11
|
+
const realfs = tslib_1.__importStar(require("fs"));
|
|
12
|
+
const path = tslib_1.__importStar(require("path"));
|
|
13
|
+
const os = tslib_1.__importStar(require("os"));
|
|
14
|
+
class RealFsTestCase {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.getFs = () => {
|
|
17
|
+
return realfs;
|
|
18
|
+
};
|
|
19
|
+
this.createTmpDir = () => {
|
|
20
|
+
return realfs.mkdtempSync(path.join(os.tmpdir(), "mrl-test"));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
describe(CachingHost_1.CachingHost, () => {
|
|
25
|
+
describe.each([["fs", new RealFsTestCase()]])("%s", (_testCaseName, testCase) => {
|
|
26
|
+
let baseDir;
|
|
27
|
+
let fs;
|
|
28
|
+
let SYMLINK_JSON_PATH;
|
|
29
|
+
let SYMLINK_TXT_PATH;
|
|
30
|
+
let FILE_JSON_PATH;
|
|
31
|
+
let FILE_TXT_PATH;
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
fs = testCase.getFs();
|
|
34
|
+
baseDir = testCase.createTmpDir();
|
|
35
|
+
SYMLINK_JSON_PATH = path.resolve(baseDir, "symlink.json");
|
|
36
|
+
SYMLINK_TXT_PATH = path.resolve(baseDir, "symlink.txt");
|
|
37
|
+
FILE_TXT_PATH = path.resolve(baseDir, "file.txt");
|
|
38
|
+
FILE_JSON_PATH = path.resolve(baseDir, "file.json");
|
|
39
|
+
fs.writeFileSync(FILE_JSON_PATH, JSON.stringify({ hi: "mom" }), { encoding: "utf-8" });
|
|
40
|
+
fs.symlinkSync(FILE_JSON_PATH, SYMLINK_JSON_PATH);
|
|
41
|
+
fs.writeFileSync(FILE_TXT_PATH, "hi dad", { encoding: "utf-8" });
|
|
42
|
+
fs.symlinkSync(FILE_TXT_PATH, SYMLINK_TXT_PATH);
|
|
43
|
+
});
|
|
44
|
+
function expectFileToExist(file) {
|
|
45
|
+
return expect(fs.existsSync(file));
|
|
46
|
+
}
|
|
47
|
+
function expectFileContents(file) {
|
|
48
|
+
return expect(fs.readFileSync(file, { encoding: "utf-8" }));
|
|
49
|
+
}
|
|
50
|
+
function expectSymlinkTarget(src, target) {
|
|
51
|
+
const stat = fs.lstatSync(src);
|
|
52
|
+
expect(stat.isSymbolicLink() && fs.readlinkSync(src)).toEqual(target);
|
|
53
|
+
}
|
|
54
|
+
it("Answers exists() properly", async () => {
|
|
55
|
+
expect.assertions(2);
|
|
56
|
+
await realfs.promises.writeFile(path.join(baseDir, "b.txt"), "hi", { encoding: "utf-8" });
|
|
57
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
58
|
+
expect(host.exists(path.join(baseDir, "b.txt"))).toBe(true);
|
|
59
|
+
expect(host.exists(path.join(baseDir, "nosuchfile.txt"))).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
it("properly handles deletes", async () => {
|
|
62
|
+
expect.assertions(2);
|
|
63
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
64
|
+
host.writeFile(path.join(baseDir, "b.txt"), "hi", { encoding: "utf-8" });
|
|
65
|
+
host.deleteFile(path.join(baseDir, "b.txt"));
|
|
66
|
+
host.deleteFile(path.join(baseDir, "a.json"));
|
|
67
|
+
await host.flush();
|
|
68
|
+
expectFileToExist(path.join(baseDir, "b.txt")).toBeFalsy();
|
|
69
|
+
expectFileToExist(path.join(baseDir, "a.txt")).toBeFalsy();
|
|
70
|
+
});
|
|
71
|
+
it("handles simple read/write workflow", async () => {
|
|
72
|
+
expect.assertions(1);
|
|
73
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
74
|
+
host.writeFile(FILE_JSON_PATH, "cow", { encoding: "utf-8" });
|
|
75
|
+
expect(host.readFile(FILE_JSON_PATH, { encoding: "utf-8" })).toEqual("cow");
|
|
76
|
+
});
|
|
77
|
+
it("handles target symlink changing", async () => {
|
|
78
|
+
expect.assertions(1);
|
|
79
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
80
|
+
host.writeFile(FILE_JSON_PATH, "cow", { encoding: "utf-8" });
|
|
81
|
+
expect(host.readFile(FILE_JSON_PATH, { encoding: "utf-8" })).toEqual("cow");
|
|
82
|
+
});
|
|
83
|
+
it("handles writing symlinks properly", async () => {
|
|
84
|
+
expect.assertions(8);
|
|
85
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
86
|
+
// file.json should now hold "hmm"
|
|
87
|
+
host.writeFile(SYMLINK_JSON_PATH, "hmm", { encoding: "utf-8" });
|
|
88
|
+
expect(host.readFile(SYMLINK_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
89
|
+
expect(host.readFile(FILE_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
90
|
+
// Write it out so we can verify disk is right
|
|
91
|
+
await host.flush();
|
|
92
|
+
expectFileToExist(SYMLINK_JSON_PATH).toBeTruthy();
|
|
93
|
+
expectFileToExist(FILE_TXT_PATH).toBeTruthy();
|
|
94
|
+
expectFileContents(FILE_JSON_PATH).toBe("hmm");
|
|
95
|
+
expectFileContents(SYMLINK_JSON_PATH).toBe("hmm");
|
|
96
|
+
expectSymlinkTarget(SYMLINK_JSON_PATH, FILE_JSON_PATH);
|
|
97
|
+
expect(host.readFile(SYMLINK_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
98
|
+
});
|
|
99
|
+
it("handles writing symlinks properly if you read it first", async () => {
|
|
100
|
+
expect.assertions(8);
|
|
101
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
102
|
+
host.readFile(SYMLINK_JSON_PATH);
|
|
103
|
+
// file.json should now hold "hmm"
|
|
104
|
+
host.writeFile(path.join(baseDir, "symlink.json"), "hmm", { encoding: "utf-8" });
|
|
105
|
+
expect(host.readFile(SYMLINK_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
106
|
+
expect(host.readFile(FILE_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
107
|
+
// Write it out so we can verify disk is right
|
|
108
|
+
await host.flush();
|
|
109
|
+
expectFileToExist(SYMLINK_JSON_PATH).toBeTruthy();
|
|
110
|
+
expectFileToExist(FILE_TXT_PATH).toBeTruthy();
|
|
111
|
+
expectFileContents(FILE_JSON_PATH).toBe("hmm");
|
|
112
|
+
expectFileContents(SYMLINK_JSON_PATH).toBe("hmm");
|
|
113
|
+
expectSymlinkTarget(SYMLINK_JSON_PATH, FILE_JSON_PATH);
|
|
114
|
+
expect(host.readFile(SYMLINK_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
115
|
+
});
|
|
116
|
+
it("handles creating new symlinks", async () => {
|
|
117
|
+
expect.assertions(8);
|
|
118
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
119
|
+
host.readFile(SYMLINK_JSON_PATH);
|
|
120
|
+
// file.json should now hold "hmm"
|
|
121
|
+
host.writeFile(path.join(baseDir, "symlink.json"), "hmm", { encoding: "utf-8" });
|
|
122
|
+
expect(host.readFile(SYMLINK_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
123
|
+
expect(host.readFile(FILE_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
124
|
+
// Write it out so we can verify disk is right
|
|
125
|
+
await host.flush();
|
|
126
|
+
expectFileToExist(SYMLINK_JSON_PATH).toBeTruthy();
|
|
127
|
+
expectFileToExist(FILE_TXT_PATH).toBeTruthy();
|
|
128
|
+
expectFileContents(FILE_JSON_PATH).toBe("hmm");
|
|
129
|
+
expectFileContents(SYMLINK_JSON_PATH).toBe("hmm");
|
|
130
|
+
expectSymlinkTarget(SYMLINK_JSON_PATH, FILE_JSON_PATH);
|
|
131
|
+
expect(host.readFile(SYMLINK_JSON_PATH, { encoding: "utf-8" })).toEqual("hmm");
|
|
132
|
+
});
|
|
133
|
+
it("makes directories", async () => {
|
|
134
|
+
expect.assertions(3);
|
|
135
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
136
|
+
host.mkdir(path.join(baseDir, "foo", "bar", "baz"), { recursive: true });
|
|
137
|
+
// Write it out so we can verify disk is right
|
|
138
|
+
await host.flush();
|
|
139
|
+
expectFileToExist(path.join(baseDir, "foo")).toBeTruthy();
|
|
140
|
+
expectFileToExist(path.join(baseDir, "foo", "bar")).toBeTruthy();
|
|
141
|
+
expectFileToExist(path.join(baseDir, "foo", "bar", "baz")).toBeTruthy();
|
|
142
|
+
});
|
|
143
|
+
it("can unlink empty dirs", async () => {
|
|
144
|
+
expect.assertions(1);
|
|
145
|
+
// base setup
|
|
146
|
+
const fooDirPath = path.join(baseDir, "foo");
|
|
147
|
+
fs.mkdirSync(fooDirPath, { recursive: true });
|
|
148
|
+
// prep obj
|
|
149
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
150
|
+
host.rmdir(fooDirPath);
|
|
151
|
+
// Write it out so we can verify disk is right
|
|
152
|
+
await host.flush();
|
|
153
|
+
expectFileToExist(fooDirPath).toBeFalsy();
|
|
154
|
+
});
|
|
155
|
+
it("doesnt let you delete a directory with files", async () => {
|
|
156
|
+
expect.assertions(2);
|
|
157
|
+
const fooDirPath = path.join(baseDir, "foo");
|
|
158
|
+
const barFilePath = path.join(fooDirPath, "bar.txt");
|
|
159
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
160
|
+
host.mkdir(fooDirPath, { recursive: true });
|
|
161
|
+
host.writeJson(barFilePath, { hi: 5 });
|
|
162
|
+
expect(() => {
|
|
163
|
+
host.rmdir(fooDirPath);
|
|
164
|
+
}).toThrow();
|
|
165
|
+
// Write it out so we can verify disk is right
|
|
166
|
+
await host.flush();
|
|
167
|
+
expectFileToExist(fooDirPath).toBeTruthy();
|
|
168
|
+
});
|
|
169
|
+
it("doesn't let you rmdir() a file", () => {
|
|
170
|
+
expect.assertions(1);
|
|
171
|
+
const host = new CachingHost_1.CachingHost(fs);
|
|
172
|
+
expect(() => {
|
|
173
|
+
host.rmdir(FILE_JSON_PATH);
|
|
174
|
+
}).toThrow();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
//# sourceMappingURL=CachingHost.spec.js.map
|