feat: accept custom delimiter for lines()#1220
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds support for a custom separator for the lines() API so users can split output on any string or regex rather than just newlines.
- Updates
getLinesto accept adelimiterparameter and uses it in both async iteration and.lines() - Exposes a new
delimiteroption in shell invocations and passes it through toProcessPromiseandProcessOutput - Expands tests to cover custom‐delimiter behavior
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/core.test.js | Adds and updates tests for custom‐delimiter support |
| src/util.ts | Extended getLines signature to accept delimiter |
| src/core.ts | Propagates delimiter option into process logic |
| build/util.cjs | Mirrors getLines change in compiled output |
| build/core.cjs | Mirrors core logic updates in compiled output |
| .size-limit.json | Bumps bundle size limits to account for new code |
| } | ||
| const bound: [string, string, Options][] = [] | ||
| const boundCtxs: [string, string, Options][] = [] | ||
| const delimiters: Array<string | RegExp | undefined> = [] |
There was a problem hiding this comment.
Using a module‐scoped delimiters stack to manage per-call delimiters can lead to race conditions or mismatches when multiple outputs are processed concurrently. Consider storing the delimiter on each ProcessOutput or ProcessPromise instance instead of relying on shared mutable state.
| } | ||
|
|
||
| lines(): string[] { | ||
| lines(delimiter?: string | RegExp): string[] { |
There was a problem hiding this comment.
[nitpick] The lines method currently pushes the passed delimiter into a global array before iterating, then pops it later. This pattern is error‐prone and hard to follow—encapsulate the delimiter on the instance rather than using a shared stack to improve clarity and reduce side effects.
lines()lines()
|
Does this resolve the issue? |
|
Yeah, sure! 👍 |
closes #1218