ccqa-tools 1.37.0
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/README.md +177 -0
- package/dist/coverage/collector.cjs +229 -0
- package/dist/coverage/collector.d.cts +183 -0
- package/dist/coverage/collector.d.ts +183 -0
- package/dist/coverage/collector.js +225 -0
- package/dist/coverage/core.cjs +176 -0
- package/dist/coverage/core.d.cts +157 -0
- package/dist/coverage/core.d.ts +157 -0
- package/dist/coverage/core.js +163 -0
- package/dist/coverage/middleware.cjs +161 -0
- package/dist/coverage/middleware.d.cts +23 -0
- package/dist/coverage/middleware.d.ts +23 -0
- package/dist/coverage/middleware.js +158 -0
- package/dist/coverage/next-loader.cjs +158 -0
- package/dist/coverage/next-loader.d.cts +18 -0
- package/dist/coverage/next-loader.d.ts +19 -0
- package/dist/coverage/next-loader.js +158 -0
- package/dist/coverage/next.cjs +101 -0
- package/dist/coverage/next.d.cts +33 -0
- package/dist/coverage/next.d.ts +33 -0
- package/dist/coverage/next.js +100 -0
- package/dist/coverage/register.cjs +741 -0
- package/dist/coverage/register.d.cts +1 -0
- package/dist/coverage/register.d.ts +1 -0
- package/dist/coverage/register.js +716 -0
- package/dist/coverage/slack.cjs +228 -0
- package/dist/coverage/slack.d.cts +47 -0
- package/dist/coverage/slack.d.ts +47 -0
- package/dist/coverage/slack.js +225 -0
- package/dist/coverage/temporal-workflow.cjs +154 -0
- package/dist/coverage/temporal-workflow.d.cts +28 -0
- package/dist/coverage/temporal-workflow.d.ts +28 -0
- package/dist/coverage/temporal-workflow.js +153 -0
- package/dist/coverage/temporal.cjs +253 -0
- package/dist/coverage/temporal.d.cts +40 -0
- package/dist/coverage/temporal.d.ts +40 -0
- package/dist/coverage/temporal.js +250 -0
- package/package.json +95 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
//#region src/coverage/wire.ts
|
|
4
|
+
/**
|
|
5
|
+
* Enables the instrumentation. Unset means the register hook is never loaded
|
|
6
|
+
* and the application pays nothing at all.
|
|
7
|
+
*
|
|
8
|
+
* `1` / `true` turns it on and leaves attribution to the incoming carrier.
|
|
9
|
+
* Any other value is itself a `<runId>.<specId>` and becomes the ambient spec
|
|
10
|
+
* for the process — the only way to attribute an entry point that has no
|
|
11
|
+
* inbound request to read, such as a worker started per spec.
|
|
12
|
+
*/
|
|
13
|
+
const ENV_NAME = "CCQA_COVERAGE";
|
|
14
|
+
const SPEC_ID = /^[A-Za-z0-9._\-/]{1,200}$/;
|
|
15
|
+
/**
|
|
16
|
+
* Accepts a carrier value only if it looks like an id we wrote.
|
|
17
|
+
*
|
|
18
|
+
* The cookie is client-controlled, so this is the first of two gates: the
|
|
19
|
+
* second is the hub refusing runs it never started.
|
|
20
|
+
*/
|
|
21
|
+
function parseSpecId(raw) {
|
|
22
|
+
if (!raw) return void 0;
|
|
23
|
+
const value = raw.trim();
|
|
24
|
+
if (!SPEC_ID.test(value)) return void 0;
|
|
25
|
+
if (value === "1" || value === "true") return void 0;
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/coverage/runtime-env.ts
|
|
30
|
+
function readConfig(env = process.env) {
|
|
31
|
+
const raw = env[ENV_NAME];
|
|
32
|
+
const include = (env["CCQA_COVERAGE_INCLUDE"] ?? "src").split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
33
|
+
return {
|
|
34
|
+
enabled: raw !== void 0 && raw !== "" && raw !== "0" && raw !== "false",
|
|
35
|
+
ambientSpecId: parseSpecId(raw),
|
|
36
|
+
root: env["CCQA_COVERAGE_ROOT"] ?? process.cwd(),
|
|
37
|
+
include,
|
|
38
|
+
debug: env["CCQA_COVERAGE_DEBUG"] === "1" || env["CCQA_COVERAGE_DEBUG"] === "true"
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Diagnostics go to stderr and nowhere else. A `--import` preload is inherited
|
|
43
|
+
* by every child node process, and writing to stdout corrupts whatever the host
|
|
44
|
+
* was parsing there — enough to make a framework's own toolchain fail to start.
|
|
45
|
+
*/
|
|
46
|
+
function debugLog(config, message) {
|
|
47
|
+
if (!config.debug) return;
|
|
48
|
+
process.stderr.write(`[ccqa-tools] ${message}\n`);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/coverage/next/index.ts
|
|
52
|
+
/**
|
|
53
|
+
* Next.js integration.
|
|
54
|
+
*
|
|
55
|
+
* Next bundles its server code, so the load hooks in
|
|
56
|
+
* `ccqa-tools/coverage/register` never see the application's own modules — only the
|
|
57
|
+
* bundle. The instrumentation therefore has to happen at build time, while the
|
|
58
|
+
* context that attributes it still comes from the register hook wrapping
|
|
59
|
+
* `node:http`. Both halves are required:
|
|
60
|
+
*
|
|
61
|
+
* // next.config.ts
|
|
62
|
+
* export default withCoverage({ ...yourConfig })
|
|
63
|
+
*
|
|
64
|
+
* NODE_OPTIONS='--import ccqa-tools/coverage/register' CCQA_COVERAGE=1 next start
|
|
65
|
+
*
|
|
66
|
+
* Only server bundles are instrumented. Instrumenting the client would ship
|
|
67
|
+
* `__ccqaCoverage` calls to browsers, where the front-end side of ccqa's
|
|
68
|
+
* coverage already reads V8's own counters and needs nothing injected.
|
|
69
|
+
*/
|
|
70
|
+
const require = createRequire(import.meta.url);
|
|
71
|
+
/** Wraps a Next config, preserving any `webpack` hook it already has. */
|
|
72
|
+
function withCoverage(config, options = {}) {
|
|
73
|
+
if (!(options.enabled ?? process.env["CCQA_COVERAGE"] !== void 0)) return config;
|
|
74
|
+
const root = resolve(options.root ?? readConfig().root);
|
|
75
|
+
const include = (options.include ?? ["src"]).map((dir) => resolve(root, dir));
|
|
76
|
+
const previous = config.webpack;
|
|
77
|
+
return {
|
|
78
|
+
...config,
|
|
79
|
+
webpack(webpackConfig, context) {
|
|
80
|
+
const next = previous ? previous(webpackConfig, context) : webpackConfig;
|
|
81
|
+
if (!context.isServer) return next;
|
|
82
|
+
next.module ??= {};
|
|
83
|
+
next.module.rules ??= [];
|
|
84
|
+
next.module.rules.push({
|
|
85
|
+
enforce: "post",
|
|
86
|
+
test: /\.(?:[cm]?js|jsx|tsx?)$/,
|
|
87
|
+
include,
|
|
88
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
89
|
+
use: [{
|
|
90
|
+
loader: require.resolve("./next-loader.cjs"),
|
|
91
|
+
options: { root }
|
|
92
|
+
}]
|
|
93
|
+
});
|
|
94
|
+
debugLog(readConfig(), `instrumenting server bundles under ${include.join(", ")}`);
|
|
95
|
+
return next;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { withCoverage };
|