@final-commerce/common 2.12.1-preprod.1 → 2.13.0-staging2.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/README.md +6 -6
- package/bin/gate-done.mjs +26 -13
- package/bin/lib/budget.mjs +1 -1
- package/dist/index.d.mts +75 -367
- package/dist/index.d.ts +75 -367
- package/dist/index.js +177 -585
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -544
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +26 -101
- package/dist/pos-types/index.d.ts +26 -101
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -223,12 +223,12 @@ node -p "const c = require('@final-commerce/common'); c.formatCurrency(2500, 'EU
|
|
|
223
223
|
|
|
224
224
|
### `gate-done` time budgets
|
|
225
225
|
|
|
226
|
-
`gate-done` (the pre-push hook) runs
|
|
226
|
+
`gate-done` (the pre-push hook) runs four sweeps: npm audit, gitleaks, Vitest with coverage, and a bundle-size or build check. It gives them two separate time budgets, both set in milliseconds through environment variables:
|
|
227
227
|
|
|
228
|
-
| Variable | Default | Covers
|
|
229
|
-
| -------------------------- | -------- |
|
|
230
|
-
| `GATE_DONE_BUDGET_MS` | `90000` | gitleaks and the bundle sweep |
|
|
231
|
-
| `GATE_DONE_TEST_BUDGET_MS` | `300000` | the Vitest sweep on its own
|
|
228
|
+
| Variable | Default | Covers |
|
|
229
|
+
| -------------------------- | -------- | ---------------------------------------- |
|
|
230
|
+
| `GATE_DONE_BUDGET_MS` | `90000` | npm audit, gitleaks and the bundle sweep |
|
|
231
|
+
| `GATE_DONE_TEST_BUDGET_MS` | `300000` | the Vitest sweep on its own |
|
|
232
232
|
|
|
233
233
|
A budget only counts time spent in its own sweeps, so a slow test suite never takes time from the other sweeps, and the other sweeps never take time from the tests. Husky's pre-push hook inherits your shell environment, so you can raise a budget for one push or for good:
|
|
234
234
|
|
|
@@ -237,7 +237,7 @@ GATE_DONE_TEST_BUDGET_MS=600000 git push # one push
|
|
|
237
237
|
export GATE_DONE_TEST_BUDGET_MS=600000 # in ~/.zshrc, for every push
|
|
238
238
|
```
|
|
239
239
|
|
|
240
|
-
If a sweep runs past its budget, `gate-done` kills it and blocks the push with a timeout message (`Vitest killed after 300.0s by the test budget … not a test failure`), not as a test failure. Values that are not positive integers are ignored with a warning, and the default applies.
|
|
240
|
+
If a sweep runs past its budget, `gate-done` kills it and blocks the push with a timeout message (`Vitest killed after 300.0s by the test budget … not a test failure`), not as a test or audit failure. Values that are not positive integers are ignored with a warning, and the default applies.
|
|
241
241
|
|
|
242
242
|
## License
|
|
243
243
|
|
package/bin/gate-done.mjs
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* gate-done — pre-push hook.
|
|
4
4
|
*
|
|
5
|
-
* Runs
|
|
5
|
+
* Runs four sweeps under two time budgets:
|
|
6
6
|
*
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
9
|
-
* 3.
|
|
7
|
+
* 1. npm audit — known CVE check against the installed dependency tree (warn only)
|
|
8
|
+
* 2. gitleaks — credential / secret scanning (git log + staged)
|
|
9
|
+
* 3. vitest — full test suite with coverage threshold enforcement
|
|
10
|
+
* 4. bundle — size-limit or custom bundle-size script (if configured)
|
|
10
11
|
*
|
|
11
12
|
* Budgets (milliseconds, read from the environment — Husky's pre-push inherits the shell):
|
|
12
13
|
*
|
|
13
|
-
* GATE_DONE_BUDGET_MS default 90000 shared by sweeps 1 and
|
|
14
|
-
* GATE_DONE_TEST_BUDGET_MS default 300000 sweep
|
|
14
|
+
* GATE_DONE_BUDGET_MS default 90000 shared by sweeps 1, 2 and 4
|
|
15
|
+
* GATE_DONE_TEST_BUDGET_MS default 300000 sweep 3 (Vitest) on its own
|
|
15
16
|
*
|
|
16
17
|
* A budget only drains while its own sweeps run, so a slow test suite cannot
|
|
17
18
|
* starve the bundle sweep and vice versa.
|
|
18
19
|
*
|
|
19
|
-
* Any sweep failure exits 1, blocking the push.
|
|
20
|
+
* Any sweep failure except npm audit exits 1, blocking the push.
|
|
20
21
|
* A sweep killed by its budget also exits 1, but is reported as a timeout,
|
|
21
22
|
* not as a failure of the thing it was checking.
|
|
22
23
|
*
|
|
@@ -104,9 +105,21 @@ info(
|
|
|
104
105
|
`tests ${testBudget.ms / 1000}s (GATE_DONE_TEST_BUDGET_MS).`,
|
|
105
106
|
);
|
|
106
107
|
|
|
107
|
-
// ── 1.
|
|
108
|
+
// ── 1. npm audit ─────────────────────────────────────────────────────────────
|
|
108
109
|
|
|
109
|
-
info('Sweep 1/
|
|
110
|
+
info('Sweep 1/4 — npm audit (known CVEs)…');
|
|
111
|
+
checkBudget(sweepBudget, 'npm audit');
|
|
112
|
+
|
|
113
|
+
const auditResult = run(sweepBudget, 'npm audit', 'npm audit --audit-level=high');
|
|
114
|
+
if (auditResult.status !== 0) {
|
|
115
|
+
warn('npm audit found high or critical vulnerabilities. Run `npm audit` for details.');
|
|
116
|
+
} else {
|
|
117
|
+
ok('npm audit: no high/critical vulnerabilities.');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ── 2. gitleaks ───────────────────────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
info('Sweep 2/4 — gitleaks secrets scan…');
|
|
110
123
|
checkBudget(sweepBudget, 'gitleaks');
|
|
111
124
|
|
|
112
125
|
const hasGitleaks = capture(sweepBudget, 'command -v gitleaks 2>/dev/null').status === 0;
|
|
@@ -126,9 +139,9 @@ if (!hasGitleaks) {
|
|
|
126
139
|
ok('gitleaks: no secrets detected.');
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
// ──
|
|
142
|
+
// ── 3. vitest coverage ────────────────────────────────────────────────────────
|
|
130
143
|
|
|
131
|
-
info('Sweep
|
|
144
|
+
info('Sweep 3/4 — Vitest test suite + coverage thresholds…');
|
|
132
145
|
checkBudget(testBudget, 'Vitest');
|
|
133
146
|
|
|
134
147
|
const vitestResult = run(testBudget, 'Vitest', 'npx vitest run --coverage');
|
|
@@ -139,9 +152,9 @@ if (vitestResult.status !== 0) {
|
|
|
139
152
|
|
|
140
153
|
ok('Vitest: all tests passed, coverage thresholds met.');
|
|
141
154
|
|
|
142
|
-
// ──
|
|
155
|
+
// ── 4. bundle size ────────────────────────────────────────────────────────────
|
|
143
156
|
|
|
144
|
-
info('Sweep
|
|
157
|
+
info('Sweep 4/4 — bundle size audit…');
|
|
145
158
|
checkBudget(sweepBudget, 'bundle audit');
|
|
146
159
|
|
|
147
160
|
const pkgPath = resolve(process.cwd(), 'package.json');
|
package/bin/lib/budget.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A budget is a pool of milliseconds that only drains while one of its own
|
|
5
5
|
* sweeps is running, so gate-done can give the Vitest sweep its own allowance
|
|
6
|
-
* without the fast sweeps (gitleaks, bundle) eating into it.
|
|
6
|
+
* without the fast sweeps (audit, gitleaks, bundle) eating into it.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { spawnSync } from 'node:child_process';
|