@esposter/shared-node 0.0.0-stage → 4.1.1
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/LICENSE +201 -0
- package/README.md +72 -2
- package/dist/bench.d.ts +5 -0
- package/dist/bench.js +10 -0
- package/dist/cache.d.ts +7 -0
- package/dist/cache.js +27 -0
- package/dist/child-process.d.ts +16 -0
- package/dist/child-process.js +17 -0
- package/dist/execSync-CtM99iYq.js +17 -0
- package/dist/reporter.d.ts +6 -0
- package/dist/reporter.js +133 -0
- package/package.json +69 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020-present Jimmy Chen
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @esposter/shared-node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![Apache-2.0 licensed][badge-license]][url-license]
|
|
4
|
+
|
|
5
|
+
Node-only shared tooling for Esposter — the machine-wide download cache, hidden-window child processes and benchmark reporting reused across packages. Server/build environment only; never import in browser code.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- 📖 [Documentation](#documentation)
|
|
10
|
+
- ⚖️ [License](#license)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## <a name="documentation">📖 Documentation</a>
|
|
15
|
+
|
|
16
|
+
We highly recommend you take a look at the [documentation](https://esposter.com/docs/api/modules/_esposter_shared-node.html) to level up.
|
|
17
|
+
|
|
18
|
+
### What's Included
|
|
19
|
+
|
|
20
|
+
The machine-wide download cache, the hidden-window child process wrappers, and the benchmark reporting toolkit consumed by the repo's `vitest bench` runs (see the `bench` skill).
|
|
21
|
+
|
|
22
|
+
`@esposter/shared-node/child-process` exports `spawn`, `spawnSync`, `execFile`, `execFileSync` and `execSync` with node's own names and types. Each forces `windowsHide: true` last, so a console child never opens its own terminal window on Windows, including from a windowless parent such as a Claude Code hook. Import these instead of `node:child_process`; the repo's lint rule enforces it.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { spawnSync } from "@esposter/shared-node/child-process";
|
|
26
|
+
|
|
27
|
+
spawnSync("pnpm", ["install"], { stdio: "inherit" });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`@esposter/shared-node/cache` exports `CACHE_ROOT` (`~/Esposter/cache`), the one folder every checkout, worktree and ephemeral run on a machine shares for what it downloads, and `readContentAddressedObject`, a read-through cache for objects named by the hex SHA-256 of their bytes. A hit is read from `CONTENT_CACHE_DIRECTORY`; a miss is downloaded once and kept only if its bytes hash to its name, so a hit never goes stale and any source of the same content shares one copy.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { readContentAddressedObject } from "@esposter/shared-node/cache";
|
|
34
|
+
|
|
35
|
+
const bytes = await readContentAddressedObject(
|
|
36
|
+
hash,
|
|
37
|
+
async () => new Uint8Array(await (await fetch(url)).arrayBuffer()),
|
|
38
|
+
);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Export | Description |
|
|
42
|
+
| ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
|
|
43
|
+
| `BenchmarkMarkdownReporter` | Vitest reporter — writes `Foo.bench.md` + `Foo.bench.json` beside `Foo.bench.ts` |
|
|
44
|
+
| `BENCHMARK_RUN_OPTIONS` | Run options every `bench.compare` passes, fixing the iteration count |
|
|
45
|
+
| `buildBenchmarkFileReport` | Projects a module's reported tests into a structured `BenchmarkReport` |
|
|
46
|
+
| `formatBenchmarkMarkdown` | Renders a `BenchmarkReport` to Markdown tables |
|
|
47
|
+
| `writeBenchmarkReport` | Persists the JSON + Markdown report artifacts |
|
|
48
|
+
| `readBenchmarkEnvironment` | Captures CPU/OS/runtime metadata for reproducible results |
|
|
49
|
+
| `BenchmarkFile` · `BenchmarkGroup` · `BenchmarkReport` · `BenchmarkResult` · `BenchmarkTestCase` | Report data models |
|
|
50
|
+
|
|
51
|
+
### Architecture Notes
|
|
52
|
+
|
|
53
|
+
- **Node-only**: depends on Node built-ins (`fs`, `os`) — must not be bundled into the browser app.
|
|
54
|
+
- Depends on `@esposter/shared` for shared types and utilities.
|
|
55
|
+
- Wired into `vitest bench` via `BenchmarkMarkdownReporter`; the emitted artifacts are committed and diffed offline as the speed gate.
|
|
56
|
+
|
|
57
|
+
### Commands
|
|
58
|
+
|
|
59
|
+
Run from `packages/shared-node/`:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm build # compile to dist/
|
|
63
|
+
pnpm test # vitest watch mode (coverage is run from the repo root)
|
|
64
|
+
pnpm lint:fix # auto-fix lint
|
|
65
|
+
pnpm typecheck # type check
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## <a name="license">⚖️ License</a>
|
|
69
|
+
|
|
70
|
+
This project is licensed under the [Apache-2.0 license](https://github.com/Esposter/Esposter/blob/main/LICENSE).
|
|
71
|
+
|
|
72
|
+
[badge-license]: https://img.shields.io/github/license/Esposter/Esposter.svg?color=blue
|
|
73
|
+
[url-license]: https://github.com/Esposter/Esposter/blob/main/LICENSE
|
package/dist/bench.d.ts
ADDED
package/dist/bench.js
ADDED
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/services/cache/constants.d.ts
|
|
2
|
+
export declare const CACHE_ROOT: string;
|
|
3
|
+
export declare const CONTENT_CACHE_DIRECTORY: string;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/services/cache/readContentAddressedObject.d.ts
|
|
6
|
+
export declare const readContentAddressedObject: (hash: string, download: () => Promise<Uint8Array>, directory?: string) => Promise<Buffer>;
|
|
7
|
+
//#endregion
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InvalidOperationError, Operation, SITE_NAME, getResultAsync, noop } from "@esposter/shared";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
//#region src/services/cache/constants.ts
|
|
8
|
+
const CACHE_ROOT = join(homedir(), SITE_NAME, "cache");
|
|
9
|
+
const CONTENT_CACHE_DIRECTORY = join(CACHE_ROOT, "content");
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/services/cache/readContentAddressedObject.ts
|
|
12
|
+
const readContentAddressedObject = async (hash, download, directory = CONTENT_CACHE_DIRECTORY) => {
|
|
13
|
+
const path = join(directory, hash);
|
|
14
|
+
if (existsSync(path)) return readFile(path);
|
|
15
|
+
const bytes = Buffer.from(await download());
|
|
16
|
+
if (createHash("sha256").update(bytes).digest("hex") !== hash) throw new InvalidOperationError(Operation.Read, hash, "does not hash to its name");
|
|
17
|
+
await mkdir(directory, { recursive: true });
|
|
18
|
+
const temporaryPath = `${path}.${crypto.randomUUID()}.part`;
|
|
19
|
+
await writeFile(temporaryPath, bytes);
|
|
20
|
+
await getResultAsync(() => rename(temporaryPath, path)).match(noop, async (error) => {
|
|
21
|
+
await rm(temporaryPath, { force: true });
|
|
22
|
+
if (!existsSync(path)) throw error;
|
|
23
|
+
});
|
|
24
|
+
return bytes;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { CACHE_ROOT, CONTENT_CACHE_DIRECTORY, readContentAddressedObject };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { execFile as execFile$1, execFileSync as execFileSync$1, execSync as execSync$1, spawn as spawn$1, spawnSync as spawnSync$1 } from "node:child_process";
|
|
2
|
+
//#region src/services/childProcess/execFile.d.ts
|
|
3
|
+
export declare const execFile: typeof execFile$1;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/services/childProcess/execFileSync.d.ts
|
|
6
|
+
export declare const execFileSync: typeof execFileSync$1;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/services/childProcess/execSync.d.ts
|
|
9
|
+
export declare const execSync: typeof execSync$1;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/services/childProcess/spawn.d.ts
|
|
12
|
+
export declare const spawn: typeof spawn$1;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/services/childProcess/spawnSync.d.ts
|
|
15
|
+
export declare const spawnSync: typeof spawnSync$1;
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { n as withHiddenWindow, t as execSync } from "./execSync-CtM99iYq.js";
|
|
2
|
+
import { execFile as execFile$1, execFileSync as execFileSync$1, spawn as spawn$1, spawnSync as spawnSync$1 } from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
//#region src/services/childProcess/execFile.ts
|
|
5
|
+
const execFile = ((file, ...parameters) => execFile$1(file, ...withHiddenWindow(parameters)));
|
|
6
|
+
Object.defineProperty(execFile, promisify.custom, { value: (file, ...parameters) => promisify(execFile$1)(file, ...withHiddenWindow(parameters)) });
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/services/childProcess/execFileSync.ts
|
|
9
|
+
const execFileSync = ((file, ...parameters) => execFileSync$1(file, ...withHiddenWindow(parameters)));
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/services/childProcess/spawn.ts
|
|
12
|
+
const spawn = ((file, ...parameters) => spawn$1(file, ...withHiddenWindow(parameters)));
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/services/childProcess/spawnSync.ts
|
|
15
|
+
const spawnSync = ((file, ...parameters) => spawnSync$1(file, ...withHiddenWindow(parameters)));
|
|
16
|
+
//#endregion
|
|
17
|
+
export { execFile, execFileSync, execSync, spawn, spawnSync };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
//#region src/services/childProcess/withHiddenWindow.ts
|
|
3
|
+
const withHiddenWindow = (parameters) => {
|
|
4
|
+
const optionsIndex = Array.isArray(parameters[0]) || parameters[0] === void 0 && parameters.length > 1 ? 1 : 0;
|
|
5
|
+
const options = parameters[optionsIndex];
|
|
6
|
+
if (typeof options === "object" && options !== null) return parameters.toSpliced(optionsIndex, 1, {
|
|
7
|
+
...options,
|
|
8
|
+
windowsHide: true
|
|
9
|
+
});
|
|
10
|
+
const isPlaceholder = options === void 0 && optionsIndex < parameters.length;
|
|
11
|
+
return parameters.toSpliced(optionsIndex, Number(isPlaceholder), { windowsHide: true });
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/services/childProcess/execSync.ts
|
|
15
|
+
const execSync$1 = ((command, ...parameters) => execSync(command, ...withHiddenWindow(parameters)));
|
|
16
|
+
//#endregion
|
|
17
|
+
export { withHiddenWindow as n, execSync$1 as t };
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import "./bench.js";
|
|
2
|
+
import { t as execSync } from "./execSync-CtM99iYq.js";
|
|
3
|
+
import { GIBIBYTE, InvalidOperationError, Operation, getResult, getResultAsync, noop, normalizeString, takeOne } from "@esposter/shared";
|
|
4
|
+
import { arch, cpus, platform, release, totalmem } from "node:os";
|
|
5
|
+
import { writeFile } from "node:fs/promises";
|
|
6
|
+
//#region src/services/readBenchmarkEnvironment.ts
|
|
7
|
+
const readCommit = () => getResult(() => execSync("git rev-parse --short HEAD", {
|
|
8
|
+
encoding: "utf8",
|
|
9
|
+
stdio: "pipe"
|
|
10
|
+
})).match((stdout) => normalizeString(stdout), () => "unknown");
|
|
11
|
+
const readBenchmarkEnvironment = () => {
|
|
12
|
+
const cpu = cpus();
|
|
13
|
+
return [
|
|
14
|
+
`- Date: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
15
|
+
`- Commit: ${readCommit()}`,
|
|
16
|
+
`- Node: ${process.version}`,
|
|
17
|
+
`- OS: ${platform()} ${release()} (${arch()})`,
|
|
18
|
+
`- CPU: ${normalizeString(cpu[0]?.model) || "unknown"} × ${cpu.length}`,
|
|
19
|
+
`- RAM: ${(totalmem() / GIBIBYTE).toFixed(1)} GiB`
|
|
20
|
+
].join("\n");
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/services/buildBenchmarkFileReport.ts
|
|
24
|
+
const getGroupName = (testCase, benchmarkName, benchmarkCount) => benchmarkCount > 1 ? `${testCase.fullName} > ${benchmarkName}` : testCase.fullName;
|
|
25
|
+
const buildBenchmarkFileReport = (filepath, testCases) => {
|
|
26
|
+
const groups = [];
|
|
27
|
+
for (const testCase of testCases) {
|
|
28
|
+
const testCaseBenchmarks = testCase.benchmarks();
|
|
29
|
+
for (const { name, tasks } of testCaseBenchmarks) {
|
|
30
|
+
const benchmarks = [];
|
|
31
|
+
for (const task of tasks.toSorted((firstTask, secondTask) => firstTask.rank - secondTask.rank)) {
|
|
32
|
+
if (!Number.isFinite(task.latency.mean)) throw new InvalidOperationError(Operation.Read, testCase.fullName, `benchmark "${task.name}" produced no samples — it likely threw on every iteration`);
|
|
33
|
+
benchmarks.push({
|
|
34
|
+
mean: task.latency.mean,
|
|
35
|
+
name: task.name,
|
|
36
|
+
p99: task.latency.p99,
|
|
37
|
+
rme: task.latency.rme,
|
|
38
|
+
sampleCount: task.latency.samplesCount
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (benchmarks.length > 0) groups.push({
|
|
42
|
+
benchmarks,
|
|
43
|
+
fullName: getGroupName(testCase, name, testCaseBenchmarks.length)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { files: [{
|
|
48
|
+
filepath,
|
|
49
|
+
groups
|
|
50
|
+
}] };
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/services/formatBenchmarkMarkdown.ts
|
|
54
|
+
const getBaseline = (benchmarks) => benchmarks.find(({ name }) => name === "native") ?? benchmarks[0];
|
|
55
|
+
const formatRelative = (baselineMean, mean) => {
|
|
56
|
+
const ratio = baselineMean / mean;
|
|
57
|
+
return `${ratio >= 1 ? ratio.toFixed(2) : Number(ratio.toPrecision(2))}×`;
|
|
58
|
+
};
|
|
59
|
+
const HEADER = [
|
|
60
|
+
"task",
|
|
61
|
+
"vs base",
|
|
62
|
+
"mean (ms)",
|
|
63
|
+
"±rme",
|
|
64
|
+
"p99 (ms)",
|
|
65
|
+
"samples"
|
|
66
|
+
];
|
|
67
|
+
const formatTable = (rows) => {
|
|
68
|
+
const widths = rows.reduce((accumulator, row) => accumulator.map((width, index) => Math.max(width, takeOne(row, index).length)), HEADER.map((header) => header.length));
|
|
69
|
+
const formatRow = (cells) => `| ${cells.map((cell, index) => cell.padEnd(takeOne(widths, index))).join(" | ")} |`;
|
|
70
|
+
return [
|
|
71
|
+
formatRow(HEADER),
|
|
72
|
+
`| ${widths.map((width) => "-".repeat(width)).join(" | ")} |`,
|
|
73
|
+
...rows.map((row) => formatRow(row))
|
|
74
|
+
];
|
|
75
|
+
};
|
|
76
|
+
const formatBenchmarkMarkdown = (report, environment) => {
|
|
77
|
+
return [
|
|
78
|
+
"# Benchmark results",
|
|
79
|
+
"",
|
|
80
|
+
"Auto-generated by the BenchmarkMarkdownReporter on `pnpm bench`, colocated beside the bench file (a",
|
|
81
|
+
"`.bench.json` sits next to it). Diff over time to catch regressions. Tasks are listed fastest first.",
|
|
82
|
+
"`vs base` is a throughput multiplier against each group's baseline (the `native` task, else the",
|
|
83
|
+
"fastest): `1.00×` is the baseline, higher is faster, lower is slower — a fast task drifting back",
|
|
84
|
+
"toward `1.00×` is a regression. `±rme` is the relative margin of error.",
|
|
85
|
+
"Numbers are machine- and commit-dependent (see Environment); only compare runs from the same host.",
|
|
86
|
+
"",
|
|
87
|
+
"## Environment",
|
|
88
|
+
"",
|
|
89
|
+
environment,
|
|
90
|
+
"",
|
|
91
|
+
...report.files.flatMap((file) => file.groups.map((group) => {
|
|
92
|
+
const baselineMean = getBaseline(group.benchmarks)?.mean ?? NaN;
|
|
93
|
+
const rows = group.benchmarks.map(({ mean, name, p99, rme, sampleCount }) => [
|
|
94
|
+
name.replaceAll("|", String.raw`\|`),
|
|
95
|
+
formatRelative(baselineMean, mean),
|
|
96
|
+
mean.toFixed(4),
|
|
97
|
+
`±${rme.toFixed(2)}%`,
|
|
98
|
+
p99.toFixed(4),
|
|
99
|
+
`${sampleCount}`
|
|
100
|
+
]);
|
|
101
|
+
return [
|
|
102
|
+
`## ${group.fullName}`,
|
|
103
|
+
"",
|
|
104
|
+
...formatTable(rows),
|
|
105
|
+
""
|
|
106
|
+
].join("\n");
|
|
107
|
+
}))
|
|
108
|
+
].join("\n");
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/services/writeBenchmarkReport.ts
|
|
112
|
+
const TS_EXTENSION_REGEX = /\.ts$/u;
|
|
113
|
+
const writeFileOrThrow = (path, contents) => getResultAsync(() => writeFile(path, contents)).match(noop, (error) => {
|
|
114
|
+
throw new InvalidOperationError(Operation.Create, path, error.message);
|
|
115
|
+
});
|
|
116
|
+
const writeBenchmarkReport = async (moduleId, relativeModuleId, testCases, environment) => {
|
|
117
|
+
const report = buildBenchmarkFileReport(relativeModuleId, testCases);
|
|
118
|
+
const [benchmarkFile] = report.files;
|
|
119
|
+
if (benchmarkFile === void 0 || benchmarkFile.groups.length === 0) return;
|
|
120
|
+
const basePath = moduleId.replace(TS_EXTENSION_REGEX, "");
|
|
121
|
+
const reportPath = basePath.endsWith(".platform.bench") ? `${basePath}.${process.platform}` : basePath;
|
|
122
|
+
await Promise.all([writeFileOrThrow(`${reportPath}.json`, `${JSON.stringify(report, null, 2)}\n`), writeFileOrThrow(`${reportPath}.md`, formatBenchmarkMarkdown(report, environment))]);
|
|
123
|
+
};
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/services/BenchmarkMarkdownReporter.ts
|
|
126
|
+
var BenchmarkMarkdownReporter = class {
|
|
127
|
+
async onTestRunEnd(testModules) {
|
|
128
|
+
const environment = readBenchmarkEnvironment();
|
|
129
|
+
await Promise.all(testModules.map((testModule) => writeBenchmarkReport(testModule.moduleId, testModule.relativeModuleId, testModule.children.allTests(), environment)));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
//#endregion
|
|
133
|
+
export { BenchmarkMarkdownReporter as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esposter/shared-node",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.1.1",
|
|
4
|
+
"description": "Node-only shared tooling: the machine-wide download cache, hidden-window child processes, and benchmark reporting reused across packages.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"benchmark",
|
|
7
|
+
"child-process",
|
|
8
|
+
"monorepo",
|
|
9
|
+
"node",
|
|
10
|
+
"reporting",
|
|
11
|
+
"shared",
|
|
12
|
+
"tooling",
|
|
13
|
+
"typescript",
|
|
14
|
+
"vitest",
|
|
15
|
+
"windows"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/Esposter/Esposter/blob/main/packages/shared-node#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/Esposter/Esposter/issues"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": "Jimmy Chen",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Esposter/Esposter.git"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"imports": {
|
|
33
|
+
"#src/*": "./src/*.ts"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
"./bench": "./dist/bench.js",
|
|
37
|
+
"./cache": "./dist/cache.js",
|
|
38
|
+
"./child-process": "./dist/child-process.js",
|
|
39
|
+
"./reporter": "./dist/reporter.js",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"format": "oxfmt",
|
|
48
|
+
"format:check": "oxfmt --check",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"lint:fix": "eslint --fix .",
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"typecheck": "tsc"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@esposter/shared": "4.1.1"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@esposter/configuration": "4.1.1",
|
|
59
|
+
"@types/node": "^26.6.5",
|
|
60
|
+
"tsdown": "^0.23.1"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"vitest": "^5.0.4"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"vitest": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"gitHead": "47b7795ab557d7731aa60588d0b9d1cdff243328"
|
|
71
|
+
}
|