Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@antongolub
Copy link
Collaborator

@antongolub antongolub commented Jun 3, 2025

closes #1218

const cwd = tempdir()
const delimiter = '\0'

const p1 = $({
  cwd
})`touch foo bar baz; find ./ -type f -print0 -maxdepth 1`
(await p1.lines(delimiter)).sort() // ['./bar', './baz', './foo']
  
// or via options
const lines = []
const p2 = $({
  delimiter,
  cwd,
})`find ./ -type f -print0 -maxdepth 1`

for await (const line of p2) {
  lines.push(line)
}

lines.sort() // ['./bar', './baz', './foo']
  • Tests pass
  • Appropriate changes to README are included in PR

@antongolub antongolub requested review from antonmedv and Copilot June 3, 2025 19:54

This comment was marked as outdated.

@antongolub antongolub requested a review from Copilot June 3, 2025 20:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getLines to accept a delimiter parameter and uses it in both async iteration and .lines()
  • Exposes a new delimiter option in shell invocations and passes it through to ProcessPromise and ProcessOutput
  • 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> = []
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
}

lines(): string[] {
lines(delimiter?: string | RegExp): string[] {
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copilot uses AI. Check for mistakes.
@antongolub antongolub changed the title feat: accept custom separator for lines() feat: accept custom delimiter for lines() Jun 4, 2025
@antongolub
Copy link
Collaborator Author

antongolub commented Jun 4, 2025

@d7sd6u,

Does this resolve the issue?

@d7sd6u
Copy link

d7sd6u commented Jun 4, 2025

Yeah, sure! 👍

@antonmedv antonmedv merged commit 12c8c60 into google:main Jun 4, 2025
28 checks passed
@antongolub antongolub deleted the lines-delimiter branch June 4, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add nul delimited output support

3 participants