Skip to content

Commit

Permalink
chore: bump v to 8.1.9 (#917)
Browse files Browse the repository at this point in the history
* chore: optimize `echo` impl

* chore: bump version to 8.1.9
  • Loading branch information
antongolub authored Oct 5, 2024
1 parent 88a545a commit 63ceddb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zx",
"version": "8.1.8",
"version": "8.1.9",
"description": "A tool for writing better scripts",
"type": "module",
"main": "./build/index.cjs",
Expand Down
17 changes: 5 additions & 12 deletions src/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import assert from 'node:assert'
import { createInterface } from 'node:readline'
import { $, within, ProcessOutput } from './core.js'
import { type Duration, isString, parseDuration } from './util.js'
import { type Duration, isStringLiteral, parseDuration } from './util.js'
import {
chalk,
minimist,
Expand Down Expand Up @@ -46,18 +46,11 @@ export async function fetch(url: RequestInfo, init?: RequestInit) {

export function echo(...args: any[]): void
export function echo(pieces: TemplateStringsArray, ...args: any[]) {
let msg
const lastIdx = pieces.length - 1
if (
Array.isArray(pieces) &&
pieces.every(isString) &&
lastIdx === args.length
) {
msg =
args.map((a, i) => pieces[i] + stringify(a)).join('') + pieces[lastIdx]
} else {
msg = [pieces, ...args].map(stringify).join(' ')
}
const msg = isStringLiteral(pieces, ...args)
? args.map((a, i) => pieces[i] + stringify(a)).join('') + pieces[lastIdx]
: [pieces, ...args].map(stringify).join(' ')

console.log(msg)
}

Expand Down

0 comments on commit 63ceddb

Please sign in to comment.