Files
Michał Pierzchała af6f12e391 chore: adopt shared oxlint config (#2115)
* chore: adopt shared oxlint config

* fix: preserve project lint boundaries

* fix: remove redundant oxlint config
2026-08-28 11:42:58 +02:00

29 lines
1.0 KiB
TypeScript

// Minimal package-script splitting for suite registration. Workflow ownership never uses it.
/** `VAR=x VAR2="y z" ` at the head of a segment. */
export const ENV_PREFIX = /^(?:[A-Z_][A-Z0-9_]*=(?:"[^"]*"|'[^']*'|\S*)\s+)+/;
/**
* `a && b`, `a; b`, and `a | b` all run both sides; newlines and `\` continuations join
* first. Env prefixes are LEFT ON: `NODE_OPTIONS=--import ./x.ts pnpm gate lint` runs
* code, so a caller deciding whether a segment is a bare gate invocation has to see it.
*/
export function commandSegments(body: string): string[] {
return body
.replaceAll('\\\n', ' ')
.split('\n')
.map(stripComment)
.join('\n')
.split(/&&|\|\||[;\n|]/)
.map((segment) => segment.trim())
.filter(Boolean);
}
/** `echo done # && pnpm test:unit` must not credit test:unit. Quotes protect a literal `#`. */
function stripComment(line: string): string {
for (const match of line.matchAll(/"[^"]*"|'[^']*'|(?:^|\s)#/g)) {
if (match[0].endsWith('#')) return line.slice(0, match.index);
}
return line;
}