Skip to content

Commit

Permalink
fix: add arguments back to the logged banner (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf authored Aug 9, 2022
1 parent 82ef491 commit 8e08311
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions lib/run-script-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ const signalManager = require('./signal-manager.js')
const isServerPackage = require('./is-server-package.js')

// you wouldn't like me when I'm angry...
const bruce = (id, event, cmd) =>
`\n> ${id ? id + ' ' : ''}${event}\n> ${cmd.trim().replace(/\n/g, '\n> ')}\n`
const bruce = (id, event, cmd, args) => {
let banner = id
? `\n> ${id} ${event}\n`
: `\n> ${event}\n`
banner += `> ${cmd.trim().replace(/\n/g, '\n> ')}`
if (args.length) {
banner += ` ${args.join(' ')}`
}
banner += '\n'
return banner
}

const runScriptPkg = async options => {
const {
Expand Down Expand Up @@ -52,7 +61,7 @@ const runScriptPkg = async options => {

if (stdio === 'inherit' && banner !== false) {
// we're dumping to the parent's stdout, so print the banner
console.log(bruce(pkg._id, event, cmd))
console.log(bruce(pkg._id, event, cmd, args))
}

const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
Expand Down
5 changes: 3 additions & 2 deletions test/run-script-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ t.test('do the banner with no pkgid', t => {
},
stdio: 'inherit',
cmd: 'bar',
args: ['baz', 'buzz'],
pkg: {
scripts: {},
},
Expand All @@ -247,19 +248,19 @@ t.test('do the banner with no pkgid', t => {
event: 'foo',
path: 'path',
scriptShell: 'sh',
args: [],
binPaths: false,
env: {
environ: 'value',
},
stdio: 'inherit',
cmd: 'bar',
args: ['baz', 'buzz'],
}, {
event: 'foo',
script: 'bar',
path: 'path',
pkgid: undefined,
}])).then(() => t.strictSame(logs, [['\n> foo\n> bar\n']]))
}])).then(() => t.strictSame(logs, [['\n> foo\n> bar baz buzz\n']]))
})

t.test('pkg has foo script', t => runScriptPkg({
Expand Down

0 comments on commit 8e08311

Please sign in to comment.