diff --git a/Dockerfile b/Dockerfile index 06a45a2..5b53c0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,11 @@ RUN npm install --omit=dev --no-audit --no-fund # App source COPY server/ ./ +# Pre-deploy guard: FAIL the build if any inline (skip ones with a src= attribute — those are external files, nothing inline). +const re = /]*)>([\s\S]*?)<\/script\s*>/gi; +let errors = 0; +let blocks = 0; + +for (const f of files) { + const html = fs.readFileSync(path.join(dir, f), 'utf8'); + re.lastIndex = 0; + let m; + while ((m = re.exec(html))) { + if (/\bsrc\s*=/i.test(m[1] || '')) continue; // external script + blocks++; + const code = m[2]; + // File line where this block's body starts, so the reported line is file-relative (not block-relative). + const openTagEnd = m.index + m[0].indexOf('>') + 1; + const startLine = html.slice(0, openTagEnd).split('\n').length - 1; // 0-indexed offset + try { + new vm.Script(code, { filename: f, lineOffset: startLine }); + } catch (e) { + errors++; + const loc = (String(e.stack || '').split('\n')[0] || '').trim(); // e.g. "home.html:4398" + console.error('[check-syntax] ' + f + ' — ' + (e.message || 'syntax error') + + (loc && /:\d+$/.test(loc) ? (' @ ' + loc) : (' (inline