Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add arguments back to the logged banner #102

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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