perf(build): skip redundant per-file node --check when the test gate runs

The unit suite concatenates + parses every embedded app.*.js (plus argon2)
in a vm, so a syntax error already fails it. Run the ~10 cold `node --check`
spawns (~3-4s) only when tests are bypassed (PM_SKIP_TESTS) or absent.
Cuts the pre-compile freeze from ~7s to ~4s.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-11 18:32:15 +01:00
parent 0925afb689
commit b9eee0e15e
+35 -25
View File
@@ -97,32 +97,24 @@ if (-not $node) { $node = Get-Command node -ErrorAction SilentlyContinue }
$jsFiles = $files | Where-Object { $_.Relative -match '\.js$' } $jsFiles = $files | Where-Object { $_.Relative -match '\.js$' }
if ($jsFiles) { if ($jsFiles) {
if ($node) { if ($node) {
foreach ($jf in $jsFiles) { # The unit suite concatenates + parses EVERY embedded app.*.js (plus
Log "Syntax check: $($jf.Relative)" # argon2.js) inside a vm, so a syntax error already fails it. When the
# --check prints errors to stderr and returns non-zero on failure. # suite runs we skip the per-file `node --check` loop — it was ~10 cold
# Pipe $null into node so it can NEVER block waiting on stdin # node process starts (~3-4s of dead build time) checking what the tests
# (some Windows node shims read stdin when launched from a # re-parse anyway. We only fall back to node --check when the suite is
# non-interactive pre-build event, which would hang the build). # bypassed (PM_SKIP_TESTS) or absent.
$out = $null | & $node.Source --check $jf.FullPath 2>&1 # ponytail: assumes every embedded .js is an APP_PARTS module (or
if ($LASTEXITCODE -ne 0) { # argon2.js). CLAUDE.md §3.1 already requires adding a new module to
Log "JS SYNTAX ERROR in $($jf.Relative):" # APP_PARTS + this whitelist together, so the assumption holds by process.
Log ($out | Out-String) $haveTests = Test-Path (Join-Path $WebRoot 'js\tests')
throw "JS syntax check failed for $($jf.Relative) - aborting asset build." $runTests = ($env:PM_SKIP_TESTS -ne '1') -and $haveTests
}
}
Log "JS syntax OK."
# --- Unit test gate --------------------------------------------------- if ($runTests) {
# Run the frontend regression suite (crypto round-trip, CSV import, # --- Unit test gate (also covers JS syntax) -----------------------
# sync-merge arbitration) before embedding. A broken crypto/merge # crypto round-trip, CSV import, sync-merge arbitration, metadata.
# invariant now blocks the build the same way a syntax error does, # A broken invariant OR a syntax error blocks the build here instead
# instead of surfacing only after a full Delphi rebuild + manual test. # of surfacing only after a full Delphi rebuild. Zero deps (node:test).
# ~1.7 s, zero deps (node:test). Skipped automatically if the suite Log "Running frontend unit tests (also covers JS syntax)..."
# isn't present. Set PM_SKIP_TESTS=1 to bypass during rapid iteration.
if ($env:PM_SKIP_TESTS -eq '1') {
Log "PM_SKIP_TESTS=1 - skipping unit tests."
} elseif (Test-Path (Join-Path $WebRoot 'js\tests')) {
Log "Running frontend unit tests..."
Push-Location $WebRoot Push-Location $WebRoot
try { try {
$testOut = $null | & $node.Source --test 'js/tests/**/*.test.js' 2>&1 $testOut = $null | & $node.Source --test 'js/tests/**/*.test.js' 2>&1
@@ -136,6 +128,24 @@ if ($jsFiles) {
throw "Frontend unit tests failed - aborting asset build. (Set PM_SKIP_TESTS=1 to bypass.)" throw "Frontend unit tests failed - aborting asset build. (Set PM_SKIP_TESTS=1 to bypass.)"
} }
Log "Unit tests OK." Log "Unit tests OK."
} else {
# No test gate this run → syntax-check each file individually so a
# broken bundle can never reach assets.res.
foreach ($jf in $jsFiles) {
Log "Syntax check: $($jf.Relative)"
# --check prints errors to stderr, returns non-zero on failure.
# Pipe $null into node so it can NEVER block on stdin (some
# Windows node shims read stdin from a non-interactive pre-build
# event, which would hang the build).
$out = $null | & $node.Source --check $jf.FullPath 2>&1
if ($LASTEXITCODE -ne 0) {
Log "JS SYNTAX ERROR in $($jf.Relative):"
Log ($out | Out-String)
throw "JS syntax check failed for $($jf.Relative) - aborting asset build."
}
}
Log "JS syntax OK."
if ($env:PM_SKIP_TESTS -eq '1') { Log "PM_SKIP_TESTS=1 - skipping unit tests." }
} }
} else { } else {
Log "WARNING: node not found - skipping JS syntax check + unit tests. Install Node to enable them." Log "WARNING: node not found - skipping JS syntax check + unit tests. Install Node to enable them."