@vzn/vx 0.0.536 → 0.0.537

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/exec/runner.ts +27 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vzn/vx",
3
- "version": "0.0.536",
3
+ "version": "0.0.537",
4
4
  "description": "The fastest task runner and build cache for JavaScript monorepos.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,10 +21,10 @@
21
21
  "node": ">=18"
22
22
  },
23
23
  "optionalDependencies": {
24
- "@vzn/vx-linux-x64": "0.0.536",
25
- "@vzn/vx-linux-arm64": "0.0.536",
26
- "@vzn/vx-darwin-x64": "0.0.536",
27
- "@vzn/vx-darwin-arm64": "0.0.536"
24
+ "@vzn/vx-linux-x64": "0.0.537",
25
+ "@vzn/vx-linux-arm64": "0.0.537",
26
+ "@vzn/vx-darwin-x64": "0.0.537",
27
+ "@vzn/vx-darwin-arm64": "0.0.537"
28
28
  },
29
29
  "dependencies": {
30
30
  "@anthropic-ai/sandbox-runtime": "^0.0.76"
@@ -155,6 +155,22 @@ function trailingCommentStart(command: string): number {
155
155
  return comment
156
156
  }
157
157
 
158
+ /** Per line: is it a heredoc's body or terminator (`<<X` / `<<-'X'` … `X`)? */
159
+ function heredocLines(lines: readonly string[]): boolean[] {
160
+ const pending: Array<{ delim: string; tabs: boolean }> = []
161
+ return lines.map((line) => {
162
+ const open = pending[0]
163
+ if (open !== undefined) {
164
+ if ((open.tabs ? line.replace(/^\t+/, '') : line) === open.delim) pending.shift()
165
+ return true
166
+ }
167
+ for (const m of line.matchAll(/(?<!<)<<(?!<)(-?)\s*(['"]?)([A-Za-z_]\w*)\2/g)) {
168
+ pending.push({ delim: m[3]!, tabs: m[1] === '-' })
169
+ }
170
+ return false
171
+ })
172
+ }
173
+
158
174
  /**
159
175
  * The command a task runs with the args after `--` appended, shell-quoted.
160
176
  * They go before a trailing comment: appended after it, `echo args: # show`
@@ -162,6 +178,17 @@ function trailingCommentStart(command: string): number {
162
178
  */
163
179
  export function withForwardArgs(command: string, args: readonly string[] | undefined): string {
164
180
  if (!args || args.length === 0) return command
181
+ // A command that ends in a heredoc's body: appended to its terminator,
182
+ // `X FWD` closed nothing and the args never reached the command (X-12).
183
+ // They go on the last line that is a command, where `cat <<X FWD` is
184
+ // still `cat FWD` reading the heredoc.
185
+ const lines = command.trimEnd().split('\n')
186
+ const body = heredocLines(lines)
187
+ if (body[lines.length - 1] === true) {
188
+ const last = body.lastIndexOf(false)
189
+ const tail = lines.slice(last + 1).join('\n')
190
+ return `${withForwardArgs(lines.slice(0, last + 1).join('\n'), args)}\n${tail}`
191
+ }
165
192
  const quoted = args.map(shellQuote).join(' ')
166
193
  let comment = trailingCommentStart(command)
167
194
  if (comment < 0) {